“不喜欢”在SQL查询中

时间:2022-09-18 12:51:42

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

为什么这个简单的查询返回'ORA-00936: missing expression'(数据库是Oracle,您可以看到):

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

I feel silly, but what am I doing wrong?

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

3 个解决方案

#1


53  

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

您在第二个不喜欢的地方漏掉了字段名id。试一试:

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

where子句中的AND连接了两个完整条件表达式,如id不喜欢'1%',不能用于列出id不喜欢的多个值。

#2


9  

You need to specify the column in both expressions.

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

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

#3


8  

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

你之前漏掉了id;需要指定它。

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

#1


53  

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

您在第二个不喜欢的地方漏掉了字段名id。试一试:

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

where子句中的AND连接了两个完整条件表达式,如id不喜欢'1%',不能用于列出id不喜欢的多个值。

#2


9  

You need to specify the column in both expressions.

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

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

#3


8  

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

你之前漏掉了id;需要指定它。

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