How to drop all partitions from all tables belonging to this schema based on date
Hi,
I have a script to delete the partition from a table which meet certain criteria and this the block of code to do this :
DECLARE
v_sql varchar2(500);
v_date DATE;
v_partition_name user_tab_partitions.partition_name%TYPE;
v_high_value user_tab_partitions.high_value%TYPE;
CURSOR c1 IS SELECT PARTITION_NAME, HIGH_VALUE
FROM user_tab_partitions WHERE TABLE_NAME=’TEST_YFS_BAT_LOC_H’ AND PARTITION_NAME!=’P0′;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO v_partition_name, v_high_value;
EXIT WHEN c1%NOTFOUND;
v_date := to_date(SUBSTR(v_high_value,11,19),’YYYY-MM-DD HH24:MI:SS’);
IF v_date < (sysdate – 30) THEN
v_sql := ‘alter table TEST_YFS_BAT_LOC_H drop partition ‘ || v_partition_name;
EXECUTE immediate v_sql;
END IF;
END LOOP;
CLOSE c1;
END;
/
Now I want to drop all partitions from all tables belonging to this schema. So how can I do something similar action but for all ?
Thanks in advance.