MULTIPLE UPDATES/INSERTIONS TO THE SAME TABLE

How can I update/insert mutiple rows into the same table from one form ?

Hi,
Using the portal form on table you can insert only a single row. You can use master-detail form to insert multiple rows.
Thanks,
Sharmila

Similar Messages

  • Multiple (updatable) details in the same page.

    Hello,
    I tried to put two updatable details in the same page and got the error
    "Updatable SQL Query already exists on page 11. You can only add one updatable SQL query per page. Select a different page"
    So having more than one updatable detail is not allowed in apex ?
    I have a master table with three details. Should I create one page for each one of them ?
    Thanks in advance
    Bye
    Nicola

    What you want to use are called collections. Here is a simple collection example:
    The process goes in 4 steps: gather the data, display the data, update based on user input, then write the changes. Each step requires it's own piece of code, but you can extend this out as far as you want. I have a complex form that has no less than a master table and 4 children I write to based on user input, so this can get as complex as you need. Let me know if anything doesn't make sense.
    First, create the basic dataset you are going to work with. This usually includes existing data + empty rows for input. Create a Procedure that fires BEFORE HEADER or AFTER HEADER but definitely BEFORE the first region.
    DECLARE
      v_id     NUMBER;
      var1     NUMBER;
      var2     NUMBER;
      var3     VARCHAR2(10);
      var4     VARCHAR2(8);
      cursor c_prepop is
      select KEY, col1, col2, col3, to_char(col4,'MMDDYYYY')
        from table1
        where ...;
      i         NUMBER;
      cntr      NUMBER := 5;  --sets the number of blank rows
    BEGIN
      OPEN c_prepop;
        LOOP
          FETCH c_prepop into v_id, var1, var2, var3, var4;
          EXIT WHEN c_prepop%NOTFOUND;
            APEX_COLLECTION.ADD_MEMBER(
            p_collection_name => 'MY_COLLECTION',
            p_c001 => v_id,  --Primary Key
            p_c002 => var1, --Number placeholder
            p_c003 => var2, --Number placeholder
            p_c004 => var3, --text placeholder
            p_c005 => var4 --Date placeholder
        END LOOP;
      CLOSE c_prepop;
      for i in 1..cntr loop
        APEX_COLLECTION.ADD_MEMBER(
            p_collection_name => 'MY_COLLECTION',
            p_c001 => 0, --designates this as a new record
            p_c002 => 0, --Number placeholder
            p_c003 => 0, --Number placeholder
            p_c004 => NULL, --text placeholder
            p_c005 => to_char(SYSDATE,'MMDDYYYY') --Date placeholder
      end loop;
    END;Now I have a collection populated with rows I can use. In this example I have 2 NUMBERS, a TEXT value, and a DATE value stored as text. Collections can't store DATE datatypes, so you have to cast it to text and play with it that way. The reason is because the user is going to see and manipulate text - not a DATE datatype. If you are using this as part of a master/detail form, make sure that your SQL to grab the detail is limited to just the related data.
    Now build the form/report region so your users can see/manipulate the data. Here is a sample query:
    SELECT rownum, apex_item.hidden(1, c001),  --Key ID
         apex_item.text(2, c002, 8, 8) VALUE1,
         apex_item.text(3, c003, 3, 3) VALUE2,
         apex_item.text(4, c004, 8, 8) VALUE3,
         apex_item.date_popup(5, null,c005,'MMDDYYYY',10,10) MY_DATE
    FROM APEX_COLLECTIONS
    WHERE COLLECTION_NAME = 'MY_COLLECTION'This will be a report just like an SQL report - you're just pulling the data from the collection. You can still apply the nice formatting, naming, sorting, etc. of a standard report. In the report the user will have 3 "text" values and one Date with Date Picker. You can change the format, just make sure to change it in all four procedures.
    What is critical to note here are the numbers that come right before the column names. These numbers become identifiers in the array used to capture the data. What APEX does is creates an array of up to 50 items it designates as F01-F50. The F is static, but the number following it corresponds to the number in your report declaration above, ie, F01 will contain the primary key value, F02 will contain the first numeric value, etc. While not strictly necessary, it is good practice to assign these values so you don't have to guess.
    One more note: I try to align the c00x values from the columns in the collection with the F0X values in the array to keep myself straight, but they are separate values that do NOT have to match. If you have an application you think might get expanded on, you can leave gaps wherever you want. Keep in mind, however, that you only have 50 array columns to use for data input. That's the limit of the F0X array even though a collection may have up to 1000 values.
    Now you need a way to capture user input. I like to create this as a BEFORE COMPUTATIONS/VALIDATIONS procedure that way the user can see what they changed (even if it is wrong). Use the Validations to catch mistakes.
    declare
      j pls_integer := 0;
    begin
    for j1 in (
      select seq_id from apex_collections
      where collection_name = 'MY_COLLECTION'
      order by seq_id) loop
      j := j+1;
      --VAL1 (number)
      apex_collection.update_member_attribute (p_collection_name=> 'MY_COLLECTION',
          p_seq=> j1.seq_id,p_attr_number =>2,p_attr_value=>wwv_flow.g_f02(j));
      --VAL2 (number)
      apex_collection.update_member_attribute (p_collection_name=> 'MY_COLLECTION',
          p_seq=> j1.seq_id,p_attr_number =>3,p_attr_value=>wwv_flow.g_f03(j));
      --VAL3 (text)
      apex_collection.update_member_attribute (p_collection_name=> 'MY_COLLECTION',
          p_seq=> j1.seq_id,p_attr_number =>4,p_attr_value=>wwv_flow.g_f04(j));
      --VAL4 (Date)
      apex_collection.update_member_attribute (p_collection_name=> 'MY_COLLECTION',
          p_seq=> j1.seq_id,p_attr_number =>5,p_attr_value=>wwv_flow.g_f05(j));
    end loop;
    end;Clear as mud? Walk through it slowly. The syntax tells APEX which Collection (p_collection_name), then which row (p_seq), then which column/attribute (p_attr_number) to update with which value (wwv_flow.g_f0X(j)). The attribute number is the column number from the collection without the "c" in front (ie c004 in the collection = attribute 4).
    The last one is your procedure to write the changes to the Database. This one should be a procedure that fires AFTER COMPUTATIONS AND VALIDATIONS. It uses that hidden KEY value to determine whether the row exists and needs to be updated, or new and needs to be inserted.
    declare
    begin
      --Get records from Collection
      for y in (select TO_NUMBER(c001) x_key, TO_NUMBER(c002) x_1,
                 TO_NUMBER(c003) x_2,
                 c004 x_3,
                 TO_DATE(c005,'MMDDYYYY') x_dt
               FROM APEX_COLLECTIONS
               WHERE COLLECTION_NAME = 'MY_COLLECTION') loop
        if y.x_key = 0 then  --New record
            insert into MY_TABLE (KEY_ID, COL1,
                COL2, COL3, COL4, COL5)
              values (SEQ_MY_TABLE.nextval, y.x_1,
                  y.x_2, y.x_3, y.x_4, y.x_dt);
        elsif y.x_key > 0 then  --Existing record
            update MY_TABLE set COL1=y.x_1, COL2=y.x_2,
                 COL3=y.x_3, COL4=y.x_4, COL5=y.x_dt
             where KEY_ID = y.x_key;
        else
          --THROW ERROR CONDITION
        end if;
      end loop;
    end;Now I usually include something to distinguish the empty new rows from the full new rows, but for simplicity I'm not including it here.
    Anyway, this works very well and allows me complete control over what I display on the screen and where all the data goes. I suggest using the APEX forms where you can, but for complex situations, this works nicely. Let me know if you need further clarifications.

  • Multiple and conditions in the same table

    Ok I am going to kick myself for this, but I can't figure it out. I am trying to figure out how to find employees which match multiple criteria in the same table.
    create table emp
    (empno number,
    name  varchar2(10))
    create table skills
    (skill_id   number,
    skill_code varchar2(20))
    create table emp_skills
    (empno    number,
    skill_id number,
    rating   number)
    insert into emp values(1, 'SMITH');
    insert into emp values(2, 'JONES');
    insert into skills values (1, 'SQL');
    insert into skills values (2, 'PLSQL');
    insert into skills values (3, 'JAVA');
    insert into emp_skills values(1,1, 8);
    insert into emp_skills values(1,2, 9);
    insert into emp_skills values(1,3, 10);
    insert into emp_skills values(2,1,9);
    insert into emp_skills values(2,2,2);
    insert into emp_skills values(2,3,7);Now I need to come up with a query finding all employees who match all 3 of the following criteria:
    1) Have at least a 5 rating in SQL
    2) Have at least a 6 rating in PLSQL
    3) Have at least a 7 rating in JAVA
    So using this I would expect to return only SMITH since his/her skills meet all 3 criteria. I dont want to use OR in my query since I want all 3 to match not just one of them.
    I have a feeling I will need to self join the table - but this is going to be part of a dynamic query for APEX where the users can choose the skills and ratings they want employees to adhere to, so I dont know the number of criteria or the exact criteria in advance. But I figure if I can get a proof of concept SQL I can make it work dynamically.
    Any ideas are appreciated - sorry for the long post but I figure more detail is better

    with es1 as(
    select s.skill_code, es.empno, es.rating
    from skills s, emp_skills es
    where s.skill_id = es.skill_id
    /* main */
    select e.*
    from emp e
    where
    exists
    (select 'x' from es1
    where es1.rating >= 5
    and es1.skill_code = 'SQL'
    and es1.empno = e.empno)
    and
    exists
    (select 'x' from es1
    where es1.rating >= 6
    and es1.skill_code = 'PLSQL'
    and es1.empno = e.empno)
    and
    exists
    (select 'x' from es1
    where es1.rating >= 7
    and es1.skill_code = 'JAVA'
    and es1.empno = e.empno)
    -- Addition (Another example)
    with es1 as(
    select s.skill_code, es.empno, es.rating
    from skills s, emp_skills es
    where s.skill_id = es.skill_id
    /* main */
    select e.*
    from emp e
    where
    (select count(distinct es1.skill_code) from es1
    where
    ((es1.rating >= 5 and es1.skill_code = 'SQL')
    or
    (es1.rating >= 6 and es1.skill_code = 'PLSQL')
    or
    (es1.rating >= 7 and es1.skill_code = 'JAVA')
    and es1.empno = e.empno)
    =3;

  • Triggers to Update rows in the same table

    Hi,
    I have a table called as "Cal" which has the following fields
    CALID
    Description
    RecurringID
    There will be many records with the same recurring id and If the Description field is Updated, then I would like to Update the same description to all the records with the same recurring id (same table). I have tried it with triggers and the I get the ORA-00036 Maximum number of Recursive SQL reached error.
    I have a a row level trigger which captures the change and I use the statment level trigger to update the description field (same table) and I get the error mentioned above.
    Thx in advance
    Ravi

    I have three kind of suggestion.
    (1) Use session variables in a package as flag for prevention from infinitely recursive calling.
    (2) Use temporary tables for similar reason.
    (3) Use instead-of-trigger (need to create view).

  • Multiple language data in the same table and indexes

    We have 8.1.5 database with
    NLS_LANGUAGE=ENGLISH and NLS_TERRITORY=UNITED KINGDOM set at the database level. We also set the NLS_LANG appropriately when we index the data. We also use the preference setting BASE_LETTER=YES when indexing.
    Our tables contain book titles which is what we index using interMedia. Being an online book store, this table may contain titles in English (most of the titles are in English being UK) and some titles in French. Please note the French language has accents and diacritics. Normally in a French database with NLS parameters set correctly and BASE_LETTER=YES, if we search for a title with accent / diacritic it will return the record correctly and match the rows with or without the accents (e.g. searching for video will return both vidio (not the accent on e) and video). However, with the UK settings the accents are not ignored during indexing and it only returns the records that exactly match the search word (e.g. searching for video returns only video and searching for vidio returns only vidio (note the accents on e in the last two videos)).
    Question: Is there any way to appropriately index multiple language specific titles in the same database? If yes, how? Is it possible at all? Suggestions, ideas are welcome.
    null

    Similar request; if there are several different languages used in a database, but a search word can be typed in by anyone and not necessarily in the default language, I still want to be able to pick up all the records (including text in blobs) in any language where my search word = the equivelant word in the other languages; eg. searching on "tree", the search would bring back a document that contained "l'arbre". I then want to set the default language, and allow the user to select a "search in these languages" option to expand the search from the default "tree" to all languages in the database.
    I know about the multi_Lexer but does it extend functionality to this level?

  • Concurrency when inserting in the same table

    Hi,
    I have a report used by several users and in this record there is a sentence to insert in a z table. My question is, what happens whether two or more users are inserting records in that table at the same time?  There is a concurrency problem, isn't there?
    How does SAP manage this issue? or, what must I do in this case?
    Thanks in advance.
    Regards.

    Hi David,
    As SAP applications are accessed by many end users at same time, SAP has concept called LOCKING of particular tables involved in the transaction.
    You can achieve your requirement as below
    Go to t-code SE11, and create a lock object for your Ztable
    Now, system create 2 function modules - 1 for locking ENQUEUE_* & other for un-locking DEQUEUE_*  ( search for function module in SE37 )
    Before saving data to ZTABLE, call function module ENQUEUE_* to lock the table for writing data, if locking fails, means there is somebody already working on it, hence you can display error message
    After Save action, you can unlock the table by using FM ... DEQUEUE_*
    Note: you can lock and unlock event during DISPLAY/CHANGE mode if your requirement requires.
    Hope this helps you.
    Regards,
    Rama

  • Parallel Insert statements (bulk) to the same table

    Hi,
    I am in need to insert set of insert statements 50000+ in to table and wanted to split them in to tow halves and run in two SQL worksheets.
    Note that both will try to insert on the same table.
    Please let me know whether it is advisable or tell me an alternative way.
    Using...Oracle 11g DB.
    Regards
    Deep.

    935195 wrote:
    I am in need to insert set of insert statements 50000+ in to table and wanted to split them in to tow halves and run in two SQL worksheets.Small number of rows. 50,000 rows can be inserted in seconds. Not sure why you want to split it. Parallel inserts into the same table is not usually a problem. Contention could be around free lists, initrans and so on - especially if using RAC and inserting something like 50,000+ rows every second. But the table defaults usually suffice.
    Note that both will try to insert on the same table.So what? This is exactly what Oracle expects and what it is designed to do.
    Please let me know whether it is advisable or tell me an alternative way.Well, you mentioned SQL worksheets - why? Exactly how does the INSERT statements look like? Where does the data to insert come from? Is shared insert cursors used (bind variables compulsory)? The bottleneck and problem could very well be on your side and not with the actual inserts into the table.

  • Two triggers in the same table and event

    If I created two triggers on the same table and event (before insert), which of them will be triggered first ?...
    The problem from the beginning is that I created the second one as after insert and in the body of the trigger I wrote (:new.xxx:= value) ... then an error (that it should be before insert trigger or update trigger), so I created it as before update ,,, but I have already before update trigger (for primary key)..... and the problem -I think- which of them start first...
    Can make the second one as after insert and make update statement instead of assigning (:new.xxx:= value).....
    Regards

    If I created two triggers on the same table and event
    (before insert), which of them will be triggered
    first ?...As already mentioned, prior to 11g the order of firing is undetermined.
    The problem from the beginning is that I created the
    second one as after insert and in the body of the
    trigger I wrote (:new.xxx:= value) ... then an error
    (that it should be before insert trigger or update
    trigger), so I created it as before update ,,, but I
    have already before update trigger (for primary
    key)..... and the problem -I think- which of them
    start first...If there is a conflict of interest inside the code then you will have to alter your design principle around this to cater for it. Also consider combining the code into a single before insert trigger to prevent any confusion.
    Can make the second one as after insert and make
    update statement instead of assigning (:new.xxx:=
    value).....Attempting to update or query the same table as is causing the trigger to fire will result in a mutating table error. You can't do this.

  • CLR trigger - handling multiple inserts at the same time

    Hi
    I've developed a CLR trigger which operates on inserts performed on a staging table. The trigger implements some business logic and then inserts or updates a record in a target table. Whether an insert or update is performed depends on whether
    a record with the same ID already exists in the target (i.e. a select * from target where ID = 123).
    This works fine in most scenarios, but occasionally I am getting duplicates in the target table and have noticed that this seems to occur when inserts on the staging table happen at exactly the same time (i.e. multiple inserts for the same ID at
    the same time). In this situation duplicates are created in the target table because at the time of the inserts, no record with that ID exists in the target table (i.e. the select returns no records), therefore a new record is created for each.
    Is there a known way to deal with this scenario? For example, would locking the target table on insert result in the subsequent selects against the target table waiting until the target table had been updated, therefore the select would return a record
    for the given ID.
    I didn't really want to lock the whole target table on insert, because there are potentially other users reading that table (selects) and these would also have to wait for the insert to complete.
    I'd appreciate any thoughts on how to deal with this and avoid duplicates in the target table. I'm unable to change the way the data is coming in to the staging table, so my trigger code must deal with the above scenario.
    Thanks in advance.
    John

    First if you do not want any duplicate values in a column (or combination of columns) you should add a constraint to ensure this is never possible. A
    unique index
    like this should do this trick.
    CREATE UNIQUE NONCLUSTERED INDEX [IX_yourIndexName] ON [dbo].[YourTableName]
    [yourColumn1] ASC,
    -- add more columns that make the unique combination that you don't want repeated
    You can then add a try/catch block in your trigger code, if you get an exception based on this index then the record was created by another executing instance of this trigger and in that case you should do an update (or not, not sure what the rest of your
    logic is) in your catch block. This is the easiest solution and does not involve table locks. The only drawback is the first one to commit the insert will win and you have no guarantee which process or data set that will be. Also i have no idea how big the
    table is, how frequently changes are made, and what the data type is so you should
    keep this in mind when creating your index so you don't run into unexpected high index fragmentation which can lead to performance problems when executing updates and inserts.
    You could also create a
    named transaction with scope serializable around your insert/update block and execute your reads using a
    NOLOCK hint
    which should allow them to retrieve uncommitted writes and not create a long wait. The downside is is that the data might not be 100% accurate depending on if a transaction fails or not if there happens to be an update at the same time as a select but maybe
    this is not a big deal to the calling code.
    -Igor

  • Trigger to Update in the same table.

    Hi,
    I would like to create a trigger that when we insert into table ALL_CAPACITY_SNS_CELL1 it updates column Action on teh same table,if teher is an update, it will update the same table , column ACTION.
    This is what I have attempted but seems to be technically wrong.
    <pre>
    create table ALL_CAPACITY_SNS_CELL1
    ( A varchar2,
    action char(2),
    date_executed date);
    create or replace
    TRIGGER ALL_CAPACITY_HISTORY_TRACKING
    AFTER INSERT OR DELETE OR UPDATE ON ALL_CAPACITY_SNS_CELL1 FOR EACH ROW
    DECLARE
    v_operation VARCHAR2(10) := NULL;
    BEGIN
    IF INSERTING THEN
    v_operation := 'I';
    ELSIF UPDATING THEN
    v_operation := 'U';
    ELSE
    v_operation := 'D';
    END IF;
    IF INSERTING
    UPDATE ALL_CAPACITY_SNS_CELL1
    SET ACTION =v_operation,
    DATE_EXECUTED =sysdate ;
    ELSIF UPDATING THEN
    UPDATE ALL_CAPACITY_SNS_CELL1
    SET ACTION =v_operation,
    DATE_EXECUTED =sysdate ;
    END IF;
    END;
    </pre>

    CrackerJack wrote:
    But above query made all ACTION nul...so we shoudl after insert or update trigger right?Obviously it is not working. You modified my code the way it does not make sense.
    IF INSERTING
    THEN
    :NEW.ACTION := 'I';
    IF UPDATING
    THEN
    :NEW.ACTION := 'U';
    ELSE
    :NEW.ACTION := 'X';
    END IF;The code above checks if trigger fired on INSERT (IF INSERTING). In THEN branch of that IF you check if trigger fired on UPDATE. It makes no sense. Now, if you would use my trigger:
    SQL> create table ALL_CAPACITY_SNS_CELL1
      2  ( A varchar2(1),
      3  action char(2),
      4  date_executed date);
    Table created.
    SQL> create or replace
      2    TRIGGER ALL_CAPACITY_HISTORY_TRACKING
      3      BEFORE INSERT
      4         OR UPDATE
      5      ON ALL_CAPACITY_SNS_CELL1
      6      FOR EACH ROW
      7      BEGIN
      8          IF INSERTING
      9            THEN
    10              :NEW.ACTION := 'I';
    11            ELSE
    12              :NEW.ACTION := 'U';
    13          END IF;
    14          :NEW.DATE_EXECUTED := sysdate ;
    15  END;
    16  /
    Trigger created.
    SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('A')
      2  /
    1 row created.
    SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('B')
      2  /
    1 row created.
    SQL> alter session set nls_date_format='mm/dd/yyyy hh24:mi:ss'
      2  /
    Session altered.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    A I  05/13/2009 08:56:02
    B I  05/13/2009 08:56:09
    SQL> update ALL_CAPACITY_SNS_CELL1
      2  set a = 'X'
      3  where a = 'B'
      4  /
    1 row updated.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    A I  05/13/2009 08:56:02
    X U  05/13/2009 08:57:05
    SQL> update ALL_CAPACITY_SNS_CELL1
      2  set a = 'Y'
      3  /
    2 rows updated.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    Y U  05/13/2009 08:57:21
    Y U  05/13/2009 08:57:21
    SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('C')
      2  /
    1 row created.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    Y U  05/13/2009 08:57:21
    Y U  05/13/2009 08:57:21
    C I  05/13/2009 08:57:53
    SQL> SY.

  • Nsert/Update and Add Column at the same Table and at the "same" Time

    Hello,
    I want Insert/Update and Add Column at the same Table and at the "same" Time but in different sessions.
    Example:
    At first the "insert/update" statement:
    Insert into TestTable (Testid,Value) values (1,5105);
    After that the "add" statement:
    Alter table TestTable add TestColumn number;
    - sadly now I get the message: ORA-00054: resource busy and acquire with NOWAIT specified
    "insert/update" statement:
    Insert into TestTable (Testid,Value) values (2,1135);
    After that the execute commit.
    I don't know when the first session set the commit statement so I want that the DB the "Alter Table..." statement execute if it's possible.
    If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.
    Thanks for ideas

    Well I want to walk in the rain without and umbrella and still stay dry, but it ain't gonna happen.
    You can't run a DDL statement against a table with transactions pending. Session 2 has to wait until session commits or rollbacks (or until the session is killed). That's just the way it is.
    This makes sense if you think about it. The data dictionary has to be consistent across all sessions. If session 2 was allowed to change the table structure whilst session 1 has a pending transaction then the database is in an inconsistent state. This is easier to see if you consider the reverse situation - the ALTER TABLE statement run by session 2 does a DROP COLUMN TESTID rather than adding a column: now what should happen to session 1's INSERT statement? You have retrospectively invalidated a statement that was perfectly legal when it was executed.
    If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.Fnord.
    Cheers, APC

  • Load Data from a table on one server's database, to the same table structure in multiple server databases

    Hi,
    I have a situation where i have to load data from one server/database table to multiple servers/databases.
    Example:
    I need to load data from dbo.TABLE_A  (on Server: Server_A & Database: Database_A)  to the same table on the list of server databases like
    Server: Server_B , Database: Database_B
    Server: Server_C , Database: Database_C
    Server: Server_D , Database: Database_D
    Server: Server_E , Database: Database_E
    Server: Server_F , Database: Database_F
    Server: Server_G , Database: Database_G
    Server: Server_H , Database: Database_H
    so on and so forth on 250 such server database combinations.
    The table structure is the same on all the servers.
    If i make the source or destination dynamic, it throws an error while mapping ?
    I cannot get Linked server permissions and SQL Server Config thing doesn't work as well.
    Please suggest on how to load data from one source to multiple server/databases.
    Thank you.

    I just need to transfer one table's data. its like i have to use a query to pick data for
    the most recent data. So i use something like, select A, B, C, D from dbo.table where ETL_TIMESTAMP > (the max(etltimestamp) in the destination on different server). There are no foreign key relationships and the data should not be truncated. it just had
    to append the new records.

  • Trigger in mutation - Update another rows in the same table with a trigger

    Hi ,
    I try to do a before update trigger on a table , but the trigger is in mutation. I understand why it do that but my question is :
    How can I update other rows in the same table when a UPDATE is made on my table??????
    Here is my trigger :
    CREATE OR REPLACE TRIGGER GDE_COMPS_BRU_5 BEFORE
    UPDATE OF DEPARTEMENT--, DISCIPLINE, DEG_DEMANDE, CE_ETAB
    ON GDEM.COMPOSITION_SUBV
    FOR EACH ROW
    Organisme : FQRNT-FQRSC
    Date de création : 14-07-2011
    Date de modification :
    Modifié par :
    Auteur : Johanne Plamondon
    Description : Ce déclencheur s'executera lors de la modification
    du responsable dans la table COMPOSITION_SUBV
    DECLARE
    V_OSUSER V$SESSION.OSUSER%TYPE;
    V_PROGRAM V$SESSION.PROGRAM%TYPE;
    V_TERMINAL V$SESSION.TERMINAL%TYPE;
    V_MACHINE V$SESSION.MACHINE%TYPE;
    V_MODULE V$SESSION.MODULE%TYPE;
    V_LOGON_TIME V$SESSION.LOGON_TIME%TYPE;
    V_AUDIT_ID NUMBER;
    vSEQ NUMBER;
    i NUMBER;
    vID DEMANDE.ID%TYPE;
    BEGIN
    begin
    SELECT OSUSER, PROGRAM, TERMINAL,MACHINE,MODULE, LOGON_TIME
    INTO V_OSUSER,V_PROGRAM,V_TERMINAL,V_MACHINE,
    V_MODULE,V_LOGON_TIME
    FROM V$SESSION
    WHERE TYPE = 'USER'
    AND USERNAME = USER
    AND LAST_CALL_ET IN (0,1)
    AND ROWNUM < 2;
    exception when others then null; end;
    IF NVL(:NEW.SC_PART,' ') = 'CHC' THEN
    SELECT COUNT(*)
    INTO i
    FROM DEMANDE
    WHERE DEM_REF = :NEW.DEM_ID
    AND PER_NIP = :NEW.PER_NIP;
    IF i = 1 THEN
    SELECT ID
    INTO vID
    FROM DEMANDE
    WHERE DEM_REF = :NEW.DEM_ID
    AND PER_NIP = :NEW.PER_NIP;
    UPDATE COMPOSITION_SUBV
    SET --CE_ETAB     = :NEW.CE_ETAB,
    --DISCIPLINE  = :NEW.DISCIPLINE,
    DEPARTEMENT = :NEW.DEPARTEMENT,
    --DEG_DEMANDE = :NEW.DEG_DEMANDE,
    DATE_MODIF = SYSDATE,
    USER_MODIF = V_OSUSER
    WHERE DEM_ID = vID
    AND PER_NIP = :NEW.PER_NIP
    AND ANNEE = :NEW.ANNEE;
    END IF;
    END IF;
    /*EXCEPTION
    WHEN OTHERS THEN
    NULL;*/
    END;

    A standard disclaimer, the mutating trigger error is telling you that you really, really, really don't want to be doing this. It generally indicates a major data model problem when you find yourself in a situation where the data in one row of a table depends on the data in another row of that same table. In the vast majority of cases, you're far better off fixing the data model than in working around the problem.
    If you are absolutely sure that you cannot fix the data model and must work around the problem, you'll need
    - A package with a collection (or global temporary table) to store the keys that are modified
    - A before statement trigger that initializes the collection
    - A row-level trigger that adds the keys that were updated to the collection
    - An after statement trigger that iterates over the data in the collection and updates whatever rows need to be updated.
    If you're on 11g, this can be simplified somewhat by using a compound trigger with separate before statement, row-level, and after statement sections.
    Obviously, though, this is a substantial increase in complexity over the single trigger you have here. That's one of the reasons that it's generally a bad idea to work around mutating table exceptions.
    Justin

  • How to update a table (CUSTOMER) on a Report Server with the data from the same table (CUSTOMER) from another server Transaction server?

    I had an interview question that is:
    How to update a table (Customer) on a server ex: Report Server with the data from the same table (Customer) From another server ex: Transaction server?
    Set up steps so inset, update or delete operation takes place across the servers.
    It would be great if someone please enlighten me in details about this process in MS SQL Server 2008 R2.
    Also please describe would it be different for SQL Server 2012?
    If so, then what are the steps?

    I had an interview question that is:
    How to update a table (Customer) on a server ex: Report Server with the data from the same table (Customer) from another server ex: Transaction server?
    Set up steps so that inset, update or delete operation gets done correctly across servers.
    I was not sure about the answer, it would be great if someone please put some light on this and explain in details about this process in MS SQL Server 2008 R2.
    Also it would be very helpful if you please describe would it be different for SQL Server 2012? If so, then what are the steps?

  • Inserting a LONG to a BLOB in the same table

    I have a table with a LONG column and would like to concatenate all existing columns into a new column in the same table and define it as a BLOB. I'm trying to figure out a way to do this. I tried the following and got error message
    insert into cma_search_test
    select obj_id,
         line_id,
         doc_nmbr,
         supplier_part_num,
         mnfctr,
         mnfctr_part_nmbr,
         line_desc,
         ext_desc_txt,
         vend_name,
         cma_effect_dt,
         cma_expir_dt,
         last_updt_usr,
         last_updt_tmsp,
         obj_id||
         line_id||
         doc_nmbr||
         supplier_part_num||
         mnfctr||
         mnfctr_part_nmbr||
         line_desc||
         to_lob(ext_desc_txt)||
         vend_name||
         cma_effect_dt||
         cma_expir_dt||
         last_updt_usr||
         last_updt_tmsp "All_Columns"
    from cma_search
    to_lob(ext_desc_txt)||
    ERROR at line 22:
    ORA-00932: inconsistent datatypes
    Any help would be appreciated.
    Thanks,
    Tracy

    You cannot concatenate a LONG field. You will have to use a procedure to accomplish what you want.
    Use the DBMS_LOB package.

Maybe you are looking for

  • Some interfaces are not shown in the sxmb_moni

    Hi all, We are facing the following scenario:  we have one interface in XG1 (development environment) which is very simple: it consists of a sender ‘File’ and a receiver ‘IDOC’. The file format has been double checked and apparently is what XI define

  • Print quality tip for Epson printers with wifi

    Just wanted to post a resolution to a print quality problem we were having with an Epson Artisan 730. I discovered that if we cnnected via wifi the printer driver used offered much lower quality and fewer options then we were used to under Snow Leopa

  • Insert multiple values

    CREATE or REPLACE TRIGGER dept_hist_trigger BEFORE delete or update ON dept FOR EACH ROW BEGIN INSERT INTO dept_hist values (:old.deptno,:old.dname,:old.loca); END; i have created a trigger like above.. but  my requirement is i want to insert 180 col

  • Getting error [Program Terminated] while doing GR postings

    Dear All, Please help me out from this error. I get this error when I am going to do GR postings. Error Message is " Message_Type_X " short dump has not been completely stored. How I solve this error. Please help me. Thanks & Regards Prateek

  • Parallels will not windows 7 after installing Lion

    After loading Lion, Parallels will not open Windows 7.  Any suggestions?