目前正在做一个项目得数据库迁移(oracle->postgresql),查找了一些资料将2者得差异整理如下:
ORACLE 与 PostgreSQL差别 | |||
NO | 问题点 | Oracle | PostgreSQL |
1 | DUAL | SELECT 1+1 FROM DUAL | SELECT 1+1
|
2 | NEXTVAL | SELECT A_TABLE_SEQUENCE.NEXTVAL FROM DUAL |
SELECT NEXTVAL('A_TABLE_SEQUENCE')
|
3 | ROWNUM | ①SELECT * FROM AGE_TYPE WHERE ROWNUM<=5 |
①SELECT *
|
②SELECT * FROM AGE_TYPE WHERE CODE IS NOT NULL AND ROWNUM<=5 ORDER BY CODE DESC |
②SELECT *
|
||
4 | (+) | ①SELECT * FROM A_TABLE A , B_TABLE B WHERE A.ID(+)=B.ID |
①SELECT *
|
②SELECT * FROM A_TABLE A , B_TABLE B WHERE A.ID(+)=B.ID AND A.COL1='COL1_VALUE' |
②SELECT *
|
||
③SELECT * FROM A_TABLE A, B_TABLE B,C_TABLE C,D_TABLE D WHERE A.ID=B.ID(+) AND A.ID=C.ID(+) AND A.COL1=D.COL1 |
③SELECT *
|
||
④!!! SELECT * FROM A_TABLE A WHERE A.COL1(+)=0 AND A.COL2(+) ='A_VALUE2' |
④!!!
|
||
5 | AS | SELECT A.COL1 A_COL1, A.COL2 A_COL2 FROM A_TABLE A |
SELECT A.COL1 AS A_COL1,
|
6 | NVL | SELECT NVL(SUM(VALUE11),0) FS_VALUE1, NVL(SUM(VALUE21),0) FS_VALUE2 FROM FIELD_SUM |
SELECT COALESCE(SUM(VALUE11),0) AS FS_VALUE1,
|
7 | TO_ NUMBER |
SELECT COL1 FROM A_TABLE ORDER BY TO_NUMBER(COL1) |
SELECT COL1
|
8 | DECODE | SELECT DECODE(ENDFLAG,'1','A','B') ENDFLAG FROM TEST |
SELECT
|
9 | 时间 问题 |
UPDATE A_TABLE SET ENTREDATE=SYSDATE |
UPDATE A_TABLE
|
SELECT TO_DATE('20010203','YYYY-MM-DD') AS DAY FROM DUAL |
SELECT TO_DATE('20010203','YYYYMMDD') AS DAY
|
||
SELECT TO_DATE(SYSDATE,'YYYY-MM-DD') AS DAY FROM DUAL |
SELECT TO_DATE(CURRENT_DATE,'YYYY-MM-DD') AS DAY
|
||
SELECT TO_DATE(SYSDATE,'YYYY/MM/DD') AS DAY FROM DUAL |
SELECT TO_DATE(CURRENT_DATE,'YYYY/MM/DD') AS DAY
|
||
10 | || | SELECT NULL||'-'||NULL AS VALUES1 FROM DUAL |
SELECT COALESCE(NULL,'')||'-'||COALESCE(NULL,'') AS VALUES1
|
11 | aggregate | SELECT ROUND(AVG(SUM(BASICCNT1))) BASICCNT FROM ACCESS_INFO_SUM1_V WHERE YEARCODE BETWEEN '200305' AND '200505' GROUP BY SCCODE |
SELECT ROUND(AVG(AIV.BASICCNT)) AS BASICCNT
|
12 | 「"」 | ①SELECT LENGTH('') AS VALUE1 FROM DUAL [Result]VALUE1=NULL |
①SELECT LENGTH('') AS VALUE1 FROM DUAL
|
②SELECT TO_DATE('','YYYYMMDD') AS VALUE2 FROM DUAL [Result]VALUE2=NULL |
②SELECT TO_DATE('','YYYYMMDD') AS VALUE2
|
||
③SELECT TO_NUMBER('',1) AS VALUE3 FROM DUAL [Result]VALUE3=NULL |
③SELECT TO_NUMBER('',1) AS VALUE3 FROM DUAL
|
||
④INSERT INTO TEST(VALUE4)VALUES('') [Result]VALUE4=NULL (注:VALUE3字段 为 数 值 类 型) |
④INSERT INTO TEST(VALUE4)VALUES('')
|
||
⑤INSERT INTO TEST(VALUE5)VALUES('') [Result]VALUE5=NULL (注:VALUE5字段 为 字符 类 型) |
⑤INSERT INTO TEST(VALUE5)VALUES('')
|
||
⑥INSERT INTO TEST(VALUE6)VALUES(TO_DATE('','YYYYMMDD')) [Result]VALUE6=NULL (注:VALUE6字段 为时间类 型) |
⑥INSERT INTO TEST(VALUE6)VALUES(TO_DATE('','YYYYMMDD'))
|
||
13 | CEIL | SELECT CEIL(SYSDATE - TO_DATE('20051027 14:56:10','YYYYMMDD HH24:MI:SS')) AS DAYS FROM DUAL |
SELECT
|
14 | NULLIF | 无NULLIF函数 | SELECT NULLIF(VALUE1,VALUE2) AS COL1 FROM DUAL
|
15 | CONCAT | CONCAT(CHAR,CHAR) | 创建函数来解决
|
16 | ADD_ MONTHS |
add_months(date, int) | 创 建函数来解决
|
17 | LAST _DAY |
LAST_DAY(DATE) | 创 建函数来解决
|
18 | MONTHS _BETWEEN |
MONTH_BETWEEN(DATA,DATA) | 创 建函数来解决
|
19 | GRE~ ATEST |
GREATEST (LEAST) | 创 建函数来解决
|
20 | BITAND | BITAND(int,int) | SELECT 値 & 値;
|
21 | 子条件 | 在FROM子条件中字段 须有列名,
|
|
22 | MINUS | MINUS | 以EXCEPT来替代
|
23 | BIN_ TO_ NUM |
SELECT BIN_TO_NUM(1,0,1,0) AS VALUE1 FROM DUAL | SELECT CAST(B'1010' AS INTEGER) AS VALUE1 |