If I understand the question, this code should be helpful.
First procedure does what you ask, second is a procedure to send email using UTL_SMTP.
Main Topics
Browse All TopicsCan anyone please assist me, how can i implement following logic in stored procedure which will be executed on daily basis. -
-Step1-Insert sysdate-2weeks data to historical table from regular table A
-Step2- Once step2 execute successfully, then count number of rows loaded into historical table with number of rows from regular table A for sysdate-2weeks. If count matches, then, drop the partition which belong to sysdate-2 weeks from regular table. And if does not match then email the alert to team. Also, if any of the step fail, then raise alert alarm to team by sending email.
Thanks in advance
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This part of your requirement is not clear: "stored procedure which will be executed on daily basis. -
-Step1-Insert sysdate-2weeks data to historical table from regular table A"
You want the procedure to run every day, but gather data for two weeks? Or, should it only gather data from the date that is exactly two weeks ago?
Then, if you really want to "drop the partition" in a PL\SQL procedure, you should be aware that DDL statements like this are not directly supported in PL\SQL. You can use them, either in "execute immediate('DDL command')" or in the more complex procedures of the DBMS_SQL package that you can use if you want to. So, it is possible to do DDL commands in PL\SQL but there are some restrictions. Also, you will need to use a query to determine the name of the partition that you want to drop. We don't know your table partitioning details, so we cannot write that query for you based on the data you have given us so far.
Mark-
Below are my responses
-should it only gather data from the date that is exactly two weeks ago?
- am aware that DDL need to be used.
-need to determine query to drop whihc partition name. The table is partitoned by range on createdate column. The partition is created daily based on sysdate and two weeks older partition need to be dropped daily for which can you let me know how can i extract partition for date create -sysdate-2weeks.
Can your partition names be used to determine the oldest partition? Maybe yes, or maybe no. You haven't told us what mechanism creates these partitions and how it determines a name for the partition. If the partition name cannot be used, then you need a more-complex query to extract the "high_value" (which is in a "long" data type) and convert that to varchar2 so that you can compare them and find the partition with the minumum values.
Here is a query that I use to get table partition information, but this works in our system because the mechanism I use to create new partitions always includes the current date in the partition name, so I can easily identify the partitions with the highest values (which is what this query looks for). It would be just as easy in our system to select the "min" instead of the "max" partition name to find the earliest partition for a table.
select substr(tp.TABLE_OWNER,1,10
substr(tp.TABLE_NAME,1,27)
substr(tp.PARTITION_NAME,1
tp.HIGH_VALUE,
substr(tp.TABLESPACE_NAME,
pc.column_name
from dba_tab_partitions tp, dba_part_key_columns pc
where tp.PARTITION_NAME = (select max(x.partition_name) from dba_tab_partitions x
where x.table_owner = tp.table_owner and x.table_name = tp.table_name)
and tp.table_owner not in ('SYS','SYSTEM')
and tp.table_name not like 'BIN$%'
order by table_owner, table_name;
Business Accounts
Answer for Membership
by: Sharath_123Posted on 2009-11-02 at 20:03:45ID: 25725961
Can you try to write code for your requirement? From there, the experts can assist you.