oracle数据库迁移至mysql 之 sysdate格式化及运算替换

来源:互联网 发布:甘肃广电网络最新人事 编辑:程序博客网 时间:2024/06/06 02:09

例1,查询当前系统日期

select to_char(sysdate,'yyyy-mm-dd') from dual

 

 

替换为

select current_date;

或者

select curdate();

 

 

 

 

例2,查询当前系统时间

select to_char(sysdate,'hh24:mm:ss') from dual;

 

 

替换为

select curtime();

或者

select current_time;

例3,查询系统日期和时间

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

替换为

select sysdate();

或者

select now();

例4,时间戳

SELECT   systimestamp   FROM  dual;

修改为

Select Current_timestamp();

或者

Select current_timestamp;

例5,格式化日期

to_char(SYSDATE, 'yyyyMMdd')

修改为

date_format(now(),'%Y%m%d');

例6 取当前时间与数据库某列内字段值相差的分钟数

TO_NUMBER(sysdate - #olddate#) * 24 * 60

修改为

time_to_sec(timediff(now(),t.stub_generated))/60

例7 取数据库库内某列内时间前一天并格式化

to_char(to_date(#olddate#,'yyyy-MM-dd')-1,'yyyyMMdd')

修改为

date_format( date_sub(str_to_date(#unionStartDate#,'%Y-%m-%d'),interval 1 day),'%Y%m%d');

 

1 0