Showing posts with label PLSQL. Show all posts
Showing posts with label PLSQL. Show all posts

2014-01-31

Using Oracle collection instead of cursor

Environment: Oracle 11.2.0.3

ORA-01555 "Snapshot too old" occurs when "fetch across commits" is used (committing inside of open cursor loop).
Possible solution is to use Oracle collection instead of cursor:

set serveroutput on
declare
    TYPE nested_typ IS TABLE OF NUMBER;
    t1   nested_typ;
begin
   select AGENT_INSURER_ID BULK COLLECT into t1
     from AGENT_INSURER 
    where 1=1;  -- conditions
--
  FOR i IN t1.FIRST..t1.LAST LOOP
    DBMS_OUTPUT.PUT_LINE('ROW_NUM: '||i||' AGENT_INSURER_ID: '||t1(i));
    procedure1(t1(i)); -- which has COMMIT inside
  END LOOP;
end;
/

2009-06-24

change sysdate

environment: Oracle 10.2

To change sysdate for testing purposes in one database,
create new scheduler job with e.g. 1 minute interval.

Following example code has +7 days offset.
Parameter fixed_date changes only sysdate, it doesn't change systimestamp.

begin
EXECUTE IMMEDIATE ( 'alter system set fixed_date='
|| ''''
|| to_char(systimestamp+7,'YYYY-MM-DD-HH24:MI:SS')
|| '''');
end;