Clear History Table Every 6 Months - Review my PL/SQL Snippet

The code below clears employees history table every 6 months. The code below executes fine, i'm just trying to make
sure if there is any logic error or not, I don't think so, but i would like to confirm from you.
-- This table holds delete date that deletes records from employee and customer history tables
CREATE TABLE historyDeletionDate (deleteHistoryDate DATE);
CREATE OR REPLACE PROCEDURE clear_emphistory
IS
   dateOfDeletion DATE;
BEGIN
   BEGIN
      SELECT deleteHistoryDate
        INTO dateOfDeletion
        FROM historyDeletionDate;
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
         dateOfDeletion := SYSDATE;
   END;
   IF TRUNC(dateOfDeletion) <= TRUNC(SYSDATE) THEN
      EXECUTE IMMEDIATE 'truncate table CUSTOMERHISTORY';
      EXECUTE IMMEDIATE 'PURGE RECYCLEBIN';
      UPDATE historyDeletionDate SET deleteHistoryDate = ADD_MONTHS(SYSDATE, 6);
   END IF;
END;
/

Hi,
It look good to me: efficient and clear.
Production code should have some comments in it. Pretend that someone (someone you like) has to take over your job without any training on you code. What would that person find useful?
Instead of a one-row, one column table just to hold the next scheduled deleteHistoryDate, consider having a multi-row, 2-column table that also serves as a log of when deletions were actually done. You could have a scheduledDate column that is entered when the job is schduled, and a completedDate column that is originally NULL, but filled in when the job completes. The firest query would be:
SELECT  scheduledDate
  INTO  dateOfDeletion
  FROM  historyDeletionDate
WHERE  completedDate     IS NULL;

