能否实现这样的功能:select cola from table where flag='a' if (存在字段colb) and colb='b'就思就是如果存在字段colb,则语句相当于是select cola from table where flag='a' and colb='b'如果不存在colb,则语句相当于是:select cola from table where flag='a' 

解决方案 »

  1.   


    --可以根据此判断列是否存在后,动态执行语句
    select count(*) from user_tab_columns 
    where table_name=upper('table') and column_name=upper('colb');
      

  2.   

    可以是可以,就是麻烦点。
    写个过程,首先打开个游标
    select column_name from user_tab_columns where table_name='YOURTABLENAME'
    然后检查COLB是否在返回的结果集中,
    然后IF ... ELSE ...END IF。
      

  3.   

    现在主要问题是我想在一个SQL语句完成这个。
      

  4.   

    select count(*) from user_tab_columns 
        where table_name=upper('table') and column_name=upper('colb');