Use replace() function in an update to change more than one sub string of a column

user1298426

Say I have student table with a column name.
This name column has values 'studentone', 'studenttwo', 'studentthree'
& I want to replace them with 'student1', 'student2', 'student3'.

For single replacement it's quite straight forward:

update student set name = replace(name, 'one', '1')

But what about multiple replacements? Any idea?

Bohemian

I would just use multiple update statements, but if you absolutely must do it in one statement, just nest the replace calls:

update student set
  name = replace(replace(replace(name, 'one', '1'), 'two', '2'), 'three', '3')

This works because (although inefficient) calls to replace() have no effect if the search term is not found.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Inline use of function returning more than one value in C#

From Dev

Replace strings with more than one character

From Dev

Filter on more than one column

From Dev

Use Column value as string pattern in REPLACE function

From Dev

MySql: Update more than one column

From Dev

Replacing more than one elements with replace function

From Dev

More than one row UPDATE

From Dev

GoJS: use more than one parameter in a conversion function

From Dev

How can I use ScriptManager more than one function?

From Dev

replace more than one pattern python

From Dev

How to remove more than one whitespace from a string in javascript(Can not use regex replace function)?

From Dev

how to use more than one string in like expression in sql

From Dev

Inline use of function returning more than one value in C#

From Dev

Replace strings with more than one character

From Dev

Javascript - Replace more than one value

From Dev

Use replace() function in an update to change more than one sub string of a column

From Dev

C++: Replace character in a string with more than one number?

From Dev

Use Column value as string pattern in REPLACE function

From Dev

MySql: Update more than one column

From Dev

JavaScript function find and change CSS of column if it has more than one DIV

From Dev

Sorting more than one column

From Dev

Replacing more than one elements with replace function

From Dev

Use anonyous function in object for more than one task

From Dev

More than one row UPDATE

From Dev

Fetch more than one column

From Dev

GoJS: use more than one parameter in a conversion function

From Dev

More than one function to IF statement

From Dev

Subquery with more than one column

From Dev

Use count() in more than one column and order results

Related Related

  1. 1

    Inline use of function returning more than one value in C#

  2. 2

    Replace strings with more than one character

  3. 3

    Filter on more than one column

  4. 4

    Use Column value as string pattern in REPLACE function

  5. 5

    MySql: Update more than one column

  6. 6

    Replacing more than one elements with replace function

  7. 7

    More than one row UPDATE

  8. 8

    GoJS: use more than one parameter in a conversion function

  9. 9

    How can I use ScriptManager more than one function?

  10. 10

    replace more than one pattern python

  11. 11

    How to remove more than one whitespace from a string in javascript(Can not use regex replace function)?

  12. 12

    how to use more than one string in like expression in sql

  13. 13

    Inline use of function returning more than one value in C#

  14. 14

    Replace strings with more than one character

  15. 15

    Javascript - Replace more than one value

  16. 16

    Use replace() function in an update to change more than one sub string of a column

  17. 17

    C++: Replace character in a string with more than one number?

  18. 18

    Use Column value as string pattern in REPLACE function

  19. 19

    MySql: Update more than one column

  20. 20

    JavaScript function find and change CSS of column if it has more than one DIV

  21. 21

    Sorting more than one column

  22. 22

    Replacing more than one elements with replace function

  23. 23

    Use anonyous function in object for more than one task

  24. 24

    More than one row UPDATE

  25. 25

    Fetch more than one column

  26. 26

    GoJS: use more than one parameter in a conversion function

  27. 27

    More than one function to IF statement

  28. 28

    Subquery with more than one column

  29. 29

    Use count() in more than one column and order results

HotTag

Archive