"instead of" trigger on a view with a condition

I'm trying to create an instead-of trigger on a view but I want it all such that:
1. It fires only for a certain condition.
2. When the condition isn't met, I want the normal DML on the view to continue as it normally would.
3. I want to avoid writing as much manual DML code as possible for long-term maintainability.
My first attempt is like this:
create or replace trigger PROPOSAL_PARTS_V_IRU
  instead of update on proposal_parts_v
  for each row
  WHEN :old.PART_MASTER_ID <> :new.PART_MASTER_ID
BEGIN
  do_stuff_for_part_master_change;
END;So when the OLD and NEW PART_MASTER_IDs have changed, I want special processing. Else, I want it to do whatever it normally does (let the view get updated and the database will manage the update of the underlying table).
When compiling that I get "ORA-25004: WHEN clause is not allowed in INSTEAD OF triggers".
OK I will accept that even though I want it to work.
So my next attempt could be:
create or replace trigger PROPOSAL_PARTS_V_IRU
  instead of update on proposal_parts_v
  for each row
BEGIN
  IF :old.PART_MASTER_ID <> :new.PART_MASTER_ID THEN
    do_stuff_for_part_master_change;
  ELSE
    UPDATE proposal_parts -- Manually update the underlying table with manually-written DML but I hate having to do this in case the view or table columns change.
    SET...
    WHERE...
  END;So my question is...is there any syntax to do something like this?
create or replace trigger PROPOSAL_PARTS_V_IRU
  instead of update on proposal_parts_v
  for each row
BEGIN
  IF :old.PART_MASTER_ID <> :new.PART_MASTER_ID THEN
    do_stuff_for_part_master_change;
  ELSE
    update_row;
  END;...where "update_row" is some sort of built-in command that tells oracle to continue with the current update as if the trigger never existed.
Back in the day I seem to remember that Oracle Forms had a trigger and syntax like this where you could intercept a DML and if under certain conditions it wasn't true, you could say "update_row" (or maybe it was "update_record?...whatever) and it meant "continue with update as if this instead-of trigger never existed".
Is anything available like that for the DB now? I know in older versions no, but we are now on 11g...anything new come out like this?
Otherwise I have to manually write an update statement and I'd rather not if I don't need to.
Thanks!

