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

后端 未结 12 851
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-04 00:05

    Yes, you're missing using cursors

    DECLARE
      CURSOR foo_cur IS 
        SELECT NEEDED_FIELD WHERE condition ;
    BEGIN
      OPEN foo_cur;
      FETCH foo_cur INTO foo_rec;
      IF foo_cur%FOUND THEN
         ...
      END IF;
      CLOSE foo_cur;
    EXCEPTION
      WHEN OTHERS THEN
        CLOSE foo_cur;
        RAISE;
    END ;
    

    admittedly this is more code, but it doesn't use EXCEPTIONs as flow-control which, having learnt most of my PL/SQL from Steve Feuerstein's PL/SQL Programming book, I believe to be a good thing.

    Whether this is faster or not I don't know (I do very little PL/SQL nowadays).

提交回复
热议问题