oracle常用函数

当前日期加1天
SQL> select sysdate, sysdate+1 from dual ;

SYSDATE             SYSDATE+1
——————- ——————-
2015-10-29 21:40:46 2015-10-30 21:40:46


当前日期加1个月
SQL> select sysdate, add_months(sysdate,1) from dual ;

SYSDATE             ADD_MONTHS(SYSDATE,1)
——————- ——————-
2015-10-29 21:41:43 2015-11-29 21:41:43

 

两个时间相差多少天
SQL> select to_date('2015-10-02 11:30:00','yyyy-mm-dd hh:mi:ss')-to_date('2015-10-01 11:30:00','yyyy-mm-dd hh:mi:ss') from dual; 

TO_DATE('2015-10-0211:30:00',')
——————- ——————-
1

 

 

1. concat (x, y)  连接x和y

 

select concat('w', 'o') from dual; --wo

 

2. length(x)      返回x的长度值

 

select length('hello') from dual; --5

 

3. substr(x, start, [length])    截取字符串

start为负数的话,表示从右端数到start,然后截取该位置的左到右length个字符

 

select substr('ABCDE',1,3) from dual;--ABC

select substr('ABCD',-3,3) from dual;--BCD

 

4. instr(sourceString,destString,start,appearPosition)  返回找到字符串的位置

    instr('源字符串' , '目标字符串' ,'开始位置','第几次出现')

当起始位置为负数的时候,从右边开始找,返回找到字符的从左至右的位置

 

select instr('contact','c',1,2) from dual; --6

select instr('contact','c',-1,2) from dual;--1

 

5. lower (string)        将字符转成小写

 

select lower('HELLO') from dual;--hello

 

6. upper(string)         将字符转成大写

 

select upper('hello') from dual;  --HELLO

 

7. initcap(string)       将字符串首字母转成大写

 

select initcap('hello') from dual;--Hello

 

8. replace(string, x, y) 在string中用y替换x

 

select replace('aabcc and bbc','b','d') from dual;--aadcc and ddc

 

9. translate(string, x, y)

 

针对x中每一个字符的位置,并检查y的相同位置,然后用该位置的字符替换 string中的字符。

 

select translate('accd','cd','ef') from dual;--aeef

select translate('深圳北京深大圳','深圳','华强南') from dual;--华强北京华大强

 

10. lpad(x,n [,y])        字符串的左侧填充一些字符

select lpad('hello',8,'*') from dual;--***hello

select lpad('hello',3,'*') from dual;--hel

 

11. rpad(x, n [,y])       字符串的右侧填充一些字符

select rpad('hello',8,'*') from dual;--hello***

select rpad('hello',3,'*') from dual;--hel

 

12. ltrim(x,y)  

慎用,从最左边第一个字符开始,在x中截掉y中包含的每一个字符,一旦在x的字符中遇到y中没有的字符则结束 .

 

select ltrim('abcdab','a') from dual; --bcdab

select ltrim('abbdab','ab') from dual;--dab

 

13. rtrim(x,y) 同上

 

select rtrim('abcdef', 'f') from dual;--abcde

select rtrim('abcdfe', 'f') from dual;--abcdfe

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值