Oracle数据库移植到Aurora(PostgreSQL)数据库,SQL修正

实现业务

为迎接双11之类活动,增加服务器承载能力,将原有数据库进行升级,用户数据相关依然保存在原服务器,其他数据保存在谷歌云。

空文字

Oracle SQL
select * from 表名 where 字段 is not null
PostgreSQL
select * from 表名 where 字段 is not null and 字段 <> ‘’

substr

第一种情况
Oracle SQL
select * from 表名 p where substr(p.字段,0,4) = xx
PostgreSQL
select * from 表名 p where substr(p.字段,1,4) = xx
第二种情况
Oracle SQL
select * from 表名 where substr(字段,-3) = xx
PostgreSQL
select * from 表名 where substr(字段,’…$’) = xx

Rownum

第一种情况
Oracle SQL
select ‘test001’ as a from dual where rownum=1
PostgreSQL
select a from(select ‘test001’ as a,row_number() over () as rownum) r where rownum=1
第二种情况
Oracle SQL
select ‘test001’ as a from dual where rownum= ‘xx’
PostgreSQL
select a from(select ‘test001’ as a,row_number() over () as rownum) r where rownum <= to_number(#{xx},‘9999’)

sysdate

Oracle SQL
insert 表名(字段) values(sysdate)
PostgreSQL
insert 表名(字段)values(current_timestamp)

子查询别名

Oracle SQL
select * from (select ‘test001’ as a from dual) where a =‘test001’;
PostgreSQL
select * from(select ‘test001’ as a) r where a=‘test001’;

to_date

第一种情况
Oracle SQL
select to_date(‘20200101’) from dual;
PostgreSQL
select to_date(‘20200101’,‘yyyyMMdd’);
第二种情况
Oracle SQL
select to_date(‘20200101’||‘23:59:59’,‘YYYYMMDD
HH24:MI:SS’) from dual;
PostgreSQL
select to_timestamp(‘20200101’||‘23:59:59’,‘YYYYMMDD HH24:MI:SS’)

月的计算 add_months

Oracle SQL
select add_months(to_date(‘20200101’,‘yyyyMMdd’),‘MM’) from dual;
PostgreSQL
select to_date(‘20200101’,‘yyyyMMdd’)-interval ‘24 month’;

trunc

Oracle SQL
select trunc(to_date(‘20200101’,‘yyyyMMdd’),‘MM’) from dual;
PostgreSQL
select date_trunc(‘month’,to_date(‘20200101’,‘yyyyMMdd’));

between…to…

Oracle SQL
select * from 表名 where 字段 between to_number(‘20200901’) and ‘20200930’;
PostgreSQL
select * from 表名 where to_number(字段,‘99999999’) between to_number(‘20200901’,‘99999999’) and to_number(‘20200930’,‘99999999’);

to_char

Oracle SQL
select to_char(#{regTms},‘YYYYMMDD’) from dual;
※#{regTms}=2020-08-28 00:00:00.0

猜你喜欢

转载自blog.csdn.net/qq_41520636/article/details/110239511
今日推荐