Oracle常用函数
字符串拼接函数concat(字符串1,字符串2)
字符串检索函数instr(待检索字符串,检索子串[,起始检索位置])
字符串长度函数length(字符串)
字符串大小写转换函数,lower(),upper()
字符串去除两边空格 trim(),ltrim(),rtrim()
字符串替换函数replace()
字符串截取函数substr()
SELECT CONCAT('HELLO',' WORLD') FROM DUAL;
SELECT INSTR('oWo','1',2) FROM DUAL;
SELECT LENGTH('Hello') FROM DUAL;
SELECT LOWER('Hello'),UPPER('Hello') FROM DUAL;
SELECT LTRIM(' oolloo '), RTRIM(' oolloo '), TRIM(' oolloo ') FROM DUAL;
SELECT REPLACE('hello hello world','hello','Hello') FROM DUAL;
SELECT SUBSTR('Hello',2,1) FROM DUAL;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
数值函数
绝对值函数 abs()
向上取整函数 ceil()
向下取整函数 floor()
对数函数 log()
取模函数mod()
幂函数power()
四舍五入函数round()
平方根函数sqrt()
截断函数trunc()
SELECT ABS(-3) FROM DUAL;
SELECT CEIL('5.4') FROM DUAL;
SELECT FLOOR('5.4') FROM DUAL;
SELECT LOG(2,4) FROM DUAL;
SELECT MOD(8,3) FROM DUAL;
SELECT POWER(2,4) FROM DUAL;
SELECT ROUND(4.536,2) FROM DUAL;
SELECT SQRT(9) FROM DUAL;
SELECT TRUNC(4.536,2) FROM DUAL;
SELECT TRUNC(456.3,-2) FROM DUAL;
SELECT ROUND(456.3,-2) FROM DUAL;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
日期函数
月份加减函数add_months()
日期四舍五入函数round()
日期提取函数extract()
SELECT ADD_MONTHS(SYSDATE,4) FROM DUAL;
SELECT ADD_MONTHS(SYSDATE,-4) FROM DUAL;
SELECT LAST_DAY(SYSDATE) FROM DUAL;
SELECT
ROUND(SYSDATE,'YEAR'),
ROUND(SYSDATE,'MONTH'),
ROUND(SYSDATE,'DDD'),
ROUND(SYSDATE,'DAY')
FROM
DUAL;
SELECT
SYSDATE,
EXTRACT(YEAR FROM SYSDATE),
EXTRACT(MONTH FROM SYSDATE),
EXTRACT(DAY FROM SYSDATE),
EXTRACT(HOUR FROM SYSTIMESTAMP),
EXTRACT(MINUTE FROM SYSTIMESTAMP),
EXTRACT(SECOND FROM SYSTIMESTAMP)
FROM
DUAL;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
转换函数
日期或数值转字符串函数to_char()
字符串转日期函数to_date()
字符串转数值函数to_number()
SELECT
TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS')
FROM
DUAL;
SELECT
TO_CHAR(-12345.6,'L9.99999EEEEPR')
FROM
DUAL;
SELECT TO_DATE('1999-05-29 22:30','YYYY-MM-DD HH24:MI:SS') FROM DUAL;
SELECT TO_NUMBER('-$12,345.67','$99,999.99') FROM DUAL;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
其他函数
空if函数NVL(),NVL2()
SELECT NVL(NULL,'3.1415') FROM DUAL;
SELECT NVL2(NULL,1,2) FROM DUAL;