1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Procedure to delete and insert new records

Discussion in 'SQL PL/SQL' started by Mattz, Feb 15, 2016.

  1. Mattz

    Mattz Active Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    55
    Location:
    Houston
    SQl wizards,
    I was hoping one of you can help me structure an procedure that can help me delete records based off a qualifier from the new data set that is ready to be loaded- Basically an delete before insert. I have attached the excel sheet with details on what i wish to achieve, any pointers in the right direction is greatly appreciated.


    heres what i have so far- but its not working though .

    create or replace PROCEDURE REMOVE_DUPS
    IS
    BEGIN
    -- Insert timestamp into temp table
    DELETE FROM dailyproduction WHERE qualifier IN (SELECT qualifier FROM dailyproduction_temp);
    -- Copy the temp table into main table
    INSERT INTO dailyproduction select * from dailyproduction_temp;
    -- Drop temp tables
    DELETE FROM DailyProduction_Temp;

    END REMOVE_DUPS;
     

    Attached Files:

  2. Bharat

    Bharat Community Moderator Forum Guru

    Messages:
    1,747
    Likes Received:
    147
    Trophy Points:
    1,805
    Location:
    Vijayawada, India
    Are you facing any issues with the above code?

    Have you tried executing the above script in dev instance ?
     
    Mattz likes this.
  3. Mattz

    Mattz Active Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    55
    Location:
    Houston
    Hi Bharat,
    The code is working ok for now, but was not sure if this is the best way to do it.? is there any better way to write it?? Would using a trigger better solve my case scenario?? The actual data set would be millions of rows though