0

I have a table having one field "SUSCRIBER_ID" and structure of the table is that SUSCRIBER_ID field should not be null. Now, i want to update the value of that field with below conditions.

UPDATE table_name SET SUSCRIBER_ID = DECODE (REGEXP_REPLACE (SUSCRIBER_ID,'^\D*',NULL),NULL,SUSCRIBER_ID);

error is coming name SUSCRIBER_ID can not be null however when REGEXP_REPLACE is return the null value then i am skipping the records

data is in the table

name
---------
sumit123sumit

Please assist

1 Answer 1

1
UPDATE table_name SET SUSCRIBER_ID = DECODE (REGEXP_REPLACE (SUSCRIBER_ID,'^\D*',NULL),
                                             NULL,
                                             SUSCRIBER_ID,
                                             REGEXP_REPLACE (SUSCRIBER_ID,'^\D*',NULL))

I believe you need a final default argument with the REGEXP_REPLACE() itself.

As @AlexPoole said , Other way is using NVL()

UPDATE table_name SET SUSCRIBER_ID = NVL (REGEXP_REPLACE (SUSCRIBER_ID,'^\D*',NULL),
                                          SUSCRIBER_ID);
Sign up to request clarification or add additional context in comments.

1 Comment

To avoid repetition I'd make that NVL(REGEXP_REPLACE (SUSCRIBER_ID,'^\D*',NULL), SUSCRIBER_ID), but some people prefer the clarity of decode or case...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.