Trigger for insert in other table

hi im merwyn and im new in JDBC
my problem is i want to insert the values from one table to another immediately the value is inserted in first table
my first table defination is
create table ItemEJBTable
     ( itemCode int primary key,
     itemDescription varchar (50),
     quantityOnHand varchar(50),
     rate varchar(50),
     releaseDate varchar(50),
     singer varchar (50),
     title varchar (50),
     type varchar (50)
)and other table
create table Item_Master
     ( Item_Code int primary key,
     Item_Desc varchar (50),
     Qty_on_hand varchar(50),
     Rate varchar(50),
     Release_Date varchar(50),
     Singer varchar (50),
     Title varchar (50),
     Type varchar (50)
)i have also done trigger
create trigger EJBtoItem
on ItemEJBTable for insert as
BEGIN
INSERT into Item_Master(Item_Code,Item_Desc,Qty_on_hand,Rate,Release_Date,Singer,Title,Type)
VALUES(new.itemCode,new.itemDescription,new.quantityOnHand,new.rate,new.releaseDate,new.singer,new.title,new.type)
PRINT 'Successful'
ENDbut SQL2000 gives me this error
The name 'itemCode' is not permitted in this context.
Only constants, expressions, or variables allowed here.
Column names are not permitted.what is the solution of this????
sorry if i posted in wrong section but im adding the values to table throught jsp page
pls help
Edited by: merwyn on Mar 14, 2009 10:52 PM

