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; |