比如有两个表table1,table2,和变量flag 我用select....from decode(flag,1,tabel1,2,table2) where .... 是不是说这不可以用的?如果不可以用,那请问我有什么办法可以实现相同的功能?
直接在sql语句里是没发实现的! 过程里就可以了!
select....from decode(flag,1,tabel1,2,table2) where .... flag是那里来的!如果是程序里,那就程序中就写好,再传进去啊!
flag 是游标里传进去的,我现在在写的是存储过程里碰到的问题,游标无法通过编译.
既然这样就方便了,哈哈! 过程里多一步, tablname if flag then tablname := tabel1; else tablname := tabel2; end if; execute immediate 'select....from '''||tablname||'''where ....';
如:decode(值,if1,then1,if2,then2,......,else then)
什么意思?举个例子!
我用select....from decode(flag,1,tabel1,2,table2) where ....
是不是说这不可以用的?如果不可以用,那请问我有什么办法可以实现相同的功能?
过程里就可以了!
flag是那里来的!如果是程序里,那就程序中就写好,再传进去啊!
过程里多一步,
tablname
if flag then
tablname := tabel1;
else
tablname := tabel2;
end if;
execute immediate 'select....from '''||tablname||'''where ....';
如同if--elseif-elseif-这种条件语句.
select decode(值,if1,then1,if2,then2,...,else) from table_name;
替代的方法:
select * from tabel1 where flag=1
union
select * from table2 where flag=2