Migration of Oracle SQL to DB2 SQL

Source: Internet
Author: User

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:

 
 
  1. SELECT ORDNO,CUSNO,  
  2. CASE MONTH(SHIPDATE)  
  3. WHEN ´´01´´ THEN ´´Jan´´  
  4. WHEN ´´02´´ THEN ´´Feb´´  
  5. WHEN ´´03´´ THEN ´´Mar´´  
  6. WHEN ´´04´´ THEN ´´Apr´´  
  7. WHEN ´´05´´ THEN ´´May´´  
  8. WHEN ´´06´´ THEN ´´Jun´´  
  9. WHEN ´´07´´ THEN ´´Jul´´  
  10. WHEN ´´08´´ THEN ´´Aug´´  
  11. WHEN ´´09´´ THEN ´´Sep´´  
  12. WHEN ´´10´´ THEN ´´Oct´´  
  13. WHEN ´´11´´ THEN ´´Nov´´  
  14. WHEN ´´12´´ THEN ´´Dec´´  
  15. END  
  16. FROM FILE  

Application instance:

Oracle SQL:

 
 
  1. select decode(t.organtypecode, 
    ´´D´´, t.parent, ´´S´´, t.parent, t.id)  
  2. from A_ORGAN t  
  3. where t.parent = 35 
  4. DB2 SQL:  
  5. select case x.organtypecode  
  6. when ´´D´´ then  
  7. x.parent  
  8. when ´´S´´ then  
  9. x.parent  
  10. else  
  11. x.id  
  12. end  
  13. from a_Organ x  
  14. 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:

 
 
  1. select t.id  
  2. from a_organ t  
  3. start with t.id in (select decode(t.organtypecode,  
  4. ´´D´´,  
  5. t.parent,  
  6. ´´S´´,  
  7. t.parent,  
  8. t.id)  
  9. from A_ORGAN  
  10. where t.id = 35)  
  11. connect by t.parent = prior t.id  
  12. DB2 SQL:  
  13. WITH FKK(id) as  
  14. (select o.id from a_organ o  
  15. where o.id=35 
  16. UNION ALL  
  17. select case x.organtypecode  
  18. when ´´D´´ then x.parent  
  19. when ´´S´´ then x.parent  
  20. else x.id  
  21. end  
  22. from FKK fk, a_organ x  
  23. where fk.id=x.parent)  
  24. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.