Tuesday, 7 June 2011

replace function with SQL, forgotten gem

Oracle/PLSQL: Replace Function


In Oracle/PLSQL, the replace function replaces a sequence of characters in a string with another set of characters.

The syntax for the replace function is:

replace( string1, string_to_replace, [ replacement_string ] )

string1 is the string to replace a sequence of characters with another set of characters.

string_to_replace is the string that will be searched for in string1.

replacement_string is optional. All occurrences of string_to_replace will be replaced with replacement_string in string1. If the replacement_string parameter is omitted, the replace function simply removes all occurrences of string_to_replace, and returns the resulting string.

 

How cool is this for renaming a server and your update statements over the F986101 and the F98611.  Just use:

Note that the AS/400 and oracle have the exact syntax for this string operator (amazing?)

update JDEPLAN900.f986101
set omdatp = replace(omdatp, 'SVR003', 'SVR703')
where omdatp like '%SVR003%'

This will get the – Logic, –XAPI etc etc.

That just made my machine rename scripts MUCH more simple.

No comments:

Extending JDE to generative AI