以下补充以下常用的函数,更多的请看oracle函数API文档
to_char(8.58,'9.99')
to_char(8.50,'9.00')
to_char(8.50,'9.99')
create table employee(
id number,
crete_date date timestamp default localtimestamp --毫秒级时间戳,插入一条数据会自动填写
);
--将2019-5-11字符串转为date类型
select to_date('2019-5-11','yyyy-mm-dd') date1;
--2019年5月22日字符串转为date类型
to_date('2019年5月22日','yyyy"年"mm"月"dd"日"') date2 from dual;
select to_nuber('1,234','9,999') --第二个参数,是格式
nvl(sal,0)
--不为空,返回sal,如果为空,就返回0
nvl2(sal,sal,0)
--不为空,返回工资本身,为空,返回0
ltrim(' here',' ') --删除空白符(空格)
ltrim('---hello world','-') --删除“-”,最终结果显示为hello world
ltrim(' hello world') --删除空格
substr
截取字符
decode(age,10,'少年',20,'青年',中年)
--相当于switch,age=10,返回少年,age=20,返回青年,其他的则返回中年
ceil(7.6)
--返回8
round(7.6)
--返回7
Select round(100.256,2) from dual; --返回100.26
select round(100.256,3) from dual; --返回100.256
Select trunc(100.256,2) from dual; --返回100.25
select trunc(100.256,3) from dual; --返回100.256
原文:https://www.cnblogs.com/kexing/p/10863806.html