开发者

Oracle stored procedure cursor always returns zero rows

开发者 https://www.devze.com 2023-04-03 08:22 出处:网络
I have this cursor in a procedure in a package: PROCEDURE CANCEL_INACTIVE(IN_DAYS_OLD NUMBER) IS CURSOR inactive IS

I have this cursor in a procedure in a package:

PROCEDURE CANCEL_INACTIVE(IN_DAYS_OLD NUMBER)
IS
    CURSOR inactive IS
          SELECT * FROM MY_TABLE
          WHERE STATUS_CHANGED_DATE <= TRUNC(SYSDATE-IN_DAYS_OLD) 
          AND CANCEL_CD IS NULL;

  rec  inactive%ROWTYPE;

BEGIN
     OPEN inactive;
  开发者_运维百科   LOOP
          FETCH inactive INTO rec;
          EXIT WHEN inactive%NOTFOUND;

          -- do an update based on rec.id
     END LOOP;
END;

END CANCEL_INACTIVE;

Every time I test or run the procedure, inactive always has zero rows. However, when I put the EXACT same query into a SQL window, I get the rows I'm looking for.

What the heck?


Probably you'are testing on noncommited data.

Or: you're not commiting your update based on rec.id.

Or: your update does nothing. (the where clause is not satisfied by any rows on target table)

0

精彩评论

暂无评论...
验证码 换一张
取 消