jaga
jaga

Reputation: 33

Replacing a string without using regular expression in netezza

Is there any way to replace a string in netezza sql without using regular expression function (i.e. regexp_replace()) eg: replace('perfect','fect','fume')

TIA

Upvotes: 2

Views: 777

Answers (2)

Niederee
Niederee

Reputation: 4295

Without the SQL Extensions Toolkit you can just use substr and instr functions. You may have to run them multiple times depending on the recurrence of the string in question. Below is an example:

    select substr(a.txt,1,instr(a.txt,'fect')-1)
          ||'fume'
          ||substr(a.txt,instr(a.txt,'fect')+length('fect'),255)
    from (select 'perfect' as txt) a

Upvotes: 2

dcieslak
dcieslak

Reputation: 2715

In case you have the SQL Extensions Toolkit installed then you can use:

select sql_functions..replace('prefect', 'fect', 'fume')

Upvotes: 1

Related Questions