Store the procedure to take place the functioning of certain values in the column.

Hello

Can someone tell me please how to do this?
I have three 1:emp(empno,ename,deptno,sal) of table
2:emp_changes(empno,ChangeTime(timestamp),Operation(VARCHAR2))
3:emp_metadata(TableName(varchar),MaxTime(timestamp))


I want to create a trigger that will follow any DML operation on the emp table and add a line for each empno (as main in emp), operation timstamp operation and the name of the operation (Insert, update, or delete) in the emp_changes table.
As it will insert or update in table emp_metadata with the name of the table and the maximum time of table emp_changes.


emp_changes table will be that a single row.if there is no line it will insert in the contrary case, it will update this line.


anone can you please write this trigger for me?



Thank you
Madam.

Published by: Nico on August 9, 2010 04:15

Try this:

SQL> create or replace trigger my_emp_trig after insert or update or delete on emp
  2  for each row
  3  declare
  4  v_empno NUMBER := 0;
  5  v_systimestamp TIMESTAMP := SYSTIMESTAMP;
  6  v_meta_cnt NUMBER := 0;
  7  begin
  8  BEGIN
  9  SELECT empno INTO v_empno FROM emp_Change where empno = :new.empno;
 10  exception
 11  when no_Data_found then
 12  v_empno := 0;
 13  end;
 14  IF (v_empno = 0) THEN
 15  IF INSERTING THEN
 16  insert into emp_change values(:new.empno,v_systimestamp,'INSERT');
 17  ELSIF UPDATING THEN
 18  insert into emp_change values(:new.empno,v_systimestamp,'UPDATE');
 19  ELSE
 20  insert into emp_change values(:new.empno,v_systimestamp,'DELETE');
 21  END IF;
 22  SELECT COUNT(*) INTO v_meta_cnt from emp_metadata where tablename = 'EMP';
 23  IF (v_meta_cnt = 0) THEN
 24  insert into emp_metadata values('EMP',v_systimestamp);
 25  ELSE
 26  update emp_metadata set maxtime = v_systimestamp where tablename = 'EMP';
 27  END IF;
 28  ELSE
 29  IF INSERTING THEN
 30  update emp_change set operation='INSERT',changetime=v_systimestamp
 31  WHERE empno = :new.empno;
 32  UPDATE emp_metadata set maxtime = v_systimestamp where tablename = 'EMP';
 33  ELSIF UPDATING THEN
 34  update emp_change set operation='UPDATE',changetime=v_systimestamp
 35  WHERE empno = :new.empno;
 36  UPDATE emp_metadata set maxtime = v_systimestamp where tablename = 'EMP';
 37  ELSE
 38  update emp_change set operation='DELETE',changetime=v_systimestamp
 39  WHERE empno = :new.empno;
 40  UPDATE emp_metadata set maxtime = v_systimestamp where tablename = 'EMP';
 41  END IF;
 42  END IF;
 43  end;
 44  /

Trigger created.

SQL> insert into emp values(1,'A',1000);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from emp_change;

     EMPNO CHANGETIME                                                                  OPERATION
---------- --------------------------------------------------------------------------- ----------
         1 06-AUG-10 06.59.04.696958 AM                                                INSERT

SQL> select * from emp_metadata;

TABLENAME
----------------------------------------------------------------------------------------------------
MAXTIME
---------------------------------------------------------------------------
EMP
06-AUG-10 06.59.04.696958 AM

SQL> insert into emp values (2,'B',1000);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from emp_change;

     EMPNO CHANGETIME                                                                  OPERATION
---------- --------------------------------------------------------------------------- ----------
         1 06-AUG-10 06.59.04.696958 AM                                                INSERT
         2 06-AUG-10 06.59.28.532472 AM                                                INSERT

SQL> select * from emp_metadata;

TABLENAME
----------------------------------------------------------------------------------------------------
MAXTIME
---------------------------------------------------------------------------
EMP
06-AUG-10 06.59.28.532472 AM

SQL> update emp set sal = 20000 where empno = 1;

1 row updated.

SQL> commit;

Commit complete.

SQL> select * from emp_change;

     EMPNO CHANGETIME                                                                  OPERATION
---------- --------------------------------------------------------------------------- ----------
         1 06-AUG-10 06.59.51.060050 AM                                                UPDATE
         2 06-AUG-10 06.59.28.532472 AM                                                INSERT

