|
| 1 | +/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */ |
| 2 | + |
| 3 | +/****************************************************************************** |
| 4 | + * |
| 5 | + * You may not use the identified files except in compliance with the Apache |
| 6 | + * License, Version 2.0 (the "License.") |
| 7 | + * |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0. |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + * NAME |
| 19 | + * dmlrupd1.js |
| 20 | + * |
| 21 | + * DESCRIPTION |
| 22 | + * Example of 'DML Returning' with a single row match |
| 23 | + * Use demo.sql to create the required table or do: |
| 24 | + * DROP TABLE dmlrupdtab; |
| 25 | + * CREATE TABLE dmlrupdtab (id NUMBER, name VARCHAR2(40)); |
| 26 | + * INSERT INTO dmlrupdtab VALUES (1001, 'Venkat'); |
| 27 | + * INSERT INTO dmlrupdtab VALUES (1002, 'Neeharika'); |
| 28 | + * COMMIT; |
| 29 | + * |
| 30 | + *****************************************************************************/ |
| 31 | + |
| 32 | +var oracledb = require( 'oracledb' ); |
| 33 | +var dbConfig = require('./dbconfig.js'); |
| 34 | + |
| 35 | +oracledb.getConnection( |
| 36 | + { |
| 37 | + user : dbConfig.user, |
| 38 | + password : dbConfig.password, |
| 39 | + connectString : dbConfig.connectString |
| 40 | + }, |
| 41 | + function(err, connection) |
| 42 | + { |
| 43 | + if (err) |
| 44 | + { |
| 45 | + console.error(err); |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + connection.execute( |
| 50 | + "UPDATE DMLRUPDTAB SET NAME = :name WHERE ID = :id RETURNING ID, NAME INTO :RID, :RNAME", |
| 51 | + { |
| 52 | + id: 1001, |
| 53 | + name: "Krishna", |
| 54 | + rid: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT }, |
| 55 | + rname: { type: oracledb.STRING, dir: oracledb.BIND_OUT } |
| 56 | + }, |
| 57 | + { isAutoCommit: true }, |
| 58 | + function(err, result) |
| 59 | + { |
| 60 | + if (err) |
| 61 | + { |
| 62 | + console.error(err); |
| 63 | + return; |
| 64 | + } |
| 65 | + console.log(result.outBinds); |
| 66 | + }); |
| 67 | + }); |
0 commit comments