1. 程式人生 > 實用技巧 >Oracle資料庫遷移PostgreSQL

Oracle資料庫遷移PostgreSQL

資料庫差異

1.函式

描述 PostgreSQL Oracle
當前時間 current_date,now() sysdate
日期格式化 to_date(text, text) to_date(text)
對時間或者數字擷取 date_trunc() trunc()
空判斷 coalesce(a, 0) nvl(a, 0)
數值型別轉換

to_number(int, text)

例: to_number(123, "666666") : text表示精度

to_number(int)
字元型別轉換 to_char(int, text) 例如 to_char(123,"666666") : text表示精度 to_char(int)
條件判斷 case...when...then decode()
偽表dual 不支援 支援

2.表連線(左連線,右連線)

oracle: 左連線 : a.id = b.id(+) ;

右連線 : a.id(+) = b.id

postgreSQL: 左連線:a left join b on a.id = b.id;

右連線:a right join b on a.id = b.id

3.分頁

oracle使用rownum分頁, postgreSQL使用limit.

注意:PostGreSQL資料分頁是利用limit
關鍵字 的,搭配子查詢,

PostGreSQL的子查詢相比較Oracle而言更嚴格,必須使用別名,

Limit放在order by後面。