關於sql語句中條件語句where後的多個and/or的優先級

摘要:

    SQL的WHERE子句中包含多個AND和OR

示例:

    SQL解析器在處理操作時會優先處理and操作:

    假如有表product字段如下:id、product_id、product_price、product_name,現在要查找產品號爲100或者101,並且價格大於200的商品,程序員可能會這樣寫:            select * from product where product_id = 100 or product_id = 101 and product_price > 200

    上述代碼中,SQL解析器首先進行and 的操作,最後就成了這個意思:查找產品號爲101且價格大於200或產品號爲100 的商品。

添加圓括號即可:

select * from product where (product_id = 100 or product_id = 101) and product_price > 200

sql注入中的萬能密碼一般都會多加幾個or,username' or 1=1 or 1=1 --+

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章