oracle 常用函数 -持续更新

函数分为单行函数和多行函数

单行函数
单行函数对每一行都会执行输出结果

函数参数描述
ascii(x)x:任意字符返回指定字符对应的十进制数

举例:

select ascii('A') A,ascii('a') A,ascii('0') zero from dual;
函数参数描述
chr(x)x:数字给定数字返回对应字符

举例:

select chr(54740) zhao,chr(65) chr65 from dual;
函数参数描述
concat(x,y)x:

举例:

select concat('你好啊~','我的朋友!'),concat (xm,'你好!')  from emp;
等同于:select '你好啊~'||'我的朋友!',xm||'你好!'  from emp;
函数参数描述
initcap(x)x:字符串返回字符串并将首字母大写

举例:

select initcap('smith') hh from dual;
函数参数描述
instr(c1,c2,i,j)c1:被搜索的字符串 c2:希望搜索到的字符串 i:搜索开始的位置,默认为1 j:出现的位置,搜索到第几个时结束返回字符串并将首字母大写

举例:

select  instr('asdfgasdfg','as',1,2) from dual;
函数参数描述
length( c)c:字符串返回字符串的长度,中文和英文字符相同长度

举例:

select length('小腿') from dual; //结果2
函数参数描述
upper( c)c:字符串将字符串中英文字母转换为大写

举例:

select upper('adc 的') from dual;
函数参数描述
exp( n)n:数字获取e 的n次方

举例:

select exp(8) from dual;
函数参数描述
power( m,n)m:底数 n:指数计算m的n 次方值

举例:

select power(2,8) from dual;
函数参数描述
round( m,n)m:要四舍五入的数 n:指定的位数 大于0时表示要保留的小数,小于0时表示从个位向左的第几位开始四舍五入四舍五入

举例:

select round(234.456,2),round(234.456,-2) from dual;
函数参数描述
trunc( m,n)m:要截取的数 n:指定的位数 大于0时表示从小数点后几位开始截取,小于0时表示从个位向左的第几位开始截取,个位到该位换成0截取数

举例:

select trunc(210.546,2),trunc(234.456,-2) from dual; -- 210.54 200
函数参数描述
add_months( date,n)date:日期 n 增加几个月 大于0时表示增加,小于0时表示减少,必须为整数增加月份

举例:

select add_months(to_date('1999-06-12','yyyy-mm-dd'),2) from dual; 
函数参数描述
to_char( str,formatStr)str:日期字符/其他字符 formatStr:格式化字符按指定格式转换为字符串

yyyy :
mm:
dd:
hh24: 24小时制 时
hh12: 12小时制 时
mi:
ss:
举例:

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss' ) from dual; 
函数参数描述
trim( tstr from str)tstr:要被去掉的字符 不填时默认为空格,只能有一个字符 str:字符串去掉首位指定的字符

举例:

select trim('a' from 'aaddffaa' ) from dual;  -- ddff
函数参数描述
last_day( date)date:日期返回指定日期的最后一天

举例:

select last_day(sysdate) from dual;
函数参数描述
moths_between( date1,date2)date1: 指定日期1 date2:指定日期2返回date1与date2 之间相隔的月份(date1-date2)

举例:

select months_between(to_date('1998-03-22','yyyy-mm-dd'),to_date('1998-04-22','yyyy-mm-dd')) from dual;
函数参数描述
next_day( date,str)date: 指定日期 str:星期几 如 星期一、星期二返回距离date 最近的下一个星期几的日期

举例:

select next_day(sysdate,'星期二') from dual;
函数参数描述
decode( n,match1,data1,match2,data2,…)n: 被匹配的变量 match1:匹配字符1,data1:返回内容1将变量进行匹配,返回对应的内容,类似于switch,未匹配到返回空字符

举例:

select decode( 10 ,10,'10号部门'20'20hao',30,'30hao') from dual;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值