I need to comparte the high_value which is of LONG datatype to sysdate which is of DATE datatype. I need to fetch the partition names of all the partitions which is 90 days old. The code is some what like this.
declare
dt date;
time_to_stay number:=1; --CONFIGURE AS PER THE REQUIREMENT
begin
for x in (select partition_name , high_value, partition_position
from user_tab_partitions
where table_name = 'DEMO')
loop
execute immediate 'select '||x.high_value||' from dual' into dt;
if to_date(dt) < sysdate-time_to_stay AND x.partition_position <>'1' then
execute immediate 'ALTER TABLE DEMO DROP PARTITION '|| x.partition_name|| ' UPDATE GLOBAL INDEXES';
This query executes but does not deletes the partitions. However I see that main issue is converison of LONG datatype of high_value to DATE to make the comparision between high_value and sys_date.
How can I fix this?
execute immediate 'ALTER TABLE DEMO DROP PARTITION FOR (TIMESTAMP '''||TO_CHAR(sysdate - 2, 'yyyy-mm-dd hh24:mi:ss')||''') UPDATE GLOBAL INDEXES';
for example