데이터베이스/Oracle

3. 오라클 기초 (문자함수)

왕초보코딩탈출 2018. 2. 18. 23:23

1. INITCAP (첫 글자만 대문자로 출력하고 나머지는 소문자)


1
select first_name , initcap(first_name)from EMPLOYEES;
cs



2. lOWER / UPPER (모두 소문자 / 모두 대문자)


1
select first_name , LOWER(first_name), UPPER(first_name) from EMPLOYEES;
cs



3. LENGTH / LENGTHB (문자열길이 / 바이트수)

영어일땐 바이트수가 보통 1byte라 동일하지만 한글일 땐 보통 할글자수에 2byte이기 때문에 곱절로 나옴


1
select first_name , LENGTH(first_name), LENGTHB(first_name),LENGTH('오라클'),LENGTHB('오라클')  from EMPLOYEES;
cs



4. SUBSTR / SUBSTRB  (특정 부분 골라내기 ) ex : 주민등록번호 성별 골라내기 등.


1
2
3
4
select first_name , SUBSTR(first_name,1,3)from EMPLOYEES;
 
select SUBSTR('001212-1000000',-7,1from dual;
 
cs



---------------------------------------------------------------------------------------


5. INSTR (특정 글자의 위치 찾기)

INSTR(컬럼 or 문자열 ,'찾는 글자', '시작',' 몇 번째인지 ')

1
select hire_date, INSTR(hire_date,'/',1,2from EMPLOYEES;
cs






6.   LPAD     /   RPAD(문자로 채우기)
       왼쪽    /  오른쪽
1
select first_name , LPAD(first_name,10,'*'), RPAD(first_name,10,'*'),LPAD('오라클',10,'*'),RPAD('오라클',10,'*')  from EMPLOYEES;
cs



7.   LTRIM    /   RTIRM( 문자 지우기)

        왼쪽    /  오른쪽


1
select first_name , LTRIM(first_name,'E'), RTRIM(first_name,'e'),LTRIM('오라클','오'), RTRIM('오라클','클')from EMPLOYEES;
cs



7.   REPLACE 문자 바꿔주기


1
select REPLACE('901212-1000000',SUBSTR('901212-1000000',-6,7),'******'from dual;
cs