본문 바로가기
DB/SQLPLUS

[Oracle] 문자 함수

by KhyeonS 2022. 6. 13.

이번에는 문자 함수를 알아볼 것 이다.


 

 

문자 함수 
  • lower(char), upper(char), substr(str, m, n) : m~n이 아니라 m부터 시작해서 +n.
  • replace(str, 바뀔_문자, 바꿀_문자), ltrim(expr) and rtrim(expr) : 좌측과 우측에서 빈자리를  절삭.
  • initcap(expr) : 첫번째 대문자, length(expr) : 문자열의 개수.
  • instr(expr, char) :   해당 expr에서 첫번째로 찾은 char 문자의 위치.
  • lpad(expr, n, #) and rpad(expr, n, -) : 문자열이 지정된 n 보다 적을 때 빈 공간을 좌측에 #, 우측에 -로 채움,
  • concat(열_명, char) : 지정된   테이블에서 문자열을 합침, concat() 함수 내에 또 concat() 함수를 넣어서 다양하게 표현할 수 있다.

EX)

ltim (exrp) and rtrim (expr) 좌측과 우측에서 빈자리를 절삭

select ltrim('   Korea Economy   ') from dual; 
select rtrim('   Korea Economy   ') from dual;

 

 

initcap(expr): 첫번째 대문자

 select initcap('korea economy conditions') from dual;



length(expr): 문자열의 갯수:빈칸도 계산

 select length('Korea Economy Conditions') from dual;



insrt(expr, char):해당 expr에서 첫번째 찾은 char문자의 위치

 select length('Korea Economy Conditions') from dual;



 lpad(expr, n, #) and rpad(expr, n, - ):문자열이 지정된 n 보다 적을 때 빈 공간을 좌측에 #, 우측에 -로 채움

 select 'Korea Economy   ', lpad('Korea', 100, '#'), rpad('Economy   ', 15, '%')from dual;



 concat (열_명, char): 지정된 테이블에서 문자열을 합침
 concat()함수내에 또 concat()함수를 넣어서 다양하게 표현할 수 있다.

select concat(employee_id, last_name) from employees where employee_id = '100'; 
select concat(employee_id, last_name), concat(emploee_id, concat(':', last_name)) 
from employees where employee_id = 100;
concat (employee_id, last_name) => 100king
concat(employee_id, concat(' ', last_name)) => 100 king <= employee_id || '  '|| last_name

 

'DB > SQLPLUS' 카테고리의 다른 글

[ORACLE]변환 함수  (0) 2022.06.14
[Oracle] 날짜 함수  (0) 2022.06.13
[ORACLE] DUAL 테이블, 임의로 이름 항목이름 정해주기  (0) 2022.06.12
[ORACLE] Count () 함수  (0) 2022.06.12
[ORACLE] TRUNC, ROUND 함수  (0) 2022.06.12

댓글