Return to Snippet

Revision: 71043
at December 12, 2016 04:52 by bbrumm


Initial Code
/*REPLACE*/

/*Example 1*/
SELECT 'Today is the 26th of February, 2015' AS ORIGINAL_STRING,
REPLACE('Today is the 26th of February, 2015', 'a', 'X') AS REPLACE_STRING
FROM dual;

/*Example 2*/
SELECT 'Today is the 26th of February, 2015' AS ORIGINAL_STRING,
REPLACE('Today is the 26th of February, 2015', 'the', 'probably the') AS REPLACE_STRING
FROM dual;

/*Example 3*/
SELECT 'Today is the 26th of February, 2015' AS ORIGINAL_STRING,
REPLACE('Today is the 26th of February, 2015', 'th') AS REPLACE_STRING
FROM dual;

/*Example 4*/
SELECT 'Today is the 26th of February, 2015' AS ORIGINAL_STRING,
REPLACE('Today is the 26th of February, 2015', 'X', 'Y') AS REPLACE_STRING
FROM dual;

/*Example 5*/
SELECT 'Today is the 26th of February, 2015' || CHR(13) AS ORIGINAL_STRING,
REPLACE('Today is the 26th of February, 2015' || CHR(13), CHR(13), ' ') AS REPLACE_STRING
FROM dual;

/*Example 6*/
SELECT 'Today is the 26th of February, 2015' || CHR(13) || CHR(10) AS ORIGINAL_STRING,
REPLACE('Today is the 26th of February, 2015' || CHR(13) || CHR(10), CHR(13) || CHR(10), ' ') AS REPLACE_STRING
FROM dual;

/*Example 7*/
SELECT NULL AS ORIGINAL_STRING,
REPLACE(NULL, NULL, 'x') AS REPLACE_STRING
FROM dual;

/*Example 8*/
SELECT 'My first name is (x), my last name is (y), and I am from (z).' AS ORIGINAL_STRING,
REPLACE(REPLACE(REPLACE('My first name is (x), my last name is (y), and I am from (z).', '(x)', 'John'), '(y)', 'Smith'), '(z)', 'England') AS REPLACE_STRING
FROM dual;

/*Example 9*/
SELECT 'What''s the date today?' AS ORIGINAL_STRING,
REPLACE('What''s the date today?', '''', '"') AS REPLACE_STRING
FROM dual;

/*Example 10*/
SELECT 'What''s the date today?' AS ORIGINAL_STRING,
 REPLACE('What''s the date today?', '''') AS REPLACE_STRING
 FROM dual;

Initial URL
http://www.databasestar.com/oracle-replace/

Initial Description
A few examples of the Oracle REPLACE function

Initial Title
Oracle REPLACE Function

Initial Tags
sql, Oracle

Initial Language
SQL