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

Replace first digit of phone number

I need to transfer the phone_number fields from other tables so that the first digit starts not with 7, but with 8. How can I implement this correctly?
For example, numbers of the type 87001059505, and not 77001059505, should be inserted in the table

My try:

SELECT
(PHONE_NUMBER case when phone_number is not null then phone_number := (8+substr(phone_number,2)) end)
FROM CALL_HISTORY

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 :

It isn’t clear whether you want to view your data this or do an update. Assuming the former, use:

SELECT CASE WHEN phone_number LIKE '7%'
            THEN '8' || SUBSTR(phone_number, 2)
            ELSE phone_number END AS phone_number
FROM CALL_HISTORY;

Assuming the latter, use:

UPDATE CALL_HISTORY
SET phone_number = '8' || SUBSTR(phone_number, 2)
WHERE phone_number LIKE '7%';
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