oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.25k stars 1.07k forks source link

how can i execute many insert sql statements #1183

Closed DOVER123 closed 4 years ago

DOVER123 commented 4 years ago

i have many insert sql like var sql=insert into xxx values(xxxx); insert into xxx values(xxxx); insert into xxx values(xxxx); insert into xxx values(xxxx);

i try connection.excutemany but it can't work,should i use connectoin.excute() and excute it one by one?

cjbj commented 4 years ago

Yes.

dmcghan commented 4 years ago

Is the statement the same for each insert, just the values going in are different?

i try connection.excutemany

What did you try? Why don't you show us?

but it can't work

Did you get an error? Why don't you show us?

DOVER123 commented 4 years ago

yes,just the value different。i used it like this;

var sql ="insert into xxx values(xxxx); insert into xxx values(xxxx); insert into xxx values(xxxx); insert into xxx values(xxxx);" connection.excuteMany(sql)

i think i konw where i was wrong, I should use it like "insert into xxx values(:a)" and make a binds for it,connection.excuteMany(sql,binds),now it worked。

then i have another question 。

i have a sql like this "insert into xxxTable select "A","B","C“ from dual"

xxxTable have three fields。

i use connection.excuteMany("insert into xxxTable select :key from dual",[{key:"A,B,C"},{key:"D,E,F"}]),

then i got a error :Ora-00947: not enough values

dmcghan commented 4 years ago

i use connection.excuteMany("insert into xxxTable select :key from dual",[{key:"A,B,C"},{key:"D,E,F"}]),

Each bind is a single value. key is a single bind. Its value is the string "A,B,C".

But really, why would you do this select from dual anyway? It's not needed.

DOVER123 commented 4 years ago

@dmcghan hahah i see,DBA just give it to me ,I supposed it would be ok. now i know,i will not use it again thank you very much

cjbj commented 4 years ago

Here is documentation on executeMany(): https://oracle.github.io/node-oracledb/doc/api.html#batchexecution

The IN bind doc for execute() may also be useful: https://oracle.github.io/node-oracledb/doc/api.html#inbind