replace_all

NAME

replace_all(): Replaces characters in a given text with a given replace-text.

TYPE

Function

DESCRIPTION

This function replaces any appearance of character within a given set, with a replace-text.

SYNOPSIS

replace_all(txt TEXT CHARSET utf8, from_characters VARCHAR(1024) CHARSET utf8, to_str TEXT CHARSET utf8)
  RETURNS TEXT CHARSET utf8 

Input:

  • txt: input text, on which to work the search/replace. It is unmodified.
  • from_characters: a set of characters. Any appearance of any character within this set makes for a replace action.
  • to_str: text to be injected in place of any character in from_characters.
    Can be an empty text, which makes for a deletion of any character in the set.

EXAMPLES

Replace any appearance of comma, colon & semicolon with a pipeline:

SELECT replace_all('common_schema: routines, views;tables', ';:,', '|') AS replaced_text;
+---------------------------------------+
| replaced_text                         |
+---------------------------------------+
| common_schema| routines| views|tables |
+---------------------------------------+

As above, include whitespace (note that adjacent characters are NOT compressed)

SELECT replace_all('common_schema: routines, views;tables', ';:, \t', '|') AS replaced_text;
+---------------------------------------+
| replaced_text                         |
+---------------------------------------+
| common_schema||routines||views|tables |
+---------------------------------------+

ENVIRONMENT

MySQL 5.1 or newer

SEE ALSO

replace_sections(), trim_wspace()

AUTHOR

Shlomi Noach
 
common_schema documentation