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
复制
select to_date('
2019-
5-
11',
'yyyy-mm-dd') date1;
to_date('
2019年
5月
22日',
'yyyy"年"mm
"月"dd
"日"') date2 from dual;
to_number
复制
select to_nuber(
'1,234',
'9,999')
nvl 空值赋值
复制nvl(sal,
0)
nvl2(sal,sal,
0)
字符串处理
ltrim 删除左边空白符或指定字符
复制ltrim(
' here',
' ')
ltrim(
'---hello world',
'-')
ltrim(
' hello world')
rtrim 删除右边空白符或指定字符,与上面类似trim 删除空白符或制定字符,与上面类似
substr 截取字符
decode 条件取值
复制decode(age,
10,
'少年',
20,
'青年',中年)
--相当于
switch,age=
10,返回少年,age=
20,返回青年,其他的则返回中年
数学函数
abs 绝对值ceil 返回较大的最小整数
复制
ceil(
7.6)
floor 返回较小的最大整数
复制round(
7.6)
round 返回四舍五入的数值
复制
Select round(
100.256,
2)
from dual;
select round(
100.256,
3)
from dual;
trunc 截取
复制
Select trunc(
100.256,
2)
from dual;
select trunc(
100.256,
3)
from dual;
power 幂次方mod 取余数sqrt 平方根
转载于:https://www.cnblogs.com/chaoyang123/p/11549387.html
相关资源:JAVA上百实例源码以及开源项目