我写了个存贮过程,其中有个隐式游标
for curl in (Select repo_code,repo_module,repo_name,sts From repo_tm 
Where sts='A' And repo_code = nrepo_kind1
and repo_module =nrepo_kind2
  Order By repo_code )
其中nrepo_Kind1,nrepo_kind2是存贮过程中的变量,如果要实现查询条件动态,如实现结果为 repo_module in('11','12') and repo_code Not In ('9901','9902','9977'),也就是说实现nrepo_kind1,nrepo_kind2动态,可能有时为in 有时为= 有时为like ,在存贮过程中应该如何编写呢?
请大大们多多指教!

解决方案 »

  1.   

    And instr(nrepo_kind1,repo_code)>0
    and instr(nrepo_kind2,repo_module)>0;
      

  2.   

    用动态sql
    ...
    sqlstr:='Select repo_code,repo_module,repo_name,sts ';
    sqlstr:=sql||'From repo_tm ';
    sqlstr:=sql||'Where sts=:v1 ';
    sqlstr:=sql||'And repo_code '||condition_str1; -- 修改此处的查询条件
    sqlstr:=sql||'and repo_module'||condition_str2;-- 修改此处的查询条件
    sqlstr:=sql||'Order By repo_code';open curl for sqlstr using xxx;
    loop
    fetch cur1 into xxx,xxx,...;
    exit when cur1%notfound;
    ...
    end loop;
    close cur1;
    ...
      

  3.   

    bzszp(SongZip)兄的方法是什么意思啊?
    njhart2003() 兄的方法可以试试!
      

  4.   

    SQL> select 1 from dual where '111' in ('111','222');         1
    ----------
             1已用时间:  00: 00: 00.31
    SQL> select 1 from dual where instr('''111'',''222''','''111''')>0;         1
    ----------
             1已用时间:  00: 00: 00.10
    SQL> 
    效果相同,但是只有第二种才可以用于动态sql中达到in语句同样的效果。
      

  5.   

    bzszp(SongZip)兄的方法很方便,谢谢啦!
    njhart2003() 兄的方法也可行,谢谢!