王朝网络
分享
 
 
 

使用Instr()与decode()进行多条件组合查询

王朝other·作者佚名  2008-05-31
宽屏版  字体: |||超大  

系统中碰到了要处理多条件组合查询的情况,好比说有4个独立的条件,那么组合出的查询条件便有24种,不可能写24条Sql语句再分别指定给24种组合情况吧,条件数再多点呢,人都会搞疯的。。。。于是我求助于高手,获得了使用instr()和decode()函数的实现方法。

下面先说明一下instr()的功能和语法:(函数的语法是从http://www.techonthenet.com/Oracle/functions/index.htm处得到的,相当清楚明了:)

In Oracle/PLSQL, the instr function returns the location of a substring in a string.

The syntax for the instr function is:

instr (string1, string2, [start_position], [nth_appearance])

string1 is the string to search.

string2 is the substring to search for in string1.

start_position is the position in string1 where the search will start. This argument is optional. If omitted, it defaults to 1. The first position in the string is 1. If the start_position is negative, the function counts back start_position number of characters from the end of string1 and then searches towards the beginning of string1.

nth_appearance is the nth appearance of string2. This is optional. If omiited, it defaults to 1.

再说明一下decode()的功能和语法:

In Oracle/PLSQL, the decode function has the functionality of an IF-THEN-ELSE statement.

The syntax for the decode function is:

decode ( eXPression , search , result [, search , result]... [, default] )

expression is the value to compare.

search is the value that is compared against expression.

result is the value returned, if expression is equal to search.

default is optional. If no matches are found, the decode will return default. If default is omitted, then the decode statement will return null (if no matches are found).

综合使用得到的SQL语句如下:

select e.到达日期,

e.角色名,

d.单据标题,

d.单据编号,

e.节点编号,

e.处理动作,

e.处理日期,

b.流程实例编号

from gzl_流程类型 a,

gzl_流程实例 b,

gzl_流程定义 c,

dj_单据 d,

gzl_流程流转状态 e

where a.流程类型编号 = c.流程类型编号 and e.处理标记 = '是'

and e.用户id = 'tetdmis' and b.流程定义编号 = c.流程定义编号

and b.活动编号 = d.单据编号 and c.流程定义编号 = b.流程定义编号

and e.流程实例编号 = b.流程实例编号

and instr(decode(:流程类型条件, '-1', a.流程类型编号, :流程类型条件), a.流程类型编号) > 0

and (to_char(e.处理日期, 'yyyy-mm-dd') between :开始日期 and :结束日期)

and instr(decode(:节点名称条件, '-1', e.处理动作, :节点名称条件),

e.处理动作) > 0

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有