Similar Messages

  • Need to Clear table every 2 months....Urgent plsss

    I need to clear a table every 2 months in a report program. Can anyone tell me how i can do this ???

    Hi,
                     You can do it programatically.
    first store the range of month in internal table. e.g in ur case the months are 04 to 08.
    In ur print subroutine for header.
    write this code.
    loop at itab.
    case sy-tabix.
    when 1.
    write: 10 itab-month.
    when 2.
    write: 20 itab-month.
    when 3.
    write: 30 itab-month.
    when 4.
    write: 40 itab-month.
    when 5.
    write: 50 itab-month.
    endcase.
    endloop.
    this will display months in column.
    Now you 've to display the required data for these months.
    e.g ur main itab in which all the data is populated is itab_main.
    loop at itab_main.
    loop at itab. " months itab
    case sy-tabix.
    when 1.
    write: 10 itab_main-value.
    when 2.
    write: 20 itab_main-value.
    when 3.
    write: 30 itab_main-value.
    when 4.
    write: 40 itab_main-value.
    when 5.
    write: 50 itab_main-value.
    endcase.
    endloop.
    endloop.
    This will display your output in columns for months.
    Solution 2.
    if u want to display ur month outpur in a new row.
    U can use event.
    at new month.
    sort ur table by year month first.
    hope it work.
    Regards

  • BB 8330 Messenger auto clears history??

    Ok, so my BB messenger has decided to auto clear history after every sentence I send, usually before or while the the other  party is replying??? Its becoming maddening... and I need any advice to make it stop!
    Also, it seems to randomly go into silent mode, even when my profile is set properly? this is a new phone, had it less than a month, surely there cant be anything that wrong with it, other than user error hehe!
    All replies will be greatly appreciated, thanks in advance y'all!

    Hi and welcome to the forums!
    Please go to options, status, and record the file free number and post it back.
    What version of BBM are you running?
    Thanks,
    Bifocals
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • History seems to clear at the end of every month using the Safari App

    Hi,
    I use Safari a lot and noticed something a little odd with the History clearing itself automatically at what seems to be the start of every month. I have also noticed Safari on my iMac also does a similar thing but not the same.
    Can anyone help at all on this?
    Many thanks
    Adam

    Don't know about the Mac, but for my phone I have noticed sites I do not visit often disappear from URL history when typing in a URL after a time. Never really tracked it down to how long.

  • My 'clear history button is not working. When I click on it it doesn't do anything and the letter are gray instead if blue like usual. I've gone to every type of settings I can bit I don't know how to fix it. Please help .

    My 'clear history button is not working. When I click on it it doesn't do anything and the letters are gray instead of blue like usual. I've gone to every type of settings I can think of but I don't know how to fix it. Please help .

    T
    Try:
    - Reset the iOS device. Nothing will be lost      
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings                 
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                               
    iOS: Back up and restore your iOS device with iCloud or iTunes
    - Restore to factory settings/new iOS device.                       

  • When I open firefox it is returning to the last viewed page instead of my homepage even though I have the settings set to clear history every time I close Firefox. I check and all of the previous history is still there and not deleted..

    When I open firefox it is returning to the last viewed page instead of my homepage even though I have the settings set to clear history every time I close Firefox. I check and all of the previous history is still there and not deleted..

    Make sure that Firefox closes properly and that that there are no longer Firefox or plugin-container processes left on the Processes tab in the Task Manager. Otherwise session restore will reopen the page(s) from the previous session.
    See "Hang at exit":
    * http://kb.mozillazine.org/Firefox_hangs
    * https://support.mozilla.com/kb/Firefox+hangs

  • Have tried several times to clear my browsing history and every time I do firefox freezes

    ''locking this thread as duplicate, please continue at [https://support.mozilla.org/en-US/questions/991437 /questions/991437]''
    have tried several times to clear my browsing history and every time I do firefox freezes and stops responding, then I have to "force quit" from the main menu
    running 28.1

    Problems with bookmarks and history not working properly can be caused by a corrupted places.sqlite database file.
    You can check for problems with the places.sqlite database file in the Firefox profile folder.
    *http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox
    *https://support.mozilla.org/kb/Bookmarks+not+saved#w_fix-the-bookmarks-file

  • Cost to change hash partition key column in a history table

    Hi All,
    I have the following scenario.
    We have a history table in production which has 16 hash partitions on the basis of key_column.
    But the nature of data that we have in history table that has 878 distinct values of the key_column and about 1000 million data and all partitons are in same tablespace.
    Now we have a Pro*C module which purges data from this history table in the following way..
    > DELETE FROM hsitory_tab
    > WHERE p_date < (TO_DATE(sysdate+1, 'YYYYMMDD') - 210)
    > AND t_date < (TO_DATE(sysdate+1, 'YYYYMMDD') - 210)
    > AND ROWNUM <= 210;
    Now (p_date,t_data are one of the two columns in history table) data is deleted using thiese two date column conditions but key_column for partition is different.
    So as per aboove statement this history table containd 6 months data.
    DBA is asking to change this query and use partiton date wise.Now will it be proper to change the partition key_column (the existing hash partiton key_column >have 810 distinct values) and what things we need to cosider to calculate cost behind this hash partition key_column cahange(if it is appropriate to change >partition )key_column)Hope i explained my problem clearly and waiting for your suggestions .
    Thanks in advance.

    Hi Sir
    Many thanks for the reply.
    For first point -
    we are in plan to move the database to 10g after a lot of hastle between client.For second point -
    If we do partition by date or week we will have 30 or 7 partitions .As suggested by you as we have 16 partitions in the table best approach would be to have >partition by week then we will have 7 partitions and then each query will heat 7 partitions .For third point -
    Our main aim to reduce the timings of a job(a Pro*C program) which contains the following delete query to delete data from a history table .So accroding to the >query it is deleting data every day for 7 months and while deleting it it queries this hug etable by date.So in this case hash partition or range partiton or >hash/range partition which will be more suitable.
    DELETE FROM hsitory_tab
    WHERE p_date < (TO_DATE(sysdate+1, 'YYYYMMDD') - 210)
    AND t_date < (TO_DATE(sysdate+1, 'YYYYMMDD') - 210)
    AND ROWNUM <= 210;I have read in hash partition is used so that data will be evenly distributed in all partitions (though it depends on nature of data).In my case i want some suggestion from you to take the best approach .

  • Getting the new products included every month

    Hi friends,
    Iam having two tables
    PRODUCT_CATEGORY - Has the details of the Category of Products
    PRODUCT_SUBCATEGORY - The Subcategory details of the Products.
    I need to create a view to store the product introduced every month, how can i do this?[as i have the created date in the product category table]
    PRODUCT_CATEGORY
    id -- name -- cdate---------------------> fields
    PRODUCT_SUBCATEGORY
    id--catid--name--descriptions ----------------------> Fields
    Help me in this

    Requirements are not very clear..
    Like this..?
    sql>select * from t;
    ID DT
    1  30-JAN-07 
    1  31-DEC-06 
    sql>
    create or replace view vu1
    as
    select * from t
    where to_char(dt,'fmmmyyyy')=to_char(sysdate,'fmmmyyyy');
    View created
    sql>select * from vu1;
    ID DT
    1  30-JAN-07 
    --now db date changed to 01-feb
    sql>select * from vu1;
    no rows selected                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • In ALV: Subtotals for every month, not for every day, possible?

    Hello,
    in my Alv-Grid I have a date column, which I want to use to generate subtotals. But I don't want to have a subtotal for every date, but for every month. Is there a method to accomplish this with subtotals? Thanks.
    Regards, Lars.

    Hi Stembergg,
    1. Its not possible with only date field.
    2. However, if you have one EXTRA FIELD
       which contains the Month
       only then it is possible.
      ( You may hide this extra field if   u don't
      won't to display. But anyhow, u need to
      modify your logic and the internal table
       and accordingly populate the extra field)
    3. There is contraint in alv
        that we cannot use any function for any column value
        for any claculation/grouping purpose.
    Hope it helps.
    Regards,
    Amit M.
    Message was edited by: Amit Mittal

  • Why firefox 3.6 downloads all of the files again after restartarting the browser from a website if the "clear history when Firefox closed" is not Enabled?

    We have a corporate website, we officially support FF3, FF4, IE8 and IE9. Our web site is quite big, so we really need browser caching, first time page load is around 15 seconds. With files in the cache getting new page is less than a second.
    Everything works perfect except with FF3. With FF4, IE8, IE9 if we are on the website, clicking everywhere is fast, the page is in the cache. If we restart the browser, it is still fast, it loads files from the cache.
    But with FF3 we have a problem. Every time we restart the browser, it is loading the files again from the server, instead of using the local cache (checked with Firebug). I can reproduce the problem anytime, it is the same with every FF3 instances. I double checked, the "clear history when Firefox closed" option is not enabled.
    Could you advise please how to use the local cache either after browser restart?
    Thank you!
    Chris

    Just read that the default memory storage on FF is set to 5 mbs. You can up that by clicking on tools, advanced and overriding the default and set it to 50 mbs (if you use lots of tabs) or 10 mbs (if you use just a few).
    I open a blank tab and clear the cache periodically, while I am working. I can have several tabs open and watch videos on Youtube, by doing this. Have you cleared your cache?
    Since I have an older computer, I've also used CCleaner for years. I use it often, but always before signing off. You can get it free...search for CCleaner, download from Pirifoam free. I didn't change any of the settings and it clears crap left behind from uninstalling programs, clears all browsers at once of: cookies, history, passwords, etc. I love it!
    I had freezing, before using the "open blank tab, clear the cache" thing. Now I have no problems. Plus, as I said...you can change the default memory usage for FF and that should help too.
    Hope this helps! Good luck! :)

  • Two renewal orders and charges showing every month for one account and same renewal package, WHY

    Why am I charged twice with two different orders every month for one package of 800 mins. Are they giving me 1600 minutes! I need only 800 minutes please, so please refund these extra order charges please. I just noticed this thing month today and on checking order history find that same practice has been followed for all my previous months transcations!

    Hello and welcome to the Skype Community.
    The duplicate charge has been reversed and the funds will be returned to you.

  • I see people from different ages at my work and every month I need to count how many people from each age I've seen that month. How can I do to give the entries to numbers in a single cell and make numbers count them for me?

    I see people from different ages at my work and every month I need to count how many people from each age I've seen that month. How can I do to give the entries to numbers in a single cell and make numbers count them for me? The final result would be a spreadsheet telling there were 8 people from 20 to 39 years old, 14 peolple from 40 to 59 and so on...

    jpqcampos wrote:
    This appears to be an 'input form' using 'Radio Buttons' to select the category. Neither of these features are supported in Numbers '09.
    You can input the data on one table and summarize it on a second table, but the input table will continue to hold data for each event.
    And by using the Reorganize button, you can hide all but two rows of that table to approximate the appearance and performance of an input form.
    Here are the two tables, Data on the left and Summary on the right. Notes below.
    The grey-filled columns in both tables are 'working' columns, and may be hidden (as shown in the image below).
    Data table:
    D1 contains the word "TRUE" (in capital letters). (This row is always shown.)
    D2 is empty, or may contain any value except "TRUE" (This row is always hidden under the Reorganize rule.)The rest of Row 2 of this table requires the data shown: a number outside the range to be counted (999), and two checkboxes, both checked.
    D3 (and filled down the rest of column D):   =AND(OR(B2,C2),NOT(OR(B3,C3)))
    The formula returns TRUE only for the first unused row in the table (ie. the first row for which neither checkbox has been checked)
    Summary table:
    Column A contains labels for the age ranges to be counted.
    Column B contains the same information in the form necessary for the formulas in columns C and D. They need a numeric value, and that value must be the largest acceptable value in the range to be counted.
    C2 (and filled right to column D, then both filled down to row 5):
        =COUNTIFS(Data :: $A,"<="&$B,Data :: B,TRUE)-SUM(C$1:C1)
    Two changes from the previous example:
    COUNTIFS is used to separate the Native and Foreign counts as well as the age range to be counted.
    The amount subtracted from each result is the SUM of the earlier results, and includes the text value in the first cell of the column (which is interpreted by SUM as a zero).
    See note below regarding my earlier formula.
    When the greyed columns are hidden and the checkbox in the Reorganize pane is checked, the two tables will appear as shown below:
    Close the reorganize pane, and the 'data entry form' is ready to use.
    To use, enter the age first, then check one of the boxes.
    As soon as one box is checked, the row will be hidden, and the next (unused) row will be shown.
    Regards,
    Barry
    Note regarding formula in my earlier post:
    The earlier formula will give erroneous results as it subtracts only the count directly above it from its count of persons in the age range 0-n.
    In E2 of that table, replace "-E1" with "-SUM(E1:E$1)
    Fill down to E8.
    Ignore the instructions (in that post) following "Fill down to E8."
    B

  • Calculating given occurance of a given day in every month

    Hi,
    I'm using oracle 10.2.0.1.0 and forms 6i.
    I have inputs like frequency, day and start date.
    Suppose
    Start Date : 12-03-2011
    Day : Saturday
    Frequency : 2
    What i want to do is, i want to calculate 2nd occurance of saturday(2nd Saturday), in every month, starting from the given date, till the end of the year.
    The given start date, is anyway the 2nd occurance of saturday in March.
    So now in april -- its is 09-04-2011
    May -- 14-05-2011
    June -- 11-06-2011
    Is there a way to calculate like this?
    Please help
    Thanks

    Hi,
    Another way is to use the NEXT_DAY function, like this:
    WITH     parameters     AS
         SELECT     DATE '2011-03-12'     AS start_date
         ,     'SATURDAY'          AS week_day
         ,     2               AS week_num     -- This isn't really a frequency
         FROM     dual
    ,     all_dates     AS
         SELECT  start_date
         ,     NEXT_DAY ( ADD_MONTHS ( TRUNC (start_date, 'MONTH')
                              , LEVEL - 1
                              ) + (7 * week_num)
                             - 8
                     , week_day
                    )     AS a_date
         FROM     parameters
         CONNECT BY     LEVEL     <= 12
    SELECT       a_date
    FROM       all_dates
    WHERE       a_date          >= start_date
    AND       TRUNC (a_date, 'YEAR') = TRUNC (start_date, 'YEAR')
    ORDER BY  a_date
    ;If you're doing this in Oracle Forms, then you don't need a sub-query like parameters. You can pass the parameters in PL/SQL variables, and use dual as the base table in all_dates (or use a PL/SQL loop).
    The calculation of a_date works like this:
    First, we find the beginning of the month.
    Then, we add wekk_num weeks to that. For example, if week_num=2, that will give us the beginning of the 3rd week.
    We're interested in the week before that, so we subtract 7, and we also subtract another 1 because NEXT_DAY always returns a date after (not the same as) its 1st argument.
    Unfortunately, NEXT_DAY is always dependent on NLS_LANGUAGE. If you specify 'Saturday', but that day is called 'Lördag' in your NLS language, you'll get an error. If that's a possibility, then you can change the first sub-query like this:
    WITH     parameters     AS
         SELECT     DATE '2011-03-12'     AS start_date
         ,     TO_CHAR ( DATE '2011-04-02'     -- or any Saturday
                   , 'DAY'          
                   )          AS week_day
         ,     2               AS week_num
         FROM     dual
    ) ...Instead of April 2, 2011, you can you any Saturday you want; just be sure it's a Saturday.

  • How to clear UNB table in the payroll result?

    Hi,
    We are getting the payroll error- The gross wages do not cover the negative offset that has been forwarded. Therefore, no gross up is permitted while running the Grossup.
    I see the below table "UNB table" in the last payroll result. "UNB - Unbalance table used for tax retrocalculation" .
    I think we are getting the above error because of this UNB table, can anyone help me to how to clear this table?
    When we run the regular payroll, no tax is being deducted.
    Please help
    Saurabh

    Hi Arti,
    Thanks for your reply!!..
    Seeing your reply, it gives me bit confidence to crack the existing problem, however, I'm still not clear with your answer... let me explain you the problem-
    1. Employee was given 350,000 though Taxable Bonus WT with regular pay check
    2. Later it came to know- out of the above amount, 75000 was Grossup amount
    3. So in next payroll run, they entered -75000/- in regular Taxable bonus WT and +75000 in Grossup WT and also they deleted one IT210 record of GA tax authority which was wrongly created; and ran the payroll
    4. Since then, in next payroll period- No tax is being deducted, so we are creating IT221 infotypes with Tax wagetype
    5. If we are running the Grossup wage, payroll error- The gross wages do not cover the negative offset that has been forwarded; therefore, no grossup is permitted.
    While running the regular payroll, overpayment Wagetype is being generated.
    Now, I saw this UNB table is created and the below wagetype are there in the UNB table-
    WT /5UT amount 0.00
    WT 5430 amount -75000
    WT 0200 amount 12500 ( Monthly salary)
    WT 4530 amount 350000
    Now I am thinking, if we are deducting tax through IT221,if we clear this UNB table, our problem might get resolved
    It will be a great help for me if you can tell-
    1. how to check, claims process is implemented or not?
    2. I have good HCM experiece but this claims process is very new to me- pls guide me how to do that
    Waiting for your reply, thanks in advance
    Saurabh Garg

Maybe you are looking for

  • Using DB in iweb site

    Hello, I recently created a site using iweb, and I'm wondering if there is any way to use DB technology within the site. For example, can I have someone search for a topic using keywords, and have certain pages returned from one of my databases based

  • Import CLASS with no package name in VAJ

    IMport statement in VAJ for .class (no source and No package specified in the class) goes always to the "default package". Is there any way how to: 1. change package in existing class wihout source 2. do the "package naming" when the class is importe

  • Constant error messages related to PACESupport

    When using Disk Utility, I consistently get a series of three error messages stating "System extension cannot be used." The extensions are: PACESupportkext PACESupport2kext PACESupportSnowLeopard.kext If anyone has any information about how to remedy

  • Calculate salary of employee from April to December ??

    Hi all, I want to find the salary of the employee from April to December month for that particular year entered on the selection screen, and then from January to March as well. How is it possible? I tried looking into various infotypes, but I couldn'

  • RH 8 and RoboHelp Server 8

    Hello Everyone,  I need some guidance on how to publish WebHelp Pro to RoboHelp Server 8.  We received an error message:  "Warning: Failed to Publish to "RoboHelp Server". reason:  Cannot connect to server:  XXXXXX". We're able to access the RoboHelp