The following articles mainly focus on the migration solution from Oracle SQL to DB2 SQL. Migration from Oracle SQL to DB2 SQL has become very popular, if you want to know more about its practical application, you can browse the following articles and I believe it will be helpful to you.
1. decode in cancel
DB2 solution: Use case conditional expressions.
Two syntax modes of case:
(1) CASE
WHEN condition THEN result 1
ELSE result 2
END
(2) CASE expression 1
WHEN expression 2 THEN result 1
ELSE result 2
END
The above WHEN can be repeated multiple times, just like the expression of SWITCH... CASE in C.
For example:
- 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
Application instance:
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. Start with... Connect By recursive query in Oracle
DB2 solution: Use the with public recursive expression.
DB2 solution: Use case conditional expressions.
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;
The above content is a description of the migration solution from Oracle SQL to DB2 SQL, hoping to help you in this regard.