create package test_age as type mycursor is ref cursor; end; / create or replace procedure ps_dyck(p_rc out test_age.mycursor) As begin open p_rc for select * from dyck; end; /以下是测试: declare 变量; v_rc test_age.mycursor; begin ps_dyck(v_rc); loop fetch v_rc into 变量; exit when v_rc%notfound; .... end loop; end; /
修改一下: create or replace procedure ps_dyck As cursor cur_table_name is select * from dyck; test cur_table_name%rowtype; begin open cur_table_name; loop fetch cur_table_name into test; dbms_output.put_line(test.col_name) exit when cur_table_name%notfound; end loop; end ps_dyck;
不能隻在存儲過程中寫上 select * from dyck,因為這樣無法返回從dyck中取到的數據, 樓上各位的方法都可以,你自己試試!!
As
test table_name%rowtype;
begin
select * into test from dyck;
end
test table_name%rowtype;楼主要实现什么功能哪?
改了存储过程是对了,可运行时又错了?
楼上的这句什么意思:
test table_name%rowtype;楼主要实现什么功能哪?
------------------------------------------------------------声明test为表记录变量
as
type mycursor is ref cursor;
end;
/
create or replace procedure ps_dyck(p_rc out test_age.mycursor)
As
begin
open p_rc for select * from dyck;
end;
/以下是测试:
declare
变量;
v_rc test_age.mycursor;
begin
ps_dyck(v_rc);
loop
fetch v_rc into 变量;
exit when v_rc%notfound;
....
end loop;
end;
/
create or replace procedure ps_dyck
As
cursor cur_table_name is
select * from dyck;
test cur_table_name%rowtype;
begin
open cur_table_name;
loop
fetch cur_table_name into test;
dbms_output.put_line(test.col_name)
exit when cur_table_name%notfound;
end loop;
end ps_dyck;
樓上各位的方法都可以,你自己試試!!
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.CommandText = "ps_dyck"; OracleParameter pOutput;
pOutput = cmd.Parameters.Add("pcur", OracleClient.OracleType.Cursor);
pOutput.Direction = ParameterDirection.Output; cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
OracleDataReader dr = cmd.ExecuteReader();
Table table = new Table(); while(dr.Read())
{ }
是不是这样来执行存储过程的?我是今天刚刚开始学存储过程的!请指点