數據庫差異
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 |
PGSQL |
整數類型 |
integer |
smallint |
integer |
||
bigint |
||
數字類型 |
decimal(P,S) |
decimal |
number(P,S) |
numeric |
|
number(18,2) |
money |
|
可變長度的字符串 |
varchar2 |
character varying(n), varchar(n) |
varchar2(1) |
boolean |
|
固定長度的字符串 |
char |
character(n), char(n) |
日期類型 |
date |
timestamp [ (p) ] [ without time zone ] |
timestamp |
timestamp [ (p) ] with time zone |
|
|
date |
|
|
time [ (p) ] [ without time zone ] |
|
|
time [ (p) ] with time zone |
|
|
interval [ fields ] [ (p) ] |
|
字符數據 |
clob |
text |
3.表連接(左連接,右連接)
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后面。