oracle日期转换

来源:互联网 发布:全民淘宝客能挣钱吗 编辑:程序博客网 时间:2024/06/06 17:25
--To_date格式
    --to_date(字符串,’yyyymm’) 201201
    select to_date(201611,'yyyymm')  from dual;
    --to_date(字符串,’yyyy-mm’)
    select to_date(201611,'yyyy-mm') from dual;
    --to_date(字符串,’yyyymmdd’) 
    select to_date(20161116,'yyyymmdd') from  dual;
    --to_date(字符串,’yyyy-mm-dd’)
    select to_date(20161116,'yyyy-mm-dd') from dual;
    --to_date(字符串,’yyyymmdd hh’)
    select to_date(2016111610,'yyyymmdd hh') from dual;
    --to_date(字符串,’yyyy-mm-dd hh’)
    select to_date(2016111610,'yyyy-mm-dd hh') from dual;
    select to_date(2016111616,'yyyy-mm-dd hh24') from dual;
    --to_date(字符串,’yyyymmdd hh24:mi’)
    select to_date(201611161651,'yyyymmdd hh24:mi') from dual;
    --to_date(字符串,’yyyymmdd hh24:mi:ss’) 
    select to_date(20161116165143,'yyyymmdd hh24:mi:ss') from dual;
    --sysdate
    select sysdate from dual;
--To_char语法
    --to_char(日期,’d’)—返回值为本周第几天;
    select to_char(sysdate,'d') from dual;
    --to_char(日期,’dd’)—返回值为本月第几天;
    select to_char(sysdate,'dd') from dual;
    --to_char(日期,’w’)—返回值为本月第几周
    select to_char(sysdate,'w') from dual;
    --to_char(日期,’ww’)—返回值为本年第几周
    select to_char(sysdate,'ww') from dual;
    --to_char(日期,’mm’)—返回值为日期月份
    select to_char(sysdate,'mm') from dual;
    --to_char(日期,’yyyy’)—返回值为年
    select to_char(sysdate,'yyyy') from dual;
    --to_char(日期,’yyyymm’)—返回值为年月
    select to_char(sysdate,'yyyymm') from dual;
    --to_char(日期,’yyyymmdd’)—返回值为年月日
    select to_char(sysdate,'yyyymmdd') from dual;
    --to_char(日期,’yyyymmdd hh24’)—返回值为年月日时
    select to_char(sysdate,'yyyymmdd hh24') from dual;
    --to_char(日期,’yyyymmdd hh24:mi’)—返回值为年月日时分
    select to_char(sysdate,'yyyymmdd hh24:mi') from dual;
    --to_char(日期,’yyyymmdd hh24:mi:ss’)—返回值为年月日时分秒
    select to_char(sysdate,'YYYYMMDD HH24:MI:SS') from dual; 
    
    
0 0
原创粉丝点击