@@ -2142,23 +2142,22 @@ For example:
21422142var oracledb = require (' oracledb' );
21432143. . .
21442144
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+ });
21552155` ` `
21562156
21572157If run with Oracle's sample HR schema, the output is:
21582158
21592159` ` `
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' ] ]
21622161` ` `
21632162
21642163Using this format is recommended for efficiency.
@@ -2167,31 +2166,31 @@ Alternatively, rows may be fetched as JavaScript objects. To do so,
21672166specify the ` outFormat` option to be ` OBJECT ` :
21682167
21692168` ` ` javascript
2170- var oracledb = require (' oracledb' );
2169+ oracledb .outFormat = oracledb .OBJECT ;
2170+ ` ` `
21712171
2172- . . .
2172+ The value can also be set as an ` execute () ` option:
21732173
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+ });
21882186` ` `
21892187
2190- If run with Oracle's sample HR schema, the output is:
2188+ The output is:
21912189
21922190` ` `
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' } ]
21952194` ` `
21962195
21972196In the preceding example, each row is a JavaScript object that
@@ -2207,15 +2206,16 @@ The column names of a query are returned in the
22072206attribute:
22082207
22092208` ` ` 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+ });
22192219` ` `
22202220
22212221When using a [` ResultSet` ](#resultsetclass), metadata is also
@@ -2549,9 +2549,9 @@ CREATE OR REPLACE FUNCTION mydofetch RETURN dorow PIPELINED IS
25492549 line VARCHAR2 (32767 );
25502550 status INTEGER ;
25512551 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);
25552555 END LOOP ;
25562556END ;
25572557/
0 commit comments