05-oralce转换函数

to_char() 设置日期的显示格式

to_char()  进行数字格式化{如:to_char(987654321.789,'999,999,999,999,999.9999') 将数字三位一逗号显示}

--to_char(sysdate,'yyyy-mm-dd')日期以年月日显示

--to_char(sysdate,'mm') 只取出日期中的月份

--年月日显示

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

SYSDATE TO_CHAR(SY
------------ ----------
13-APR-19 2019-04-13

--日月年显示

select sysdate,to_char(sysdate,'dd-mm-yyyy') 日月年 from dual;

select sysdate,
to_char(sysdate,'yyyy') 单取年,
to_char(sysdate,'mm') 单取月,
to_char(sysdate,'dd') 单取日
from dual;

--查询雇佣日期为2月的员工信息
select * from emp where to_char(hiredate,'mm')='02';

--to_char() 将数字格式化显示

select
to_char(987654321.789,'999,999,999,999,999.9999') 将数字三位一逗号显示,
to_char(987654321.789,'000,000,000,000,000.0000')将数字三位一逗号显示
from dual;

select
to_char(987654321.789,'L999,999,999,999,999.9999') L以本地环境显示货币符号,
to_char(987654321.789,'$000,000,000,000,000.0000')设置以$符号显示货币
from dual;

--to_date() 将字符串转换为日期

select
to_date('1922-10-15','yyyy-mm-dd') 字符串转换为日期
from dual;

select sysdate,
to_char(sysdate,'yyyy-mm-dd hh:mi:ss') 以年入月日显示,
to_char(/*'1992-11-2'*/sysdate,'mm') 取出日期中的月份,
to_char('987654321.345','999,999,999,999.9999') 格式化字符串3位1逗号显示,
to_date('1992-11-2','yyyy-mm-dd') 将字符转为日期
from dual;

原文地址:https://www.cnblogs.com/joeshang/p/10703072.html