i have in a procedure which fills a table the following sql
SELECT NVL(SUM(COL1), 0),
NVL(SUM(COL2), 0)
INTO v_mytable.COLUMN1,
v_mytable.COLUMN2
FROM t1, t2
WHERE t1.id = t2.id
AND t1.date = t2.date
also, for 99% of the table rows, those columns = 0 and this query take a long time to be executed when it will return 0 for both columns in most cases.
Is it better to use exception handeling as the following :
BEGIN
SELECT SUM(COL1),
SUM(COL2)
INTO v_mytable.COLUMN1,
v_mytable.COLUMN2
FROM t1, t2
WHERE t1.id = t2.id
AND t1.date = t2.date
EXCEPTION WHEN NO_DATA_FOUND THEN
v_mytable.COLUMN1 := 0 ;
v_mytable.COLUMN2 := 0 ;
END;
Thanks.
Those two blocks do completely different things. Your SELECT statement would not throw a
NO_DATA_FOUNDerror if COL1 and/or COL2 were always NULL. It would simply put a NULL inv_mytable.COLUMN1andv_mytable.COLUMN2.You could do
I wouldn’t expect that to be any faster, however.