发布网友 发布时间:2022-04-07 16:33
共9个回答
懂视网 时间:2022-04-07 20:54
create or replace package excuteBatchOperate 2 as 3 type sqlStr_Array is table of varchar2(1000) index by binary_integer; 4 procedure excuteBulkData(sqlStr in sqlStr_Array); 5 end excuteBatchOperate;2、在packagebody内创建存储过程
1 create or replace package body excuteBatchOperate 2 as 3 procedure excuteBulkData(sqlStr in sqlStr_Array) 4 as 5 begin 6 for i in 1..sqlStr.count loop 7 execute immediate sqlStr(i); 8 end loop; 9 end excuteBulkData; 10 end excuteBatchOperate;
3、.Net demo如下,可以去掉注释,修改SQL语句测试
1 public static int excuteBulkData(IList<string> list) 2 { 3 using (ODAC.OracleConnection conn = new ODAC.OracleConnection(connStr)) 4 { 5 using (ODAC.OracleCommand comm = conn.CreateCommand()) 6 { 7 //IList<string> list = new List<string>(); 8 //list.Add("insert into parts1(pname) values(‘sadfsa‘)"); 9 //list.Add("insert into parts1(pnum,pname) values(22222,‘rrrrrr‘)"); 10 conn.Open(); 11 comm.CommandType = CommandType.StoredProcedure; 12 comm.CommandText = "excuteBatchOperate.excuteBulkData"; 13 ODAC.OracleParameter Param1 = new 14 ODAC.OracleParameter(@"v_string", ODAC.OracleDbType.Varchar2); 15 Param1.Direction = ParameterDirection.Input; 16 Param1.CollectionType = ODAC.OracleCollectionType.PLSQLAssociativeArray; 17 Param1.Value = list.ToArray(); 18 comm.Parameters.Add(Param1); 19 return comm.ExecuteNonQuery(); 20 } 21 } 22 }示例
向Oracle中传入数组,批量执行SQL语句
标签:
热心网友 时间:2022-04-07 18:02
很简单,在原来的基础上前面加个begin,后面加个end;
这样多条语句就可以串联执行了
begin
insert into 表(id,name,age) values(1,'a',18);
insert into 表(id,name,age) values(1,'a',18);
insert into 表(id,name,age) values(1,'a',18);
insert into 表(id,name,age) values(1,'a',18);
end
热心网友 时间:2022-04-07 19:20
通过脚本好像只能一条一条的插,如果你插入的字段可以从其他表转过来的话,可以通过SQL插多条热心网友 时间:2022-04-07 20:55
如果想省事可以设置变量使用物化视图,不过还是要一个一个输入变量的值;或者用SQLLOADER直接从文档导入。如果数据内容在数据库中的其他表里面也可以用子句热心网友 时间:2022-04-07 22:46
可以这样:热心网友 时间:2022-04-08 00:54
alter table store_information rename column store_name to name;热心网友 时间:2022-04-08 03:19
只能这样,没有办法热心网友 时间:2022-04-08 06:00
insert into test1 select * from test2热心网友 时间:2022-04-08 08:58
insert into 表名 select * from 表名;