系統中遇到了要處理多條件組合查詢的情況,使用instr()和decode()函數的實現方法。
下面先說明一下instr()的功能和語法:(函數的語法是從處得到的,相當清晰明了:)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