develope_kkyu

[ORACLE] 문자 함수 본문

SQL

[ORACLE] 문자 함수

developekkyu37 2022. 12. 27. 17:31
728x90

문자 함수

  •  INICAP(char), LOWER(char), UPPER(char)

inicap 함수는 매개변수로 들어오는 char의 첫 문자는 대문자로, 나머지는 소문자로 반환한는 함수이다. 첫 문자를 인식하는 기준은 공백과 알파벳을 제외한 문자이다.

select initcap('good mornig') from dual;

lower 함수는 매개변수로 들어오는 문자를 모두 소문자로 반환한다.

select lower('Good Morning') from dual;

upper 함수는 매개변수로 들어오는 문자를 모두 대문자로 반환한다.

select upper('Good Morning') from dual;

  •  CONCAT(char1, char2), SUBSTR(char,pos,len), SUBSTRB(char,pos,len)

concat 함수는 ' || ' 연산자처럼 매개변수로 들어오는 두 문자를 붙여 반환한다.

 

select concat('Good', 'morning') from dual;

substr 함수는 잘라올 대사 문자열인 char의 pos번째 문자부터 len 길이만큼 잘라낸 결과를 반환하는 함수이다.

select substr('good morning',6,4) from dual;

 

substrb 함수는 문자 개수가 아닌 문자열의 바이트(BYTE) 수만큼 잘라낸 결과를 반환한다.

select substrb('ABCDEFG',1,4), substrb('가나다라마바사',1,4) from dual;

  • REPLACE(char, search_str, replace_str)

replace 함수는 char 문자열에서 search_str 문자열을 찾아 이를 replace_str 문자열로 대체한 결과를 반환하는 함수이다.

select replace('Bad Morning','Bad', 'Good') from dual;

  • INSTR(str, substr, pos, occur), LENGTH(chr)

instr 함수는 str 문자열에서 substr과 일치하는 위치를 반환하는데, pos는 시작 위치로 디폴트 값은 1, occur은 몇 번째 일치하는지를 명시하며 디폴트 값은 1이다.

select instr('John Wick','Wick') from dual;

length 함수는 매개변수로 들어온 문자열의 개수를 반환한다.

select length('good morning') from dual;

728x90

'SQL' 카테고리의 다른 글

[ORACLE] 날짜 함수  (0) 2022.12.27
[ORACLE] 숫자 함수  (0) 2022.12.27
[ORACLE] 기본키(Primary key)  (0) 2022.12.26
[ORACLE] C, R, U, D 기초  (0) 2022.12.23