'NOT LIKE' in an SQL query

烈酒焚心 提交于 2019-12-20 09:49:24

问题


Why does this simple query return 'ORA-00936: missing expression' (the database is Oracle as you can tell):

SELECT * FROM transactions WHERE id NOT LIKE '1%' AND NOT LIKE '2%'

I feel silly, but what am I doing wrong?


回答1:


You have missed out the field name id in the second NOT LIKE. Try:

SELECT * FROM transactions WHERE id NOT LIKE '1%' AND id NOT LIKE '2%'

The AND in the where clause joins 2 full condition expressions such as id NOT LIKE '1%' and can't be used to list multiple values that the id is 'not like'.




回答2:


You need to specify the column in both expressions.

SELECT * FROM transactions WHERE id NOT LIKE '1%' AND id NOT LIKE '2%'



回答3:


You've missed the id out before the NOT; it needs to be specified.

SELECT * FROM transactions WHERE id NOT LIKE '1%' AND id NOT LIKE '2%'


来源:https://stackoverflow.com/questions/1762712/not-like-in-an-sql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!