SQL 查询中的“不喜欢”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1762712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:29:04  来源:igfitidea点击:

'NOT LIKE' in an SQL query

sqloracleora-00936

提问by Ariod

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

为什么这个简单的查询会返回“ORA-00936:缺少表达式”(如您所知,数据库是 Oracle):

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

I feel silly, but what am I doing wrong?

我觉得很傻,但我做错了什么?

回答by mikej

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

您错过了id第二个中的字段名称NOT LIKE。尝试:

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

The ANDin 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'.

ANDwhere 子句中的in 连接了 2 个完整的条件表达式,例如id NOT LIKE '1%'和 不能用于列出 id 为“不喜欢”的多个值。

回答by tvanfosson

You need to specify the column in both expressions.

您需要在两个表达式中指定列。

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

回答by martin clayton

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

您在 NOT 之前错过了 id;它需要被指定。

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