select * from tablename where nvl(COL1,0)<>3; select * from tablename where COL1<>3 OR COL1 IS NULL;这两种哪个执行效率高呢? 个人感觉是用nvl高些,望高手指教.
我认为nvl略低些。 nvl(COL,0)<>3等价于 if COL is null if 0<>3 return TRUE else return FALSE else if COL<>3 return TRUE else return FALSE 也就是说每行的COL都要比较两次,先判断是否为空,再判断是否<>3。 而COL1<>3 OR COL1 IS NULL则等价于 if COL is null return TRUE else if COL<>3 return TRUE else return FALSE 比NVL在COL为NULL时少判断一次。
select * from tablename where COL1<>3 OR COL1 IS NULL;这两种哪个执行效率高呢?
个人感觉是用nvl高些,望高手指教.
nvl(COL,0)<>3等价于
if COL is null
if 0<>3
return TRUE
else
return FALSE
else
if COL<>3
return TRUE
else
return FALSE
也就是说每行的COL都要比较两次,先判断是否为空,再判断是否<>3。
而COL1<>3 OR COL1 IS NULL则等价于
if COL is null
return TRUE
else
if COL<>3
return TRUE
else
return FALSE
比NVL在COL为NULL时少判断一次。