'NOT LIKE' in an SQL query

后端 未结 4 435
青春惊慌失措
青春惊慌失措 2021-02-02 08:42

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%\'         


        
4条回答
  •  死守一世寂寞
    2021-02-02 09:32

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

提交回复
热议问题