国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開發(fā) > 綜合 > 正文

使用Instr()與decode()進(jìn)行多條件組合查詢

2024-07-21 02:32:41
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
    系統(tǒng)中碰到了要處理多條件組合查詢的情況,好比說有4個(gè)獨(dú)立的條件,那么組合出的查詢條件便有24種,不可能寫24條Sql語(yǔ)句再分別指定給24種組合情況吧,條件數(shù)再多點(diǎn)呢,人都會(huì)搞瘋的。。。。于是我求助于高手,獲得了使用instr()和decode()函數(shù)的實(shí)現(xiàn)方法。     下面先說明一下instr()的功能和語(yǔ)法:(函數(shù)的語(yǔ)法是從http://www.techonthenet.com/Oracle/functions/index.htm處得到的,相當(dāng)清楚明了:)
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()的功能和語(yǔ)法: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語(yǔ)句如下:select e.到達(dá)日期,
       e.角色名,
       d.單據(jù)標(biāo)題,
       d.單據(jù)編號(hào),
       e.節(jié)點(diǎn)編號(hào),
       e.處理動(dòng)作,
       e.處理日期,
       b.流程實(shí)例編號(hào)  from gzl_流程類型     a,
       gzl_流程實(shí)例     b,
       gzl_流程定義     c,
       dj_單據(jù)          d,
       gzl_流程流轉(zhuǎn)狀態(tài) e
 where a.流程類型編號(hào) = c.流程類型編號(hào) and e.處理標(biāo)記 = '是'
       and   e.用戶id = 'tetdmis' and b.流程定義編號(hào) = c.流程定義編號(hào)    
       and b.活動(dòng)編號(hào) = d.單據(jù)編號(hào) and c.流程定義編號(hào) = b.流程定義編號(hào)
       and  e.流程實(shí)例編號(hào) = b.流程實(shí)例編號(hào)
    
  and instr(decode(:流程類型條件, '-1', a.流程類型編號(hào), :流程類型條件), a.流程類型編號(hào)) > 0
      and (to_char(e.處理日期, 'yyyy-mm-dd') between :開始日期 and :結(jié)束日期)      
       and instr(decode(:節(jié)點(diǎn)名稱條件, '-1', e.處理動(dòng)作, :節(jié)點(diǎn)名稱條件),
                 e.處理動(dòng)作) > 0

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 新化县| 吐鲁番市| 商丘市| 沁阳市| 河池市| 陆良县| 铁岭市| 明星| 新泰市| 南阳市| 衡东县| 桓台县| 拉萨市| 太白县| 海盐县| 襄汾县| 乡宁县| 呼伦贝尔市| 宜章县| 娄底市| 海阳市| 汤阴县| 石柱| 团风县| 南安市| 平利县| 福鼎市| 思南县| 安义县| 安阳市| 永新县| 睢宁县| 延津县| 余姚市| 长宁区| 安丘市| 镇远县| 邵武市| 新竹市| 庆云县| 琼海市|