How to remove specific initial characters from a column in oracle?

by scotty_walker , in category: MySQL , 6 days ago

How to remove specific initial characters from a column in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 5 days ago

@scotty_walker 

You can remove specific initial characters from a column in Oracle by using the SUBSTR function along with a CASE statement. Here's an example of how you can achieve this:

1
2
3
4
5
6
UPDATE your_table
SET your_column = CASE
    WHEN SUBSTR(your_column, 1, 3) = 'ABC' THEN SUBSTR(your_column, 4)
    WHEN SUBSTR(your_column, 1, 2) = 'XY' THEN SUBSTR(your_column, 3)
    ELSE your_column
  END;


In this example:

  • your_table is the table containing the column you want to modify
  • your_column is the name of the column you want to remove specific initial characters from
  • You can specify different initial characters to remove and the corresponding lengths to remove in the SUBSTR function and the WHEN conditions in the CASE statement.


Make sure to backup your data before running the update statement to avoid any potential data loss.