Substr与substrb 字符串截取函数,负数代表从右开始截取
SQL> select substr('我是中国人',2) from dual;
SUBSTR('我是中国人',2)
----------------------
是中国人
SQL> select substrb('我是中国人',2) from dual;
SUBSTRB('我是中国人',2)
-----------------------
是中国人
SQL> select substr('我是中国人',-2) from dual;
SUBSTR('我是中国人',-2)
-----------------------
国人
SQL> select substrb('我是中国人',-2) from dual;
SUBSTRB('我是中国人',-2)
------------------------
人
Length与lengthb 长度计算函数
SQL> select length('我是中国人') from dual;
LENGTH('我是中国人')
--------------------
5
SQL> select lengthb('我是中国人') from dual;
LENGTHB('我是中国人')
---------------------
10
Instr与Instrb 字符串查找函数 instr(原字符串,查的字符串,起始位置,第几个匹配) 返回字符串位置,找不到返回0 .
SQL> select Instr('abcabcdabcdef','a',1,3) from dual;
INSTR('ABCABCDABCDEF','A',1,3)
------------------------------
8
Upper与lower 大小写转换函数
SQL> select upper('AaBbCc') from dual;
UPPER('AABBCC')
---------------
AABBCC
SQL> select lower('AaBbCc') from dual;
LOWER('AABBCC')
---------------
aabbcc
Trim/Rtrim/Ltrim 字符串trim函数
SQL> select trim(' A B ') from dual;
TRIM('AB')
----------
A B
SQL> select rtrim('xABx','x') from dual;
RTRIM('XABX','X')
-----------------
xAB
SQL> select ltrim('xABx','x') from dual;
LTRIM('XABX','X')
-----------------
ABx
Trunc 截取函数(不进行四舍五入)
SQL> select trunc(1234.123456,'-2') from dual;
TRUNC(1234.123456,'-2')
-----------------------
1200
SQL> select trunc(1234.123456,'2') from dual;
TRUNC(1234.123456,'2')
----------------------
1234.12
SQL> select trunc(1234.123456,'4') from dual;
TRUNC(1234.123456,'4')
----------------------
1234.1234
SQL> select trunc(1234.123456,'5') from dual;
TRUNC(1234.123456,'5')
----------------------
1234.12345
SQL> select trunc(sysdate,'yy') from dual;
TRUNC(SYSDATE,'YY')
-------------------
2007-01-01
SQL> select trunc(sysdate,'mi') from dual;
TRUNC(SYSDATE,'MI')
-------------------
2007-10-01 11:55:00
SQL> select trunc(sysdate,'dd') from dual;
TRUNC(SYSDATE,'DD')
-------------------
2007-10-01
SQL> select trunc(sysdate,'day') from dual;
TRUNC(SYSDATE,'DAY')
--------------------
2007-09-30
Next_day与last_day
SQL> select sysdate from dual;
SYSDATE
-----------
2007-10-01
SQL> select next_day(sysdate,'星期一') from dual;
NEXT_DAY(SYSDATE,'星期一')
--------------------------
2007-10-08 11:57:29
SQL> select next_day(sysdate,1) from dual;
NEXT_DAY(SYSDATE,1)
-------------------
2007-10-07 11:57:42
SQL> select next_day(sysdate,2) from dual;
NEXT_DAY(SYSDATE,2)
-------------------
2007-10-08 11:57:56
SQL> select last_day(sysdate) from dual;
LAST_DAY(SYSDATE)
-----------------
2007-10-31 12:00:
Round 四舍五入函数
SQL> select round(123.456,2) from dual;
ROUND(123.456,2)
----------------
123.46
SQL> select round(123.456,-2) from dual;
ROUND(123.456,-2)
-----------------
100
SQL> select round(123.456,-1) from dual;
ROUND(123.456,-1)
-----------------
120
Ceil与floor 取整函数
SQL> select ceil(1.1) from dual;
CEIL(1.1)
----------
2
SQL> select floor(9.9) from dual;
FLOOR(9.9)
----------
9
Decode与nvl Decode相当于一个三元运算函数 nvl 如果值为空时默认值.