现在有一个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怎么写......

解决方案 »

  1.   

    declare
        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 语句的
      

  2.   

    declare @str nvarchar(4000)
    select @str=case when type=1 then 'select * from table1' when type=2 then 'select * from table2' end
    from table
    where id=3exec(@str)
      

  3.   

    这个sql 在ms sql里,应该是对的,在oracle里,就不清楚了,关键是exec 调用不知道可以不
      

  4.   


    我都说了,oracle 里 exec 是执行不了 sql 语句的,因为 exec 会解析为begin 
    end;