Instead of Trigger Problems

Good morning and thanks in advance for the help.  I'm new to oracle and sql in general, so bear with me if my create statements are wrong.  I am using Oracle 11g.
I am trying to create a trigger to do an update on a timesheet view in APEX.  The view draws from the assignment table and needs to store the data in the timesheet table.
CREATE TABLE assignment (
   assignment_id   number
   employee_id   number
   project_id   number)
CREATE TABLE timesheet (
   timesheet_id  number
   assignment_id  number
   week_start_date  date
   hours   number)
INSERT ALL
  INTO assignment (employee_id, project_id) VALUES (1, 1)
  INTO assignment (employee_id, project_id) VALUES (1, 2)
  INTO assignment (employee_id, project_id) VALUES (2, 1)
  INTO assignment (employee_id, project_id) VALUES (3, 2)
CREATE OR REPLACE FOR VIEW timesheet_view AS
SELECT *
FROM (SELECT A.assignment_id, project_id, employee_id, week_start_date, hours
      FROM timesheet T
      RIGHT OUTER JOIN assignment A
        ON T.assignment_id = A.assignment_id)
PIVOT (MAX(hours) FOR week_start_date IN (to_date('06/03/2013', 'MM/DD/YYYY') AS "06/03/2013",
to_date('06/10/2013', 'MM/DD/YYYY') AS "06/10/2013",
to_date('06/17/2013', 'MM/DD/YYYY') AS "06/17/2013",
to_date('06/24/2013', 'MM/DD/YYYY') AS "06/24/2013")
The view has many more columns since this needs to track weeks until they decide to stop using the app.
The view thus looks like this:
assignment_id  project_id  employee_id  06/03/2013  06/10/2013  06/17/2013  06/24/2013
1                      1                1                 25               15              15              15
2                      2                1                 15               25              25              -
3                      1                2                 40               40              40              40
4                      2                3                 40               -                40              -
So my question is, how do I create a trigger to insert into the timesheet table? I know how to create an instead of trigger, but what I don't know how to do is reference the column names for the date and then take the data that has been updated in each and store that in the timesheet table with the column name going in the week_start_date column and the value from the row at that column going into the hours column.  I'd love to be able to do it dynamically since adding a line to the trigger for every single date would be quite unruly.
Any help is greatly appreciated.

Yuck.  But you are hardcoding dates as columns into the view, so you'll have to change the view sometime anyway?  Could you not generate columns based on the MODEL clause?
Alternatively, have you considered adding a hidden (from the front end) column (weekno) for each date column to your view, but hiding it; in that column you could hardcode the date for the following column?
assignment_id  project_id  employee_id  week1dt         06/03/2013 week2dt          week3dt       06/10/2013  etc.
1                      1                1                06/10/2013    125             06/17/2013      06/10/2013    15           
edit: I was just wondering about an alternative: if you could prepend the week date (eg "06/03/2013") to the hours data for the row/column (e.g. "06/03/2013,40") then substring the hours (split on ",") in the APEX view, but you would have the weekdate to be able to use in your table update.  Just a thought; I've no experience with APEX.

Similar Messages

  • Big Problem with Instead Of Trigger

    I have following problem: I created my own user-table where I want to store some
    attributes like user-foto etc... This table I join with the HTMLDB
    wwv_flow_fnd_user (I gave myself the select grant on it) in a view
    On the view I created an INSTEAD-OF-Trigger for DELETE-Operations where I delete
    only my user-table. But when I execute it it gives me an
    ORA-01031: insufficient privileges
    I can not understand it.
    <pre>
    ===========================================================
    SQL*Plus: Release 10.2.0.1.0 - Production on Tue Sep 27 05:28:13 2005
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> DROP TABLE my_users
    2 ;
    Table dropped.
    SQL> CREATE TABLE my_users AS
    2 SELECT user_id
    3 FROM flows_020000.wwv_flow_fnd_user
    4 ;
    Table created.
    SQL> ALTER TABLE my_users ADD my_attr VARCHAR2(10);
    Table altered.
    SQL> ALTER TABLE my_users ADD CONSTRAINT pk_my_users PRIMARY KEY( user_id );
    Table altered.
    SQL> CREATE OR REPLACE VIEW v_my_users
    2 AS
    3 SELECT u2.user_id,
    4 u.user_name,
    5 u.first_name,
    6 u.last_name,
    7 u2.my_attr
    8 FROM flows_020000.wwv_flow_fnd_user u,
    9 my_users u2
    10 WHERE u2.user_id = u.user_id
    11 ;
    View created.
    SQL> CREATE OR REPLACE TRIGGER trg_del_v_my_users
    2 INSTEAD OF DELETE ON v_my_users
    3 FOR EACH ROW
    4 BEGIN
    5 DELETE my_users
    6 WHERE user_id = :OLD.user_id
    7 ;
    8 END;
    9 /
    Trigger created.
    SQL> DELETE v_my_users WHERE 1=2
    2 ;
    DELETE v_my_users WHERE 1=2
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ===========================================================
    </pre>
    And: If there is no PK on table my_users I got not error!
    Can anybody explain it?
    And: How can I include my listings in the forum with courier font?

    Is the primary key in this table referencing any table(s) in other schema? How should this work?
    Look at the script above:
    ALTER TABLE my_users ADD CONSTRAINT pk_my_users PRIMARY KEY( user_id );
    Bye,
    Rumburak

  • Problem in creating Entity for view which has "INSTEAD OF " trigger

    Hi ,
    I have an entity based on a Non updatable Database view (DB_VIEW).this database view has an INSTEAD OF trigger which validates
    and save data into a table.
    And I have a BC4J view based on this entity.
    Problem :
    When I try to insert a record using bc4j view object,I get following error
    ORA-22816: unsupported feature with RETURNING clause
    Query sent by view Object is :
    BEGIN INSERT INTO DB_VIEW(COLUMN1,COLUMN2,COLUMN3) VALUES (:1,:2,:3) RETURNING ROWID INTO
    :4; END;
    I am not able to insert any record in that view.
    I tried removing rowID from my BC4J entity and View but problem is that in Databae view there is no
    column which can be set as a primary key other then ROWID.

    I had the same problem.
    Oracle 9.2 sadly does not support the RETURNING clause for database views with INSTEAD OF triggers.
    Here is Steves Solution:
    1. Create a custom entity def impl class for your entity on the Java panel
    2. override the isUseReturningClause() and return false
    That should work in 9.0.3.4, 9.0.4 build 1419, and 9.0.5.1 production.
    from How to disable generation of RETURNING clause?
    Hth, Markus

  • Instead of trigger example - INSERT works but UPDATE and DELETE does not?

    Below is a demostration script of what I am trying to troubleshoot. Tests are done on 10gR2;
    conn system/system
    drop table tt purge ;
    create table tt nologging as select * from all_users ;
    alter table tt add constraint pk_tt_user_id primary key (user_id) nologging ;
    analyze table tt compute statistics for table for all indexed columns ;
    conn hr/hr
    drop database link dblink ;
    create database link dblink
    connect to system identified by system
    using 'xe.turkcell' ;
    select * from global_name@dblink ;
    drop view v_tt ;
    create view v_tt as select username, user_id, created from tt@dblink order by 2 ;
    select count(*) from v_tt ;
    COUNT(*)
    13
    drop sequence seq_pk_tt_user_id ;
    create sequence seq_pk_tt_user_id
    minvalue 1000 maxvalue 99999
    increment by 1;
    create synonym tt for tt@dblink ;
    CREATE OR REPLACE PROCEDURE prc_update_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
    BEGIN
    IF old_tt.user_id != new_tt.user_id THEN
    RETURN; -- primary key
    END IF;
    IF old_tt.user_id IS NOT NULL AND new_tt.user_id IS NULL THEN
    DELETE FROM tt
    WHERE user_id = nvl(old_tt.user_id,
    -99);
    RETURN;
    END IF;
    IF (old_tt.username IS NULL AND new_tt.username IS NOT NULL) OR
    (old_tt.username IS NOT NULL AND new_tt.username != old_tt.username) THEN
    UPDATE tt
    SET username = new_tt.username
    WHERE user_id = nvl(old_tt.user_id,
    -99);
    END IF;
    IF (old_tt.created IS NULL AND new_tt.created IS NOT NULL) OR
    (old_tt.created IS NOT NULL AND new_tt.created != old_tt.created) THEN
    UPDATE tt
    SET created = new_tt.created
    WHERE user_id = nvl(old_tt.user_id,
    -99);
    END IF;
    END prc_update_tt;
    CREATE OR REPLACE PROCEDURE prc_insert_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
    new_tt_user_id NUMBER;
    BEGIN
    SELECT seq_pk_tt_user_id.NEXTVAL INTO new_tt_user_id FROM dual;
    INSERT INTO tt
    (username, user_id, created)
    VALUES
    (new_tt.username, new_tt_user_id, new_tt.created);
    END prc_insert_tt;
    CREATE OR REPLACE PROCEDURE prc_delete_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
    BEGIN
    DELETE FROM tt
    WHERE user_id = nvl(old_tt.user_id,
    -99);
    END prc_delete_tt;
    CREATE OR REPLACE TRIGGER trg_iof_v_tt
    INSTEAD OF UPDATE OR INSERT OR DELETE ON v_tt
    FOR EACH ROW
    DECLARE
    new_tt v_tt%ROWTYPE;
    old_tt v_tt%ROWTYPE;
    BEGIN
    dbms_output.put_line('INSTEAD OF TRIGGER fired');
    dbms_output.put_line(':NEW.user_id ' || :NEW.user_id);
    dbms_output.put_line(':OLD.user_id ' || :OLD.user_id);
    dbms_output.put_line(':NEW.username ' || :NEW.username);
    dbms_output.put_line(':OLD.username ' || :OLD.username);
    dbms_output.put_line(':NEW.created ' || :NEW.created);
    dbms_output.put_line(':OLD.created ' || :OLD.created);
    new_tt.user_id := :NEW.user_id;
    new_tt.username := :NEW.username;
    new_tt.created := :NEW.created;
    old_tt.user_id := :OLD.user_id;
    old_tt.username := :OLD.username;
    old_tt.created := :OLD.created;
    IF inserting THEN
    prc_insert_tt(old_tt,
    new_tt);
    ELSIF updating THEN
    prc_update_tt(old_tt,
    new_tt);
    ELSIF deleting THEN
    prc_delete_tt(old_tt,
    new_tt);
    END IF;
    END trg_iof_v_tt;
    set serveroutput on
    set null ^
    insert into v_tt values ('XXX', -1, sysdate) ;
    INSTEAD OF TRIGGER fired
    :NEW.user_id -1
    :OLD.user_id
    :NEW.username XXX
    :OLD.username
    :NEW.created 30/01/2007
    :OLD.created
    1 row created.
    commit ;
    select * from v_tt where username = 'XXX' ;
    USERNAME USER_ID CREATED
    XXX 1000 31/01/2007          <- seems to be no problem with insert part but
    update v_tt set username = 'YYY' where user_id = 1000 ;
    INSTEAD OF TRIGGER fired
    :NEW.user_id
    :OLD.user_id
    :NEW.username YYY
    :OLD.username
    :NEW.created
    :OLD.created
    1 row updated.
    commit ;
    select count(*) from v_tt where username = 'YYY' ;
    COUNT(*)
    0               <- here is my first problem with update part, Oracle said "1 row updated."
    delete from v_tt where user_id = 1000 ;
    INSTEAD OF TRIGGER fired
    :NEW.user_id
    :OLD.user_id
    :NEW.username
    :OLD.username
    :NEW.created
    :OLD.created
    1 row deleted.
    commit ;
    select count(*) from v_tt ;
    COUNT(*)
    14               <- here is my second problem with delete part, Oracle said "1 row deleted."
    Any comments will be welcomed, thank you.
    Message was edited by:
    TongucY
    changed "-1" values to "1000" in the where clause of delete and update statements.
    it was a copy/paste mistake, sorry for that.

    What table do you process in your procedures ? You don't use DBLINK to
    reference remote table in your procedures.
    Seems, you have table "TT" in "HR" schema too.
    Look:
    SQL> create table tt nologging as select * from all_users where rownum <=3;
    Table created.
    SQL> select * from tt;
    USERNAME                          USER_ID CREATED
    SYS                                     0 25-APR-06
    SYSTEM                                  5 25-APR-06
    OUTLN                                  11 25-APR-06
    SQL> conn scott/tiger
    Connected.
    SQL> create database link lk65 connect to ... identified by ... using 'nc65';
    Database link created.
    SQL> select * from tt@lk65;
    USERNAME                          USER_ID CREATED
    SYS                                     0 25-APR-06
    SYSTEM                                  5 25-APR-06
    OUTLN                                  11 25-APR-06
    SQL> create view v_tt as select username, user_id, created from tt@lk65 order by 2;
    View created.
    SQL> select * from v_tt;
    USERNAME                          USER_ID CREATED
    SYS                                     0 25-APR-06
    SYSTEM                                  5 25-APR-06
    OUTLN                                  11 25-APR-06
    SQL> create sequence seq_pk_tt_user_id
      2  minvalue 1000 maxvalue 99999
      3  increment by 1;
    Sequence created.
    SQL> CREATE OR REPLACE PROCEDURE prc_insert_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
      2  new_tt_user_id NUMBER;
      3  BEGIN
      4  SELECT seq_pk_tt_user_id.NEXTVAL INTO new_tt_user_id FROM dual;
      5  INSERT INTO tt
      6  (username, user_id, created)
      7  VALUES
      8  (new_tt.username, new_tt_user_id, new_tt.created);
      9  END prc_insert_tt;
    10  /
    Warning: Procedure created with compilation errors.
    SQL> show error
    Errors for PROCEDURE PRC_INSERT_TT:
    LINE/COL ERROR
    5/1      PL/SQL: SQL Statement ignored
    5/13     PL/SQL: ORA-00942: table or view does not exist
    SQL> edit
    Wrote file afiedt.buf
      1  CREATE OR REPLACE PROCEDURE prc_insert_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
      2  new_tt_user_id NUMBER;
      3  BEGIN
      4  SELECT seq_pk_tt_user_id.NEXTVAL INTO new_tt_user_id FROM dual;
      5  INSERT INTO tt@lk65
      6  (username, user_id, created)
      7  VALUES
      8  (new_tt.username, new_tt_user_id, new_tt.created);
      9* END prc_insert_tt;
    SQL> /
    Procedure created.Rgds.

  • How can I retrieve the condition in an update or delete using instead of trigger

    I have 2 tables, on which a view is created. To distinguish the tables within the view trigger, a column "source" had been added in the view creation. I want to be able to delete row(s) in table t1 or table t2 through the view, depending on a condition. The problem is that I don't know how I can get back the delete condition IN the INSTEAD of trigger :
    CREATE TABLE t1(m NUMBER, n VARCHAR2(10), o date);
    CREATE TABLE t2(a NUMBER, b VARCHAR2(10), c date);
    -- The view is created based on the 2 tables.
    CREATE OR REPLACE VIEW vt12 AS
    SELECT 't1' source, m, n, o
    FROM t1
    UNION
    SELECT 't2' source, a, b, c
    FROM t2;
    -- The trigger will fire whenever INSERT is performed on the tables through the view
    create or replace trigger tvt12 instead of insert or delete on vt12
    begin
    if inserting then
    if :new.source = 't1' then
    insert into t1 values (:new.m, :new.n, :new.o);
    else
    -- will insert a default value of -1 for the fourth column "d"
    insert into t2(a,b,c,d) values (:new.m, :new.n, :new.o, -1);
    end if;
    elsif deleting then
    -- We don't know the condition for the deletion, so all rows from the
    -- table from which the current row is coming will be deleted
    if :old.source = 't1' then
    delete t1;
    else
    delete t2;
    end if;
    end if;
    end;
    show error
    insert into vt12 values ('t1',1,'1',sysdate);
    insert into vt12 values ('t2',2,'2',sysdate+1);
    insert into vt12 values ('t1',3,'3',sysdate+2);
    insert into vt12 values ('t2',4,'4',sysdate+3);
    insert into vt12 values ('t1',5,'5',sysdate+4);
    insert into vt12 values ('t2',6,'6',sysdate+5);
    commit;
    select * from vt12;
    select * from t1;
    select * from t2;
    delete vt12 where m = 1;
    commit;
    select * from vt12;
    select * from t1;
    select * from t2;
    When I execute this script, the delete statement seems to recognize that the condition is affecting a row in table t1, and therefore deletes all rows from the table, as specified in the delete statement of the trigger... But, what I want to do is ONLY to delete the row affected by the original condition. So my question is to know how I can get back the original condition for the delete, and still use it in the trigger, that will be executed INSTEAD of the delete statement.. I checked in the doc, and everywhere an example of INSTEAD OF trigger can be found, but it's always and only using an INSTEAD OF INSERT trigger, which doesn't need a condition.
    Can anyone help ?
    null

    I've never faced this case myself, but from the documentation it would seem that the INSTEAD OF DELETE is also a FOR EACH ROW trigger. Therefore, you don't really have to worry about the actual "where" clause of the original "delete" operation: Oracle has it all parsed for you, so you just need to redirect, in turn, each view record being deleted to the appropriate table.
    In extenso: for your
    delete vt12 where m = 1;
    => the INSTEAD OF trigger fires once for all records in vt12 where m=1, and I would guess that you trigger code should look like:
    begin
    delete from t1 where m = :old.m and n = :old.n and o = :old.o;
    delete from t2 where a = :old.m and b = :old.n and c = :old.o;
    end;
    It's a bit of overkill compared to the "where" clause of the original "delete" statement, but it should do the job...
    BTW, if by any luck you do have some primary key on tables t1 and t2 (say: columns o and c respectively), then obviously you can make the thing simpler:
    begin
    delete from t1 where o = :old.o;
    delete from t2 where c = :old.o;
    end;
    HTH - Didier

  • Insert order by records into a view with a instead of trigger

    Hi all,
    I have this DML query:
    INSERT INTO table_view t (a,
                              b,
                              c,
                              d,
                              e)
          SELECT   a,
                   b,
                   c,
                   d,
                   e
            FROM   table_name
        ORDER BY   dtable_view is a view with an INSTEAD OF trigger and table_name is a table with my records to be inserted.
    I need the ORDER BY clause because in my trigger i call a procedure who treat each record and insert into a table, used in the view. I need to garantee these order.
    If i put an other SELECT statement outside, like this:
    INSERT INTO table_view t (a,
                              b,
                              c,
                              d,
                              e)
          SELECT   a,
                   b,
                   c,
                   d,
                   e
            FROM   table_name
        ORDER BY   dIt works. But I can put these new SELECT because these query is created automatic by Oracle Data Integrator.
    What I'm asking you is if there any solution to this problem without changing anything in the Oracle Data Integrator. Or, in other words, if there is any simple solution other than to add a new SELECT statement.
    Thanks in advance,
    Regards.

    Sorry... copy+paste error :)
    INSERT INTO table_view t (a,
                              b,
                              c,
                              d,
                              e)
        SELECT   *
          FROM   (  SELECT   a,
                             b,
                             c,
                             d,
                             e
                      FROM   table_name
                  ORDER BY   d)I need to insert him by a D column order, because my trigger needs to validate each record and insert him. I have some restrictions. For example, my records are:
    2     1     2006     M
    1     2     2007 M
    1     3     2007     S 2007
    1     2     2007     S 2007
    2     1     2009     S
    2     1     2009     S
    I want to insert the 'M' records first and then the 'S' records because the 'S' records only makes sense in target table is exists 'M' records
    Regards,
    Filipe Almeida

  • Instead of Trigger for tabular form

    I have a tabular layout on a form that returns data from a database view. Based on user interaction I would like to update the underlying view records that are returned by a query in the form using an INSTEAD OF trigger. I have my trigger working, however I can only get it to update the first record of the tabular layout item on the form. I realize that INSTEAD OF triggers are row level triggers, but is there a way to get this trigger to fire for multiple records? I've written a simple update statement in the form that updates the view: update newborn.nb_ltfu_positive_v
    set export_dt = sysdate
    where barcode = :nb_ltfu_positive_v.barcode;
    and my INSTEAD OF trigger looks like this: if :old.export_dt <> :new.export_dt then
    update nbpat set export_dt = sysdate
    where spec = :old.spec;
    end if;
    if :old.export_dt <> :new.export_dt then
    update nbhear_audiotest set export_dt = sysdate
    where barcode = :old.barcode;
    end if;
    Do I need to do some looping in the trigger?
    Any assistance would be greatly appreciated.
    Thanks

    No you cannot do any looping in the database trigger. The database trigger will for every record which is involved in an UPDATE issued againt the view.
    The problem is your code inside the form. In general you do not issue "manual" update against a table/view in forms, but let forms do so. So, if you want to update a record in a tabular block in forms you would just assign the new value to the forms-item, such as
    :BLOCK.EXPORT_DT:=SYSDATE;in your example. This code marks the "active" reocrd in the block as "to be updated" in the next transactions, mean when the user presses "Save". If you want to update multiple records in forms, this is either done when the user navigates between different record and then does some changes in the block-fields, or if you want to do it "programmatical", by looping over the block, something like:
    FIRST_RECORD;
    LOOP
      EXIT WHEN :SYSTEM.RECORD_STATUS ='NEW';
      -- do some stuff on the current record, exampel code
      :BLOCK.EXPORT_DT:=SYSDATE;
      EXIT WHEN :SYSTEM.LAST_RECORD='TRUE';
      NEXT_RECORD;
    END LOOP;hope this helps

  • Instead of Trigger Error

    Hi ALL,
    I am trying to create INSTEAD OF trigger on the existing VIEW, but I getting error as:-
    Not found
    The requested URL /apex/wwv_flow.show was not found on this server
    I'm creating trigger as :-
    CREATE OR REPLACE TRIGGER "trigger_name"
    INSTEAD OF UPDATE ON "view_name"
    FOR EACH ROW
    BEGIN
    UPDATE query;
    UPDATE query;
    END;
    but when I'm writting only one update query rather two update queires in the above trigger, it is creating but not with two update queries.
    Also I created another INSTEAD OF trigger on the same View as:-
    CREATE OR REPLACE TRIGGER "trigger_name"
    INSTEAD OF INSERT ON "view_name"
    FOR EACH ROW
    BEGIN
    INSERT query;
    INSERT query;
    END;
    this trigger is created without any errors than why INSTEAD OF(FOR UPDATE) trigger is not creating.... can anybody help me out with this issue.....
    thxs
    regards,
    Kumar

    Hi again,
    everything is working very much fine(I mean instead of trigger with update as well as with insert) when I'm creating on apex workspace.... this is the issue with my development enviornment.... so this is the problem with development DB or something else?????
    thxs
    regards,
    Kumar

  • View, instead of trigger and ORA-01031

    Hello,
    I have a view based on outer joins like
    CREATE VIEW vt ( colV1, colV2, colV3, colV4, colV5, colV6, colV7, colV8 ) AS
    SELECT A.colA1, A.colA2, C.colB0, B.colB2, B.colB3, B.colB4, C.colC2, H.colH2
      FROM  tabA    A
           ,tabB    B
           ,tabC    C
           ,( SELECT  ...
                FROM   tabD  D
                      ,tabE  E
                WHERE  D.colD1 = E.colE1
             )  H                                
      WHERE A.colA1 = B.colB1
        AND LTRIM(B.colB2,'A') = LTRIM(C.colC1(+),'A')    
        AND B.colB3 = H.colH1(+); and an instead of trigger
    CREATE OR REPLACE TRIGGER vt_upd
      INSTEAD OF UPDATE ON vt
    BEGIN
      UPDATE    tabB
         SET    colB4 = :NEW.colV6
         WHERE  colB0 = :NEW.colV2;
    END;An now the problem: an update statement UPDATE vt set colV6=1 WHERE colV1=1; in SQL*Plus works as it should, but performing an update in APEX from a tabular or edit form shows an error: ORA-01031:ORA-01031: insufficient privileges, update...The strange thing: in both sessions there is the same user USER1 logged on !
    Why this difference ? Can anybody explain ?
    Regards,
    Heinz

    Hi Heinz,
    Your statement -
    what I wrote as table tabC in reality is a view to one table and one view in another schema.That'll be it, you need to grant explicit rights for the objects in that schema to the schema that is your parsing schema for your workspace.
    In other words, if you have -
    1) Workspace 'A' with parsing schema 'B'
    and you are trying to do -
    select foo from c.bar
    i.e. you're trying to query an object in schema 'C'.
    Then you need to (as a DBA or connected to schema C) -
    grant select on bar to b;Roles won't work (when used through APEX)...I can't say that any other way, you might find it works in SQLPlus with roles, but through APEX it won't...you need those explicit grants.
    Hope this makes sense.
    John.

  • "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)?

  • 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 with Instead of Trigger - ORA-01031

    I am having trouble with a form based on a view that uses an instead of trigger.
    When I attempt to update a complex view that uses instead of triggers in an APEX form, I get the following message:
    ORA-20001: Error in DML: p_rowid=21388, ... ORA-01031: insufficient privileges
    The view works correctly when updates are executed from SQL Plus.
    The view "VW" is based on several tables in the application schema "X", which is parsed by APEX, and several tables in another schema "Z". I have explicitly granted select permission on the tables in schema "Z" to schema "X", but this doesn't resolve the error.
    Any idea how to fix this problem? From reading other posts, it sounds like the only issue should be explicit grants on the tables in other schemas. I do not attempt to update the tables in schema "Z", and do not have update permissions to those tables.
    Sinerely, Justin

    Justin,
    you might try to grant the views to the FLOWS_xxxxx user, which performs the Apex processes.
    Dik Dral

  • ERROR - 16016 - FOR FORM CREATED ON A VIEW AND USING INSTEAD OF TRIGGER

    I have created a form based on a view. The view has instead of Trigger on it.
    When I try to update the form I get the following error:
    Error: An unexpected error occurred: ORA-22816: unsupported feature with RETURNING clause (WWV-16016)
    Can anyone tell what the problem is?
    Thanks
    null

    THANKS A LOT IT WORKED.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Rene' Castle ([email protected]):
    This is a bug with views. If you can edit the PL/SQL code that is generated, you can remove the RETURNING clause and it will work.
    NOTE: This will have to be done every time you edit the form.
    <HR></BLOCKQUOTE>
    null

  • BIG Trigger Problem!!!

    Hi friends,
    I need to write a before insert and update trigger,that Select and (insert respectively update) the same table.
    I tried some solutions
    like the solution of Tom -->askTom
    here is the Link http://asktom.oracle.com/~tkyte/Mutate/index.html
    but that don't work for me. The problem is that I have
    first to select something from Table A and then
    check this with the values which have to be inserted or updated in Table A. Only when the the new values(from one column) are not in Table A they can be inserted or updated.Otherwise the Trigger have to raise an error.
    Can somebody tell me a way how to implement such a trigger???Please with an example.
    thanxx
    Schoeib

    As far as I know there is no easy solution for this. There is a good reason why Oracle throws the mutating table exception in its BEFORE triggers. One possible way round it is to use a view with an INSTEAD OF trigger on it, and prevent people have direct access to the table..
    However, it does seem to be as though you are trying to get the database to resolve problems that really ought to solved at the front-end. If at all possible you should try to correct whatever application is entering data into your system.
    Cheers, APC

  • Issue in Invoking an Updatable View with Instead of Trigger

    Hi,
    I am trying to insert a record using Updatable View with Instead of Trigger. When i try to save the data, i get the below error:
    java.sql.SQLException: ORA-01403: no data found
    ORA-06512: at line 1
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:457)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:405)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:889)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:476)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:204)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:540)
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:213)
    at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1075)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1466)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3752)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3887)
    at oracle.jdbc.driver.OracleCallableStatement.executeUpdate(OracleCallableStatement.java:9323)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1508)
    at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate(PreparedStatement.java:172)
    at oracle.jbo.server.OracleSQLBuilderImpl.doEntityDML(OracleSQLBuilderImpl.java:432)
    at oracle.jbo.server.EntityImpl.doDMLWithLOBs(EntityImpl.java:8566)
    Can someone help me resolve this issue?
    Also it would be great if you can share Sample codes for Invoking an updatable view with instead of trigger on Save/commit.
    Regards,
    Jeevan

    As a trigger is executed in the db and not in your app it's really hard to help as you did not give any useful information.
    Have you read this blog http://stegemanoracle.blogspot.com/2006/03/using-updatable-views-with-adf.html ?
    Timo
    Edited by: Timo Hahn on 22.09.2011 09:15
    And my friend google also found http://technology.amis.nl/blog/1447/adf-business-components-resfresh-after-insertupdate-and-instead-of-triggers

