您好,登录后才能下订单哦!
本篇内容介绍了“PostgreSQL与Oracle的sql区别有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
Oracle | 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区别有哪些”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。