Oracle:三大类型转换

三大类型:varcher2,number,date,转换方式有两种:显式和隐式,这里主要学习显式。
日期格式元素:
格式 说明 举例
YYYY Full year in numbers 2011
YEAR Year spelled out(年的英文全称) twenty eleven
MM Two-digit value of month 月份(两位数字) 04
MONTH Full name of the month(月的全称) 4月
DY Three-letter abbreviation of the day of the week(星期几) 星期一
DAY Full name of the day of the week 星期一
DD Number day of the month
02

时间格式:
格式 举例
HH24:MI:SS AM 15:45:32 PM

数字格式:
9 数字,0-9中任意一值
0
$ 美元符
L 本地货币符号
. 小数点
, 千位符

1、使用to_char(日期,‘格“常量”式')函数将日期转成字符串:

      例1:显示如下格式:2018年05月10日 星期四
      selelct to_char(sysdate,'yyyy"年"mm"月"dd"日"day');
      例2:显示格式:2015-04-25 今天是星期六 15:15:15
      select to_char(sysdate,'yyyy-mm-dd"今天是"day hh24:mi:ss');
2、使用to_char(数值,格式)函数将数值转成字符串。
      例1:显示格式:$1,234
        select to_char(1234,'$9,999') from clual;
      例2:显示格式:¥1,234
        select to_char(1234,'L9,999') from clual;
3、使用to_char('字符串','格式')函数,将字符串转成date类型:
      例:chax 1980年12月17日入职的员工
          select * from emp
          where hiredate=todate('1980年12月17日','yyyy"年"mm"月"dd"日"');
4、使用to_number('字符串')函数将字符串转成数字。

猜你喜欢

转载自blog.csdn.net/weixin_41113108/article/details/80274345