Differences between Oracle and DB2 stored procedures

Source: Internet
Author: User
Tags oracle rownum

This article mainly describes the differences between the Oracle database and the DB2 stored procedure. If you are curious about the differences between the Oracle database and the DB2 stored procedure, you can click to view the following articles. The following is a detailed description of the articles. I hope you can learn from them.

Differences between Oracle and DB2 stored procedures

1) The stored procedure is actually implemented by SQL statements at, but logical processes can be added.

Oracle's stored procedure only understands its syntax, and has recently learned the DB2 stored procedure. I always feel that it has no effect to look at its syntax or something. Let's take a look at the Oracle Stored Procedure file in the project and try to change it to db2. Several differences are found:

 
 
  1. Create or replace procedure proname(var_in in number,var_out out number)  
  2. As  
  3. Var1 varchar2(18);  
  4. Var2 user.name%TYPE;  
  5. Begin  
  6. Var_out := 0;  
  7. Execute immediate ‘truncate table user’;  
  8. …  
  9. End  
  10. create procedure proname(in var_in int,out var_out int)  
  11. Declare var1 varchar(18);  
  12. Begin  
  13. Set var_out=0;  
  14. …  
  15. End  

1) DB2 does not support the "or replace" syntax. The parameter names and IN/OUT locations must also be exchanged. The declare keyword must be used for variable declaration, you must use the set keyword when assigning values to variables.

2) For the % TYPE Function in Oracle, DB2 does not seem to have a good implementation method yet.

3) Similarly, the command truncate for clearing tables in Oracle and DB2 cannot be referenced as is, but it also provides two implementation methods: first, import the content of an empty file into the table to import null. dat; second, set the table feature to not record the log alter table tablename. however, the second method may cause the original table to be unavailable in some cases. The specific method has not been clarified yet.

4) The performance of SQL statements is different from that of Oracle and db2. For example, Oracle rownum, db2 can use fetch first n only, or row_number () over.

Of course, the method for calling a stored procedure is the same, call proname (2 ,?), Used for output parameters? .

For the above 2nd points to a good solution, this function is used in the DB2 stored procedure is quite a lot.

The above content is an introduction to the differences between the stored procedures in Oracle and DB2. I hope you will find some gains.

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.