现在有一个sql语句是这样的
select case when type=1 then 'select * from table1' when type=2 then 'select * from table2' end
from table
where id=3所以查出来的结果无非就2个sql语句的string来的现在我想执行SQL语句得到的这个string
比如得到了select * from table1
那么我想exec('select * from table1')就是一个语句全部搞定那种.....
exec(这里怎么写);请问sql怎么写......
select case when type=1 then 'select * from table1' when type=2 then 'select * from table2' end
from table
where id=3所以查出来的结果无非就2个sql语句的string来的现在我想执行SQL语句得到的这个string
比如得到了select * from table1
那么我想exec('select * from table1')就是一个语句全部搞定那种.....
exec(这里怎么写);请问sql怎么写......
str_sql varchar2(1000);
cur_ref sys_refcursor;
begin
select case when type=1 then 'select * from table1' when type=2 then 'select * from table2' end
into str_sql
from table
where id=3;
open cur_ref for str_sql;
end;
/至于你说的,一个 SQL 全搞定,不知道你要干嘛,在 oracle 里 exec 应该是没有办法执行 sql 语句的
select @str=case when type=1 then 'select * from table1' when type=2 then 'select * from table2' end
from table
where id=3exec(@str)
我都说了,oracle 里 exec 是执行不了 sql 语句的,因为 exec 会解析为begin
end;