Sherin Shaziya
Sherin Shaziya

Reputation: 147

Guide me in understanding the logic used in SQL query

SELECT 
    CASE 
        WHEN REGEXP_SUBSTR(purchaser_id, '[a-z]') IS NOT NULL 
            THEN NULL 
            ELSE purchaser_id 
    END AS s_purchaser_id
FROM 
    table1;

Does this mean if there is any alpha-numeric value it will replace to NULL?

Thanks!

Upvotes: 0

Views: 34

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522254

The logic says that if a purchaser_id contain a lowercase letter, the s_purchaser_id output will be NULL, otherwise the output will be just be the same purchaser_id.

Some samples:

purchaser_id | s_purchaser_id
ABC          | ABC
abc          | NULL
ABCabc       | NULL

Upvotes: 1

Related Questions