比如我有5个查询条件,但 我可能用到其中的两个或者三个,总之就是查询条件的数量不定,怎么查询?

解决方案 »

  1.   

    动态sql·   拼接字符串  
      

  2.   

    动态的SQl语句拼接字符串可以实现的
      

  3.   


    --类似这样的
    ...
    strsql := 'select count(*) from table where 1=1 ';if a <> '' then
      strsql := strsql || 'and col1 =' || a || ''' ';
    end if;
      
    if b <> '' then
      strsql := strsql || 'and col2 =' || b || ''' '; 
    end if;
    ...execute immediate strsql into v_num;
    ...