Considerations for compatibility with Oracle and DB2 Development

Source: Internet
Author: User

We are working on compatibilityOralce,Db2During development, you need to pay attention to some issues to avoid incompatibility and problems for developers. In this example, the premise is that the db2 version is 9.7 and the database is created after the PLSQL compilation option is enabled. Next we will begin to introduce these.

Note:

1. If table fields are used after like, they should be replaced with the locate function. For example:

Oralce statement:

 
 
  1. select * from fw_right a where '03' like a.rightid||'%'; 

Compatible Syntax:

 
 
  1. select * from fw_right a where locate('03',a.rightid) = 1; 

Oralce statement:

 
 
  1. select * from fw_right a where '03' like '%'||a.rightid||'%'; 

Compatible Syntax:

 
 
  1. select * from fw_right a where locate('03',a.rightid) > 0; 

2. aliases used in views should not have the same name as the current table field.

If the following statement is used, the error "SQL0153N" is reported in db2.

 
 
  1. CREATE OR REPLACE VIEW V_WF_TODOLIST AS  
  2.  
  3. select c.process_def_id, c.process_def_name, a.action_def_id,  
  4.  
  5. a.work_item_id, a.bae007, a.action_def_name,  
  6.  
  7. a.state,  a.pre_wi_id,  a.work_type,  
  8.  
  9. a.operid, a.x_oprator_ids,  b.process_key_info,  
  10.  
  11. to_char(to_date(a.start_time, 'yyyymmddhh24miss'),'yyyy-mm-dd hh24:mi:ss') as start_time,  
  12.  
  13. to_char(to_date(a.complete_time,'yyyymmddhh24miss'),'yyyy-mm-dd hh24:mi:ss') as complete_time,  
  14.  
  15. a.filter_opr, a.memo,a.bae002,a.bae003, a.bae006,c.x_action_def_ids  
  16.  
  17. from wf_work_item a, wf_process_instance b, wf_action_def c  
  18.  
  19. where a.action_def_id  = c.action_def_id  
  20.  
  21. and b.process_def_id = c.process_def_id  
  22.  
  23. and a.bae007 = b.bae007  
  24.  
  25. and a.state in('0','2') 

Compatible Syntax:

 
 
  1. CREATE OR REPLACE VIEW V_WF_TODOLIST AS  
  2.  
  3. select c.process_def_id, c.process_def_name, a.action_def_id,  
  4.  
  5. a.work_item_id, a.bae007, a.action_def_name,  
  6.  
  7. a.state,  a.pre_wi_id,  a.work_type,  
  8.  
  9. a.operid, a.x_oprator_ids,  b.process_key_info,  
  10.  
  11. to_char(to_date(a.start_time, 'yyyymmddhh24miss'),'yyyy-mm-dd hh24:mi:ss') as start_time_0,  
  12.  
  13. to_char(to_date(a.complete_time,'yyyymmddhh24miss'),'yyyy-mm-dd hh24:mi:ss') as complete_time_0,  
  14.  
  15. a.filter_opr, a.memo,a.bae002,a.bae003, a.bae006,c.x_action_def_ids  
  16.  
  17. from wf_work_item a, wf_process_instance b, wf_action_def c  
  18.  
  19. where a.action_def_id  = c.action_def_id  
  20.  
  21. and b.process_def_id = c.process_def_id  
  22.  
  23. and a.bae007 = b.bae007  
  24.  
  25. and a.state in('0','2') 

3. order by or fetch first n rows only is not allowed in the following cases:

  • Full outer query view
  • Full outer query in the RETURN Statement of "SQL table function"
  • Specific query table definition
  • Subqueries without parentheses

Otherwise, "SQL20211N specification order by or fetch first n rows only is invalid. "Error.

Oralce statement:

 
 
  1. CREATE OR REPLACE VIEW V_FW_BLANK_BULLETIN as  
  2.  
  3. select id, bae001,  operunitid, operunittype, unitsubtype, ifergency,  
  4.  
  5. title,  content, digest,  duetime,  validto, aae100,  
  6.  
  7. bae006, bae002,  bae003,  id as colid,  
  8.  
  9. substr(digest,1,20) as digest2  
  10.  
  11. from fw_bulletin  
  12.  
  13. where duetime <= to_char(sysdate,'yyyymmddhh24miss')  
  14.  
  15. and (to_char(validto) >= to_char(sysdate,'yyyymmddhh24miss') or validto is null)  
  16.  
  17. and aae100 ='1' 
  18.  
  19. order by ifergency desc, id desc,  duetime desc 

Compatible Syntax:

 
 
  1. CREATE OR REPLACE VIEW V_FW_BLANK_BULLETIN as  
  2.  
  3. select * from (select id, bae001,  operunitid, operunittype, unitsubtype, ifergency,  
  4.  
  5. title,  content, digest,  duetime,  validto, aae100,  
  6.  
  7. bae006, bae002,  bae003,  id as colid,  
  8.  
  9. substr(digest,1,20) as digest2  
  10.  
  11. from fw_bulletin  
  12.  
  13. where duetime <= to_char(sysdate,'yyyymmddhh24miss')  
  14.  
  15. and (to_char(validto) >= to_char(sysdate,'yyyymmddhh24miss') or validto is null)  
  16.  
  17. and aae100 ='1' 
  18.  
  19. order by ifergency desc, id desc,  duetime desc) 

After learning about the preceding precautions during Oracle and DB2 development, we can avoid incompatibility issues as much as possible during development. This article will introduce you here, hoping to help you.

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.