Oracle PL/SQL - Are NO_DATA_FOUND Exceptions bad for stored procedure performance?

后端 未结 12 870
Happy的楠姐
Happy的楠姐 2021-02-03 23:14

I\'m writing a stored procedure that needs to have a lot of conditioning in it. With the general knowledge from C#.NET coding that exceptions can hurt performance, I\'ve always

12条回答
  •  醉酒成梦
    2021-02-03 23:47

    Rather than having nested cursor loops a more efficient approach would be to use one cursor loop with an outer join between the tables.

    BEGIN
        FOR rec IN (SELECT a.needed_field,b.other_field
                      FROM table1 a
                      LEFT OUTER JOIN table2 b
                        ON a.needed_field = b.condition_field
                     WHERE a.column = ???)
        LOOP
           IF rec.other_field IS NOT NULL THEN
             -- whatever processing needs to be done to other_field
           END IF;
        END LOOP;
    END;
    

提交回复
热议问题