Maybe you are looking for

  • External NTSC Monitor - 4:3 and 16:9 Question

    I'm trying to find a configuration setting in FCP 5.0 when outputting to an external NTSC monitor that will force the image to "letterbox", rather than crop to 4:3. I have a nice Sony NTSC monitor, but it's not the model that allows switching between

  • Radio buttons disabling functionality in OOPS ALV

    Hi, I am facing this peculiar problem in OOPS ALV. the requirement was to have a field and 2 radio buttons in ALV as editable when user clicks on CHANGE mode. but initially the table should be in display mode. I have used the icons in ALV to provide

  • Some of my albums track lists are incorrect in my iPod

    I've noticed this problem with my iPod probably a week or so after I bought it. It is a brand new 80 gb iPod. What is happening is that a few of my albums on my iPod list the tracks incorrectly. I've noticed this happening with about a dozen of my al

  • I don't want some fields to be added in the Tab order.

    I dragged a few objects from the OBJECT LIBRARY, say 1. TextField1 2. TextField2 3. TextField3 4. Text1 5. ImageField1 6. Button1 7. CheckBox1 8. CheckBox2 Then I selected 'TAB ORDER' from the 'VIEW MENU' now I want to keep out 'ImageField1' and 'Tex

  • Problem getting session vars to stay defined

    I am frustrated please help. I have used earlier versions of CF but cf 8 is very new to me. I want to set session variables with in the application.cfc, I thought I had it correct for session management to be initiated, as session variables can be de