Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I have column by the name of phone_number and it consists different types of numbers for example:

phone_number
078912354
93784385483
009378248448
776868886

So I want to remove all the initial numbers which starts with(0,93,0093). The expected result which I want is:

phone_number
78912354
784385483
78248448
776868886

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here’s one option:

Sample data:

SQL> select * from test order by phone_number;

PHONE_NUMBER NEW_PHONE_NUMBER
------------ --------------------
009378248448
078912354
776868886
93784385483

Remove leading characters you mentioned:

SQL> update test set
  2    new_phone_number = regexp_replace(phone_number, '^(0093|093|93|0)');

4 rows updated.

Result:

SQL> select * from test order by phone_number;

PHONE_NUMBER NEW_PHONE_NUMBER
------------ --------------------
009378248448 78248448
078912354    78912354
776868886    776868886
93784385483  784385483

SQL>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading