1、'' is null為true,''和null是同一個東西。 神經病寫法:無論vc_itemids是null還是'',or後面的那一句都為false,判空只能使用is null 或者 is not null。下麵的vc_itemids只需要前面的判空就可以了。 分析: 2.低效的子查詢 神經病寫 ...
1、'' is null為true,''和null是同一個東西。
神經病寫法:無論vc_itemids是null還是'',or後面的那一句都為false,判空只能使用is null 或者 is not null。下麵的vc_itemids只需要前面的判空就可以了。
分析:
2.低效的子查詢
神經病寫法:子查詢並沒有用到外面查詢的列,但是外面沒查詢一條數據,就執行一次子查詢,但是子查詢的數據都是一樣的,應寫成臨時數據。
改善寫法:
declare my_date varchar2(20); begin select t1.real_date into my_date from (select '20200520' real_date from dual) t1; --使用上面的變數值放到where條件里 SELECT * FROM table_a A, table_b b WHERE A.item1 IN ('1', '2', '5') and a.item2 = b.item3(+) and a.item6 >= my_date and a.item5 is null; end;