riedelme wrote:
gti_matt wrote:
I'm trying to create an instead-of trigger on a view but I want it all such that:
1. It fires only for a certain condition.You can use IF Logic inside a trigger to do or not do anything. As long as it is a condition you can check you can code IF logic around it
2. When the condition isn't met, I want the normal DML on the view to continue as it normally would.You will have to code all of your logic in the INSTEAD of trigger. The whole purpose of the INSTEAD OF trigger is to execute INSTEAD OF performing DML on the view. There is no way to go back to the "normal DML" when the INSTEAD OF trigger exists.
You can put all of the logic you will need in the INSTEAD OF trigger and use IF conditions. Use IF logic to code both your special and "normal" processing.
3. I want to avoid writing as much manual DML code as possible for long-term maintainability.You will have to code the operative lines somewhere. Reusable functions and/or procedures in a package?Yep using an "IF" I knew about...no problem there.
But was just looking for a cheap and easy way to say (for the "else" condition) to revert to normal DML processing. Sounds like in a DB trigger there is no such syntax I guess.
This is an example from Oracle Forms, I was looking for a database equivalent of this(see http://sqltech.cl/doc/dev2000/help/fbhelp18.htm):
Built-in Subprograms for On-Event Triggers For most of the transactional On-event triggers, there is a corresponding built-in subprogram.
On-Event Trigger
Corresponding Built-in
On-Delete
DELETE_RECORD
On-Insert
INSERT_RECORD
On-Update
UPDATE_RECORD
When you call one of these built-in subprograms from its corresponding transactional trigger, Form Builder performs the default processing that it would have done normally at that point in the transaction.
For example, if you call the INSERT_RECORD procedure from an On-Insert trigger, Form Builder performs the default processing for inserting a record in the database during a commit operation.
When these built-ins are issued from within their corresponding transactional triggers, they are known as do-the-right-thing built-ins. That is, they do what Form Builder would normally have done at that point if no trigger had been present. Thus, an On-Insert trigger that calls the INSERT_RECORD procedure is functionally equivalent to not having an On-Insert trigger at all. Such a trigger is explicitly telling Form Builder to do what it would have done by default anyway.Note that the author calls them the "do-the-right-thing" built-ins. That's what I was looking for but on the DB side. Sounds like Oracle didn't come up with that (yet)?

Similar Messages

  • Issue with instead of trigger on a view

    Gurus,
    I have an issue with an instead of trigger on a view. The trigger is listed below. The insert and update seem to be working fine but the delete section is not.
    From the application, we have a screen on which we attach images. We trigger of an insert and update when we attach images. We are using hibernate as our object relational mapping tool.
    We have added some logging into the delete section but that portion of the trigger does not seem to be executing at all.
    Please advise.
    Thanks
    Hari
    CREATE OR REPLACE TRIGGER trg_vw_result_image_uid
    INSTEAD OF
    INSERT OR DELETE OR UPDATE
    ON vw_result_image
    REFERENCING NEW AS NEW OLD AS OLD
    DECLARE
    v_cnt number(38);
    v_cnt_old number(38);
    v_err_msg VARCHAR2 (250);
    BEGIN
    -- v_rslt_id number(38);
    -- v_cnt number(38);
    select count(1) into v_cnt from result_image_master
    where RSLT_IMAGE_ID = :new.RSLT_IMAGE_ID;
    --select count(1) into v_cnt from result_image_master
    -- where ACC_BLKBR_ID = :new.ACC_BLKBR_ID
    -- and upper(RSLT_IMAGE_NM) = upper(:new.RSLT_IMAGE_NM);
    select count(1) into v_cnt_old from result_image_master
    where RSLT_IMAGE_ID = :old.RSLT_IMAGE_ID;
    insert into t2( TEXT_VAL, DT1, seq1)
    values (' before v_cnt', sysdate, t6.NEXTVAL);
    --if v_cnt = 0
    --****INSERTING
    IF INSERTING
    THEN
    insert into t2( TEXT_VAL, DT1, seq1)
    values (' v_cnt is 0 and inserting into result_image_master', sysdate, t6.NEXTVAL);
    insert into t2( TEXT_VAL, DT1, seq1)
    values (' inserted bb id :'||:new.ACC_BLKBR_ID, sysdate, t6.NEXTVAL);
    insert into result_image_master (
    RSLT_IMAGE_ID
    ,RSLT_IMAGE_HBR_VER
    ,RSLT_IMAGE_TYPE_ID
    ,RSLT_IMAGE_NM
    ,RSLT_IMAGE_LABEL
    ,RSLT_IMAGE_SEQ
    ,RSLT_SHOW_ON_RPT
    ,RSLT_SLIDE_NO
    ,RSLT_CELL_NO
    ,RSLT_X_COORD
    ,RSLT_Y_COORD
    ,ACC_BLKBR_ID
    ,CREATED_BY
    ,DATE_CREATED
    ,MODIFIED_BY
    ,DATE_MODIFIED
    values (
    :new.RSLT_IMAGE_ID
    ,:new.RSLT_IMAGE_HBR_VER
    ,:new.RSLT_IMAGE_TYPE_ID
    ,:new.RSLT_IMAGE_NM
    ,:new.RSLT_IMAGE_LABEL
    ,:new.RSLT_IMAGE_SEQ
    ,:new.RSLT_SHOW_ON_RPT
    ,:new.RSLT_SLIDE_NO
    ,:new.RSLT_CELL_NO
    ,:new.RSLT_X_COORD
    ,:new.RSLT_Y_COORD
    ,:new.ACC_BLKBR_ID
    ,:new.CREATED_BY
    ,:new.DATE_CREATED
    ,:new.MODIFIED_BY
    ,:new.DATE_MODIFIED
    insert into result_image_blob (
    RSLT_IMAGE_ID
    ,rslt_image_blob
    values (
    :new.RSLT_IMAGE_ID
    ,:new.rslt_image_blob
    --****UPDATING
    ELSIF UPDATING
    -- v_cnt > 0 --
    THEN
    insert into t2( TEXT_VAL, DT1, seq1)
    values (' updating result_image_master', sysdate, t6.nextval);
    insert into t2( TEXT_VAL, DT1, seq1)
    values (' updating bb id :'||:new.ACC_BLKBR_ID, sysdate, t6.nextval);
    update result_image_master
    set RSLT_IMAGE_HBR_VER = RSLT_IMAGE_HBR_VER + 1
    ,RSLT_IMAGE_TYPE_ID = :new.RSLT_IMAGE_TYPE_ID
    ,RSLT_IMAGE_NM = :new.RSLT_IMAGE_NM
    ,RSLT_IMAGE_LABEL = :new.RSLT_IMAGE_LABEL
    ,RSLT_IMAGE_SEQ = :new.RSLT_IMAGE_SEQ
    ,RSLT_SHOW_ON_RPT = :new.RSLT_SHOW_ON_RPT
    ,RSLT_SLIDE_NO = :new.RSLT_SLIDE_NO
    ,RSLT_CELL_NO = :new.RSLT_CELL_NO
    ,RSLT_X_COORD = :new.RSLT_X_COORD
    ,RSLT_Y_COORD = :new.RSLT_Y_COORD
    ,ACC_BLKBR_ID = :new.ACC_BLKBR_ID
    ,MODIFIED_BY = :new.MODIFIED_BY
    ,DATE_MODIFIED = :new.DATE_MODIFIED
    where RSLT_IMAGE_ID = :new.RSLT_IMAGE_ID;
    update result_image_blob
    set rslt_image_blob = :new.rslt_image_blob
    where RSLT_IMAGE_ID = :new.RSLT_IMAGE_ID;
    END IF;
    IF DELETING OR v_cnt_old > 0
    THEN
    insert into t2( TEXT_VAL, DT1, seq1) values (' deleting rows ...', sysdate, t6.NEXTVAL);
    DELETE from result_image_blob where RSLT_IMAGE_ID = :old.RSLT_IMAGE_ID;
    insert into t2( TEXT_VAL, DT1, seq1) values ('deleting result_image_blob : '||:old.RSLT_IMAGE_ID , sysdate, t6.NEXTVAL);
    DELETE from result_image_master where RSLT_IMAGE_ID = :old.RSLT_IMAGE_ID;
    insert into t2( TEXT_VAL, DT1, seq1) values ('deleting result_image_master : '||:old.RSLT_IMAGE_ID , sysdate, t6.NEXTVAL);
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    v_err_msg := SQLERRM;
    insert into t2( TEXT_VAL, DT1, seq1) values (v_err_msg, sysdate, t6.nextval);
    END;
    Edited by: bhanujh on Sep 13, 2010 7:55 AM

    bhanujh wrote:
    The error msg that we are getting is
    09/08/2010 4:02:09 PM: Unable to save the results :: Could not execute JDBC batch updateSorry, we don't recognize this message as any valid Oracle error.
    :p

  • Instead of trigger not populating view

    I've got a interactive report. I created a view based on this so I can use it elsewhere. I had it wokring, have been distracted by other projects, came back and ARUGH...you know the story. The view is not updating with anything. Is it my trigger?
    VIEW
    CREATE OR REPLACE FORCE VIEW  "GET_USERNAME_VW" ("DOC_INFO_ID", "DOC_TITLE", "DOC_LINK", "ECRNO", "OWNER", "ISO_NUMBER", "STATUS_ID", "FILE_TYPE", "APPROVAL_REQ", "APPROVED", "JOB_DESC", "USER_NAME") AS
      select     "DOC_INFO"."DOC_INFO_ID" as "DOC_INFO_ID",
         "DOC_INFO"."DOC_TITLE" as "DOC_TITLE",
         "DOC_INFO"."DOC_LINK" as "DOC_LINK",
         "DOC_INFO"."ECRNO" as "ECRNO",
         "DOC_INFO"."OWNER" as "OWNER",
         "DOC_INFO"."ISO_NUMBER" as "ISO_NUMBER",
         "DOC_INFO"."STATUS_ID" as "STATUS_ID",
         "DOC_INFO"."FILE_TYPE" as "FILE_TYPE",
         "DOC_INFO"."APPROVAL_REQ" as "APPROVAL_REQ",
         "DOC_INFO"."APPROVED" as "APPROVED",
         "SH_JOB_DESCRIPTION"."JOB_DESC" as "JOB_DESC",
         "SH_EMPLOYEES"."USER_NAME" as "USER_NAME"
    from     "SH_EMPLOYEES" "SH_EMPLOYEES",
         "SH_JOB_DESCRIPTION" "SH_JOB_DESCRIPTION",
         "DOC_INFO" "DOC_INFO"
    where   "DOC_INFO"."OWNER"="SH_JOB_DESCRIPTION"."JOB_DESC"
        and     "SH_JOB_DESCRIPTION"."JOB_DESC_ID"="SH_EMPLOYEES"."JOB_DESC_ID"
    and "DOC_INFO"."STATUS_ID" IN (1,2)
    /TRIGGER
    create or replace TRIGGER "bi_GET_APPROVAL"
    INSTEAD OF UPDATE ON GET_USERNAME_VW
    REFERENCING NEW AS n                
    FOR EACH ROW
    BEGIN
    update doc_info
    set approval_req = :n.approval_req    
        WHERE DOC_INFO_ID = :old.DOC_INFO_ID;
    update doc_info
    set approved = :n.approved
        WHERE DOC_INFO_ID = :old.DOC_INFO_ID;
    END;

    My overlook - - In my testing I had been setting the status_id on my form to something other than 1 or 2. Friday afternoon has me making dumb mistakes - those kind that can really mess things up if you act on them. Better to take a break!
    Thanks anyway!!
    Have a great weekend.

  • View with selection conditions with system fields.

    Hi Experts,
    I have a view. Now i want to control the data that is selected using 'Selection Conditions'.
    here i want to use system field SY-DATUM.
    My requirement is  i want to control the output like
    Valid_From_Date GE SY-DATUM and
    Valid_To_Date     LE  SY-DATUM
    which means that i would be showing only active users in this view.
    How can i go about this? System is not allowing system fields in comparision value.
    Any help on this is highly appreciated. Thanks.
    regards,
    Simha

    Hi,
    I am getting a warning first 'enter constant as comparision value'
    when i trying to activate the view i am getting the below error.
    A join condition on a field of the system table SY (or SYST) was defined.
    This is not permitted for database views because the system table is not known to the database
    Have tried to activate the view you created?
    How to go about this?
    Regards,
    Simha

  • Form with view having instead-of-trigger gives FRM-40501 and ORA-02014

    I created a data-entry from with a 'view' as datas-source block. This view gives crosstab query results with a data from a single base-table but it is complex and uses decode and aggregate funciton 'max' just to create group by in a crosstab query. I have created a instead of trigger on this view to update or insert a record in base table. A test to update base table works fine at SQl prompt. A test to insert at SQL shows '1 row created' but in fact when I query the database, it does not show newly inserted row. Also, when I compile and run this form, I get FRM-40501 and ORA-02014. Help!!!
    I know that DML operations on a view with DECODE, aggregate functions or group by can not be performed but I thought the "instead of" trigger on the view to update the base table should eleminate this restriction and hence pusued further but now stuck!
    BTW: I can post details of base table, view, and instead of trigger, if you want to see them to further decipher the problem. Just let me know. Thanks!
    VERSIONS: Forms in developer suite v10.1.2.0.2 on Windows XP 64 bit desktop - ; Backend database: 9.2.0.8 on Windows 2003 EE server
    Edited by: user8647268 on Aug 19, 2009 1:19 PM
    Edited by: user8647268 on Aug 19, 2009 1:25 PM

    I just forgot to ask you one question: In my experience with forms, I have captured before_value and after_value and implemented logic based on results many times. This form I am working on is kinda first multi-record form where I have a tabular page with date and about 7 other columns forming a grid of cells, which users wanted. Each line is a record from a view. I tried relying on forms to do DML on underlying table and since the underlying table is a paritioned table, I ran into FRM-40509 and ORA-00936, where returning ROWID becomes problematic. I found a note 167550.1 which says to set Key mode to 'Updateable' or 'Non-Updateable' but not 'Unique' or 'Automatic' as a solution #1. Solution#1 failed i.e. the errors persisted. The note also says in that case, implement Solution #2, which is to write explicit trigger to do each of the DML on view. Here I run into kinda problem: In a tabular form with say 31 records each row having 7 cells which is like capturing 217 before values..that is too many. Addressing them with ':old.xxx' or ':new.xxx' which works in instead of trigger, does not work in trigger inside forms. Without checking these before and after values, it inserts rows with nulls for empty cells where we wnated it to skip and do nothing. So iam looking for a way to capture before value using some kinda standard form mechanism..Do you have any suggestions! (Sorry for long explanation but that is the only way to do it..)

  • View-Update in forms with Instead-Of trigger

    I has created a view and an Instead-Of trigger on that view.
    Now, I want to update this view in FORMS 6. I am unable to update this view and getting error FRM-40602.
    Is there any way to update this view updatable in FORMS6 or FORMS6 has not this feature?

    Hi,
    This has been acknowledged by Oracle as bug earlier. The work-around for this is as follows:
    1. Create table 1
    2. Create table 2
    3. Create view
    4. Create instead of insert trigger on view
    5. Create instead of update trigger on view
    6. Now, in the forms, go to the Block property
    7. Look for the 'Key mode' property. By default it is 'Automatic'. Set it to Updateable (If your database design supports updating primary keys) or Unique (preferable).
    8. Now run the form. It should work.
    All the best.
    Sunil Kumar G S

  • [PLEASE] Prob with instead of Trigger  [URGENT !]

    Hi,
    I have an INSTEAD OF TRIGGER on a view which update 2 based tables.
    Each time the user update information,the system processes the update operation and insert a new row into the base tables.None of the based tables has any trigger.
    Why this insertion occures ? How can i stop it and update only the based tables without inserting the same row ?
    Thks for your advice
    lamine
    SQL> CREATE OR REPLACE TRIGGER UPDATE_PP_TR
    SQL>       INSTEAD OF UPDATE ON V_CONTACTS1_PP
    SQL>       FOR EACH ROW
    SQL>       begin
    SQL>         update ORGANIZATIONS
    SQL>         set
    SQL>           org_name = nvl(:new.org_name,org_name)
    SQL> .....
    SQL>           ,updated_by = v('USER')
    SQL>           ,updated_date = sysdate
    SQL>         where org_id = :new.org_id;
    SQL>         update INDIVIDUALS
    SQL>         set
    SQL>           ,gender = nvl(:new.gender,gender)
    SQL>           ,first_name = nvl(:new.first_name,first_name)
    SQL>           ,last_name = nvl(:new.last_name,last_name)
    SQL> ......
    SQL>           ,updated_by = v('USER')
    SQL>           ,updated_date = sysdate
    SQL>          where org_id = :new.org_id;
    SQL>        end UPDATE_PP_TR;

    Thks Andrew for your reply,
    The INSTEAD OF trigger doesn't insert new row as i said before.... apologies.... It processes 2 things:
    - update the field with the new value (what i want)
    - Replace any existing data that has the same reference_key by the new value.
    If we change the email of an individual and it happens that they are many people in the same company,then the INSTEAD OF TRIGGER updates the email and replace the other employees records by the one that has been updated.
    But if the company employes only 1 person then the process is ok.It's bizarre only for many employees in the same company.
    i.e:
    Martin Tom , [email protected], FRANCE SOFT
    Paul Henri, [email protected], FRANCE SOFT
    Jason Case, [email protected], FRANCE SOFT
    If i update Martin Tom's email to [email protected], Paul and Jason would be replace by Marin Tom's record....
    Martin Tom , [email protected], FRANCE SOFT
    Martin Tom , [email protected], FRANCE SOFT
    Martin Tom , [email protected], FRANCE SOFT
    Maybe my instead of trigger is written improperly.....
    Any advise ?

  • Instead-of Trigger of View on a Remote Table Fails!!!

    Hi all,
    I'm trying to create an INSTEAD OF (UPDATE or INSERT) trigger on a view V1 in DATABASE DB1 (Linux 7.3 or 7.2, ORACLE 9.2.0.1.0 - Production).The view V1 is created on a remote table through a DBLINK.But I always get such error when I update the view V1 using statements such as "update v1 set oid=oid+1000" :
    ORA-03113 end-of-file on communication channel
    But I can execute those statements successfully in Oracle of version 9.0.1.0.0 .
    What I want to say is that if some special configs is needed to support instead-of trigger of a view on a remote table ?

    Hi all,
    I'm trying to create an INSTEAD OF (UPDATE or INSERT) trigger on a view V1 in DATABASE DB1 (Linux 7.3 or 7.2, ORACLE 9.2.0.1.0 - Production).The view V1 is created on a remote table through a DBLINK.But I always get such error when I update the view V1 using statements such as "update v1 set oid=oid+1000" :
    ORA-03113 end-of-file on communication channel
    But I can execute those statements successfully in Oracle of version 9.0.1.0.0 .
    What I want to say is that if some special configs is needed to support instead-of trigger of a view on a remote table ?

  • INSTEAD of Trigger View for an Oracle EBS New form development

    Hello,
    I am developing a new EBS form based on a database view.
    This form is an EBS form will run in an 11.5.10.2 environment and developed using 6i.
    The form has one data block that is based on the view. The view is joined and based on following tables.
    Hz_Parties Hp,
    Hz_Cust_Accounts
    Hz_Cust_Acct_Sites_All
    Hz_Party_Sites
    Hz_Locations
    Ra_Salesreps_All
    Hz_Cust_Site_Uses_All
    Ar_Vat_Tax_All
    xx_custom_table t
    The view is inherently not updatable. Therefore, I am thinking to write an INSTEAD OF trigger on the view. The question. The form which is based on the view is require to update Oracle EBS tables mentioned above. As you know, there are APIs available to update above tables.
    Typically, you would write API in a program unit in the form and call from triggers. But here the form is based on the view. And to support DMLs on the view, I HAVE TO write INSTEAD of trigger(or that is the only way i know) so the question is:
    1. Do I write these APIs under INSTEAD of triggers?
    2. Or, I write these API in the form triggers and write DML referencing OLD and NEW values in INSTEAD of trigger? Where, these OLD and NEW values will refer on above tables.
    Please advise.
    And lastly, Do I have to write an INSTEAD of trigger? The USER_UPDATEABLE_COLUMNS view for this table shows no columns are updateable at the moment
    Thanks,
    A

    As you know, there are APIs available to update above tables.No, I don't B-) You'd better ask this in the eBusiness Suite form, as this is very EBS, not Forms, specific.
    In general, I would say that in this case you can use the EBS API's in the instead of trigger, not in the form.
    Or you can base the form on stored procedures, not directly on the view.

  • INSTEAD OF TRIGGER

    제품 : PL/SQL
    작성날짜 : 1999-07-13
    INSTEAD OF Trigger
    1. 개념
    INSTEAD OF trigger는 Oracle8에서 새로이 소개된 방법으로, DML문장에 의해
    직접 변경할 수 없는 view를 변경하기 위해 사용된다. 즉, base table이 fire
    하는 trigger를 생성하는 것이 아니고 view를 대상으로 trigger를 생성하여
    view에 대한 DML문장을 수행시 대신 trigger가 fire되어 base table을 직접
    변경하게 되는 것이다.
    기본적으로 DML이 불가능한 view는 다음 사항들을 포함하고 있는 경우이
    다. 이러한 사항을 포함한 view들에 대해서 instead of trigger를 생성하면 DML을
    수행할 수 있게 된다.
    (1) DISTINCT operator
    (2) group functions: AVG, COUNT, MAX, MIN, STDDEV, SUM, VARIANCE등
    (3) set operations: UNION, MINUS 등
    (4) GROUP BY, CONNECT BY, START WITH clauses
    (5) ROWNUM pseudocolumn
    (6) join (updatable join view인 경우는 제한적으로 DML수행가능 <Bul:11642>참
    조)
    2. EXAMPLE
    instead of trigger의 예를 다음과 같이 작성하였다.
    (1) base tables
    create table dept
    (deptno number(4) primary key,
    dname varchar2(14),
    loc varchar2(13));
    create table emp
    (empno number(4),
    ename varchar2(10),
    sal number(7,2),
    mgr number(4),
    deptno number(2) );
    (2) 직접 dml을 수행할 수 없는 view
    create view emp_dept
    as select empno, ename, sal, emp.deptno, dname
    from emp, dept where emp.deptno=dept.deptno;
    [참고] 이 예에서 dept table의 deptno가 primary key나 unique로 선언되어 있
    다면 emp_dept view는 updatable join view가 되어 key-reserved table인 emp table
    에 대한 dml은 trigger를 사용하지 않아도 직접 수행 가능하다. <Bul:11642>참

    (3) instead of trigger
    view에 DML을 수행시 내부적으로 수행되기를 원하는 logic을 임의로 user가
    작성하면 된다.
    아래의 예에서는 emp_dept에 insert문장을 수행하는 경우 기존에 존재하는
    dept정보에 대해서는 update를 수행하고, 새로은 dept정보는 insert하도록 하였다.
    그리고 emp table에 대해서는 empno가 primary key이므로 중복되는 row는
    자동으로 오류가 발생하게 되며, 새로운 값을 insert하게 되면
    emp table에 직접 insert를 하게 된다.
    create or replace trigger emp_dept_insert
    instead of insert on emp_dept
    referencing new as n
    for each row
    declare
    dept_cnt number;
    begin
    if :n.empno is not null then
    insert into emp(empno, ename, sal)
    values (:n.empno, :n.ename, :n.sal);
    end if;
    if :n.deptno is not null then
    select count(*) into dept_cnt
    from dept where deptno = :n.deptno;
    if dept_cnt > 0 and (:n.dname is not null) then
    update dept set dname = :n.dname where deptno = :n.deptno;
    else insert into dept(deptno, dname) values(:n.deptno, :n.dname);
    end if;
    end if;
    end;
    (4) DML statement
    다음과 같이 insert 문장을 view에 수행하면 emp_dept_insert trigger가
    fire되어 실제 emp와 dept table에 반영이 되어 emp_dept view에 insert가
    수행된 것 같이 보이게 된다.
    insert into emp_dept values (5000, 'EYKIM', 100, 10, 'SALES');
    insert into emp_dept(empno, ename, deptno) values (6000, 'YOUNKIM', 20);
    insert into emp_dept (empno, deptno, dname) values (7000, 50, 'NEW_DEPT');

    No, the INSTEAD OF trigger is on the View, and so only fires if you perform Insert/Update/Delete on the View.

  • How do I update a view with a join

    I have a module with database block based on a view with joins, so I am not able to perform insert, update & delete directly.
    Therefore I created an unbound item that can be changed. The relevant database record is searched and updated.
    So, with above work around, insert, update & delete is possible.
    This works just fine.
    Now, the 'save icon' in the menu (diskette icon), does not get activated automatically when there are changes to be saved. This is because the view is not changed.
    So, I enable the 'save icon' manually in the when-validate-item trigger. But now when I navigate to another record, the 'save icon' gets de-activated by QMS/headstart code. This is because the view is not changed.
    So, I tried set_record_property (CHANGED_STATUS) to let the application
    know there are changes to be saved.
    But then, I get an error:
    * FRM-40654: Record has been updated by another user. Re-query block to see
    change.
    What is the proper way to handle this problem?
    null

    Peter,
    I think you've gone down the wrong track with your workaround.
    You should base your form on the view and allow update and insert to the view just as if it was a table.
    If you are using Oracle 8i, create an INSTEAD-OF trigger on the view in the database which redirects the DML to insert or update the appropriate table(s) instead of the view.
    If you are pre Oracle 8i, in the form you can create on-insert, on-update, and on-delete triggers to redirect the DML to the appropriate table.
    The only other tricky situation comes if you have items in your form that are server-derived (in the TAPI) of the table(s) in question. If so, you must explicitly code the form to retrieve these server-derived values. Also note that with a view, you cannot have a server derived primary key since there would be no way to retrieve it in the form. (Views don't have a rowid.) You must derive primary key columns in the form when the form is based on the view.
    Regards,
    Lauri

  • Trigger on a view on a linked db

    I have an access db that i have 'hooked' into with a database link inside of Oracle. I then have an oracle view based on that linked database so i can see the records that are over in access. This all works well. What i would like to do now is create a trigger that fires each time a new record is added over in access.
    I cannot create that trigger on the database link because it is DDL and that is prohibited.
    I cannot create an After Insert trigger on my oracle view because that is prohibited on views.
    I can create an Instead Of trigger on the view but it never fires because the insert takes place in access not in oracle.
    Is there any way for Oracle to 'detect' when a new record has been added in the Access database?

    Feel like I'm getting really close to figuring this out. I created an mv on the db link like so:
    DROP MATERIALIZED VIEW mv_Test_SYSDATE
    CREATE MATERIALIZED VIEW mv_Test_SYSDATE
    TABLESPACE users
    REFRESH COMPLETE
    START WITH SYSDATE
    NEXT SYSDATE + 0.002 AS
    SELECT acctnum, name, odometer, lastdate, cardnumber
    from card@myaccessdb
    If i go into the access db and insert a new record I can see the record count in the mv change after a few minutes (i'm guessing 2.8 minutes).
    Which makes me happy. The problem now is that when i set up my trigger like so:
    CREATE OR REPLACE TRIGGER "AZ"."TEST_MV_TRIGGER"
    AFTER INSERT ON AZ.MV_TEST_SYSDATE
    FOR EACH ROW
    BEGIN
    INSERT INTO TEST ("ACCTNUM","NAME","ODOMETER","LASTDATE","CARDNUMBER")
    VALUES (:new.acctnum,:new.name,:new.odometer,:new.lastdate,:new.cardnumber);
    END;
    It actually does fire off of the mv which is a positive. But when i look in table test i see that it has pumped every record over, instead of just the newly added one from the access db.
    I can understand why because i suppose the mv refresh is for the entire table. but I'm not at where I want to be because I want to capture the delta on the access table.
    Any ideas?

  • Creating an Updateable View with Key Preservable Tables

    Hello everyone,
    I'm trying to create a view of two tables that I have in order to perform an instead of trigger on said view. The table structures for the tables I am using are as follows:
    Project Tasks Table
    TASK_ID  (Primary Key)
    TASK_NAME
    TASK_DUE_DATE
    Task Assignments Table
    ASSIGNMENT_ID (Primary Key)
    TASK_ID (Foreign Key)
    USER_ID
    ASSET_ID
    Given that, I'd like to create a view of a left outer join of the tables, so that every task is shown, regardless of whether or not it is assigned to someone. I've successfully created the view, which can be seen here:
    select
    P.TASK_ID,
    P.TASK_DUE_DATE,
    P.TASK_NAME,
    TA.ASSET_ID,
    TA.USER_ID
    from PROJECT_TASKS P
         left outer join PROJECT_TASK_ASSIGNMENTS TA
        on P.PROJECT_TASKS.TASK_ID = TA.PROJECT_TASK_ASSIGNMENTS.TASK_ID;
    I have also created a trigger on this view, to update both tables on an insert to the view. However, I cannot execute the trigger as when I check if the columns are user updateable, it shows NO for all of them. Is there any way I can create a view on these tables that allows for every column to be UPDATEABLE, INSERTABLE and DELETABLE?

    Hi,
    If you're writing an INSTEAD OF trigger, then it doesn't matter if anything in the view is updateable, insertable, deleteable or whatnotable.  Do all DML operations directly on the base tables.
    If you have problems, then post a complete test script that the peope who want to help you can run to re-create the problem and test their ideas.  Include CREATE TABLE and INSERT statements for you base tabels, the CREATE VIEW statement (if not exactly what you already posted), your best attempt at a CREATE TRIGGER statement, and some code that tests it.  Explain what results you want from that test (that is, what the tables should contain after it finishes.)
    Start small and take baby steps.  Start with a trigger that, say, only DELETEs.  When we get that working, then we can change iot to handle INSERTs.

  • How to create a trigger on a view

    Hello all,
    I am trying to create a trigger on a view that is used to update a few columns in the base table. Since I am new to trigger, an example will be appreciated.
    Thanks in advance.

    Are you sure that you need a trigger for this? Lots of folks that are new to triggers tend to overuse them before they understand the maintenance problems that having a bunch of triggers creates.
    That said, the Oracle documentation has an example of [creating an INSTEAD OF trigger on a view|http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_7004.htm#i2064426]
    Justin

  • Create a trigger on a view

    I try to create a database trigger on a view and when the sql return a error (ORA-00439: feature not enabled: Instead-of triggers)
    How can i create the trigger?
    Pd. I don4t have problems to create then trigger on a table.

    Are you sure that you need a trigger for this? Lots of folks that are new to triggers tend to overuse them before they understand the maintenance problems that having a bunch of triggers creates.
    That said, the Oracle documentation has an example of [creating an INSTEAD OF trigger on a view|http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_7004.htm#i2064426]
    Justin

Maybe you are looking for

  • My Mac won't print a pdf from the web

    My iMac will not print any pdf from the web. The printer (an ho Photosmart plus) will only print a blank shet of paper.

  • Sidebars on macbook pro when on TV with thunderbolt

    I have a Thunderbolt to HDMI cable going to my high def TV. I get bars on the sides of the TV and I change the resolution to 1080p and other resolutions and can't seem to get a good fit. Also the audio is not working unless I run surround sound direc

  • Help reqd on Material Master uploading in LSMW by view steps....

    Hi all.... Pls understand my requirement and post ur replies...i dont need the basic LSMW learning steps for MM,Vendor etc.,like that... My problem is...im want to upload my material master datas by steps like 1st i want to uplaod the basic views 1&2

  • How do I check my iCloud mail using Safari on an iPhone or iPad?

    I'm a satisfied user of iCloud email. Everything is setup and working great on my iPhone. Recently my iPhone died and I needed to check email using my girlfriend's phone. There was no other computer handy (just an iPhone). I assumed I could launch Sa

  • HTML not reading correctly after Mountain Lion Update

    Since I updated to Mountain Lion I am getting a consistent symbol in place of HTML on Safari and Mail ( the 'A' in a box. see the attached image). Firefox works much better than Safari but it still appears, although a lot less.  I haven't found anyth