/ Published in: SQL
                    
                                        
A few examples of the Oracle REPLACE function
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
/*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;
URL: http://www.databasestar.com/oracle-replace/
Comments
 Subscribe to comments
                    Subscribe to comments
                
                