Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Only String search

with temp(name) as (select 'abc' from dual
union select '123abc' from dual
union select '1abc3' from dual)
select * from temp where temp.name  like '%[a-z]%'

why i am not able to get all the 3 records in output , I am using Oracle SQL Developer 11g

Reason why i am using this query is : I want to check if Desired column Contains only String no Number and Special Character

like image 651
Mayank Agrawal Avatar asked Jun 05 '18 12:06

Mayank Agrawal


People also ask

How do I search for a string in SQL?

SQL Server CHARINDEX() Function The CHARINDEX() function searches for a substring in a string, and returns the position. If the substring is not found, this function returns 0. Note: This function performs a case-insensitive search.

Can SQL use RegEx?

You can use RegEx in many languages like PHP, Python, and also SQL. RegEx lets you match patterns by character class (like all letters, or just vowels, or all digits), between alternatives, and other really flexible options.


1 Answers

You are mixing SQL Server and Oracle syntax:

SQL SERVER Demo:

with temp(name) as (
      select 'abc' union all select '123abc'  union select '1abc3' 
)
select * from temp where temp.name like '%[a-z]%';
                                        -- [] is T-SQL specific

ORACLE Demo:

with temp(name) as (select 'abc' from dual
union select '123abc' from dual
union select '1abc3' from dual)
select * from temp where regexp_like(temp.name, '[a-z]')
like image 153
Lukasz Szozda Avatar answered Oct 19 '22 16:10

Lukasz Szozda