TIL/Oracle

[Oracle] REGEXP_REPLACE

야리니 2022. 5. 7. 13:31
728x90
반응형

REGEXP_REPLACE는 찾고자 하는 문자를 원하는 문자로 바꿀 수 있는 함수이다.

 

【형식】

REGEXP_REPLACE (source_char, pattern [, replace_string [, position [, occurrence [, match_param]]]] )

 

예시1)

<쿼리>

select email, regexp_replace(email, 'arirang','seoul') from test;

 

<결과>

EMAIL                   REGEXP_REPLACE(EMAIL,'ARIRANG','SEOUL')

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

arirang@abc.co.kr    seoul@abc.co.kr


예시2)

<쿼리>

select REGEXP_REPLACE(country_name, '(.)', '\1 ') "REGEXP_REPLACE" 2 from countries;

 

<결과>

REGEXP_REPLACE

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

A r g e n t i n a

A u s t r a l i a

B e l g i u m

B r a z i l

C a n a d a

S w i t z e r l a n d

C h i n a

G e r m a n y

D e n m a r k

E g y p t

F r a n c e

H o n g K o n g

I s r a e l

I n d i a

I t a l y

J a p a n

K u w a i t

M e x i c o

N i g e r i a

N e t h e r l a n d s

S i n g a p o r e

U n i t e d K i n g d o m

U n i t e d S t a t e s o f A m e r i c a

Z a m b i a

Z i m b a b w e

 

예시3)

<쿼리>

SELECT REGEXP_REPLACE (job_id, '(re|Re|RE|rE)', '[\1]'), REGEXP_REPLACE (job_title, '(re|Re|RE|rE)', '[\1]')
FROM jobs
WHERE REGEXP_LIKE(job_id, 're', 'i') OR REGEXP_LIKE(job_title, 're', 'i');

 

<결과>

 

728x90
반응형