[求助]在存贮过程中的查询语句如何让它实现动态条件查询?

zzktcs 2005-08-03 03:11:48
我写了个存贮过程,其中有个隐式游标
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 ,在存贮过程中应该如何编写呢?
请大大们多多指教!
...全文
151 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzktcs 2005-08-03
  • 打赏
  • 举报
回复
bzszp(SongZip)兄的方法很方便,谢谢啦!
njhart2003() 兄的方法也可行,谢谢!
bzszp 2005-08-03
  • 打赏
  • 举报
回复
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语句同样的效果。
zzktcs 2005-08-03
  • 打赏
  • 举报
回复
bzszp(SongZip)兄的方法是什么意思啊?
njhart2003() 兄的方法可以试试!
njhart2003 2005-08-03
  • 打赏
  • 举报
回复
用动态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;
...

bzszp 2005-08-03
  • 打赏
  • 举报
回复
And instr(nrepo_kind1,repo_code)>0
and instr(nrepo_kind2,repo_module)>0;

17,089

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