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

Check if all characters are 'X'

I have the below table:

COL
---
XXY
YXX
XXX
NULL

I want to filter out the rows which don’t consist of all ‘X’s.
Expected output:

COL
---
XXX

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 :

We can use REGEXP_LIKE here:

SELECT COL
FROM yourTable
WHERE REGEXP_LIKE(COL, '^X+$');  -- ^X+$ means all X from start to end

Another similar version:

SELECT COL
FROM yourTable
WHERE NOT REGEXP_LIKE(COL, '[^X]');  -- this means no non X present
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