Dynamically reference :old.column_ name in trigger

Hi all,
I am writing an application for which i would like to include a limited audit trail.
I have a form that is based on a table with approx 100 columns and wish to write the :old.column_name value on fields that have been updated, along with userid and date/time to an "audit" table.
I think that I can do this by using the Before_update trigger and then the IF UPDATING ('column name') condition. However, for maintenance and readabiility, I wish to be able to dynamically reference the :old.column_name value, which I cannot get working.
I know it can be done with a large IF statement, but due to the number of columns involved, this can lead to a maintenance nightmare. Also, if I can get this working, I want to include the procedure in a library for other applications, thus the need for dynamically referencing the table and column names.
My proposed logic for the before_update trigger is:
Declare Vcolumn_name Varchar2(50)
Get column names for table (using select cursor)
loop through cursor
Vcolumn_name := column name
IF UPDATING (Vcolumn_name) then
insert userid, timestamp, :old.Vcolumn_name into audit table
end IF
next cursor row
:old.Vcolumn_name is where I am having trouble.
Is this possible?
Thanks
Peter

The pre-update trigger won't store the value of the old.column . If you are querying the data and then updating then use the POST-QUERY trigger to store the current values in global variables. In the PRE-UPDATE trigger assign the global variables to the columns of the audit tables.
For instance in the PRE-FORM trigger initialize the global variables :
:GLOBAL.VAR1 := ' ';
:GLOBAL.VAR2 := ' ';
In the POST-QUERY trigger
:GLOBAL.VAR1 := :BLOCK.COLUMN1;
:GLOBAL.VAR2 := :BLOCK.COLUMN2;
In the PRE-UPDATE trigger
INSERT INTO AUDIT_TABLE (COL1, COL2)
VALUES(:GLOBAL.VAR1, :GLOBAL.VAR2);
Hope this helps.