SQL> select * from emp_metadata;

TABLENAME
----------------------------------------------------------------------------------------------------
MAXTIME
---------------------------------------------------------------------------
EMP
06-AUG-10 06.59.51.060050 AM

Tags: Database

Similar Questions

  • Store the result of a function in a variable

    Hello
    I have an interface where I do some transformations (get Oracle COST of the corresponding values of PeopleSoft). For research, I have a PL/SQL function in place. This function takes the values of the columns in my input in the runtime source data store. I want to store the result of the function in a variable, use the variable instead of calling the function again later. Any help is appreciated.

    Hello

    I had the problem...

    Gotta 'keep' the same order value to execute the PL/SQL only once...

    In this case, a first suggestion is:

    (1) create an interface to load a temporary table (yellow interface). The target table will be the PK and a field with the PL/SQL returned returns. The source will have the same tables as the real interface.
    Remember, IKM, to set the create table and options to truncate to 'yes '.

    2) add the temporary table to the real interface (drag / move the yellow interface itself in the source of real interface box) and create a join by PK.

    (3) just to map the column transformed (from the temporary table) for columns 4 targets...

    This help you?

    Published by: Cezar Santos on 02/12/2008 13:52

  • How to store the original and to remove some duplicate songs in iTunes on a PC Win7, which took place after iTunes to scan for music during a re - install?

    How to store the original and to remove some duplicate songs in iTunes on a PC Win7, which took place after iTunes to scan for music during a re - install?

    I recently had to format my hard drive and reinstall iTunes 12.3.2.35 on my Win7 PC. As part of the re - install iTunes, I clicked on the button scan for music.  This has created duplicates several of my songs.  I deleted then the duplicate songs from iTunes, but when I went to play a few songs a pop-up said "the song would not be because the original could not be found.  You want to locate? "When I tried to locate the song it is not found, but when I pulled the songs out of the trash they could be found.

    How can I keep the original and remove any duplicate songs in iTunes on PC Win7 which took place after iTunes to scan for music during a re - install?

    iTunes can create duplicates if the same content is added several times from outside the media folder when it is about to make copies of everything that is added to the library, or is added from an external drive that hosts the press kit that was disconnected during the launch of iTunes.

    Official notice of Apple on the duplicates is here: find and remove duplicates in your iTunes library. This is a manual process and article fails to explain some of the potential pitfalls such as the lost coast and membership of playlist, or sometimes the same file can be represented by multiple entries in the library as well as a removal and recycling the file will break all the others.

    Use MAJ > display > show items to reproduce exactly to display the duplicates because it is normally a selection more useful. You must manually select all but one of each group to remove. Sort the list by Date added can make easier select appropriate tracks, but it works better when executed immediately after the dupes were created.  If you have several entries in iTunes connected to a same file on the disk hard then don't not send to trash.

    Use my DeDuper script (Windows only) If you are not sure, do not want to do it by hand, or want to maintain ratings, play counts and playlist membership. See this background thread , this post for detailed instructions and Please take note of the warning to back up your library before deduping.

    (If you don't see the menu bar press ALT to temporarily view or CTRL + B to keep displayed.)

    The latest version of the script can put away the dead links as long as there is at least a double live to merge his stats and membership of the playlist and must deal wisely when the same file has been added through multiple paths.

    TT2

  • If I create a WinPE 2.0 distribution (Syslinux or PXElinux) which will take place on one of the machines running 'something Microsoft' what are the implications of license?

    The WinPE Licensing implications

    Hello

    I have a number of customers with machines that are fully licensed with XP, XPe or Vista.
    Each of these clients have a device that we have created, piloted by drivers custom within the OS.  The operating system will sometimes funny (corruption, etc.) causing the device to not function.
    I decided to create a diagnostic utility to check whether the fault is in the operating system, driver or device.  Because the fault could be deep in the operating system, the only way I can see to do is through WinPE
    I searched the net, but can do not seem to arrive at an acceptable legitimate answer... So here's my question.
    If I create a WinPE 2.0 distribution, either for CD, USB or chain loaded from Linux (Syslinux or PXElinux) which will take place on one of the machines running 'something Microsoft' what are the implications of license? Is it legal?
    Operating system licenses are not owned by us, but our customers if we do not have mass of licensing agreements or something like that.
    The plan is to create a unique distribution and add drivers to it that we encounter different machines.  I know it's frowned upon to speak Hirens on a MS site, but something similar to that (I won't use Hirens because I want that it is completely legitimate)
    I called him to the reading of the license with WAIK, but can do not seem to find anything about this.
    Thank you

    Hello

    This is not a question of normal consumption. I suggest you to contact our Legal Department for legal terms Express. http://www.Microsoft.com/about/legal/en/us/default.aspx

    I also suggest that you send your query in TechNet and check.

    http://social.technet.Microsoft.com/forums/en-us/operationsmanagergeneral/threads

  • When there are several tabs open, why the search always take place on the 2nd tab (first tab seems never to change the homepage) despite my selection of a different tab where to do a search on google?

    I have Mozilla Firefox 10.0. When I open it, it opens properly on the homepage in the first tab. Once I have another, or several, tabs opened, any tab is active, your google searches, I immediately takes place at the No. 2. Do not count how many times I go to the tab for example 4 to search (because I would compare with the page Web open in a tab 2), but it does still today the Search tab 2. It's very irritating. It must be a setting that went pear-shaped, but where / who? Any suggestions? Thank you.

    Try Firefox SafeMode to see how it works there.

    A way of solving problems, which disables most of the modules.

    (If you use it, switch to the default theme).

    • You can open the mode without failure of Firefox 4.0 + by pressing the SHIFT key when you use the desktop Firefox or shortcut in the start menu.
    • Or use the Help menu option, click restart with the disabled... modules while Firefox is running.

    Do not choose anything at the moment, just use 'continue in safe mode.

    To exit safe mode of Firefox, simply close Firefox and wait a few seconds before using the shortcut of Firefox (without the Shift key) to open it again.

    If it's good in Firefox Safe mode, your problem is probably caused by an extension, and you need to understand that one.

    http://support.Mozilla.com/en-us/KB/troubleshooting+extensions+and+themes

    When find you what is causing that, please let us know. It might help others who have this problem.

  • Replace old hard drive with an SSD.  Nowsome keys on the keyboard no longer works.  Ex 'e' and 'b' keys no longer work?  Any idea what could take place in the disc replacement?

    Replace old hard drive with an SSD.  Now some of the keys on the keyboard stopped working.  Ex 'e' and 'b' keys no longer work?  Any idea what could take place in the disc replacement?

    Probably nothing, it's probably a fluke. Try resetting the SMC and the PRAM by iMac Intel SCM and reset the PRAM. If this does not work, try a USB keyboard to test, if it works then your original keyboard has failed and must be replaced.

  • Buttons stops responding when the event takes place

    I have two independent loops while in a VI. A while loop have a structure of the event. Buttons stop responding when the event takes place. Is there a solution for this problem.

    If you change the event you can see the 'Lock Front panel' option, if you uncheck the box that your PC will not be locked. But the wisest method does not perform any operation within the structure of the event.

  • Can't seen to return the files to back up. presentl all backup takes place by carbonite.

    Original title: cannot activate the backup.

    can't seen to return the files to back up.  presentl all backup takes place by carbonite.

    Ask the staff to Carbonite support.

  • Lately when I turn on my computer, I get a message saying. "Windows mail can compact the message store. This can take up to a few minutes. »

    Lately when I turn on my computer, I get a message saying. "Windows mail can compact the message store. This can take up to a few minutes. "It looks like a real message of Windows but when I click on the link"Get help from communities", it does not work. I cancel or close the message, because I fear that the message can be fake and won't open my computer for a virus or worse. Anyone has any info on this particular message? I can't find anything in the help section of Windows. Thank you.

    original title: compaction of the database messages

    Hi Kathy,

    Please click on the orange button at the top of this page that will help you find the right forum for your problem in ads.

    Mike

  • Anyone has an idea how to manually remove items that do not appear in the Collection, but take place on the device. Specifically, an audio book downloaded via Overdrive?

    Anyone has an idea how to manually remove items that do not appear in the Collection, but take place on the device.  Specifically, an audio book downloaded via Overdrive?

    Hello

    1. what type of files are in the audio book? Could you provide me with the file extensions?
     
    If you delete the information or files audio books could not show some information. I wouldn't recommend allows you to delete the files. If you want to remove them, you can contact overdrive support.

    Hope this information helps.

    Thank you, and in what concerns:
    Shekhar S - Microsoft technical support.

    Visit our Microsoft answers feedback Forum and let us know what you think.
    If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • where is the RADIUS/Ganymede communication that takes place

    Hello

    If iam connect to a domain and my domain name is configured for authentication to the ACS, where is the RADIUS/Ganymede communication that takes place?

    -C' is from the client to the ACS

    - or is it the domain of ACS

    client--(PAP/chap/EAP)--NAS--(RADIUS/TACACS)--ACS--ad

    Kind regards

    Prem

    Please rate if this can help!

  • E-mail from Microsoft; I received an email on the new Microsoft service contracts, changes that will take place on 19 Oct.

    I received an email on the new Microsoft service contracts, changes that will take place on 19 Oct. I did not open the link. Is it a scam?

    Hello

    Be VERY careful as there are a the TWO legitimate versions and the versions of MALICIOUS software
    who are being sent. Best thing to do is to DELETE the email, then go to the
    Microsoft sites to read information.

    Check this thread:

    http://answers.Microsoft.com/en-us/feedback/forum/user/just-read-the-service-agreement-but-do-not/78052e97-1fad-4E93-8ea0-d616acf45b37

    and this one:

    http://answers.Microsoft.com/en-us/windowslive/Forum/LiveID-profile/important-changes-to-Microsoft-services-agreement/edcdb91d-b5e6-4936-b0a0-37df78cf3498

    --------------------------------------------------------------------------------------------------------

    Here are the legitimate links to information in the email.

    http://Windows.Microsoft.com/en-us/Windows-Live/Microsoft-services-agreement

    http://www.microsoft.com/en-us/default.aspx

    http://privacy.Microsoft.com/en-us/default.mspx

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle=""><- mark="" twain="" said="" it="">

  • Import of high-resolution images of ArcGIS (PC) to Illustrator C4 (Mac)-"Cannot take place due to an error" / "the file size is too big.

    I make a great conference poster that will contain images of ArcGIS. The poster will be 92 "x 42" and Imaging will cover 91 by 22 in the page. The problem is that I need very high resolution for imaging, but illustrator won't import my files. I use ArcGIS 10.3 on Windows 10 and Illustrator C4 with OS X 10.11.1 (El Capitan). I was not able to import any .tiff file into illustrator (is this possible?) and I get "cannot take place due to an error" or "the file is too big" errors when I try to put .jpeg, .png, .ai files exported from the GIS. I think that the problem is due to the differentoperating systems, rental However, can I open and edit (resize etc.) files in preview without any problem, so there is also a problem with Illustrator. The files that I use are more than 150 MB at 300 dpi, but I really prefer to use 600 dpi, Illustrator can't handle these files sizes? I don't want to lose the resolution using .jpeg, .pdf, etc., many types of compression will cause problems with vector layers from ArcGIS.  Please notify!

    Update your AICS4 to something with the ability to access more than 3 GB of memory RAM as CS6 or above. You'll never work with CS4, at least not to the resolution as you seem to think you need. Indeed, you could probably use 150ppi or the bottom of the poster and not obviously nothing to lose. And for the record, I worked for 17 years for the USGS working with ARCGIS and AI.

  • Why a menu that takes place does not change the width of my mobile site?

    Hello! I placed a vertical menu inside an accordion for a menu widget that takes place for a mobile Web site. Problem: When I open the menu with Safari on iPhone (iOS 9) the page gets some unwanted extra large. I can't find any objects that might happen on the border. What is the reason for this behavior?

    Web site: Büromöbel Lippische

    Thank you for sharing the file.

    In the content area of the accordion panel you have placed the menu as the 100% with the order of the day.

    Please select the menu and make sure that the 100% button is not active on this issue. Republish the site and it works perfectly then.

    Concerning

    Vivek

  • I tried to download the creative cloud and it didn't download correctly (after a long time) and now I can't uninstall it. It takes place on my computer but I cannot uninstall the Adobe application. Help please!

    I tried to download the creative cloud and it didn't download correctly (after a long time) and now I can't uninstall it. It takes place on my computer but I cannot uninstall the Adobe application. Help please!

    Hi Julie,.

    Please see the below help document to uninstall the application:

    Using creative cloud | Download, install, update or uninstall applications

    Otherwise, you can use the CC cleaning tool as well.

    Use the CC cleaning tool to resolve installation problems. CC, CS3 - CS6

    Kind regards

    Sheena

Maybe you are looking for