對(duì)Oracle SQL到DB2 SQL移植的淺析
以下的文章主要是對(duì)Oracle SQL到DB2 SQL移植解決方案淺析,Oracle SQL到DB2 SQL移植現(xiàn)已變得十分搶手,如果你想知道更多的關(guān)于其實(shí)際應(yīng)用方面的知識(shí),你就可以瀏覽下面的文章,相信會(huì)對(duì)你有所幫助。
1、Oracel中的decode
DB2解決方案:用case條件表達(dá)式完成。
case兩種語法模式:
(1)CASE
WHEN 條件 THEN 結(jié)果1
ELSE 結(jié)果2
END
(2)CASE 表達(dá)式1
WHEN 表達(dá)式2 THEN 結(jié)果1
ELSE 結(jié)果2
END
上面的WHEN可以重復(fù)多次,就像C中的SWITCH ..CASE的表達(dá).
例如:
- SELECT ORDNO,CUSNO,
- CASE MONTH(SHIPDATE)
- WHEN ´´01´´ THEN ´´Jan´´
- WHEN ´´02´´ THEN ´´Feb´´
- WHEN ´´03´´ THEN ´´Mar´´
- WHEN ´´04´´ THEN ´´Apr´´
- WHEN ´´05´´ THEN ´´May´´
- WHEN ´´06´´ THEN ´´Jun´´
- WHEN ´´07´´ THEN ´´Jul´´
- WHEN ´´08´´ THEN ´´Aug´´
- WHEN ´´09´´ THEN ´´Sep´´
- WHEN ´´10´´ THEN ´´Oct´´
- WHEN ´´11´´ THEN ´´Nov´´
- WHEN ´´12´´ THEN ´´Dec´´
- END
- FROM FILE
應(yīng)用實(shí)例:
Oracle SQL:
- select decode(t.organtypecode,
´´D´´, t.parent, ´´S´´, t.parent, t.id)- from A_ORGAN t
- where t.parent = 35
- DB2 SQL:
- select case x.organtypecode
- when ´´D´´ then
- x.parent
- when ´´S´´ then
- x.parent
- else
- x.id
- end
- from a_Organ x
- where x.parent = 35;
2、Oracle中的Start with...Connect By遞歸查詢
DB2解決方案:用with公共遞歸表達(dá)式來解決。
DB2解決方案:用case條件表達(dá)式完成。
Oracle SQL:
- select t.id
- from a_organ t
- start with t.id in (select decode(t.organtypecode,
- ´´D´´,
- t.parent,
- ´´S´´,
- t.parent,
- t.id)
- from A_ORGAN
- where t.id = 35)
- connect by t.parent = prior t.id
- DB2 SQL:
- WITH FKK(id) as
- (select o.id from a_organ o
- where o.id=35
- UNION ALL
- select case x.organtypecode
- when ´´D´´ then x.parent
- when ´´S´´ then x.parent
- else x.id
- end
- from FKK fk, a_organ x
- where fk.id=x.parent)
- select distinct id from FKK;
上述的相關(guān)內(nèi)容就是對(duì)Oracle SQL到DB2 SQL移植解決方案的描述,希望會(huì)給你帶來一些幫助在此方面。
【編輯推薦】