Note: This thread was originally posted in the [Java Servlet |http://forums.sun.com/forum.jspa?forumID=33] forum, but moved to this forum for closer topic alignment.

Similar Messages

  • Trigger for more  than One table

    Hi,
    is it possible to create a trigger for more than one table?
    I need a trigger that fires when anyone of the users updates a special value in one of the DB tables.
    this value is in about 8 or 10 tables, or must i create a trigger for each table?
    thanx
    marcel

    You would wrap the functionality required into a packaged procedure and then have a trigger on each of these tables that simply call this packaged procedure.
    Yes, you would have one trigger per table.

  • How to Create a table with numeric trigger for INSERT

    Let me start off by saying that I am very new to DBMS.
    I need to create a Table with INSERT Trigger. I am not exactly sure if I need to have a BEFORE ot AFTER insert trigger but leanning towards AFTER.
    I have a Java code that will need insert a row each time that piece of code is executed. I would also like an oracle trigger to insert a unique numeric value (REC_ID) for that that record.
    I am totally lost and I am not sure how to go about it. Can you point me to the right direction?
    Basically my table will have the following 3 columns
    REC_ID NUMBER NOT NULL (uniquie value inserted by the trigger)
    PROPERTY_NAME VARCHAR2(100 BYTE)
    PROPERTY_VAL VARCHAR2(100 BYTE)
    Thank you in advance
    Eric

    Take a look at the following: Also please do a search in this forum.
    http://infolab.stanford.edu/~ullman/fcdb/oracle/or-jdbc.html

  • Field != then Insert Into Other Table

    Hi,
    I cannot figure out how to create a trigger that will insert data based on if a old.field != new.field. If the field was changed in
    one table tbl_test then insert that record into the other table tbl_test_history. This is a little different since I want to insert a record if a update
    took place. The update will still take place in tbl_test but I want a insert to take place in tbl_test_history.
    CREATE OR REPLACE TRIGGER AU_INSERT_TEST_HISTORY
      AFTER UPDATE
      ON TBL_TEST   FOR EACH ROW
    WHEN (
        OLD.Orange != NEW.Orange
    OR OLD.Apple != NEW.Apple
    BEGIN
    INSERT INTO TBL_TEST_HISTORY
    (ORANGE,
      APPLE
      BANANA,
      GRAPE
      select ORANGE,
             APPLE
             BANANA,
             GRAPE
    FROM TBL_TEST, TBL_TEST_HISTORY
      WHERE  TBL_TEST.PK_TEST_ID = TBL_TEST_HISTORY.PK_TEST_ID;
    END AU_INSERT_TEST_HISTORY;
    /I will have a separate trigger that will insert records from tbl_test to tbl_test_history. This trigger compiles with no errors but when I
    create a record in tbl_test I receive an error. I am not sure if the syntax is correct, can anyone help me with this?

    My bad. I put the colon : into the when clause. They weren't there in your code. Usually I use an if condition, which is a little different.
    I added some NVL logic to to consider comparison of NULL values too.
    CREATE OR REPLACE TRIGGER AU_INSERT_TEST_HISTORY
      AFTER UPDATE  ON TBL_TEST  
      FOR EACH ROW
    BEGIN
      if nvl(:old.ORANGE,'xxx') != nvl(:new.ORANGE,'yyy')
         OR nvl(:old.APPLE,'xxx') != nvl(:new.APPLE,'yyy')
      then
        INSERT INTO TBL_TEST_HISTORY
         (ORANGE, APPLE, BANANA, GRAPE)
        values (:new.ORANGE,
                 :new.APPLE,
                 :new.BANANA,
                 :new.GRAPE);
      end if;
    END AU_INSERT_TEST_HISTORY;
    / You can additionally consider to make this trigger an AFTER INSERT OR UPDATE trigger.
    Then you would also put the inserted values from the start into your history table.
    Edited by: Sven W. on Aug 9, 2012 4:14 PM

  • Help:Oracle 9i Active database trigger for insert

    Pract 4:Active Databases
    Create a table emp1 (eno, ename, hrs, pno, super_no) and
    project (pname, pno, thrs, head_no) where
    thrs is the total hours and is the derived attribute.
    Its value is the sum of the hrs of all employees working
    on that project, eno and pno are primary keys,
    head_no is the foreign key to emp relation.
    Insert 10 tuples and write triggers to do the following
    1) Creating a trigger to insert a new employee tuple and
    display the new total hours from project table.
    2) Creating a trigger to change the hrs of
    existing employee and display the new      total hrs from project table
    3) Creating a trigger to change the project of an employee and
    display the new total hrs from project table
    4) Creating a trigger to deleting the project of an employee
    --using bom1:-
    SQL> connect hr/tiger@bom4;
    Connected.
    SQL> create table Project17
    2 (
    3 pno number(5) primary key,
    4 pname varchar2(25),
    5 thrs number(5),
    6 head_no number(5)
    7 );
    Table created.
    SQL> create table Emp17
    2 (
    3 eno number(5) primary key,
    4 ename varchar2(25),
    5 hrs number(5),
    6 pno number(5),
    7 super_no number(5),
    8 constraint Pno_fk foreign key(pno) references Project17(pno)
    9 );
    Table created.
    --Inserting records into table Emp1
    SQL> insert into Project17 values(1,'IMS',125,1);
    1 row created.
    SQL> insert into Project17 values(2,'CRM',135,1);
    1 row created.
    SQL> insert into Project17 values(3,'P and A Section',145,2);
    1 row created.
    SQL> insert into Project17 values(4,'Rishabh Dighia Steels',225,3);
    1 row created.
    SQL> insert into Project17 values(5,'BPTLibrary',215,4);
    1 row created.
    --Inserting records into table Project
    SQL> insert into Emp17 values(3,'Shubhangi',145,3,28);
    1 row created.
    SQL> insert into Emp17 values(4,'Crima',225,2,98);
    1 row created.
    SQL> insert into Emp17 values(5,'Harshada',215,4,62);
    1 row created.
    SQL> insert into Emp17 values(6,'ashish',215,4,62);
    1 row created.
    SQL> insert into Emp17 values(7,'salil',115,3,92);
    1 row created.
                        Queries:-
    connect hr/tiger@bom4;
    1) Create a trigger to insert a new emp tuple and display the new total hrs
    from project table
    create or replace trigger trigemp_ins
    after insert on Emp17
    for each row
    when(new.pno is not null)
    declare
    vthrs number(9);
    begin
    insert into Project17 values(:new.pno,pname,thrs,head_no);
    Select thrs into vthrs from Project17 where pno=:new.pno and thrs=thrs+:new.hrs;
    dbms_output.put_line('new Total Hrs:'||vthrs);
    end;
    Warning: Trigger created with compilation errors.
    SQL> show errors;
    Errors for TRIGGER TRIGEMP_INS:
    LINE/COL ERROR
    4/2 PL/SQL: SQL Statement ignored
    4/51 PL/SQL: ORA-00984: column not allowed here

    Hi,
    have a look at your insert. It misses some ":new."
    Herald ten Dam
    Superconsult.nl

  • QUERY FOR INSERT INTO  SQL TABLE

    Hi all,
    i want to insert some records into SQL table but not SAP database table. This table is only present in SQL database &
    not present in SAP database.
      i want to write a program in SAP to update the SQL table(not present in SAP database). is it possible?
       if yes, plz give me the query for inserting records into SQL table.
    Regards

    Hello,
    working on the same issue:
    Try this:
    DATA : Begin Of XY Occurs 1000,
            id(15)    TYPE C,
            Name(50)  TYPE C,
            ArtNr(50) TYPE C,
            lieferant TYPE I,
         End Of XY.
    Fill this internal Table with the SAP-Table
    START Connection to your Database
      EXEC SQL.
          Connect TO 'TEST_FH'
      ENDEXEC.
      IF SY-SUBRC EQ 0.
        EXEC SQL.
        Set Connection 'TEST_FH'     " <-- this is defines with TCode dbco
        ENDEXEC.
        IF SY-SUBRC EQ 0.
        Else.
          " OUT_Msg = '... won't connect'.
          Exit.
        EndIf.  " Else IF SY-SUBRC EQ 0
      Else.
        " OUT_Msg =  'Error at Set Connection Test_FH'.
        Exit.
      EndIf.  " IF SY-SUBRC EQ 0
    ENDE  Connection to your Database
    START Insert your table XY to an external database
        Loop AT XY.
          Try.
           EXEC SQL.
               INSERT INTO stoff
               (id, name , artnr, lieferant)
               VALUES
               ( :XY-ID,  :XY-Name, :XY-ArtNr, :XY-Lieferant )
           ENDEXEC.
           COMMIT WORK AND WAIT.     " <=== Maybe VERY important
          CATCH cx_sy_native_sql_error INTO exc_ref.
              error_text = exc_ref->get_text( ).
              Concatenate 'Table-INSERT: ' error_text Into error_text.
              MESSAGE error_text TYPE 'I'.
          ENDTRY.
        ENDLoop.     " Loop AT XY     
    END   Insert your table XY to an external database
    START: Clear Connection
        EXEC SQL.
          DISCONNECT 'TEST_FH'
        ENDEXEC.
    END : Clear Connection
    Hope it works
    Best wishes
    Frank

  • Insert into other table from form

    Hi All,
    I have created a data block with view as a data source. I need to save the data from a form to some other table.
    I have tried using INSTEAD OF Trigger. howeverwhen I try to save, getting an error : ORA-01445 cannot select ROWID from a join view without a key-preserved table.
    I appreciate any suggestions on it.
    Thanks and Regards
    Sai

    Sorry, it looked at first as if you wanted help on the problem you encountered. After reading again your response to Zaibiman I see that you were just tricking us with the detailed explanation of the error.
    To insert into a table other than the one you queried, use the on-insert trigger.
    However, an Instead Of trigger on the view is usually the best method. If you have set the key mode, defined a primary key item and removed any references to rowid, as per Zaibiman, then it should work. You'll need your own locking method if the view uses Group By or Distinct.

  • Constraint for insertion in a table if inserted rows should not more than 2

    Problem: A Teacher only can assigned for maximum 2 Subjects in the same class Standard.
    actually i want to create a table like following
    create table teaches
    teacherid int,
    standard varchar(10),
    subjectcode varchar(10),
    constraint cpk_teaches primary key(teacherid, standard, subjectcode)
    and i want that when any data inserted in the table,
    a constraint will work in the manner that there is
    NO POSSIBILITY TO INSERT the data for
    (teacherid, standard) columns THRICE (3rd time)
    actually i want that only maximum of 2 different data will insert in
    (subjectcode) for the same (teacherid, standard)

    Thanks for the suggestion,
    But, my original problem remains on the same stage.
    Actually this table has all the keys as foreign key of other tables.
    Why?, is not necessary this time.
    If you don't mind kindly give me the code of constraint, if any to solve my problem.
    Problem: I want to insert only maximum of two different Subjects for same Teacher and Standard and not more.
    In real life like following.
    Mr. TCHR-1 is teaching subject SUB-1 in standard STD-1.
    Mr. TCHR-1 is teaching subject SUB-2 in standard STD-1.
    But, can't Mr. TCHR-1 is teaching subject SUB-3 in standard STD-1.
    My table structure is not in the state of changing due to some reasons.
    It is, as previously described.
    create table teaches
    tchrid int,
    std varchar(10),
    subcode varchar(10),
    constraint cpk_teaches primary key(tchrid, subcode, std)
    )

  • Creating a button for inserting into a table

    What I can't do, because I've never needed to, is to create in a page (where I have a Interactive report) a button that when is clicked performs a simple sql (for example an insert into a table using some page item values).
    How can I do it?
    Thanks

    Here are some of the steps:
    1) Create the button.
    2) Then right click on the button name and select Create Dynamic Action
    3) Give the DA a name, click next
    4) On the "When" Step, Event should already be "Click" and the button name should be filled in
    5) For Condition, you would have a condition for when you want the button display.  Say, if your page items have a certain range of values then display this button.  No condition means the button is always displayed.
    6) For the "True Action" Step, for Action select "Execute PL/SQL Code"
        [There are other ways to do this, but this is straight-forward for me.]
    7) The in the PL/SQL Code block enter say:
    Begin
      INSERT INTO EMP (EMPNO, ENAME, HIREDATE)        
              VALUES (:P6_EMPNO, 'MARK1970', :P6_HIREDATE);
      COMMIT;
    END;   --- You would likely make them all page item variables
    8) Here the part I'm not 100% sure of.
        For "Page Items to Submit", name the page items used in YOUR QUERY -- in my example these are  P6_EMPNO,P6_HIREDATE   (Note no use of & or : or . here)
        Hmm.  Start by putting nothing in the "Page Items to Return".   If that fails, then try the same page items  P6_EMPNO,P6_HIREDATE there as well.
    [ I'm too lazy to go run this down at the moment.]
    9) I think that's it.
    Howard

  • Help me in creating a Trigger for Insert and Update Options

    Hi
    Please help me in creating a Trigger .
    My requirement is that after insert or update on a Table , i want to fire an event .
    I have started this way ,but doesn't know how to fully implement this .
    say i have a dept table
    CREATE TRIGGER DepartmentTrigger
    AFTER INSERT ON Dept
    BEGIN
    INSERT INTO mytable VALUES("123","Kiran");
    END DepartmentTrigger;
    Please tell me how can i put the Update option also .
    Thanks in advance .

    Please tell me how can i put the Update option also .Add "Or Update". ;-)
    Here are a few suggestions, but you definitely need to refer to the manual page that the previous poster suggested.
    CREATE OR REPLACE TRIGGER DepartmentTrigger
    AFTER INSERT Or Update ON Dept
    BEGIN
    INSERT INTO mytable VALUES(:new.Dept,'DEPT ADDED OR CHANGED');
    END DepartmentTrigger;
    The "Or Replace" means you can replace the trigger while you're developing without having to type in a drop statement every time. Just change and rerun your script, over and over until you get it right.
    Adding "Or Update" or "Or Delete" makes the trigger fire for those events too. Note, you may want seperate triggers in different scripts and with different names for each event. You have to decide if your design really does the same thing whether it's an insert or an update.
    :new.Dept is how you would refer to the changed vale of the Dept column (:old.Dept is the prior value). I changed the double quotes on the string in the VALUES clause to single quotes.
    Andy

  • Stored Procedure for insert in a table

    Hi everybody
    I have to insert a line into a table to initialize the supply of a datawarehouse.
    The table contains:
    Id_chargement Oracle sequence
    date_chargement sysdate
    status 'EN COURS'
    I read some message in this forum but I don't find the solution.
    Can I call a procedure in the workflow ? Or must be use the preprocessing of the first map to call this stored procedure ?
    But for the second solution, if I had a map before, I must change this call.So, it's not very interesting.
    Have you a idea
    Thank you for your help
    Frederic from France

    Hi Mahesh,
    I created a procedure as
    begin
    insert into <table name> values( <timestamp value>);
    end;
    i added this procedure in the process flow, and as you said i added 1- Success, 2 - warning, 3 - error.
    I am able to deploye the procedure and process flow,
    after that when execute the process flow, that just says completed with errors,
    no other information and oracle error messages are abilable in the
    result panel
    Job Final Status : Completed with errors
    Job Processed Count : 1
    Job Error Count : 0
    Job Warning Count : 0
    can you say , what could be the problem??
    Thanks & regards
    raja

  • JDBC Receiver adapter Error for insert into DB2 table

    Hi all,
    I want to insert data into a DB2 table on AS400 via a Receiver JDBC adapter.
    The communication channel seems to be ok but when I try to send the message, I obtain the following message on the adapter monitoring :
    Error: TransformException error in xml processor class, rollback:
    Error processing request in sax parser: Error when executing statement for table/stored proc. 'GIK.GDT01' (structure 'Statement'): java.sql.SQLException: La table GDT01 de la bibliothèque GIK est incorrecte pour cette opération.
    Could someone help me?
    In the communication channel I have seen we can choose "native SQL String" as message protocol.
    Do you think it could be a workaround for me? if yes, could someone send me an example about it?
    thanks a lot,
    Philippe

    Hi,
    Try to remove GIK.GDT01 in table tag of your XML structure and put GDT01 alone and see.
    The solution to your problem is found on this particular link.
    http://www.websina.com/bugzero/faq/exception-as400.html
    Tell me if it works
    Best regards,
    Felix

  • Need Logic for Inserting data into table from another table

    Hi,
    Could you please give me some logic on below:
    TABLE_A has columns A,B,C,D
    What i did
    ==========
    Created new table
    TABLE_1_A with columns A1,A2,B1,B2,B3
    Requirement
    ===========
    I should populate columns A1,A2 (table TABLE_1_A) with the data from column A (table TABLE_A)
    & simillarly populate columns B1,B2 with the data from B.
    the data is huge in the table_a.
    Database: 10g
    Thanks.

    Hi,
    Here's one way:
    INSERT INTO  table_1_a
            (a1, a2, b1, b2)
    SELECT      a,  a,  b,  b
    FROM      table_a
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    If you're asking about a DML statement, such as INSERT, the sample data will be the contents of the table before the DML, and the results will be state of the changed table(s) when everything is finished.
    Explain, using specific examples, how you get those results from that data.
    See the forum FAQ {message:id=9360002}

  • Using Bulk operations for INSERT into destination table and delete from src

    Hi,
    Is there any way to expediate the process of data movement?
    I have a source set of tables (with its pk-fk relations) and a destination set of tables.
    Currently my code as of now, is pickin up the single record in cursor from the parentmost table, and then moving the data from other respecitve tables. But this is happening one by one... Is there any way I can make this take less time?
    If I use bulk insert and collections, i will not be able to use the DELETE in the same block for same source record.
    Thanks
    Regards
    Abhivyakti

    Abhivyakti
    I'm not 100% sure how your code flows from what you've stated, but generally you should try and avoid cursor FOR LOOPS and possibly BULK COLLECTING.
    I always follow the sequence in terms of design:
    1. Attempt to use bulk INSERTS, UPDATES and/or DELETES first and foremost. (include MERGE as well!)
    2. If one cannot possibly do the above then USE BULK COLLECTIONS using a combination of RETURNING INTO's and
    FORALL's.
    However, before you follow this method and if you relatively new to Oracle PL/SQL,
    share the reason you cannot follow the first method on this forum, and you're bound to find some
    help with sticking to method one!
    3. If method two is impossible, and there would have to be a seriously good reason for this, then follow the cursor FOR LOOP
    method.
    You can combine BULK COLLECTS with UPDATES and DELETES, but not with INSERTS
    bulk collect into after insert ?
    Another simple example of BULK COLLECTING
    Re: Reading multiple table type objects returned
    P;

  • Query for inserting data into table and incrementing the PK.. pls help

    I have one table dd_prohibited_country. prohibit_country_key is the primary key column.
    I have to insert data into dd_prohibited_country based on records already present.
    The scenario I should follow is:
    For Level_id 'EA' and prohibited_level_id 'EA' I should retreive the
    max(prohibit_country_key) and starting from the maximum number again I have to insert them
    into dd_prohibited_country. While inserting I have to increment the prohibit_country_key and
    shall replace the values of level_id and prohibited_level_id.
    (If 'EA' occurs, I have to replace with 'EUR')
    For Instance,
    If there are 15 records in dd_prohibited_country with Level_id 'EA' and prohibited_level_id 'EA', then
    I have to insert these 15 records starting with prohibit_country_key 16 (Afetr 15 I should start inserting with number 16)
    I have written the following query for this:
    insert into dd_prohibited_country
    select     
         a.pkey,
         b.levelid,
         b.ieflag,
         b.plevelid
    from
         (select
              max(prohibit_country_key) pkey
         from
              dd_prohibited_country) a,
         (select
    prohibit_country_key pkey,
              replace(level_id,'EA','EUR') levelid,
              level_id_flg as ieflag,
              replace(prohibited_level_id,'EA','EUR') plevelid
         from
              dd_prohibited_country
         where
              level_id = 'EA' or prohibited_level_id = 'EA') b
    My problem here is, I am always getting a.pkey as 15, because I am not incrementing it.
    I tried incrementing it also, but I am unable to acheive it.
    Can anyone please hepl me in writing this query.
    Thanks in advance
    Regards
    Raghu

    Because you are not incrementing your pkey. Try like this.
    insert
       into dd_prohibited_country
    select a.pkey+b.pkey,
         b.levelid,
         b.ieflag,
         b.plevelid
       from (select     max(prohibit_country_key) pkey
            from dd_prohibited_country) a,
         (select     row_number() over (order by prohibit_country_key)  pkey,
              replace(level_id,'EA','EUR') levelid,
              level_id_flg as ieflag,
              replace(prohibited_level_id,'EA','EUR') plevelid
            from     dd_prohibited_country
           where level_id = 'EA' or prohibited_level_id = 'EA') bNote: If you are in multiple user environment you can get into trouble for incrementing your PKey like this.

Maybe you are looking for

  • ImportError: no module named java  : While running a scenario (ODI 10.1.3.)

    Hi All, When i am running a scenario i am getting the below error in the 'error log ' file....Please let me know any pointers on the same.. its urgent:- ========================================================= [oraodi@apo13100098 error]$ cat SIL_TIM

  • The touch part of my iTouch doesn't work how do i get that fixed?

    My itouch touch screen doesnt work anymore. I have restored it and put the new software on it but it doesn't work I want to know how to get that fixed or if i should just by a new ipod.

  • Taking time to fetch records from BSEG

    Hi all, When iam fetching wrbtr,augdt,zterm fields  from BSEG table by passing VBELN and BUKRS it is taking lot of time to get.My query goes like this   select vbeln wrbtr augdt zterm from bseg into table t_bsegtab for all             entries in t_vt

  • Download Speeds

    Hi I've just order but had a couple of questions about expected download speeds. The estimate for my line is 63MB down / 20MB up. Currently we are on ADSL connecting aroud 6MB and getting 650kbs on downloads ( max speed ) What sort of speed should we

  • X6 vs C6. which is better

    I Want to know does both x6 and c6 have same firmware and similer bugs or c6 has different firmware or less bugs? On this forum I have seen numerious problems in x6.