Oracle to_timestamp

// sysdate 是取得不到毫秒的如果要取得毫秒需要用 systimestamp
SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD HH:MI:SS') FROM DUAL; // ok 无ff
SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD HH24 MI SS') FROM DUAL; // ok 无ff
select to_char(SYSDATE, 'dd-MON-yy hh.mi.ss', 'NLS_DATE_LANGUAGE=American') from dual; //ok 无ff

//[Err] ORA-01821: 日期格式无法识别 SYSDATE无毫秒
select to_char(SYSDATE, 'dd-MON-yy hh.mi.ss.ff', 'NLS_DATE_LANGUAGE=American') from dual;
//ok
select to_char(systimestamp, 'dd-MON-yy hh.mi.ss.ff', 'NLS_DATE_LANGUAGE=American') from dual;

// ok
SELECT TO_CHAR(TO_TIMESTAMP('01-APR-21 09.08.00.429000 AM','DD-MON-YY HH.MI.SS.FF AM', 'NLS_DATE_LANGUAGE=American'),'YYYY-MM-DD HH24:MI:SS') FROM DUAL;
// ok
SELECT TO_CHAR(TO_TIMESTAMP('20-APR-21 11.23.43.033389','DD-MON-YY HH24.MI.SS.FF', 'NLS_DATE_LANGUAGE=American'),'YYYY-MM-DD HH24:MI:SS') FROM DUAL;

[Err] 'HH24' 不使用上下午指示符
SELECT TO_CHAR(TO_TIMESTAMP('01-APR-21 09.08.00.429000 AM','DD-MON-YY HH24.MI.SS.FF AM', 'NLS_DATE_LANGUAGE=American'),'YYYY-MM-DD HH24:MI:SS') FROM DUAL;

[Err] ORA-01816: 只能指定一次月份 HH.MM.SS.FF -> HH24:MI:SS.FF
select to_timestamp('20-APR-21 11.23.43.033389','DD-MON-YY HH24.MM.SS.FF') from dual;

[Err] ORA-01843: 无效的月份 中文系统环境的数据库无法识别APR月份 NLS_DATE_LANGUAGE
select to_timestamp('20-APR-21 11.23.43.033389','DD-MON-YY HH24.MI.SS.FF') from dual;

[Err] ORA-01877: 内部缓冲区的字符串太长
select to_timestamp('20-4月-21 11.23.43.033389','DD-MON-YY HH24.MI.SS.FF') from dual;

[Err] ORA-01877: 内部缓冲区的字符串太长
select to_timestamp('20-APR-21 11.23.43.033389','DD-MON-YY HH24.MI.SS.FF', 'NLS_DATE_LANGUAGE=American') from dual;

select to_timestamp('20-APR-21 11.23.43.033389','DD-MON-YY HH24.MI.SS.FF', 'NLS_DATE_LANGUAGE=American') from dual;

// ok
select extract(year from to_timestamp(to_char(systimestamp, 'yyyy-mm-dd hh24.mi.ss.FF'), 'yyyy-mm-dd hh24.mi.ss.FF')) from dual;
// ok
select extract(year from to_timestamp(to_char(systimestamp, 'DD-MON-YY hh24.mi.ss.FF', 'NLS_DATE_LANGUAGE=American'), 'DD-MON-YY hh24.mi.ss.FF', 'NLS_DATE_LANGUAGE=American')) from dual;

[Err] ORA-01877: 内部缓冲区的字符串太长
SELECT to_timestamp(to_char(systimestamp, 'DD-MON-YY hh24.mi.ss.FF', 'NLS_DATE_LANGUAGE=American'), 'DD-MON-YY hh24.mi.ss.FF', 'NLS_DATE_LANGUAGE=American') from dual;

posted @ 2021-04-20 20:40  叔叔不骗你  阅读(5758)  评论(0编辑  收藏  举报