1. 程式人生 > >oracle常用函式案例

oracle常用函式案例

--INSTR函式
SELECT INSTR(' HELLO WORLD','H') FROM DUAL;
--LTRIM RTRIM函式
SELECT LTRIM('*HELLO=','*') FROM DUAL;
SELECT RTRIM('=HELLO=','=') FROM DUAL;
SELECT RTRIM(LTRIM('*HELLO*','*'),'*') FROM DUAL;
--TRIM函式
SELECT TRIM('*'FROM'*HELLO*') FROM DUAL;
--REPLACE函式
SELECT REPLACE('ABCDE','E','123') FROM DUAL;
--SUBSTR函式 SELECT SUBSTR('ABCDE',2,2) FROM DUAL; --CEIL FLOOR函式 SELECT CEIL(6.01) FROM DUAL; SELECT FLOOR(6.999) FROM DUAL; --ROUND函式 SELECT ROUND(3.456,1) FROM DUAL; --TRUNC函式 SELECT TRUNC(3.456,1) FROM DUAL; --RXTRACT函式 SELECT SYSDATE "DATE", EXTRACT(YEAR FROM SYSDATE) "YEAR", EXTRACT(
MONTH FROM SYSDATE) "MONTH", EXTRACT(DAY FROM SYSDATE) "DAY", EXTRACT(HOUR FROM SYSTIMESTAMP) "HOUR",--HOUR匹配的結果沒有加上時區,在中國執行的結果要小8個小時 EXTRACT(MINUTE FROM SYSTIMESTAMP) "MINUTE", EXTRACT(SECOND FROM SYSTIMESTAMP) "SECOND" FROM DUAL; --TO_CHAR函式 SELECT TO_CHAR(SYSDATE,'YYYY"年"MM"月"DD"日" HH24:MI:SS') "DATE"
FROM DUAL