.net 调用oracle过程 数组参数,c# – 通过.NET调用带有PL / SQL集合类型参数的Oracle过程...

我试图通过.NET调用Oracle存储过程.通常这不是问题,但此存储过程包含一个PL / SQL集合类型的参数:

create or replace type test_type as table of number;

PROCEDURE TEST1 (pvTest IN test_type);

这是我的C#代码:

var receiverIds = new decimal[] { 683552, 683553, 683572, 683573, 683592, 683593, 683594, 683612 };

var receiversList = new OracleParameter("pvTest", OracleDbType.Decimal, ParameterDirection.Input);

receiversList.CollectionType = OracleCollectionType.PLSQLAssociativeArray;

receiversList.Size = receiverIds.Length;

receiversList.Value = receiverIds;

using (var oracleCommand = new OracleCommand())

{

oracleCommand.Connection = this.oracleConnection;

oracleCommand.CommandText = "test_package.TEST1";

oracleCommand.BindByName = true;

oracleCommand.Parameters.Add(parameter);

oracleCommand.CommandType = CommandType.StoredProcedure;

oracleCommand.ExecuteNonQuery();

}

所以我创建了一个如下所示的测试包:

CREATE OR REPLACE PACKAGE test_package_gkeu IS

TYPE test_type IS TABLE OF NUMBER;

PROCEDURE TEST1 (pvTest IN test_type);

END test_package_gkeu;

/

CREATE OR REPLACE PACKAGE BODY test_package_gkeu IS

PROCEDURE TEST1 (pvTest IN test_type) IS

BEGIN

null;

END TEST1;

END test_package_gkeu;

/

但是,这仍然产生完全相同的错误.经过一些更多的搜索和尝试后,我发现我需要将“INDEX BY BINARY_INTEGER”添加到“test_type”,这样可以正常工作,我可以毫无错误地调用我的程序.

然后我开始将原始过程中的SQL查询添加到此测试包中:

select *

from receiver r

where r.receiverid in (select /*+cardinality(t 5)*/ *

from table(cast((pvTest) as test_type)) t

where rownum >= 0);

PL/SQL types defined in package are invisible to SQL statements: they are pure PLSQL constructs and the SQL language can’t access them directly.

Index by tables cannot be declared globally; the following construct generates a PLS-00355: use of pl/sql table not allowed in this context.

所以我在这里陷入两难境地.如果自定义类型没有“INDEX BY”,我无法调用该过程,当我在包中声明它时,我不能在查询中使用此类型,并且由于“我不能全局声明它”索引“.

任何人都可以帮我吗?我想我需要找到一种方法来在类型没有“INDEX BY”时调用该过程,但我已经尝试了我能想到或找到的所有内容.

PS.我使用的是.NET 4.5和Oracle.ManagedDataAccess v 4.121.1.0,不幸的是,我们的Oracle数据库仍然是10g(10.2.0.4.0).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C# 访问Oracle示例+PL/SQL+存储过程+触发器 完整示例 测试可用 --PL/SQL基础1 declare begin dbms_output.('不输出不换行'); dbms_output.put_line('输出并换行'); end; --PL/SQL基础2 declare dig number(20,2); begin select avg(price) into dig from products; dbms_output.put_line('电子产品的平均价格是'||dig); end; --PL/SQL基础3 根据产品编号获得产品对象 --pname products.name%type; pname变量的类与products.name列的类一样 declare pid constant products.id%type:=1; --定义常量,初值1 pname products.name%type; pdate products.adddate%type; begin --pid:=1; select name,adddate into pname,pdate from products where id=pid; dbms_output.put_line('产品名称是:'||pname||',日期'||pdate); end; --PL/SQL基础4 根据产品编号获得产品对象 --obj products%rowtype; obj与products表的单行类一样,可以通过点运算取值obj.price declare obj products%rowtype; begin select * into obj from products where id=&编号; dbms_output.put_line('产品名称是:'||obj.name||',价格:'||obj.price); end; --PL/SQL基础5 条件if declare vid products.id%type; vprice products.price%type; begin vid:=&编号; select price into vprice from products where id=vid; if vprice100 and vprice<=1000 then dbms_output.put_line('价格在100—1000之间'); else dbms_output.put_line('价格在1000以上'); end if; end; --PL/SQL基础5 多条件case begin case '&等级' when 'A' then dbms_output.put_line('优秀'); when 'B' then dbms_output.put_line('合格'); when 'C' then dbms_output.put_line('不合格'); end case; end; select id, name, typeid, price, adddate from products create table students( Id int primary key, sex int ) insert into students select 1,1 from dual union select 2,0 from dual union select 3,1 from dual union select 4,0 from dual union select 5,1 from dual insert into students(Id) values(6) select * from students; select translate(translate('1心1意 3心2意','1','一'),'3','三') from dual; select id,nvl(translate(translate(sex,1,'女'),0,'男'),'未知') from students; select id,case as 性别 from( sele
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值