create or replace procedure p_test(p_cur out sys_refcursor)
as
begin
open p_cur for select * from emp;
end p_test;
declare
p_cur sys_refcursor;
i emp%rowtype;
begin
p_test(p_cur);
loop fetch p_cur
into i;
exit when p_cur%notfound;
DBMS_OUTPUT.PUT_LINE('---'||i.ename||'---'||i.empno);
end loop;
close p_cur;
end;
补充:Oracle存储过程返回select * from table结果
1.首先建立一个包
create or replace package LogOperation is
type listLog is ref cursor;
procedure PCenterExamine_sel(listCenterExamine out listlog,testlist out listLog,numpage in decimal);
end;
2.建立包中的主体
create or replace package body LogOperation is
procedure PCenterExamine_sel
(
listCenterExamine out listlog,
testlist out listlog,
numpage in decimal
)
as
begin
open listCenterExamine for select * from Log_CenterExamine;
open testlist for select * from Log_CenterExamine;
end;
end;
3.在程序中调用存储过程的值
public static DataSet RunProcedureGetDataSet(string storedProcName, OracleParameter[] parameters)
{
string connectionString ="192.168.1.1/db";
using (OracleConnection connection = new OracleConnection(connectionString))
{
DataSet dataSet = new DataSet();
connection.Open();
OracleDataAdapter sqlDA = new OracleDataAdapter();
sqlDA.SelectCommand = BuildQueryCommand(connection, storedProcName, parameters);
sqlDA.Fill(dataSet, "dt");
connection.Close();
return dataSet;
}
}