zoukankan      html  css  js  c++  java
  • Oracle迁移到DB2常用转换

                                

    因为项目需要,要将Oracle上的东西转移到DB2,于是收集整理了一些需要修改点的注意事项,拿出来大家分享。
      

    ORACLE和DB2实现相同功能的实例(主要以Oracle8I和DB2 7.X为例,已测试)

    取前N条记录

    Oracle

    Select * from TableName where rownum <= N;

    DB2

    Select * from TableName fetch first N rows only;

    取得系统日期

    Oracle

    Select sysdate from dual;

    DB2

    Select current timestamp from sysibm.sysdummy1;

    空值转换

    Oracle

    Select productid,loginname,nvl(cur_rate,'0') from TableName ;

    DB2

    Select productid,loginname,value(cur_rate,'0') from TableName;

    类型转换

    Oracle

    select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from dual;

    DB2

    select varchar(current timestamp) from sysibm.sysdummy1;

    ■Oracle数据类型改变函数:to_char()、to_date()、to_number()等;如果仅仅取年,月,日等,可以用to_char(sysdate, 'YYYY'),to_char('MM') ,to_char('DD')取得。只取年月日TRUNC(SYSDATE),取时分秒TO_CHAR(SYSDATE,'HH24:MI:SS')。

    ■DB2数据类型改变函数:char()、varchar()、int()、date()、time()等;取得年,月,日等的写法:YEAR(current timestamp),MONTH(current timestamp),DAY(current timestamp),HOUR(current timestamp),MINUTE(current timestamp),SECOND(current timestamp), MICROSECOND(current timestamp),只取年月日可以用DATE(current timestamp),取时分秒TIME(current timestamp)。Char()是定长字符串(1-255),varchar()为非定长字符串(1-32672)
    日期,时间形态变为字符形态: char(current date),char(current time)
    将字符串转换成日期或时间形态:TIMESTAMP('2002-10-20 12:00:00'),DATE('2002-10-20'),DATE('10/20/2002'),TIME('12:00:00')

    快速清空大表

    Oracle

    truncate table TableName ;

    DB2

    alter table TableName active not logged initially with empty table;

    关于ROWID

    Oracle

    它是由数据库唯一产生的,在程序里可以获得

    DB2

    有此概念,但不能被程序获得。解决方案待定(高人请联系本人 caoxicao@hotmail.com )。

    To_Number

    Oracle

    select to_number('123') from dual;

    DB2

    select cast('123' as integer) from sysibm.sysdummy1;

    复制创建表

    Oracle

    create table a as select * from b ;

    DB2

    create table a like b ;

     
  • 相关阅读:
    Leetcode Binary Tree Preorder Traversal
    Leetcode Minimum Depth of Binary Tree
    Leetcode 148. Sort List
    Leetcode 61. Rotate List
    Leetcode 86. Partition List
    Leetcode 21. Merge Two Sorted Lists
    Leetcode 143. Reorder List
    J2EE项目应用开发过程中的易错点
    JNDI初认识
    奔腾的代码
  • 原文地址:https://www.cnblogs.com/wuxl360/p/5542711.html
Copyright © 2011-2022 走看看