Puneeth Reddy
Puneeth Reddy

Reputation: 3

Need to add string in Oracle

Below is my data in the column.

73-11277-61 B0
 68-3038-61 C0

Always I need to add ~ before two characters in Oracle.

 73-11277-61 ~B0
  68-3038-61 ~C0

Upvotes: 0

Views: 77

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65363

  • If you mean to add before last two characters of the string without any extra consideration, then using

    SUBSTR(value,1,LENGTH(value)-2)||'~'||SUBSTR(value,-2)

    is enough.

  • If you need to add before letter characters within the pattern, then use

    REGEXP_REPLACE(value,'([[:alpha:]])','~\1')

  • If you need to add just after a white space character, then use

    REGEXP_REPLACE(value,'(\s)',' ~\2')

Demo

Upvotes: 2

Related Questions