是这样的
两张表关连查询
where条件里有三个项目是根据客户输入的不同值来判断用哪个where条件的
而且这三个项目分别都有一种情况下就不需要用来当where条件了
求助怎么个写法啊

解决方案 »

  1.   

    我怎么觉得我已经描述的很清楚了 汗这么说吧,where 有8个项目要分别等于什么的时候,抽出然后其中三个项目 a b c 好了因为这个是jsp的后台,所以就是当画面上a对应的那个项目,符合①条件的时候,a=1 符合②条件的时候a=2, 符合③条件的时候,a不作为where条件了b 和 c 以此类推
      

  2.   

    用case 语句写,,要么就用存储过程
      

  3.   

    把sql写成一个字符串 用一个stringbuffer存储
    判断下where条件 不为空就追加 
    然后 执行sql
    不知道你说的是不是这个意思 
      

  4.   

    写储存过程吧 ,过程传入的参数有三个,即p1、p2、p3,
    test_00 和  test_01 只是两个表
    create or replace procedure proc_name
    (
      p1          in  varchar2,  --data_type,
      p2          in  varchar2,  --data_type,
      p3          in  varchar2, --data_type,
      cur_return  out sys_refcursor
    )
    isbegin    if (p1 is not null  and p2 is not null and p3 is not null) then     
            dbms_output.put_line(p1||p2||p3);
            open cur_return for
                 select a.id,b.name
                   from test_00 a,test_01 b  
                  where a.id = b.id;    else
           dbms_output.put_line(p1||p2||p3);
           open cur_return for
                 select a.id,b.name
                   from test_00 a,test_01 b  
                  where a.id = b.id
                    and (a.name = p1 or a.name = p2 or a.name = p3);                
                    
        end if;
    end proc_name ;
      

  5.   

    select * from table where a=a union select * from table where b=b union select * from table c=c