oracle学习笔记(九) SQL常用函数说明以及使用

mac2022-06-30  97

SQL常用函数说明以及使用

以下补充以下常用的函数,更多的请看oracle函数API文档

to_char

复制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 --毫秒级时间戳,插入一条数据会自动填写 );

to_date

复制--将2019-5-11字符串转为date类型 select to_date('2019-5-11','yyyy-mm-dd') date1; --2019年5月22日字符串转为date类型 to_date('2019522日','yyyy"年"mm"月"dd"日"') date2 from dual;

to_number

复制select to_nuber('1,234','9,999') --第二个参数,是格式

nvl 空值赋值

复制nvl(sal,0) --不为空,返回sal,如果为空,就返回0 nvl2(sal,sal,0) --不为空,返回工资本身,为空,返回0

字符串处理

ltrim 删除左边空白符或指定字符 复制ltrim(' here',' ') --删除空白符(空格) ltrim('---hello world','-') --删除“-”,最终结果显示为hello world ltrim(' hello world') --删除空格 rtrim 删除右边空白符或指定字符,与上面类似trim 删除空白符或制定字符,与上面类似

substr 截取字符

decode 条件取值

复制decode(age,10,'少年',20,'青年',中年) --相当于switch,age=10,返回少年,age=20,返回青年,其他的则返回中年

数学函数

abs 绝对值ceil 返回较大的最小整数 复制ceil(7.6) --返回8 floor 返回较小的最大整数 复制round(7.6) --返回7 round 返回四舍五入的数值 复制Select round(100.256,2) from dual; --返回100.26 select round(100.256,3) from dual; --返回100.256 trunc 截取 复制Select trunc(100.256,2) from dual; --返回100.25 select trunc(100.256,3) from dual; --返回100.256 power 幂次方mod 取余数sqrt 平方根

转载于:https://www.cnblogs.com/chaoyang123/p/11549387.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)