Saturday, September 14, 2019

Determine whether the given is numeric , alphanumeric and hexadecimal in oracle SQL

^[^a-zA-Z]*$ or ^[[:xdigit:]]+$  => matches strings that don't contain letters
^[^g-zG-Z]*$                                => matches strings that don't contain letters after g/G

SQL> WITH vals
  2       AS (SELECT '1234567890' str FROM DUAL
  3           UNION ALL
  4           SELECT 'xyz123' str FROM DUAL
  5           UNION ALL
  6           SELECT '1234567890abcdef' str FROM DUAL)
  7  SELECT str,
  8         CASE
  9            WHEN REGEXP_LIKE (str, '^[^a-zA-Z]*$') THEN 'number'
 10            WHEN REGEXP_LIKE (str, '^[^g-zG-Z]*$') THEN 'hex'
 11            ELSE 'string'
 12         END
 13            typ
 14    FROM vals;

STR                        TYP
---------------- ---------------------------
1234567890              number
xyz123                      string
1234567890abcdef   hex


No comments:

Post a Comment

Delete Row Button to all records of Interactive Report in Oracle Apex

 1. add 'Delete' Del column to Report Query 2. Set the Following Properties for the DEL Column Type: Link Heading: Delete Targ...