Oracle / PLSQL: REPLACE Function

This article is written about how to use the Oracle/PLSQL REPLACE feature with syntax and examples.

Description

The Oracle/PLSQL REPLACE feature replaces a sequence of characters in a string with some other set of characters.

Syntax

The syntax for the REPLACE characteristic in Oracle/PLSQL is:

REPLACE( string1, string_to_replace [, replacement_string] )

Parameters or Arguments

string1 The string to replace a sequence of characters with another set of characters. string_to_replace The string that will be searched for in string1. replacement_string Optional. All occurrences of string_to_replace will be replaced with replacement_string in string1. If the replacement_string parameter is omitted, the REPLACE feature honestly gets rid of all occurrences of string_to_replace, and returns the ensuing string.

Returns

The REPLACE function returns a string value.

Applies To

The REPLACE function can be used in the following versions of Oracle/PLSQL:

Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

Example

Let’s appear at some Oracle REPLACE characteristic examples and explore how to use the REPLACE characteristic in Oracle/PLSQL.

For example:

REPLACE('123123tech', '123');
Result: 'tech'

REPLACE('123tech123', '123');
Result:'tech'

REPLACE('222tech', '2', '3');
Result: '333tech'

REPLACE('0000123', '0');
Result: '123'

REPLACE('0000123', '0', ' ');
Result: '    123'