时间:2021-07-01 10:21:17 帮助过:36人阅读
POSTGRESQL | |
---|---|
select * from (select rownum r,e.* from emp e where rownum <=5) t where r>0; | select * from emp limit 5 offset 0; |
ORACLE | POSTGRESQL |
---|---|
select * from emp where rownum = 1; | select * from emp limit 1; |
ORACLE | POSTGRESQL |
---|---|
select rownum,t.* from emp t; | select row_number() over(), t.* from emp t; |
ORACLE | POSTGRESQL |
---|---|
SYSDATE | current_timestamp, current_date |
Oracle delete语句可以没有from,pg必须要有from
ORACLE | POSTGRESQL |
---|---|
delete from emp where empno = xxx; delete emp where empno = xxx | delete from emp where empno = xxx |
Oracle支持类型自动转换,例如数字自动换换为字符串等;PG中需要显示转换,或者添加CAST
PostgreSQL在from关键字后的子查询必须要有别名,Oralce可以没有。
PG having语句必须在group by之后,oracle可以在group by之前
Oracle中使用start with … connect by…, PG中使用with recusive
ORACLE | POSTGRESQL |
---|---|
select * from larearrelation where rearedgens = 1 and rearflag = 1 and rearlevel = ‘01’ connect by prior agentcode = rearagentcode start with rearagentcode = ‘10032226’; | with recursive rs as ( select * from larearrelation where rearagentcode = ‘10032226’ union all select a. *from larearrelation a, rs where a.rearagentcode = rs.agentcode ) select ** from rs where rearedgens = 1 and rearflag = ‘1’ and rearlevel = ‘01’ |
postgresql中update语句时,set的字段不能有别名
ORACLE | POSTGRESQL |
---|---|
update emp t set t.name = ‘xxx’ where t.empno = 2 | update emp set name = ‘xxx’ where empno = 2 |
oracle日期相减自动转换为数字,结果为相差的天数。 pg日期相减为interval类型,得到相差天数需要进行类型转换
oracle的递归查询中level表示查询深度(或者递归层次),在PG中没有此含义的关键字,需要自行在with recursive实现
ORACLE | POSTGRESQL |
---|---|
select max(level) from larearrelation where rearedgens = 1 and rearflag = 1 and rearlevel = ‘01’ connect by prior agentcode = rearagentcode start with rearagentcode = ‘10032226’; | with recursive rs as ( select larearrelation.*, 1 depth from larearrelation where rearagentcode = ‘10032226’ union all select a./**, rs.depth + 1 depth from larearrelation a, rs where a.rearagentcode = rs.agentcode ) select max(rs.depth) from rs where rearedgens = 1 and rearflag = ‘1’ and rearlevel = ‘01’ |
ORACLE | POSTGRESQL |
---|---|
select seqname.nextval from dual; | select nextval(‘seqname’) |
Oralce外连接支持使用 (+), PostgreSQL需使用left jion或者right join标准sql语法
oracle支持unique关键字去重复,pg中只能使用distinct
ORACLE | POSTGRESQL |
---|---|
listagg | string_agg |
ORACLE | POSTGRESQL |
---|---|
Minus | except |
null和’’在oracle中是一致的,最终都会存储为null,在PG中会进行区分
Oracle中 ! =,< >操作符中间允许有空格,PG中不可以
PG中无效的别名,可以尝试加as关键字,例如name
ORACLE | POSTGRESQL |
---|---|
SELECT REGEXP_SUBSTR(‘17,20,23’,’,+’,1,1,’i’) FROM DUAL; | select (regexp_matches(‘17,20,23’, ‘,+’))[1] |
oracle字段名大写,PG字段名小写
PostgreSQLとOracleのsql差异
标签:oralce sysdate 结果 重复 16px 需要 table reg 含义