比如在存储过程中:
if A=1 then
  select A.A1 from A ;
elseif A=2 then
  select B.B1 from B;
endif以上语句用decode能办到么??
有没有一个函数,可以执行符合SQL语法的字符串?如果有的话(假设函数名为excsql),我的设想是:
excsql(decode(A,1,'select A.A1 from A',2,'select B.B1 from B'))

解决方案 »

  1.   

    SQL> select decode(&A,1,(select 1 from dual) ,2, (select 2 from dual))from dual;DECODE(1,1,(SELECT1FROMDUAL),2
    ------------------------------
                                 1
      

  2.   

    xiaoxiao1984(笨猫儿^_^) 
    如果子查询返回的是多行,怎么办?
      

  3.   

    返回多场纪录的时候:
    select A.A1 from A where &A=1 union select B.B1 from B where &A=2;
      

  4.   

    楼主说清楚点,A是个表,怎么能If A=1 then呢
      

  5.   

    select decode(&A,1,'select 1 from dual' ,2, 'select 2 from dual') into exsql
    from dual;execute immediate exsql;