Search code examples
sqlplsqlplsqldeveloper

remove extra "WWW_" using sql SUBSTRING


In the Name_code column, we have these types of

WWW_XX_YYYY
XX_YYYY
XX_E100
XX_MESE
WWW_XX_MESE
WWW_XX_TECH

I want O/P the value like this

XX_YYYY
YYYY
E100
MESE
XX_MESE
XX_TECH

SUBSTR(Name_code,4, length(Name_Code)-3) i tried this but no result

How will do That?


Solution

  • You can use instr to find the index of the first underscore (_), and then substr from the character after that to the end of the table:

    SELECT SUBSTR(mycol, INSTR(mycol, '_') + 1)
    FROM   mytable