oracle 存储过程cursor xxx is后面的select 语句能加判断条件得出吗?

cursor XX is
select * from table;
能不能加条件判断?
如 cursor XX is
if (a=1) then
select * from table1;
elsif (a=2) then
select * from table2;
end if;

不能那样写,但是可以这样写
cursor xx is
SELECT case a when 1 then t1.field1, t1.field2, t1.field3...t1.fieldn
when 2 then t2.field1, t2.field2, t2.field3...t2.fieldn
ELSE NULL END
FROM table1 t1, table2 t2
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-01
如果是查询条件,可以用case when 构建,表的话好像没什么好办法。

有个办法,比较麻烦,
建一个临时表table3 like table1
if (a=1) then
insert into table3 select * from table1;
elsif (a=2) then
insert into table3 select * from table2;
end if;

cursor XX is
select * from table3

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网