-- 문자 함수
-- CHR(N): ACSII 값을 문자로 변환
SELECT 1 FROM DUAL; -- DUAL 가상테이블
SELECT CHR(65) FROM DUAL;
SELECT CHR(249) FROM DUAL;
SELECT 'AAAA' || CHR(97) || 'BBBB'
FROM DUAL;
-- LPAD(RPAD) : 나머지를 특정 문자로 채움
SELECT LPAD('BBB', 10) FROM DUAL;
SELECT LPAD('BBB', 10, '-') FROM DUAL;
SELECT RPAD('BBB', 10) FROM DUAL;
SELECT RPAD('BBB', 10, '-') FROM DUAL;
--INSTR: indexOf
SELECT INSTR('A1234B5678A1234B', 'A')
FROM DUAL;
-- 숫자 이후에 나오는 위치
SELECT INSTR('A1234B5678A1234B', 'A', 2)
FROM DUAL;
SELECT INSTR('A1234B5678A1234B', 'B', 7)
FROM DUAL;
-- 처음부터 순서대로 읽음
SELECT INSTR('A1234B5678A1234B', 'B', 1, 1)
FROM DUAL;
SELECT INSTR('A1234B5678A1234B', 'B', 1, 2)
FROM DUAL;
-- REPLACE : 문자열 치환(문자열)
SELECT REPLACE('AAAAAAVVVVSXACDA', 'A')
FROM DUAL;
SELECT REPLACE('AAAAAAVVVVSXACDA', 'A', 'ㄱ')
FROM DUAL;
SELECT REPLACE('AAAAAAVVVVSXACDA', 'AA', 'ㄱ')
FROM DUAL;
-- TRANSLATE : 문자 치환(한문자)
SELECT TRANSLATE('AAAAAAVVVVSXACDA', 'A', 'ㄱ')
FROM DUAL;
SELECT TRANSLATE('AAAAAAVVVVSXACDA', 'AA', 'ㄱ')
FROM DUAL;
-- 숫자 함수
SELECT CEIL(13.1) -- 14
FROM DUAL;
SELECT FLOOR(13.5) -- 13
FROM DUAL;
-- 나눈 나머지
SELECT MOD(5, 3) -- 2
FROM DUAL;
SELECT MOD(5, 7) -- 5
FROM DUAL;
-- 승수
SELECT POWER(2, 3) -- 8
FROM DUAL;
-- 반올림
SELECT ROUND(13.5)
FROM DUAL;
-- 부호
SELECT SIGN(13.4) -- + == 1
FROM DUAL;
SELECT SIGN(0) -- == 0
FROM DUAL;
SELECT SIGN(-1.4) -- == -1
FROM DUAL;
-- 버림
SELECT TRUNC(13.123456) -- 13
FROM DUAL;
SELECT TRUNC(13.123456, 3) -- 13.123
FROM DUAL;
SELECT TRUNC(13.123456, -1)
FROM DUAL;
SELECT ASCII('A') -- CHR의 반대
FROM DUAL;
-- 변환 함수 DATE -> STRING
-- TO_CHAR
SELECT TO_CHAR(SYSDATE)
FROM DUAL;
SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD-HH24-MI-SS')
FROM DUAL;
SELECT TO_CHAR(10000000, '999,999,999')
FROM DUAL;
SELECT TO_DATE('20180424')
FROM DUAL;
SELECT TO_DATE('20180424', 'YYYYMMDD')
FROM DUAL;
SELECT TO_DATE('04242018', 'MMDDYYYY')
FROM DUAL;
-- parseInt()
SELECT TO_NUMBER('100') + 1
FROM DUAL;
-- 날짜 함수 - 날짜에 N만큼 더한 일자
SELECT SYSDATE, ADD_MONTHS(SYSDATE, -1)
FROM DUAL;
-- 해당하는 월의 마지막 일자
SELECT LAST_DAY(SYSDATE)
FROM DUAL;
SELECT LAST_DAY(TO_DATE('2018-04-24', 'YYYY-MM-DD'))
FROM DUAL;
SELECT LAST_DAY(TO_DATE('2018-04', 'YYYY-MM'))
FROM DUAL;
SELECT SUBSTR('ABCDEFG', 3) -- 3번째부터 쭉~~~ 가져온다
FROM DUAL;
SELECT SUBSTR('ABCDEFG', 3, 2) -- 3번째부터 2글자
FROM DUAL;
SELECT LENGTH('ABCDEFG')
FROM DUAL;