您好,欢迎访问一九零五行业门户网

asp.net中oracle 存储过程(图文)_jquery

在大型数据库系统中,存储过程和触发器具有很重要的作用。无论是存储过程还是触发器,都是sql 语句和流程控制语句的集合。
oracle代码
create or replace procedure gd_cursor(mycs1 out sys_refcursor,mycs2 out sys_refcursor,a out varchar)asbegin a:='test'; open mycs1 for select 1 from dual; open mycs2 for select 2 from dual;end;
c#代码
/// /// 执行oracle存储过程返回多个结果集 /// /// 存储过程名称 /// 返回个数 /// 参数 /// 任意对象数组 public object[] excuteproc_n_result(string strprocname, int resultcount, params oracleparameter[] paras) { using (oracleconnection conn = new oracleconnection(user id=用户名;password=密码;data source=数据库;)) { oraclecommand cmd = new oraclecommand(strprocname, conn); if (paras != null && paras.length > 0) { for (int j = 0; j < paras.length; j++) { if (paras[j].value == null) { paras[j].value = dbnull.value; } } } cmd.parameters.addrange(paras); cmd.commandtype = commandtype.storedprocedure; conn.open(); cmd.executenonquery(); int i = 0; //int noutputparameterscount = 0; object[] objresult = new object[resultcount]; foreach (oracleparameter p in cmd.parameters) { if (p.direction == parameterdirection.output || p.direction == parameterdirection.inputoutput) { if (p.value is oracledatareader) { oracledatareader reader = p.value as oracledatareader; objresult[i++] = convertdatareadertodatatable(reader); } else { objresult[i++] = p.value; } } } return objresult; } } /// /// 将datareader 转为 datatable /// /// oledbdatareader protected datatable convertdatareadertodatatable(oracledatareader reader) { datatable objdatatable = new datatable(tmpdatatable); try { int intfieldcount = reader.fieldcount;//获取当前行中的列数; for (int intcounter = 0; intcounter 0) then --判断条件 param2 := '有匹配的值'; else param2 := '无匹配的值'; end if;exception when others then rollback;end;
如下图
第五步:测试刚才编写的存储过程
exec sp_demo('男');
end
注意事项
不能在一个存储过程中删除另一个存储过程,只能调用另一个存储过程
如果用create or replace procedure,创建存储过程的时候注意不要与用户下现有的存储过程同名,造成现在存储过程被覆盖
存储过程参数不带取值范围,in表示传入,out表示输出
以上通过两种方式介绍哦oracle存储过程,希望对大家有所帮助。
其它类似信息

推荐信息