Oracle存储过程返回结果集的有关问题
Oracle存储过程返回结果集的问题
我想在存储过程里实现类似效果:
if a = 1
select * from table1
else
select * from table2
这个sql server里很容易实现。oracle怎么实现,用包和游标?
------解决方案--------------------
LZ需求说的不明确,你的SELECT准备怎么处理呢,是显示出来,还是做什么操作呢?
------解决方案--------------------
create or replace package xxx as
type table1set is table of table1%rowtype index_by binary_integer;
type table2set is table of table2%rowtype index_by binary_integer;
procedure yyy (a in int,tab1 inout table1set,tab2 inout table2set);
end xxx;
create or replace package body xxx as
procedure yyy (a in int,tab1 inout table1set,tab2 inout table2set) as
begin
if(a==1)
select * into tab1 from table1;
elsif
select * into tab2 from table2
endif;
end yyy;
end xxx;
------解决方案--------------------
跟一般语言一样的,根据你的业务逻辑判断返回不用结果集,可以用游标返回。
我想在存储过程里实现类似效果:
if a = 1
select * from table1
else
select * from table2
这个sql server里很容易实现。oracle怎么实现,用包和游标?
------解决方案--------------------
LZ需求说的不明确,你的SELECT准备怎么处理呢,是显示出来,还是做什么操作呢?
------解决方案--------------------
create or replace package xxx as
type table1set is table of table1%rowtype index_by binary_integer;
type table2set is table of table2%rowtype index_by binary_integer;
procedure yyy (a in int,tab1 inout table1set,tab2 inout table2set);
end xxx;
create or replace package body xxx as
procedure yyy (a in int,tab1 inout table1set,tab2 inout table2set) as
begin
if(a==1)
select * into tab1 from table1;
elsif
select * into tab2 from table2
endif;
end yyy;
end xxx;
------解决方案--------------------
跟一般语言一样的,根据你的业务逻辑判断返回不用结果集,可以用游标返回。