SELECT CHR(65) FROM DUAL;
-> A
SELECT LOWER('JENNIE') FROM DUAL;
-> jennie
SELECT UPPER('jennie') FROM DUAL;
-> JENNIE
SELECT LTRIM(' JENNIE') FROM DUAL;
-> JENNIE
SELECT LTRIM('블랙핑크', '블랙') FROM DUAL;
-> 핑크
SELECT RTRIM('JENNIE ') FROM DUAL;
-> JENNIE
SELECT RTRIM('블랙핑크', '핑크') FROM DUAL;
-> 블랙
LEADING
, TRAILING
, BOTH
SELECT (' JENNIE ') FROM DUAL;
-> JENNIE
SELECT (LEDING '블' FROM '블랙핑크') FROM DUAL;
-> 랙핑크
SELECT (TRAILING '크' FROM '블랙핑크') FROM DUAL;
-> 블랙핑
SELECT SUBSTR('블랙핑크제니', 3, 2) FROM DUAL;
-> 핑크
SELECT SUBSTR('블랙핑크제니', 3, 4) FROM DUAL;
-> 핑크제니
SELECT LENGTH('JENNIE') FROM DUAL;
-> 6
SELECT REPLACE ('블랙핑크제니', '제니', '지수') FROM DUAL;
-> 블랙핑크지수
SELECT REPLACE ('블랙핑크제니', '제니') FROM DUAL;
-> 블랙핑크
SELECT ABS(-1) FROM DUAL;
->1
SELECT SIGN(-7) FROM DUAL;
-> -1
SELECT SIGN(7) FROM DUAL;
-> 1
SELECT ROUND(163.76, ,1) FROM DUAL;
-> 163.8
SELECT TRUNC(54.29, 1) FROM DUAL;
-> 54.2
SELECT TRUNC(54.29, -1) FROM DUAL;
-> 50
SELECT CEIL(72.86) FROM DUAL;
-> 72.86
SELECT CEIL(-33.4) FROM DUAL;
-> -33
SELECT FLOOR(22.3) FROM DUAL;
-> 22
SELECT FLOOR(-22.3) FROM DUAL;
-> -23
SELECT MOD(15,7) FROM DUAL;
-> 1
SELECT MOD(15,-4) FROM DUAL;
-> 3
SELECT SYSDATE FROM DUAL;
-> 2024-03-27 17:00:00
SELECT EXTRACT(YEAR FROM SYSDATE) AS YEAR,
EXTRACT(MONTH FROM SYSDATE) AS MONTH,
EXTRACT(DAY FROM SYSDATE) AS DAY
FROM DUAL;
->
YEAR | MONTH | DAY
2024 | 03 | 27
SELECT ADD_MONTHS(TO_DATE('2021-12-31','YYYY-MM-DD'), -1) AS PREV_MOTH
ADD_MONTHS(TO_DATE('2021-12-31','YYYY-MM-DD'), 1) AS NEXT_MOTH
FROM DUAL;
-> PREV_MONTH | NEXT_MONTH
2021-11-30 00:00:00 | 2022-01-31 00:00:00
가능한 명시적 형변환하여 사용하도록 하는 것이 성능저하 및 에러발생에 대비할 수 있음.
SELECT TO_NUMBER('123') FROM DUAL;
-> 123
SELECT TO_CHAR(123) FROM DUAL;
-> '123'
SELECT TO_DATE('20240327', 'YYYYMMDD') FROM DUAL;
-> 2024-03-27
SELECT MEMBER_NO,
NVL(REVIEW_SCORE, 0) AS REVIEW_SCORE
FROM REVIEW;
-> REVIEW_SCORE가 NULL이면 0으로 반환 / NULL이 아니면 REVIEW_SCORE 반환
SELECT MEMBER_NO,
NVL(REVIEW_SCORE, 0) AS REVIEW_SCORE,
REVIEW
FROM REVIEW;
WHERE PRODUCT_ID = '100001';
-> REVIEW_SCORE 데이터가 0일 경우 NULL 반환, 아니면 REVIEW_SCORE 데이터 반환.
NULL이 아닌 최초의 인수 반환.
SELECT NAME,
COALESCE(PHONE, EMAIL, FAX) AS CONTACT
FROM MEMBERINFO;
-> NULL이면 PHONE, EMAIL, FAX 중 NULL이 아닌 것 중 순서대로 적힌 것 중 최초 인수 반환.
CASE WHEN SUBWAY_LINE='1' THEN 'BLUE'
WHEN SUBWAY_LINE='2' THEN 'GREEN'
WHEN SUBWAY_LINE='3' THEN 'ORANGE'
[ELSE 'GREY']
END
=
CASE SUBWAY_LINE
WHEN '1' THEN 'BLUE'
WHEN '2' THEN 'GREEN'
WHEN '3' THEN 'ORANGE'
[ELSE 'GREY']
END
=
DECODE(SUBWAY_LINE,'1','BLUE','2','GREEN','3','ORANGE'[,'GREY'])