@@ -2142,23 +2142,22 @@ For example:
2142
2142
var oracledb = require (' oracledb' );
2143
2143
. . .
2144
2144
2145
- connection .execute (" SELECT first_name, salary, hire_date "
2146
- + " FROM employees, departments "
2147
- + " WHERE employees.department_id = departments.department_id "
2148
- + " AND departments.department_name = 'Accounting' " ,
2149
- function ( err , result ) {
2150
- if (err) { console . error ( err . message ); return ; }
2151
- var rows = result . rows ;
2152
- for ( var i = 0 ; i < rows . length ; i ++ )
2153
- console .log (" Row " + i + " : " + rows[i] );
2154
- });
2145
+ connection .execute (
2146
+ " SELECT department_id, department_name " +
2147
+ " FROM departments " +
2148
+ " WHERE manager_id < :id " ,
2149
+ [ 110 ], // bind value for :id
2150
+ function (err , result )
2151
+ {
2152
+ if (err) { console . error ( err . message ); return ; }
2153
+ console .log (result . rows );
2154
+ });
2155
2155
` ` `
2156
2156
2157
2157
If run with Oracle's sample HR schema, the output is:
2158
2158
2159
2159
` ` `
2160
- Row 0 : Shelley,12000 ,Tue Jun 07 1994 01 : 00 : 00 GMT - 0700 (PDT )
2161
- Row 1 : William,8300 ,Tue Jun 07 1994 01 : 00 : 00 GMT - 0700 (PDT )
2160
+ [ [ 60 , ' IT' ], [ 90 , ' Executive' ], [ 100 , ' Finance' ] ]
2162
2161
` ` `
2163
2162
2164
2163
Using this format is recommended for efficiency.
@@ -2167,31 +2166,31 @@ Alternatively, rows may be fetched as JavaScript objects. To do so,
2167
2166
specify the ` outFormat` option to be ` OBJECT ` :
2168
2167
2169
2168
` ` ` javascript
2170
- var oracledb = require (' oracledb' );
2169
+ oracledb .outFormat = oracledb .OBJECT ;
2170
+ ` ` `
2171
2171
2172
- . . .
2172
+ The value can also be set as an ` execute () ` option:
2173
2173
2174
- connection .execute (" SELECT first_name, salary, hire_date "
2175
- + " FROM employees, departments "
2176
- + " WHERE employees.department_id = departments.department_id "
2177
- + " AND departments.department_name = 'Accounting'" ,
2178
- [], // No bind variables
2179
- {outFormat: oracledb .OBJECT },
2180
- function (err , result ) {
2181
- if (err) { console .error (err .message ); return ; }
2182
- var rows = result .rows ;
2183
- for (var i = 0 ; i < rows .length ; i++ )
2184
- console .log (" Row " + i + " : " +
2185
- rows[i].FIRST_NAME + " , " ,
2186
- rows[i].SALARY + " , " , rows[i].HIRE_DATE );
2187
- });
2174
+ ` ` ` javascript
2175
+ connection .execute (
2176
+ " SELECT department_id, department_name " +
2177
+ " FROM departments " +
2178
+ " WHERE manager_id < :id" ,
2179
+ [110 ], // bind value for :id
2180
+ { outFormat: oracledb .OBJECT },
2181
+ function (err , result )
2182
+ {
2183
+ if (err) { console .error (err .message ); return ; }
2184
+ console .log (result .rows );
2185
+ });
2188
2186
` ` `
2189
2187
2190
- If run with Oracle's sample HR schema, the output is:
2188
+ The output is:
2191
2189
2192
2190
` ` `
2193
- Row 0 : Shelley, 12000 , Tue Jun 07 1994 01 : 00 : 00 GMT - 0700 (PDT )
2194
- Row 1 : William, 8300 , Tue Jun 07 1994 01 : 00 : 00 GMT - 0700 (PDT )
2191
+ [ { DEPARTMENT_ID : 60 , DEPARTMENT_NAME : ' IT' },
2192
+ { DEPARTMENT_ID : 90 , DEPARTMENT_NAME : ' Executive' },
2193
+ { DEPARTMENT_ID : 100 , DEPARTMENT_NAME : ' Finance' } ]
2195
2194
` ` `
2196
2195
2197
2196
In the preceding example, each row is a JavaScript object that
@@ -2207,15 +2206,16 @@ The column names of a query are returned in the
2207
2206
attribute:
2208
2207
2209
2208
` ` ` javascript
2210
- connection .execute (" SELECT department_id, department_name "
2211
- + " FROM departments "
2212
- + " WHERE department_id = :did" ,
2213
- [180 ],
2214
- function (err , result )
2215
- {
2216
- if (err) { console .error (err .message ); return ; }
2217
- console .log (result .metaData ); // show the metadata
2218
- });
2209
+ connection .execute (
2210
+ " SELECT department_id, department_name " +
2211
+ " FROM departments " +
2212
+ " WHERE manager_id < :id" ,
2213
+ [110 ], // bind value for :id
2214
+ function (err , result )
2215
+ {
2216
+ if (err) { console .error (err .message ); return ; }
2217
+ console .log (result .metaData ); // show the metadata
2218
+ });
2219
2219
` ` `
2220
2220
2221
2221
When using a [` ResultSet` ](#resultsetclass), metadata is also
@@ -2549,9 +2549,9 @@ CREATE OR REPLACE FUNCTION mydofetch RETURN dorow PIPELINED IS
2549
2549
line VARCHAR2 (32767 );
2550
2550
status INTEGER ;
2551
2551
BEGIN LOOP
2552
- DBMS_OUTPUT .GET_LINE (line, status);
2553
- EXIT WHEN status = 1 ;
2554
- PIPE ROW (line);
2552
+ DBMS_OUTPUT .GET_LINE (line, status);
2553
+ EXIT WHEN status = 1 ;
2554
+ PIPE ROW (line);
2555
2555
END LOOP ;
2556
2556
END ;
2557
2557
/
0 commit comments