oracle 转换函数

转换函数

字符串数值和日期三类数据之间是可以实现转换的

No.

函数名

含义

1

字符串 to_char( | 日期,格式)

将日期或数字按格式转为字符串

2

日期 to_date( | 字符串,格式)

将字符串按格式转为日期

3

数字 to_number( | 字符串)

将字符串转为数字

to_char()

一、日期变为字符串必须指定转换的格式

日期yyyymmdd

时间hh hh24miss

数字任意数字9,货币L

  不可以直接显示年月日 可以用||来实现

示例1将日期显示格式化

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

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

示例2:查询所有在4月份雇佣的雇员。

select * from emp where to_char(hiredate,'mm')='04';

select * from emp where to_char(hiredate,'mm')=4; --自动转型

示例3:将数字格式化显示,使用货币格式化显示。

select to_char('4758475847583','9,9999,9999,9999') from dual;

select to_char('4758475847583','L9,999,999,999,999') from dual;

将字符串变为日期

          

示例4:将指定字符串按照格式转化为日期

select to_date('2017-11-21','yyyy-mm-dd') from dual;

、将字符串转化为数字。

        没什么意义

示例5to_number()演示。

select to_number('12')+to_number('1') from dual;

select '12'+'1' from dual;

原文地址:https://www.cnblogs.com/dongweichang/p/7878546.html