SQL “Join” on null values

前端 未结 14 1283
旧巷少年郎
旧巷少年郎 2020-12-13 14:04

For reasons beyond my control, I need to join two tables and I need null values to match. The best option I could think of was to spit out a UUID and use that as my comparis

14条回答
  •  时光说笑
    2020-12-13 14:52

    I believe you could still could use nvl() for join:

    SELECT *
    FROM T1
    JOIN T2 ON NVL(T2.COL1,-1)=NVL(T1.COL1,-1);
    

    But you will need to add function based indexes on columns col1

    CREATE INDEX IND_1 ON T1 (NVL(COL1,-1));
    CREATE INDEX IND_2 ON T2 (NVL(COL1,-1));
    

    Indexes should improve the speed of the join on NVL(..) significantly.

提交回复
热议问题