Similar Messages

  • Dynamic Column Names in Trigger

    I have a trigger which fires on each row. The issue is that I have a lot of duplicate code because there are many columns. Is it possible to abstract the new and old column name references?
    CREATE OR REPLACE TRIGGER a
    BEFORE INSERT OR UPDATE ON table
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
        l_new_column_value VARCHAR2(2000);
        CURSOR l_table_columns IS
        SELECT column_name
        FROM   user_tab_columns
        WHERE  table_name = 'TABLE';
    BEGIN
        FOR col IN l_table_columns LOOP
            EXECUTE IMMEDIATE 'SELECT TO_CHAR(:NEW.' || col.column_name || ') FROM dual'
            INTO l_new_column_value;
        END LOOP;
        IF l_new_column_value IS NOT NULL THEN
            -- Do something useful here.
        END IF;
    ENDI could even do something to the effect of using a CASE statement to assign the value into l_new_column_value based upon the name of the :NEW column, but I still would not know the name of that column and need a way to generically reference it.
    Is something like this possible?

    I've read the linked thread and the method is very interesting and would definitely lend itself to this problem. However, I don't have access to the database server to create an SQL file for it to execute -- if I've followed the thread correctly.
    The application is for auditing purposes. Currently it's a proof of concept but I feel that unless I can automate some of it, it will be doomed to remain as a concept.
    Is it possible to know on the trigger iteration which column the trigger is looking at? I could then use something like this:
    l_new_column_value := CASE :NEW.trigger_column_in_iteration
                          WHEN 'COL1' THEN :NEW.col1
                          WHEN 'COL2' THEN :NEW.col2
                          WHEN 'COL3' THEN :NEW.col3
                          END;

  • I've moved my Aperture library to another computer, and masters are referencing an old path name.  How can I update these references?  Reloctating masters does not work in this case :(

    I've moved my Aperture library from one computer to another using Finder.
    I merged the library with one which was already on the computer.
    Now, the photos I imported have reference to the old path name on my old computer.
    How can I update these references as "Relocate Masters" does not work in this case?

    Just one suggestion to be able to reconnect all at once:
    Create a smart album containing the images with missing masters:
    File -> New ->  Smart Album,     and add a rule: File Status is "Missing"     (or File Status is "offline")
    Then select the images in this album and go to the File menu:
    and select:   File -> Locate referenced File
    If you are lucky, Aperture will reconnect all at once, if you point the first image version to its counterpart.

  • How to check if column_ name is used by any procedure ,package ,function

    Hello
    Help Is greatly appreciated .
    Kindly please let me know for the folllwoing:
    How to check if column_ name is used by any procedure ,package ,function ,trigger or in any dataabse objects

    >
    How to check if column_ name is used by any procedure ,package ,function ,trigger or in any dataabse objects
    >
    In general you can't. Code can always exist outside the database and it is always possible that you have dynamic code and there is no way to find references like that if used by dynamic code. That dynamic code reference could be based on a query stored in a table.
    And there is no way of knowing if external code (e.g. a Java app) references that column.
    Another issue is that a column could exist in multiple schemas and in multiple objects of different types in those schemas. So a global DB search for 'MY_COLUMN' might turn up references in multiple schemas and you may only care about one schema.
    Unfortunately a reference to 'MY_COLUMN' in code could refer to many different objects or to an object in different schemas so how would you resolve those? Especially if you take synonyms into account which can ponit about anywhere.
    Why don't you tell us what it is you are really trying to do?
    Are you trying to find the references to a particular column? Why? Are you planning on removing/renaming the column? If so then the simplest way is to remove/rename the column and see what objects become invalid. Those invalid objects will have become invalid because that column is no longer available.
    As suggested you can use DBA_SOURCE for references in code that use the standard names. But for tables/views you need to use all_tab_columns. And for dynamic code or client code (e.g. a Java application) there is no way.

  • Dynamic Reference to Registered XSD

    I generate docs from SELECT like this,
    <span style="color:red;">(I do not store this type of doc in DB/XDB)</span>:
    <div style="color:blue;">
    SELECT '&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;' || chr(10) ||
    xmlelement
    (&quot;ReinsuranceXfer&quot;,
    xmlattributes
        ('http://blah.com/blah2/types/common' AS &quot;xmlns&quot;,
         'http://www.w3.org/2001/XMLSchema-instance' AS &quot;xmlns:xsi&quot;,
         'http://blah.com/blah2/types/common http://blah3/xmlschemas/Sales_v1.xsd'
         AS &quot;xsi:schemaLocation&quot;),
     xmlelement
        (&quot;SalesTransactions&quot;,
         xmlattributes('DirectTransactions' AS &quot;xsi:type&quot;).......
    </div>
    the schema &quot;Sales_v1.xsd&quot; is XDB-registered.
    In stead of hard-coding <strong>&quot;Sales_v1.xsd&quot;</strong> in PL/SQL or View definition
    I want to DYNAMICALLY reference the value, so when I switch to
    version 2, registering the new schema (deleting the old one)
    the value <strong>&quot;Sales_v2.xsd&quot;</strong>
    can be dynamically referenced.
    Is there a better/&quot;smarter&quot; way to achieve the dynamic reference
    than this ?
    <div style="color:blue;">
    SELECT substr(any_path, instr(any_path, '/', -1) + 1) xsd
        FROM resource_view
       WHERE any_path LIKE '%Sales%.xsd';
    </div>
    thanks
    10gr2

    You can't invoke methods on bits of String as if they were references to objects. (Java isn't like PHP in this regard.)
    You can, however, use arrays as db suggested.
    Let's say I have a hundred toggle buttons. I might give them names like "okButton" "exitButton" etc. Or I might make them elements of an array of buttons, buttonArr.
    And I have a method toggle(int) that accepts an integer as input and verifies that the argument is within the range 1 to 100, throwing an exception if it is not. This method is intended to select the toggle button that corresponds to the integer it receives as input as selected. So the method would be implemented as
    buttonArr.setSelected(true);

  • How do i dynamically reference the contents of an item in a where clause

    I have a select statement that references an item i.e. 'where sysdate=:diary.day1' at the moment, however i want to use this select to loop through every day of the week, so on the fist record it will change depending on where you are in the loop either 'where sysdate=:diary.day1' or 'where sysdate=:diary.day2' etc. I tried using a variable for this but it just uses the characters ':diary.day1' and not the contents of this item.

    Not sure what you want but dynamic reference the content of an item may be done with NAME_IN builtin.
    WHERE sysdate = TO_DATE( NAME_IN(var), 'fmt')
    where var is a variable which contain item name, for example 'DAIRY.DAY1'
    P.S. SYSDATE function contain not only date but time portion too.
    So very little chances that this equation will be true

  • Dynamic reference to buttons

    Hi all,
    I'd like to make dynamic references to togglebuttons (I'm using netbeans). In pseudo code, I would like to be able to do something like:
    For(int i = 1, i<10, i++){
    buttonName = toggleButton;
    buttonName.concat(numToString(i));
    convert buttonName to handler 'handle'
    handle.setSelected(true);
    With classes, it seems to me that I could use Class.forName, but I have no idea how to make this work for an interface element, and I can't find it on the web.
    Any help is welcome, thanks!
    Edited by: jefke33 on Jun 20, 2009 1:12 PM
    Edited by: jefke33 on Jun 20, 2009 1:13 PM

    You can't invoke methods on bits of String as if they were references to objects. (Java isn't like PHP in this regard.)
    You can, however, use arrays as db suggested.
    Let's say I have a hundred toggle buttons. I might give them names like "okButton" "exitButton" etc. Or I might make them elements of an array of buttons, buttonArr.
    And I have a method toggle(int) that accepts an integer as input and verifies that the argument is within the range 1 to 100, throwing an exception if it is not. This method is intended to select the toggle button that corresponds to the integer it receives as input as selected. So the method would be implemented as
    buttonArr.setSelected(true);

  • How do you remove an old device name from your iTunes account?

    I have several old device names/backups on my iTunes that I want to remove.  They were from old iPhones that we've turned into iPod's for my kids which we needed to create a new device name for them.  So now when I restore a device, I have a list of about 10 different names to choose from.
    How can I erase the old names/backups that we no longer use?  I still have 3 on there that I want to keep though so I don't want to erase all of them.

    iTunes Prefs > Devices.
    Selec a backup and delete it there.

  • My old iPad icloud account has an old account name that I no longer subscribe to and will not let me access it. I need to in order to transfer my info to my new iPad. It won't let me change the account name to access the icloud.

    I am updating my iPad from first generation to fifth. I can access my app store info with no problem, but I cannot access iCloud. It has an account name that is greyed out and it's an account name of a service we no longer subscribe to. I keep getting a window that says user name or password is wrong, but it only gives me an option to enter a password that doesn't match up with that old account name. I need to transfer to the new ipad, but how do I get cloud access?

    You need to reset the password for the "old" account, and then use that to turn off iCloud.  Then you will be able to sign in with your new ID.
    You can reset your password at iForgot.apple.com.
    If you don't know the answers to the security questions, you will need to start there.
    http://support.apple.com/kb/HT5312
    -If you established a rescue email address, there will be a link on the "Passwords & Security" page of id.apple.com.  Clicking the link will send the reset to your rescue email address (NOTE:  This is not the same address as your Apple ID email)
    -If there is no link on the page, then you didn't establish a rescue email address.  Contact AppleCare at 800.694.7466 (If you are in the US), and ask for account security.  You will need to answer some questions to verify your identity, AND you will need access to a computer to generate a temporary support pin.
    -If you are not in the US, click http://support.apple.com/kb/HT5699 - Apple ID: Contacting Apple for help with Apple ID account security
    HTH

  • Apple changed my Apple ID to the email address associated with my iTunes account. I now can no longer access my account because the old user name is no longer valid and has no password. I have been on the phone with tech support for hours trying to fix.

    Apple changed my Apple ID to the email address associated with my iTunes account. I now can no longer access my account because the old user name is no longer valid and has no password. I have been on the phone with tech support for hours trying to fix this. I can not update any of the apps associated with that user name.

    Is this itunes on the iPad or on my computer? Thank you for the reply.

  • Is there a way to access Time Machine files associated with an old user name?

    My iMac was running super slow and there was a bunch of programs, etc. that I wanted to get rid of anyway so I thought I would do a "clean install" from my Snow Leopard disc.  I moved items on my desktop to my Seagate external drive and then unplugged it.  I have had Time Machine saving to it for a long time so I was confident I could just move a few items (pictures, music, etc.) back on to my hard drive when the install was completed.  To my surprise, when I went to Time Machine I found the items I had moved from my desktop but no earlier versions of my other files. 
    In researching this issue a little bit, it appears that perhaps I created a new user name when I did the install and that my historical items are likely still on the Seagate but stored somewhere associated with my old user name.  I understand that if I can change my user name back to the original that I may be able to access the items and transfer the items I want.  To compound the situation, I have no idea what my old user name even was.
    Does this make sense to Mac experts out there?
    If so, is there a way to see the old user names and access the Time Machine files?
    I've been avoiding telling my wife that I may have lost all our kid photos so I'm desperately hoping someone can help.

    The problem is that Time Machine detects your new OS X copy as a new Mac and it doesn't let you access to your backups. To access to them, see > http://pondini.org/TM/E3.html
    Another option would be to access to your backups manually. Open a Finder window, select the Time Machine drive in the sidebar and go to Backups.backupdb > your computer's name > one of the backups > your partition's name, and copy the data you want

  • How can I remove old calendar names from the iTunes sync list?

    I gave my calendars new names as part of reducing the total number of calendars in my iCal, and now iTunes still lists the old calendar names as well as the new ones in its "selected calendars" list, even though these names are no longer present in my iCal nor on my iPod Touch. How can I remove the old calendar names?

    The "genius" folks at the Apple Store lived up to their names. The key was to reset the iSync history in the iSync Preferences.

  • I recently changed my apple id and both my iphone 3Gs and Ipad 2 when synced went straight back to my old id name for my app store how do I change it to the new one and keep it that way?

    I recently changed my apple id and both my iphone 3Gs and Ipad 2 when synced went straight back to my old id name for my app store how do I change it to the new one and keep it that way?

    Try going into your account details on iTunes, change your info there, then sync your devices.

  • Service Registry XSD dynamic reference not working

    Hi ,
    I have published an employee canonical schema to service registry. I have referenced it in my BPEL in my wsdl file as follows
    <schema xmlns="http://www.w3.org/2001/XMLSchema">
                   <import namespace="http://systinet.com/uddi/demo/employeeList" schemaLocation="employees.xsd" id="uddi:company:HR:EmployeeCanonical" />
              </schema>
    I have deployed the BPEL and is working fine. When I updated the service registry to point to the lastest version of canonical file , the BPEL is not reflecting to the new version. I have bounced both bpel server and reg. service but still no difference.
    please let me know how I can dynamically reference the xsd in service registry.
    appreciate your help.
    thanks
    Srini

    Hi
    I am having trouble making the BPEL and Systinet to work together. I have Systinet and BPEL installed separately on 2 different servers. I deployed my web services and registered them in UDDI. I created a new BPEL process and added a partner link to refer to one of the web service I have registered in UDDI. When I create the partner link, it is forcing me to give the wsdl and it also gives an error message " There are no partner link types defined in current wsdl. Do you want create that will by default create partner link type for you?". If I say "NO' then deployment fails. If I say "Yes", then it creates a new wsdl file on the local server etc and gives "<Faulthttp://schemas.xmlsoap.org/soap/envelope/>
    <faultcode>soapenv:Server.userException</faultcode>
    <faultstring>com.oracle.bpel.client.delivery.ReceiveTimeOutException: Waiting for response has timed out. The conversation id is 75164a0815ea471a:-3be8c246:117cc377894:-537b. Please check the process instance for detail.</faultstring>". Any help is appreciated.

  • How to search for a certain cross reference using its name in FM 11?

    How to search for a certain cross reference using its name in FM 11?

    Well, thank you. I am only using Find dialog box. By "name", I'd like to give an example. The background is FM 11 structured. I have an element "xref" which is used to make cross reference. Now In Chapter 1, there is a sentence like "This is an ODU for ...". I made a cross ref of the word "ODU" to its full name "outdoor unit" in Chapter 2 (in the same book). After this, the word "ODU" in the sentence in Chapter 1 will no longer be a plain text. So I no longer can use the find dialog box to search for "ODU" because it is already an xref rather than text. I am not if it's clear.

Maybe you are looking for

  • How do I move a file from my mailbox to my desktop/

    How do I move a file from my mailbox to my desktop ?

  • Chromosomes and genes in portal look and feel

    Hi everybody. Has anyone experimented succesfully the use of genes and chromosomes in bea portal 9.2? I have troubles with look and feel editor, that doesn't show inlined css, and runtime also, that seems to always get the default.chromosome file ins

  • Preventing Change of Documents

    We would like to maintain some word documents on an existing server location and link them to some objects within SAP. We are able to do this by defining a document carrier and adding it and the document name when creating a document via CV01N.   The

  • Music Card in Italy

    Hi, I want to buy an iTunes Music Card in Italy. Do anyone know, where I can buy one? Thanks, Mammut

  • FRM-9999 Error

    I get this error when I try to run a report from a form on the web. The tricky part is that it doesn't happen always. I have noticed it happens only if the forms server is left idle for some time. The system specifications are Server O/s and version