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

后端 未结 12 958
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:13

    Since SELECT INTO assumes that a single row will be returned, you can use a statement of the form:

    SELECT MAX(column)
      INTO var
      FROM table
     WHERE conditions;
    
    IF var IS NOT NULL
    THEN ...
    

    The SELECT will give you the value if one is available, and a value of NULL instead of a NO_DATA_FOUND exception. The overhead introduced by MAX() will be minimal-to-zero since the result set contains a single row. It also has the advantage of being compact relative to a cursor-based solution, and not being vulnerable to concurrency issues like the two-step solution in the original post.

提交回复
热议问题