当前位置: 代码迷 >> Oracle开发 >> oracle存储过程 带普普通通参数 返回数据集
  详细解决方案

oracle存储过程 带普普通通参数 返回数据集

热度:53   发布时间:2016-04-24 06:33:03.0
oracle存储过程 带普通参数 返回数据集
Oracle存储过程如果要返回数据集一般使用游标,如果想让存储过程带普通参数,又返回数据集,怎么办呢?请大家帮帮忙!谢谢!
例如在sql server是这样实现的:
create procedure test_sp(@unit int)
as
begin
select * from test where id = unit
end

test是一个普通的表,
create table test(
id int,
name varchar(20),
prop varchar(20)
)
insert into table test values(1,'hal','yes')
insert into table test values(2,'jal','no')
insert into table test values(3,'kal','ok')

Oracle怎么实现上述sql server的存储过程呢? 谢谢!

------解决思路----------------------
引用:


--存储过程
create or replace procedure sql_test (unit int,po_return out sys_refcursor) is
begin  
  open po_return for select * from test where id=unit; 
end ; 

--调用
declare  
  cur1 SYS_REFCURSOR; 
  rec test%rowtype;  
 begin  
 sql_test(1,cur1);  
 loop  
   fetch cur1 into rec;  
   exit when cur1%notfound;  
 dbms_output.put_line('----------------i :'
------解决思路----------------------
rec.id);  
 end loop;  
 close cur1;  
 end; 

------解决思路----------------------


引用:
Quote: 引用:


--存储过程
create or replace procedure sql_test (unit int,po_return out sys_refcursor) is
begin  
  open po_return for select * from test where id=unit; 
end ; 

--调用
declare  
  cur1 SYS_REFCURSOR; 
  rec test%rowtype;  
 begin  
 sql_test(1,cur1);  
 loop  
   fetch cur1 into rec;  
   exit when cur1%notfound;  
 dbms_output.put_line('----------------i :'
------解决思路----------------------
rec.id);  
 end loop;  
 close cur1;  
 end; 

带普通参数和游标好像没有冲突啊,用1楼的就行了,顶一下。
  相关解决方案