Update audit table trigger by a column

Have a need to update a audit table when a specific column data has been updated\deleted\inserted on table T1 . The column is Grade_complete.
My first thought was to create an instead of trigger since the form was based on the table (T1) view
( CREATE OR REPLACE TRIGGER "AI_T1" AFTER INSERT OR UPDATE OF grade_complete ON T1........) but then I realized with instead of , I can't create a trigger with a update of . Can anyone give me some suggestions on how to resolve this ? There got to be something easy that I am just not getting it now.
Thanks.
Wan

Jure, Roel;
Thanks for the reply.
I have no permission to create triggers on the table so instead of being used. when ran the following statement , I am getting "ORA-25004: WHEN clause is not allowed in INSTEAD of triggers. Have tried if statement to no avail. Can anyone help ?
create or replace trigger ioft_test
instead of insert or update or delete on T1
referencing old as old new as new for each row
when nvl(new.grade_complete, 0) != nvl(old.grade_complete, -1)
declare
v_seq number;
begin
insert statemetn here
end;

Similar Messages

  • Need to create a audit table column change wise

    Is it possible to know which column value has been change? when ? by which operation(insert,update,delete) ?
    have any view or trigger?
    MY sample audit table like
    CREATE TABLE CHANGE_TRACK
    SERIAL NUMBER NULL,
    TABLE_NAME VARCHAR2(100 BYTE) NULL,
    COLUMN_NAME VARCHAR2(100 BYTE) NULL,
    COLUMN_VALUE VARCHAR2(1024 BYTE) NULL,
    CHANGE_TIME DATE NULL,
    OPERATION_TYPE VARCHAR2(20 BYTE) NULL
    Thanks
    Halim

    I have found my solution here
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:59412348055
    Thanks
    Halim

  • Trigger problem -- can't insert the same data into audit table

    Sir/Madam,
    I'm trying to use insert trigger with a 'long raw' datatype data for my audit purpose. Each time, the data of original table can be inserted correctly. While the trigger for audit table in which it contains almost the same data as original would failed. The error messages are some thing like following:
    java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column
    ORA-06512: at "CORPSEC.TI_ARCHIVE_PDF", line 9
    ORA-04088: error during execution of trigger 'CORPSEC.TI_ARCHIVE_PDF'
    If the column with 'long raw' datatype is taken out, then there is no error at all. I'm using Oracle 8i 8.1.6 for Windows NT and suspect there is bug in PL/SQL execution.
    The following are SQL text for the trigger:
    CREATE OR REPLACE TRIGGER "CORPSEC"."TI_ARCHIVE_PDF" AFTER INSERT ON "ARCHIVE_PDF" FOR EACH ROW DECLARE
    LOG_SEQ_NO NUMBER;
    BEGIN
    SELECT AUDIT_SEQ.NEXTVAL INTO LOG_SEQ_NO FROM DUAL
    insert into ad_archive_pdf (DOC_TITLE,PDF_FILENAME,CONTENT,DOC_DESC,AUDIT_REF_NO,AUDIT_DATE,AUDIT_MODE,AUDIT_BY)
    values (:new.DOC_TITLE,:new.PDF_FILENAME,:new.CONTENT,:new.DOC_DESC,LOG_SEQ_NO,sysdate,'I',:new.created_by);
    END;
    Any help on this. Thank in advance.
    Best regards,
    Ruijie

    See here for a discussion of how to incorporate LONG datatypes into triggers:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:635439::NO::F4950_P8_DISPLAYID

  • Trigger and Update Flag Table

    I've recently started trying to automate around a dozen procedures. These procedures are set to run immediately after the necessary previous procedure(s) is(are) done.
    What I am attempting to accomplish is a single generic trigger that will fire off each procedure when its parent procedures have finished firing. This will be accompanied by an update_flag table with three columns
    PARENT_PRC----------------------CHILD_PRC----------------------FLAG
    parent_prc_name1--------------child_prc_name1-----------------N
    parent_prc_name1--------------child_prc_name2-----------------N
    parent_prc_name3--------------child_prc_name3-----------------Y
    Logic:
    *1.*     When a procedure fires it updates this table to set any rows in which it is the “PARENT_PRC” by updating the FLAG column to = Y.
    *2.*     The trigger will execute a child procedure if its flag (or in the case of multiple parent procedures; all of its flags) are set to 'Y'. This trigger is set to fire AFTER a table update on the UPDATE_FLAG table.
    ----a.     I have to execute the procedure UFLAG in a job because I want the trigger to execute the procedure and then continue running immediately, rather than wait for the procedure to finish then commit. This way the trigger could start several procedures all running at the same time.
    ----b.     I have made it an autonomous transaction because I needed the job to fire immediately rather than be queued, which required a commit within the trigger.
    *3.*     The last step is to set the flag in UPDATE_FLAGS back to 'N' for CHILD_PRC = '||uflag||' once the child procedure is complete.
    ----a.     I have tried placing the update child_prc = 'N' in the trigger but it won’t allow a trigger that fires on update to update the same table.
    ----b.     I want to avoid putting the update statement in all of my procedures because I would like the option of running these procedures manually for testing purposes WITHOUT effecting the update_flags table.
    Number 3. is the key problem I have been having. Placing code within the trigger to update the update_flags table setting 'Y's back to 'N's once the procedures have fired causes a deadlock error.
    I believe this is simply because the trigger is attempting to update a table which (upon updating) causes the same trigger to fire before it has finish executing.
    How can I update the Flag table to reset the update flags back to 'N'?
    Is there a different way of doing this all together?
    Here is some code with dummy procedures that demonstrates what I have so far.
    With this code, executing parent procedures should set the update_flag table to 'Y' for FLAG where procedure = 'parent_prc'.
    I need to find a way to execute the child procedures AND set the FLAG column back to 'N' from the trigger.
    ex. executing parent_1 should set update_flags.flag = 'Y' where parent_prc = 'parent_1' and thus execute procedure CHILD_A and CHILD_B.
    create table update_flags (parent_prc varchar2(10), child_prc varchar2(10), flag varchar2(1));
    insert into update_flags values('parent_1', 'child_a', 'N');
    insert into update_flags values('parent_1', 'child_b', 'N');
    insert into update_flags values('parent_2', 'child_c', 'N');
    insert into update_flags values('parent_3', 'child_c', 'N');
    insert into update_flags values('parent_4', 'child_d', 'N');
    CREATE OR REPLACE procedure parent_1 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_1';
    END parent_1;
    CREATE OR REPLACE procedure parent_2 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_2';
    END parent_2;
    CREATE OR REPLACE procedure parent_3 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_3';
    END parent_3;
    CREATE OR REPLACE procedure parent_4 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_4';
    END parent_4;
    CREATE OR REPLACE procedure child_a as
    BEGIN
    dbms_output.PUT_LINE('CHILD_A Worked');
    commit;
    END child_a;
    CREATE OR REPLACE procedure child_b as
    BEGIN
    dbms_output.PUT_LINE('CHILD_B Worked');
    commit;
    END child_b;
    CREATE OR REPLACE procedure child_c as
    BEGIN
    dbms_output.PUT_LINE('CHILD_C Worked');
    commit;
    END child_c;
    CREATE OR REPLACE procedure child_d as
    BEGIN
    dbms_output.PUT_LINE('CHILD_D Worked');
    commit;
    END child_d;
    CREATE OR REPLACE TRIGGER MASTER_TRG
    AFTER UPDATE
    ON UPDATE_FLAGS
    DECLARE
    Pragma  AUTONOMOUS_TRANSACTION;
    BEGIN
      DECLARE
      job_num number;
      uflag varchar2(1000);
      BEGIN
            select  MAX(case when COUNT(case when flag='Y' then 1 end)=COUNT(*) then CHILD_PRC else '  ' end)
            into uflag
            from        update_flags
            group by    child_prc;
            IF   uflag <> '  ' THEN
                                      --update update_flags set  flag = 'N' where child_prc = uflag     --(line of code that causes deadlock error)
                            dbms_job.submit (job => job_num,
                            what => ' '||uflag||';'
            END IF; 
       END;            
    COMMIT;
    END MASTER_TRG;
    execute parent_2;
    execute parent_3;

    >
    I think I am getting my head around the transactional/trigger issue.
    >
    It doesn't sound like it since you are still talking 'triggers'. At any rate it is OP that needs to get their head around it.
    OP doesn't even know what the entire process needs to be but has already decided that
    1. a single generic trigger that will fire off each procedure when its parent procedures have finished firing
    2. an update_flag table with three columns: PARENT_PRC, CHILD_PRC, FLAG
    3. a procedure fires it updates this table to set any rows in which it is the “PARENT_PRC” by updating the FLAG column to = Y.
    4. a job - I have to execute the procedure UFLAG in a job
    5. I have made it an autonomous transaction because I needed the job to fire immediately rather than be queued, which required a commit within the trigger.
    6. there should be an option of running these procedures manually for testing purposes WITHOUT effecting the update_flags table.
    Fortunately OP had the wisdom to ask
    >
    Is there a different way of doing this all together?
    >
    Doesn't anyone design things anymore? Seems like everyone just wants to decide what the solution ought to be be and then try to force the problem to fit into it.
    The first stage is the DESIGN - not the implementation details or technology to use.
    The first design step is to outline, or flowchart, the PROCESS that needs to take place. Since OPs post lacks sufficient detail I will substitute my own 'guesstimations' to illustrate.
    1. there are one or more 'parent' processes
    2a. these parent processes are allowed to run in parallel as they do not interfere in any way with the processing done by other parent or child processes. (is this true?)
    2b. these parent processes ARE NOT allowed to run in parallel as they may interfere with each other.
    3. Each parent process can have one or more 'child' processes. (it appears that these aren't really children but rather processes that are 'dependent' on the parent or that must always be executed after, and each time that the parent executes.
    So here are just SOME of the things that are missing that must be known before possible alternatives can be explored
    1. Re item #2 - can the parent processes be executed in parallel? Or must they be executed serially? Will any of the parent processes be dependent on any other parent or child process?
    2. What is the relationship between a parent process and its child processes? Is the parent always executed first? What triggers the parent execution? How often is it executed?
    What if it is already executing? What if other parent processes are currently executing? What if one or more of its child processes are executing? What if the parent process fails for any reason - what action should be taken?
    Based on what was posted a set of parent and child processes might need nothing more than: execute parent, execute child1, execute child2, . . ., execute childn.
    3. What is the relationship between the child processes that belong to the same parent? Can they be executed in parallel (i.e. are they completely independent)? Or must they be executed in some particular order? What if one or more of the child processes fails for any reason - what action should be taken?
    4. Will any other user or process be executing these parent or child processes? That could interfered with the automated stream.
    5. What type of exception handling and recovery needs to be implemented in one or more steps of the processing fail for some reason?
    Typically there is often one or more control tables (OPs flag table) to control and limit the processing. But the table would have status information for every process not just the children:
    A. STATUS - DISABLED, ACTIVE, RUNNING, IDLE, ERROR
    B. START_TIME
    C. END_TIME
    D. RESULT_CODE
    The control table can be used by a parent or child process to determine if it is permitted to run. For example the first thing a procedure might do is check it's own STATUS. If it is already running it would exit or log an error or message. If that test is passed it might check the status of any dependent processes. For example it might check that its child processes are ACTIVE and ready to run; if a child was still running the parent would exit or log an error or message.
    The control process would lock the appropriate control table records (FOR UPDATE) and would set the status and other fields appropriately to prevent interference by other processes or procedures.
    Design first. Then look at the implementation options.

  • Database trigger to insert duplicated rows on audit table

    Hi
    It is possible to insert duplicate rows (at the moment database generate PK violation constraint for one specific table) within an audit table ?
    Certain code like this is not working, always the whole transaction makes a rollback and audit table will be empty:
    CREATE OR REPLACE TRIGGER USER.audit_TABLE_TRG
    before INSERT ON USER.TABLE
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    declare
    V_conteo number(1) := 0;
    duplicate_record EXCEPTION;
    begin
    select count(*)
    into V_conteo
    from USER.TABLE
    where <PK conditions>
    if V_conteo > 0 then
    begin
    INSERT INTO USER.AUDIT_TABLE
    (<>)
    VALUES
    (<>);
    raise duplicate_record;
    exception
    when duplicate_record then
    INSERT INTO USER.AUDIT_TABLE
    (<>)
    VALUES
    (<>);
    raise_application_error(-20019,'Duplicated column1/column2:'||:NEW.column1||'/'||:NEW.column2);
    when others then
    dbms_output.put_line('Error ...'||sqlerrm);
    end;
    end if;
    end;
    END;
    /

    >
    Exactly this is my problem , one only transaction (insert into audit table and try to insert into target table), the reason of this post is to know whether exists another way to insert all the intent duplicate records on target table into one audit table, you right ,maybe I can add one date column and modify the PK on audit table but my main problem still happens.
    >
    Can I ask you why you want to go trigger route for this if your intention is only to capture the duplicate records? Assuming that you are on at least on 10gR2, you can look at DML error table. If you go this route, there is no need for additional overhead of trigger, code failures, etc.
    Oracle can automatically store the failed records in an error table which you could later on investigate and fix it or ignore it.
    Simple example:
    SQL> create table emp (empno number primary key, ename varchar2(10), sal number);
    Table created.
    SQL> insert into emp values(1010, 'Venkat', 100);
    1 row created.
    SQL> commit;
    Commit complete.
    Create error table to log the failed records
    BEGIN
          DBMS_ERRLOG.create_error_log (dml_table_name => 'emp');
    END;
    Now let's insert a duplicate record
    SQL> insert into emp values(1010, 'John', 200) ;
    insert into emp values(1010, 'John', 200)
    ERROR at line 1:
    ORA-00001: unique constraint (VENKATB.SYS_C002813299) violated
    Now use the log table to capture
    SQL> insert into emp values(1010, 'John', 200) LOG ERRORS INTO err$_emp ('INSERT') REJECT LIMIT UNLIMITED;
    0 rows created.
    Now check the error log table and do whatever you want
    SQL> r
      1* select ORA_ERR_MESG$, empno, ename, sal from err$_EMP
    ORA_ERR_MESG$
    EMPNO
    ENAME
    SAL
    ORA-00001: unique constraint (VENKATB.SYS_C00
    2813467) violated
    1010
    John
    200
    1 row selected.This will also capture when you do
    INSERT INTO EMP SELECT * FROM EMP_STAGE LOG ERRORS INTO err$_emp ('INSERT') REJECT LIMIT UNLIMITED;
    You can capture the whole record into the log table. All columns.
    Regards
    Edited : Code

  • PLEASE HELP!! Trigger on a view that updates a table synonym?

    I have a view (PERSONINFO_VIEW) that pulls user information from several ODS.CT tables. This view contains userid, first name, last name, telephone, and email. I'm trying to create a trigger that will insert these values into a remote table with a public synonym (PERSON_CTL_SYN) using a procedure. If I run the procedure alone, it works, and the table is updated. I enter data into the view (by adding a new user account to the portal) the PERSONINFO_VIEW is updated with the new information, but the trigger that calls the procedure doesn't seem to fire, because the PERSON_CTL_SYN is not updated.
    My trigger (PERSON_SYN_INS):
    On PTS.PERSONINFO_VIEW, INSTEAD OF EACH ROW, INSERT, ENABLED
    begin
    person_syn_ins_proc(:new.userid, :new.firstname, :new.lastname,:new.phone,:new.email);
    end;
    My Procedure (PERSON_SYN_INS_PROC):
    CUSER IN VARCHAR2,
    CFIRST IN VARCHAR2,
    CLAST IN VARCHAR2,
    CPHONE IN VARCHAR2,
    CEMAIL IN VARCHAR2
    as
    cSecrGrp varchar2(30) := 'ITSUSER';
    cLoc varchar2(30) := 'OUS-ITS';
    cArea varchar2(3) := '541';
    begin
    insert into person_ctl_syn(
    person_first_name,
    person_last_name,
    person_username,
    person_email,
    person_phone_number)
    values(
    cFirst,
    cLast,
    cUser,
    cEmail,
    cPhone);
    commit ;
    end;

    I have a view (PERSONINFO_VIEW) that pulls user information from several ODS.CT tables. This view contains userid, first name, last name, telephone, and email. I'm trying to create a trigger that will insert these values into a remote table with a public synonym (PERSON_CTL_SYN) using a procedure. If I run the procedure alone, it works, and the table is updated. I enter data into the view (by adding a new user account to the portal) the PERSONINFO_VIEW is updated with the new information, but the trigger that calls the procedure doesn't seem to fire, because the PERSON_CTL_SYN is not updated.
    My trigger (PERSON_SYN_INS):
    On PTS.PERSONINFO_VIEW, INSTEAD OF EACH ROW, INSERT, ENABLED
    begin
    person_syn_ins_proc(:new.userid, :new.firstname, :new.lastname,:new.phone,:new.email);
    end;
    My Procedure (PERSON_SYN_INS_PROC):
    CUSER IN VARCHAR2,
    CFIRST IN VARCHAR2,
    CLAST IN VARCHAR2,
    CPHONE IN VARCHAR2,
    CEMAIL IN VARCHAR2
    as
    cSecrGrp varchar2(30) := 'ITSUSER';
    cLoc varchar2(30) := 'OUS-ITS';
    cArea varchar2(3) := '541';
    begin
    insert into person_ctl_syn(
    person_first_name,
    person_last_name,
    person_username,
    person_email,
    person_phone_number)
    values(
    cFirst,
    cLast,
    cUser,
    cEmail,
    cPhone);
    commit ;
    end;

  • PL/SQL Trying to update a table through trigger on the same table

    Hi everyone my name is Edwin and I'm new to this forum. I hope I can learn a lot from this community and over time contribute to it.
    The problem I'm facing at the moment is a tough one. I need to update a table (table a) with a value called block_id. This block_id is generated by a procedure I have written myself, the end result is stored in another table (table b). This block_id needs to be generated after certain rows of table a get updated with a trans_id. The trans_id is all the same for these rows in table a, but the generated block_id isn't. In my code I use an after update on collumn a of table a trigger. So if the the collumn gets updated the trigger fires. The trigger calls the procedure that generates the block_id and the procedure generates table b with all the block_id's. But then I want to update the rows in table a with the generated block_id in table b. The problem is that this self-deadlocks.
    You might think that this would call a recursive trigger, but I have written code in the trigger that checks if the block_id isn't allready filled in on table a.
    Also I really need all the values wich get updated (table a), so I believe a before update is also out of the question.
    And the first update of table a is done through an erp-packet and I can't get at that code, otherwise I would just have run my code from there.
    Message was edited by:
    user625855

    CREATE OR REPLACE TRIGGER block_id_trigger AFTER UPDATE ON unload_details_tab
    DECLARE
    current_transport_id NUMBER;
    check_value NUMBER;
    check_block_id NUMBER;
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    current_transport_id := get_curent_trans_id; --function that gets the current transport_id
    check_value := check_site_and_directive(current_transport_id); --function checks if this transport_id should have a block_id
    check_block_id := check_for_block_id(current_transport_id); --function checks if there isn't allready a block_id set.
    IF check_value = 1 AND check_block_id = 0 THEN
    create_blok_id_table(current_transport_id); --this procedure creates the blok_id in temptable
    UPDATE unload_details_tab a SET a.block_id = (SELECT DISTINCT b.blok_id FROM temptable b WHERE b.mark = a.mark_1) WHERE a.transport_id = current_transport_id; --this statement should update the table back, if I leave it out everything works fine, but when I leave it I get the self-deadlock error.
    ELSE
    null;
    END IF;
    END block_id_trigger;
    Ok, I cleaned the code somewhat.
    user625855

  • ODP OracleCommandBuilder. Updating a table including DATE columns.

    Hi
    I have a problem with the OracleCommandBuilder not creating the correct update commands when I have DATE type columns in the table.
    I have created a test table (called DATETEST) with three columns:
    STRINGCOLUMN     VARCHAR2 10
    DATECOLUMN DATE
    NUMBERCOLUMN     NUMBER
    The STRINGCOLUMN is the primary key.
    Then I created a typed dataset that looks like this:
    STRINGCOLUMN     string
    DATECOLUMN string
    NUMBERCOLUMN     long
    This is the XML schema for the typed dataset:
    <?xml version="1.0" encoding="utf-8" ?>
    <xs:schema id="DateDS" targetNamespace="http://tempuri.org/DateDS.xsd" elementFormDefault="qualified" attributeFormDefault="qualified" xmlns="http://tempuri.org/DateDS.xsd" xmlns:mstns="http://tempuri.org/DateDS.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
         <xs:element name="DateDS" msdata:IsDataSet="true">
              <xs:complexType>
                   <xs:choice maxOccurs="unbounded">
                        <xs:element name="DATETEST">
                             <xs:complexType>
                                  <xs:sequence>
                                       <xs:element name="DATECOLUMN" type="xs:string" minOccurs="0" />
                                       <xs:element name="STRINGCOLUMN" type="xs:string" minOccurs="0" />
                                       <xs:element name="NUMBERCOLUMN" type="xs:long" minOccurs="0" />
                                  </xs:sequence>
                             </xs:complexType>
                        </xs:element>
                   </xs:choice>
              </xs:complexType>
         </xs:element>
    </xs:schema>
    And this is the test code:
    Dim connection As Oracle.DataAccess.Client.OracleConnection
    Dim adapter As New Oracle.DataAccess.Client.OracleDataAdapter()
    Dim dbCommand As New Oracle.DataAccess.Client.OracleCommand()
    Dim sqlstring As String
    Dim data As New DateDS() 'Typed dataset
    Const ConnectionString As String = "User Id=............."
    Try
    'Connect to database
    connection = New OracleConnection(ConnectionString)
    connection.Open()
    'Get data from table DATETEST
    dbCommand.CommandText = "SELECT STRINGCOLUMN, TO_CHAR(DATECOLUMN) AS DATECOLUMN, NUMBERCOLUMN FROM DATETEST"
    dbCommand.Connection = connection
    adapter.SelectCommand = dbCommand
    adapter.Fill(data, "DATETEST")
    'Make changes to dataset
    data.DATETEST(0).DATECOLUMN = Now()
    data.DATETEST(0).NUMBERCOLUMN = data.DATETEST(0).NUMBERCOLUMN + 1
    'Update database
    sqlstring = "SELECT * FROM DATETEST"
    adapter.SelectCommand = New OracleCommand(sqlstring, connection)
    Dim custCB As New Oracle.DataAccess.Client.OracleCommandBuilder()
    custCB.DataAdapter = adapter
    adapter.Update(data, "DATETEST")
    'Disconnect
    connection.Close()
    connection.Dispose()
    Catch exc As Exception
    MessageBox.Show(exc.Message)
    End Try
    Getting the data from the database is not a problem.
    The dataset contains the correct information.
    But updating the database is impossible.
    I get errors like:
    ORA-01861: literal does not match format string
    And if I don't specify a DATE format in the TO_CHAR statement I get this error:
    Concurrency violation: the UpdateCommand affected 0 records.
    I think I've tried everything.
    I've used the OracleGlobalization class, with the SetSessionInfo method.
    I've tried all different types of date conversions to make sure that
    the date format on the database is the same as in the dataset.
    I've tried to change the NLS parameters on the DB server and in the registry on the client.
    I've tried to change the DATECOLUMN type in the typed dataset from string to Oracle.DataAccess.Types.OracleDate
    But it still doesn't work.
    The default date format on the DB 9i server is AMERICAN,(DD-MON-RR).
    A strange thing is that when I instead of using the ODP classes use
    the System.Data.OracleClient and its OracleCommandBuilder
    the code works perfectly without any errors.
    This is the test code that works:
    Dim connection As System.Data.OracleClient.OracleConnection
    Dim adapter As New System.Data.OracleClient.OracleDataAdapter()
    Dim dbCommand As New System.Data.OracleClient.OracleCommand()
    Dim data As New DateDS()
    Dim sqlstring As String
    Const ConnectionString As String = "User Id=......."
    Try
    'Connect to database
    connection = New System.Data.OracleClient.OracleConnection(ConnectionString)
    connection.Open()
    'Get data from table DATETEST
    dbCommand.CommandText = "SELECT STRINGCOLUMN, TO_CHAR(DATECOLUMN,'YYYY-MM-DD HH24:MI:SS') AS DATECOLUMN, NUMBERCOLUMN FROM DATETEST"
    dbCommand.Connection = connection
    adapter.SelectCommand = dbCommand
    adapter.Fill(data, "DATETEST")
    'Make changes to dataset
    data.DATETEST(0).DATECOLUMN = Now()
    data.DATETEST(0).NUMBERCOLUMN = data.DATETEST(0).NUMBERCOLUMN + 1
    'Update database
    sqlstring = "SELECT * FROM DATETEST"
    adapter.SelectCommand = New System.Data.OracleClient.OracleCommand(sqlstring, connection)
    Dim custCB As New System.Data.OracleClient.OracleCommandBuilder()
    custCB.DataAdapter = adapter
    adapter.Update(data, "DATETEST")
    'Disconnect
    connection.Close()
    connection.Dispose()
    Catch exc As Exception
    MessageBox.Show(exc.Message)
    End Try
    My experience until this came up is that the ODP provider is better on everything
    than the microsoft Oracle provider so I don't want to switch unless I have to.
    Could someone that have used the ODP OracleCommandBuilder for updating a table including DATE columns with a typed dataset please give me some tips on how to make this work?
    I would be the happiest man on earth if someone had a solution :-)
    Erik

    Don't convert the dates to strings. Ever.
    The command builder uses the metadata returned from the select command to build the insert/update commands. Using to_char in the query tells ODP that that is a varchar2 column. If you omit the to_char the commandBuilder will know to bind a date parameter in that spot.
    Also in your typed dataset you should change the type from a string to a date.
    David

  • Updates on table on specified columns

    Hi Techies,
    I have updated the table with one specified condition, based on the specified condition updation is done successfully(2000 rows).
    again I wanted to verify the records updated on the table. But when I checking the condition on the table it gives more records(5000 rows).
    Can you please tell me ,in which data dictionary table we can check the updation history (date,column,table)
    OS :Solarix 5.10
    DB 10.2.0.4
    thanks
    tippu

    Tippu wrote:
    Hi Techies,
    I have updated the table with one specified condition, based on the specified condition updation is done successfully(2000 rows).
    again I wanted to verify the records updated on the table. But when I checking the condition on the table it gives more records(5000 rows).
    Can you please tell me ,in which data dictionary table we can check the updation history (date,column,table)
    OS :Solarix 5.10
    DB 10.2.0.4
    thanks
    tippuso you updated SOMECOLUMN to value 'ABCD' and the update hit 2000 rows. Now you find that more that 2000 rows have SOMECOLUMN value of 'ABCD'. Is it possible that there were some number of rows already set to 'ABCD' before your update?

  • Check two columns and update other table

    HI ,
    I have a table called trackCenterline .Below is the table.
    What i want to do is If the segmentSequenceID is 1 it should pick the corresponding SegmentID i.e 10001 and Check for the same segment id in other table called TrackSegment which is below.  and pick the BeginMilepost of that segmentID and Update That
    Milepost in a new table .At end SegmentSequenceID number it should pick ENDMilepost and update
    TrackCenterline table.
    TrackSegment table
    In the below table for 10001 SegmentID it should pick BeginMilepost. For end Number of SegmentSequenceID in above table ID ends at 121 for that end sequenceID It should refer TrackSegment table below and pick EndMilepost and should be updated in another
    table Milepost column.
    after that a new segment starts with new sequence .and so on ...
    bhavana

    Hi Deepa_Deepu,
    According to your description, since the issue regards T-SQL. I will help you move the question in the T-SQL forums at
    http://social.technet.microsoft.com/Forums/en-US/home?forum=transactsql. It is appropriate and more experts will assist you.
    When you want to check two columns from two tables then return some results and update the third table. I recommend you use join function and combine two tables, then use update select from statement for modifying the Mailpost table. You can refer to the
    following T-SQL Statement.
    -----using join to connect to two tables
    select TrackCenterline.FeatureId,TrackCenterline.SegmentId,
    TrackCenterline.SegmentSequenceId,TrackSegment.BeginMilepost,TrackSegment.EndMilepost
    from dbo.TrackCenterline join dbo.TrackSegment
    on TrackCenterline.SegmentId=TrackSegment.SegmentId
    order by TrackCenterline.SegmentId, TrackCenterline.SegmentSequenceId
    ---the result shows as following.
    FeatureId SegmentId SegmentSequenceId BeginMilepost EndMilepost
    AMK100011 10001 1 61.0000 61.3740
    AMK100012 10001 2 61.0000 61.3740
    AMK100013 10001 3 61.0000 61.3740
    AMK1000121 10001 121 61.0000 61.3740
    AMK100021 10002 1 61.1260 61.7240
    AMK100023 10002 3 61.1260 61.7240
    AMK100033 10003 3 61.3740 62.9530
    -----Then you can use update select from statement to modify the Mailpost table, Or you can post the table structure of Mailpost
    And for more information, you can review the following article about update statement.
    http://www.techonthenet.com/sql/update.php
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Trigger Issue while updating same table

    Hi all,
    I am creating one after insert trigger on table tests, which will check, if application id is null, application will be fetched from another table and update the table
    tests table. But this trigger is not updating the application id of the table tests
    CREATE OR REPLACE
    TRIGGER TB_REC_APPL_TESTS1
    AFTER INSERT ON tests FOR EACH ROW
    DECLARE
    v_application_id NUMBER;
    v_rec_appl_tests_id NUMBER;
    v_a_recruit_id NUMBER;
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    v_rec_appl_tests_id := :NEW.rec_appl_tests_id;
    v_a_recruit_id := :NEW.a_recruit_id;
    IF :NEW.a_applic_id IS NULL THEN
    SELECT a_applic_id INTO v_application_id FROM recruit WHERE a_recrut_id = v_a_recruit_id;
    dbms_output.PUT_LINE(v_application_id||'-'||v_rec_appl_tests_id);
    UPDATE tests SET a_applic_id = v_application_id
    WHERE rec_appl_tests_id = v_rec_appl_tests_id;--:NEW.rec_appl_tests_id;
    END IF;
    commit;
    END;
    Thanks in advance,
    Pal

    user546710 wrote:
    Hi all,
    I am creating one after insert trigger on table tests, which will check, if application id is null, application will be fetched from another table and update the table
    tests table. But this trigger is not updating the application id of the table tests
    CREATE OR REPLACE
    TRIGGER TB_REC_APPL_TESTS1
    AFTER INSERT ON tests FOR EACH ROW
    DECLARE
    v_application_id NUMBER;
    v_rec_appl_tests_id NUMBER;
    v_a_recruit_id NUMBER;
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    v_rec_appl_tests_id := :NEW.rec_appl_tests_id;
    v_a_recruit_id := :NEW.a_recruit_id;
    IF :NEW.a_applic_id IS NULL THEN
    SELECT a_applic_id INTO v_application_id FROM recruit WHERE a_recrut_id = v_a_recruit_id;
    dbms_output.PUT_LINE(v_application_id||'-'||v_rec_appl_tests_id);
    UPDATE tests SET a_applic_id = v_application_id
    WHERE rec_appl_tests_id = v_rec_appl_tests_id;--:NEW.rec_appl_tests_id;
    END IF;
    commit;
    END;
    Thanks in advance,
    Palyou are creating triger on the table and updating it. It will not allow to update since you are firing trigger on same table.
    Best practice is to use other table to update or any other operation.

  • Updation of table records having 5-6 primary key columns.

    I have a table structure having 12 primary composite keys.I have created report + form on this table.My requirement is to update the table by using form items fields.I am taking help of url option on report attribute page of application to fetch data on form page when we click on edit link of report page.Now i am having two problems which are as follows:-
    (i)I am unable to update data as requirement is to update 5 to 6 primary fields along with other non primary keys.I tried to create Pl/SQL process which will run update query but this process is not updating values.Is there any way that i could fetch data direct from database table in query rather then taking item values.Is there any other workaround?
    (ii)One of the primary key column contains records which have ' , ' in them .For ex:- cluth,bearing.So when i get navigated to edit page i am only getting text displayed as clutch i.e. text before ',' is getting displayed in text field while comma and the text after this is not getting displayed in text field of form page.
    Any solutions will be very helpful.
    Thanks
    Abhi

    Hello Abhi,
    >> I am unable to update data as requirement is to update 5 to 6 primary fields along with other non primary keys
    APEX wizards support a composite PK with up to 2 segments only. For every other scenario, you’ll have to manually create your DML code.
    If you have control over your data model, I would listen very carefully to Andre advices. Using a single segment PK is the best practice way. If you can’t add PK to your table, it seems that you’ll have to write your own DML code. The Object Browser option of creating a Package with methods on database table(s) can be a great help.
    >> … I am taking help of url option … One of the primary key column contains records which have ' , ' in them …
    Using the f?p notation, to pass a comma in an item value, you should enclose the characters with backslashes. For example,
    \cluth,bearing\In your case, it should be the item/column notation.
    http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/concept.htm#BCEDJBEH
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Author of Oracle Application Express 3.2 – The Essentials and More

  • Updating A Table in a for each row trigger

    I have a trigger,
    create or replace trigger ins_ibpm_temp_trig
    after update of ethic_dt on ethics_approval_info for each row
    My issue is that I need to update the ethics_approval_info for each record based on the ethics date that was updated. I am getting the error
    ORA-04091: table ORACLETEST.ETHICS_APPROVAL_INFO is mutating, trigger/function may not see it.
    So the issue here of course is that I am trying to update a table, that is already in the middle of updating. Is there any way to get around this?

    Try these links
    Link1
    Link2
    Regards,
    Abdetu..

  • Update a table using same variable name as the column

    I am not able to update a table column using a local variable which is having same name as the table column. Example of the function is as follows:
    create or replace function trial return integer as
    column1 integer:=99;
    BEGIN
    update firsttable set column1=column1 where column2='john';
    return 0;
    END;
    Existing data in firsttable:
    COLUMN1 COLUMN2
    123 xyz
    123 abcd
    101 john

    Unfortunately table aliasing won't help... Although specifying the procedure will. Somewhat academic I know, since if you can prefix the procedure name on the variable you can just as easily rename it, unless you happen to have a bunch of other code calling it using named notation possibly.
    SQL> select ename, comm from emp where empno = 7934;
    ENAME            COMM
    MILLER
    SQL> create or replace procedure new_comm
      2   (empno in number, comm in number)
      3  is
      4  begin
      5      update emp e
      6      set e.comm = new_comm.comm
      7      where e.empno = new_comm.empno;
      8      dbms_output.put_line('updated '||sql%rowcount||' rows!');
      9  end;
    10  /
    Procedure created.
    SQL> exec new_comm (7934, 100)
    updated 1 rows!
    PL/SQL procedure successfully completed.
    SQL> select ename, comm from emp where empno = 7934;
    ENAME            COMM
    MILLER            100Message was edited by:
    3360
    Colin beat me to it

  • How to update two tables with trigger

    Hi:
    how to update two tables with trigger ?
    I have two tables :
    (1)ASIA
    MI number;
    (2)ASIA_P
    ID number;
    When I insert a new value into the asia.MI ,I also can
    insert the same value into the asia_p.id field.
    I have write a trigger as follows but it does't work.
    create or replace trigger MI_TRG
    before insert on asia
    for each row
    declare
    seq number;
    begin
    select MI_SEQ.Nextval into seq from dual;
    :new.MI:=seq;
    insert into ASIA_PRO(MI_ID)
    values
    (seq);
    end MI_TRG;
    How to realize it ?
    thanks
    zzm

    Why do you say it does not work?

Maybe you are looking for

  • Adobe Photoshop CS4 11.0.2 update

    descargue el  adobe  photoshop cs4 11.0.2 update y no me permite instalarlo. Como sigo???

  • Need help using count over function

    I have the following query Select student_id, OM, TM, TP, count(rownum) over (order by OM desc) PS from (select er.student_id, sum(er.obtained_marks) OM, sum(ds.max_marks) TM, to_char(sum(er.obtained_marks)/sum(ds.max_marks)*100,'990.00') TP from tbl

  • Apple remote with Netflix

    Am I able to use my apple remote through my Mac book pro to control Netflix or hulu?

  • How to turn off alerts for incoming emails

    How do you turn off alerts for incoming emails on the iphone?

  • PSD file too large to reopen

    I have a 450MB PSD file that will not reopen in photoshop or illustrator. Are there any downloadable programs to resize the file or extract layers ? Any help asap will be appreciated!