澳门威利斯人网站44平台首页_使用Instr()与decode()进行多条件组合查询

03月21日作者:黑曼巴


系统中碰到了要处置惩罚多前提组合查询的环境,好比说有4个自力的前提,那么组合出的查询前提便有24种,弗成能写24条Sql语句再分手指定给24种组合环境澳门威利斯人网站44平台首页吧,前提数再多点呢,人都邑搞疯的。。。。于是我告急于高手,得到了应用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 sta澳门威利斯人网站44平台首页rt.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 op澳门威利斯人网站44平台首页tional.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.处置惩罚标记 = '是'

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

and b.活动编号 = d.单据编号 and c.流程定义澳门威利斯人网站44平台首页编号 = b.流程定义编号

ande.流程实例编号 = b.流程实例编号

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

and (to_char(e.处置惩罚日期, 'yyyy-mm-dd') between :开始日期 and :停止日期)

and ins澳门威利斯人网站44平台首页tr(decode(:节点名称前提, '-1', e.处置惩罚动作, :节点名称前提),

e.处置惩罚动作) > 0

最近关注

热点内容

更多