SqlDeveloper - 在脚本化查询中检查没有IS NULL子句的NULL值

时间:2017-02-10 08:28:02

标签: python sql oracle null

for circuit in allCircuit:                   # a cvs of 4 columns

    part = circuit.split(",")

    res = cur.execute("""SELECT col4 from ATable WHERE
    ( "col1" = :a
    AND "col2" = :b
    AND "col3" = :c
    AND "col4" = :d) 
    ORDER BY col4""",a = part[0], b= part[1], c = part[2], d = part[3])

part [0]到part [3]可能包含NULL(类型)值。

但Oracle不接受where子句,如:

WHERE“col1”= NULL

WRONG

WHERE“col1”IS NULL

RIGHT

如何在我的脚本查询中添加“IS NULL”stmt而不是“col = NULL”?

1 个答案:

答案 0 :(得分:3)

在Oracle中 null不等于null 您可以在查询中使用

... and decode( col1, :a, 1, 0 )=1

... and (col1=:a or (col1 is null and :a is null))