Can %NOTFOUND return null after a fetch?

前端 未结 3 1452
难免孤独
难免孤独 2020-12-10 06:02

This question raised a very interesting point; there seems to be a contradiction in the Oracle documentation on whether it\'s possible for %NOTFOUND to be null

3条回答
  •  独厮守ぢ
    2020-12-10 06:35

    I think the part that's tripping you up is this:

    If FETCH never executes successfully, the EXIT WHEN condition is never TRUE and the loop is never exited.

    Somewhere in the past there must have been a code example which looked like this:

    LOOP
      FETCH c1 INTO name;
      EXIT WHEN c1%NOTFOUND;
      -- Do stuff
    END LOOP;
    

    Given this chunk of code, then the statement rings true. If the fetch never executes (fails), then %NOTFOUND will be null. The EXIT WHEN condition will not evaluate to TRUE (null evaluates to false). Then, indeed, the loop will continue forever.

提交回复
热议问题