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 select from table all names that started on any letter – ORACLE

How to select from table all names that contains any letter?
For example if variable is ‘BANANA’ it is great, if variable is ‘*895-+59’ it is not great

IF variable LIKE '%A-Z%' THEN
        dbms_output.put_line('GREAT');

>Solution :

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

How to select from table all names that contains any letter?

You cannot use regular expressions in a LIKE comparison but you can use them in REGEXP_LIKE:

SELECT name
FROM   table_name
WHERE  REGEXP_LIKE(name, '[A-Za-z]')

If you want the column to start with a letter then anchor it to the start of the string:

SELECT name
FROM   table_name
WHERE  REGEXP_LIKE(name, '^[A-Za-z]')

If you want to output Great or Not Great then put it in a CASE expression rather than a WHERE filter:

SELECT name,
       CASE 
       WHEN REGEXP_LIKE(name, '[A-Za-z]')
       THEN 'Great'
       ELSE 'Not Great'
       END AS is_great
FROM   table_name
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