[Share] common conversions from Oracle migration to DB2

Source: Internet
Author: User

Because of the project requirements, we need to transfer the items on Oracle to DB2, So we collected some precautions for modification and shared them with you.
 

Examples of implementing the same functions of Oracle and DB2 (taking Oracle8i and DB2 7.x as examples, tested)

Obtain the first N records Oracle Select * From tablename where rownum <= N;
DB2 Select * From tablename fetch first n rows only;
Obtain system date Oracle Select sysdate from dual;
DB2 Select current timestamp from sysibm. sysdummy1;
Null Value Conversion Oracle Select productid, loginname, nvl (cur_rate, '0') from tablename;
DB2 Select productid, loginname, value (cur_rate, '0') from tablename;
Type conversion Oracle Select to_char (sysdate, 'yyyy-MM-DD hh24: MI: ss') from dual;
DB2 Select varchar (current timestamp) from sysibm. sysdummy1;
  ■ Oracle Data Type Change functions: to_char (), to_date (), to_number (), etc. If you only use year, month, day, etc., you can use to_char (sysdate, 'yyyy'), to_char ('mm'), to_char ('dd. Only the year, month, and day trunc (sysdate) are used, and the time, minute, and second to_char (sysdate, 'hh24: MI: ss') are used ').
■ DB2 data type change functions: Char (), varchar (), INT (), date (), time (), and so on; method of obtaining year, month, and day: year (current timestamp), month (current timestamp), Day (current timestamp), hour (current timestamp), minute (current timestamp), second (current timestamp ), microsecond (current timestamp). Date (current timestamp) can be used only for year, month, and day, and time (current timestamp) can be used ). Char () is a fixed-length string (1-255), varchar () is not a fixed-length string (1-32672)
Date, time form into character form: Char (current date), char (current time)
Converts a string to a date or time format: Timestamp ('2017-10-20 12:00:00 '), date ('2017-10-20'), date ('2017/123 '), time ('12: 00: 00 ')
Quickly clear large tables Oracle Truncate table tablename;
DB2 Alter table tablename active not logged initially with empty table;
Rowid Oracle It is unique in the database and can be obtained in the program.
DB2 This concept exists, but cannot be obtained by the program. Solution to be determined (Senior contact my caoxicao@hotmail.com ).
To_number Oracle Select to_number ('123') from dual;
DB2 Select cast ('200' as integer) from sysibm. sysdummy1;
Copy and create a table Oracle Create Table A as select * from B;
DB2 Create Table A like B;

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.