Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. backp updated row

backp updated row

Scheduled Pinned Locked Moved Database
databasequestionoracleannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fuhrer
    wrote on last edited by
    #1

    hi, at oracle db i want to backup a row when an update request come for the row. how can i make this with pl/sql?

    A 1 Reply Last reply
    0
    • F Fuhrer

      hi, at oracle db i want to backup a row when an update request come for the row. how can i make this with pl/sql?

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      use Update Trigger. Whenever the row is updated use :old and :new objects to get the data from updated row and new row. If it is after update trigger, you need to use :old to get old values otherwise use select from table to get the value. Now insert them to the log table. For instance :

      CREATE OR REPLACE TRIGGER orders\_after\_update
      AFTER UPDATE
          ON orders
          FOR EACH ROW
      
      DECLARE
          v\_username varchar2(10);
      
      BEGIN
      
          -- Find username of person performing UPDATE into table
          SELECT user INTO v\_username
          FROM dual;
      
          -- Insert record into audit table
          INSERT INTO orders\_audit
           ( order\_id,
             quantity\_before,
             quantity\_after,
             username )
          VALUES
           ( :new.order\_id,
             :old.quantity,
             :new.quantity,
             v\_username );
      
      END;
      

      :)

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Simplify Code Using NDepend
      Basics of Bing Search API using .NET
      Microsoft Bing MAP using Javascript

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups