Search for row containing letters only

15 views
Skip to first unread message

GT

unread,
Jun 30, 2023, 3:11:27 PM6/30/23
to SQL Workbench/J - DBMS independent SQL tool
This is my first time posting in this forum...

I am looking for a way to search for rows containing letters only.  I tried the search methods I found on the internet using 

and column_name LIKE ('%[a-z]%') 

but is was actually searching for  %[a-z]%   and not for any individual ;etter.
I got it to work with a large AND / OR statement using each letter but I wanted to see if there was anything about a way to do this smarter.

The second thing i would like to do it to search for rows that contain at least 2 letters.

Anyone know of how to do this?

THANK YOU IN ADVANCE
Message has been deleted

Chris Young

unread,
Jun 30, 2023, 8:12:27 PM6/30/23
to SQL Workbench/J - DBMS independent SQL tool
Have you tried
column_name not like '%[^A-Za-z]%'

or for case insensitive searches:
column_name not like '%[^A-Z]%'

Thomas Kellerer

unread,
Jul 1, 2023, 4:49:44 AM7/1/23
to sql-wo...@googlegroups.com
This group is about the tool SQL Workbench/J - it's not about general SQL problems.

Having said that:

The SQL LIKE operator does not support regular expressions (it only supports % for any number of characters and _ for exactly one character).

In standard SQL you can use the SIMILAR TO operator which uses a mixture of regular expressions and SQL wildcards (% and _) e.g.:

and column_name SIMILAR TO '%[a-z]%'

Complete support for regular expression is DBMS specific. Postgres for example uses the ~ operator, while Oracle uses regexp_like

Thomas

Greg Tyber

unread,
Jul 5, 2023, 10:57:53 AM7/5/23
to sql-wo...@googlegroups.com
Thomas,
The SIMILAR to function worked. 
I had never used that before.

Do you know how I would write it so that each term had more than 3 letters in the criteria?


--
You received this message because you are subscribed to a topic in the Google Groups "SQL Workbench/J - DBMS independent SQL tool" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sql-workbench/cHo90a9JMWE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sql-workbenc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sql-workbench/42a24447-2f13-daf1-30cf-6f301980c502%40sql-workbench.net.
Reply all
Reply to author
Forward
0 new messages