Oracle REPLACE Function


/ Published in: SQL
Save to your folder(s)

A few examples of the Oracle REPLACE function


Copy this code and paste it in your HTML
  1. /*REPLACE*/
  2.  
  3. /*Example 1*/
  4. SELECT 'Today is the 26th of February, 2015' AS ORIGINAL_STRING,
  5. REPLACE('Today is the 26th of February, 2015', 'a', 'X') AS REPLACE_STRING
  6. FROM dual;
  7.  
  8. /*Example 2*/
  9. SELECT 'Today is the 26th of February, 2015' AS ORIGINAL_STRING,
  10. REPLACE('Today is the 26th of February, 2015', 'the', 'probably the') AS REPLACE_STRING
  11. FROM dual;
  12.  
  13. /*Example 3*/
  14. SELECT 'Today is the 26th of February, 2015' AS ORIGINAL_STRING,
  15. REPLACE('Today is the 26th of February, 2015', 'th') AS REPLACE_STRING
  16. FROM dual;
  17.  
  18. /*Example 4*/
  19. SELECT 'Today is the 26th of February, 2015' AS ORIGINAL_STRING,
  20. REPLACE('Today is the 26th of February, 2015', 'X', 'Y') AS REPLACE_STRING
  21. FROM dual;
  22.  
  23. /*Example 5*/
  24. SELECT 'Today is the 26th of February, 2015' || CHR(13) AS ORIGINAL_STRING,
  25. REPLACE('Today is the 26th of February, 2015' || CHR(13), CHR(13), ' ') AS REPLACE_STRING
  26. FROM dual;
  27.  
  28. /*Example 6*/
  29. SELECT 'Today is the 26th of February, 2015' || CHR(13) || CHR(10) AS ORIGINAL_STRING,
  30. REPLACE('Today is the 26th of February, 2015' || CHR(13) || CHR(10), CHR(13) || CHR(10), ' ') AS REPLACE_STRING
  31. FROM dual;
  32.  
  33. /*Example 7*/
  34. SELECT NULL AS ORIGINAL_STRING,
  35. REPLACE(NULL, NULL, 'x') AS REPLACE_STRING
  36. FROM dual;
  37.  
  38. /*Example 8*/
  39. SELECT 'My first name is (x), my last name is (y), and I am from (z).' AS ORIGINAL_STRING,
  40. 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
  41. FROM dual;
  42.  
  43. /*Example 9*/
  44. SELECT 'What''s the date today?' AS ORIGINAL_STRING,
  45. REPLACE('What''s the date today?', '''', '"') AS REPLACE_STRING
  46. FROM dual;
  47.  
  48. /*Example 10*/
  49. SELECT 'What''s the date today?' AS ORIGINAL_STRING,
  50. REPLACE('What''s the date today?', '''') AS REPLACE_STRING
  51. FROM dual;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.