Oracle – Replace Function

REPLACE

admin Functions, Oracle , , , ,

Hi Geeks,
Hope you guys are doing well.
REPLACE is very good function which helps to substitute a string. This function is pretty much easy to use.
Have a look at the syntax, isn’t it?

Syntax:

REPLACE(expr, search_string, replacement_string)

expr
It can be a column name from a table or a string. If it is a char string, it must be enclosed in single quoration marks.

search_string
User provides an argument as a string which needs to be replaced.

replacement_string
User provides an argument as a string which should replace search_string argument.

This function searches whole search_string in expr and replace with the replacement_string.

Let’s understand the concept with some examples.

Example-1


SELECT 
replace('JACK and JUE','J','BL') as NAME 
FROM dual;

When we run above SQL statement, Oracle will check if first argument contains ‘J’ and replace all the ‘J’ with ‘BL’.

NAME
BLACK and BLUE

Let’s take one more example.

Example-2


SELECT
'SWITZERLAND' AS old_val,
replace('SWITZERLAND','SWITZER','ENG') AS new_val
FROM
dual;
OLD_VALNEW_VAL
SWITZERLAND ENGLAND

You can see in the above results. Using REPLACE function, we replaced ‘SWITZERLAND’ with ‘ENG’ and new value is ‘ENGLAND’. How easy it is!

If you have any questions/suggestions, please comment below or write me an email.

If you like this blog, do share with your friends and colleagues on your social media.
For more updates join my facebook group and do like my facebook page.

Thank you,
Kapil Kumar

Sharing is caring!

You May Also Like..

SUBSTR

Oracle_SUBSTR()

Hey alians, SUBSTR is pretty cool when it comes to extract a substring out of a string in SQL. SUBSTR […]

INSTR

Oracle_INSTR()

Hey alians, While working with the data, INSTR is a very important single row function that returns a numeric value. […]

DUAL TABLE

Oracle_DUAL table

Hey geeks, DUAL table is a very important table available in the Oracle database. It gets created automatically during the […]

Leave a Reply

Your email address will not be published. Required fields are marked *