Select into a variable
486801May 25 2006 — edited May 25 2006Hi,
I am trying to write a script that will find out the min(snap_id) and max(snap_id) from STATS$SNAPSHOT. THis script will pass these two variables when sppurge.sql is run, so it will input the lowsnap and hisnap and delete the old snapshots.
So here is my script, I know it is wrong, can someone help me to fix it?
-----------------------------------
SET VERIFY OFF
SET FEEDBACK OFF
SET SERVEROUTPUT ON
DECLARE
min NUMBER := 0;
BEGIN
select min(snap_id)
into min
from STATS$SNAPSHOT
where STARTUP_TIME < (sysdate-21)
order by snap_id;
DBMS_OUTPUT.PUT( min ); DBMS_OUTPUT.NEW_LINE;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
/
---------------------------
Thanks in advance.
Robert