balexsandro
balexsandro

Reputation: 13

How to use like and in together in sql statement?

WHERE SUBSTR(NAME, 1, 1) LIKE IN ('k', 'l', 'b')

If I use this code, I get an error

ORA-00936: missing expression

There seems to be no error logically, but I am wondering which part of the code above is wrong.

I'm also curious about a way to replace LIKE IN.

Upvotes: 1

Views: 114

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522719

Removing LIKE from your current WHERE clause leaves it valid:

WHERE SUBSTR(NAME, 1, 1) IN ('k', 'l', 'b')

It isn't clear from what you posted alone above why you think you need LIKE here. If you wanted to express the above logic using LIKE, you could use:

WHERE NAME LIKE 'k%' OR NAME LIKE 'l%' OR NAME LIKE 'b%'

Note that if your version of SQL supports regex like, you could also use the regex pattern ^[klb].

Upvotes: 1

Related Questions