C#调用Oracle存储过程并返回结果集
2010-06-26 19:13
645 查看
1.创建一个存储过程:
create or replace procedure GET_PERSON
(
RC1 out sys_refcursor,
RC2 out sys_refcursor
)
is
begin
open RC1 for select * from PERSON;
open RC2 for select * from PERSON;
end GET_PERSON;
2.C#代码
OracleConnection conn = new OracleConnection("Data Source=XXX;User Id=scott;Password=tiger");
OracleCommand cmd = new OracleCommand("GET_PERSON", conn);
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter param = new OracleParameter("RC1", OracleType.Cursor);
param.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param);
param = new OracleParameter("RC2", OracleType.Cursor);
param.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param);
OracleDataAdapter adapter = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
OK!
如果是Oracle9之前的版本,需要定义包含REF CURSOR的包.
例如:
create or replace package GLOBAL_OBJECT is
type RC_OBJECT is ref cursor;
end GLOBAL_OBJECT;
create or replace procedure GET_PERSON
(
RC1 out RC_OBJECT ,
RC2 out RC_OBJECT
)
is
begin
open RC1 for select * from PERSON;
open RC2 for select * from PERSON;
end GET_PERSON;
create or replace procedure GET_PERSON
(
RC1 out sys_refcursor,
RC2 out sys_refcursor
)
is
begin
open RC1 for select * from PERSON;
open RC2 for select * from PERSON;
end GET_PERSON;
2.C#代码
OracleConnection conn = new OracleConnection("Data Source=XXX;User Id=scott;Password=tiger");
OracleCommand cmd = new OracleCommand("GET_PERSON", conn);
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter param = new OracleParameter("RC1", OracleType.Cursor);
param.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param);
param = new OracleParameter("RC2", OracleType.Cursor);
param.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param);
OracleDataAdapter adapter = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
OK!
如果是Oracle9之前的版本,需要定义包含REF CURSOR的包.
例如:
create or replace package GLOBAL_OBJECT is
type RC_OBJECT is ref cursor;
end GLOBAL_OBJECT;
create or replace procedure GET_PERSON
(
RC1 out RC_OBJECT ,
RC2 out RC_OBJECT
)
is
begin
open RC1 for select * from PERSON;
open RC2 for select * from PERSON;
end GET_PERSON;
相关文章推荐
- oracle 调用存储过程和函数返回结果集
- oracle调用存储过程和函数返回结果集
- oracle调用存储过程和函数返回结果集
- oracle调用存储过程和函数返回结果集
- 调用oracle程序包内的存储过程返回结果集
- Java 调用 Oracle 存储过程返回结果集
- 使用VB调用Oracle程序包内的存储过程返回结果集
- asp 调用 oracle存储过程并返回结果集
- JAVA调用ORACLE的存储过程、函数的返回结果集
- oracle调用存储过程和函数返回结果集
- ASP 调用 Oracle 存储过程返回结果集
- JAVA调用ORACLE带数组输入参数和返回游标结果集的存储过程
- mybatis 调用oracle中的存储过程返回结果集
- Oracle中存储过程中赋值和传参及程序调用返回DS
- c# 调用带有参数的存储过程方法--oracle【转载】
- java调用存储过程时,返回结果不是ResultSet的时候的处理
- 【Mybatis】MyBatis调用带有返回结果、output参数的存储过程上与ibatis的区别
- 调用存储过程和返回结果集
- Sybase调用存储过程并返回结果
- 用.NET调用oracle的存储过程返回记录集