[Share]Oracle遷移到DB2常用轉換

來源:互聯網
上載者:User

因為項目需要,要將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 ;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.