oracle执行批量sql语句,向Oracle中传入数组,批量执行SQL语句

1、首先用PL/SQL创建package

1 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);--单个语句中不能再使用分号(;)结束SQL语句,否则会报ORA-00911: 无效字符异常

8 end loop;

9 end excuteBulkData;

10 end excuteBatchOperate;

3、.Net demo如下,可以去掉注释,修改SQL语句测试

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

1 public static int excuteBulkData(IList list)

2 {

3 using (ODAC.OracleConnection conn = new ODAC.OracleConnection(connStr))

4 {

5 using (ODAC.OracleCommand comm = conn.CreateCommand())

6 {

7 //IList list = new List();

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 }

示例

来源:https://www.cnblogs.com/hujiapeng/p/4489753.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值