Insert Records into another tables

Hi guyz,
I have four tables as below
1) employee
empid (primary key)
deptid
emp_name
work_location
date_of_join
emp_status
date
2) Termination
empid reference employee
deptid
emp_name
work_location
terminate_date
3) Resignation
empid reference employee
deptid
emp_name
work_location
resign_date
4) Vacation
empid reference employee
deptid
emp_name
work_location
vac_date
i have list item on employee form --> emp_status is list item whic contain Termination, Resignation, Vacation
i want to update employee as well other tables if user select the respected field from the list item.
if the user select termination/resignation from the list item the date item will be enable and user should enter the date,otherwise give the error on commit please enter the date and when user commit the record on employee it should update the table employee and delete the record belongs to Termination/Reisgnation and the record will be insert into Termination/Resignation table as select by user from list item.i tried this before but im fail i write the below code on pre-update trigger as below
begin
insert into termination
(empid,deptid,emp_name,work_location,termination_date)select (empid,deptid,emp_name,work_location,date from employee where emp_status='Termination';
delete from employee where emp_status='Termination' ;
end;
same as on resignation
anybuddy help me how to do this task? to update the tables. im new in oracle.
Regards
Edited by: user10648713 on Dec 21, 2008 4:29 AM

You run into the classic Mutating table problem. You cannot issue DML-statement against the same table the trigger is based on in a FOR EACH ROW-trigger.
But even worse, you will cause any kind of client program to get in trouble if you implement such a logic. The client issues an update and as a result the record gets deleted. And, for you have a forms-module based i tell you that you will get problems with your forms-module.
I still can't see whats the sense behind it, putting records into different tables dependant on a status. Oracle is built to manage large data volumes, so even for a large number of records that doesn't make sense to me.
But anyway if you still want to deal with that multi-table-approach, go for the following:
You will need three triggers on your table: a before-statement, an after-statement and a for-each-row-trigger:
The before-statement will initialize a list of PK-Items
The for-each-row will add the id of the processed row to the list
The after-statement will loop over the list and process the rows.
Create a Package for handling the logic including three procedures
CREATE OR REPLACE PACKAGE PK_TRIGGER IS
  PROCEDURE PR_BS;
  PROCEDURE PR_ARIU(i_nEmpId IN NUMBER);
  PROCEDURE PR_AS;
END;
CREATE OR REPLACE PACKAGE BODY IS
  TYPE tData IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
  lData tData;
  PROCEDURE PR_BS IS
  BEGIN
    lData.DELETE;
  END;
  PROCEDURE PR_ARIU(i_nEmpId IN NUMBER) IS
    iPos PLS_INTEGER:=lData.COUNT+1;
  BEGIN
    lData(iPos):=i_nEmpId;
  END;
  PROCEDURE PR_AS IS
    CURSOR crEmp(i_nEmpId IN NUMBER) IS
      SELECT *
        FROM EMP
       WHERE EMP_ID=i_nEmpId;
    recEmp crEmp%ROWTYPE;
    iPos PLS_INTEGER;
  BEGIN
    iPos:=lData.FIRST;
    LOOP
      EXIT WHEN iPos IS NULL;
      -- Do whatever you want with the data in the record
      OPEN crEmp(lData(iPos));
      FETCH crEmp INTO recEmp;
      IF crEmp%FOUND THEN
        IF :NEW.EMP_STATUS='Termination' THEN
          DELETE FROM emp
           WHERE EMPID=lData(iPos);
          INSERT INTO TERMINATION (
            empid,
            deptid,
            emp_name,
            work_location,
            t_date
          ) VALUES (
            recEmp.empid,
            recEmp.deptid,
            recEmp.emp_name,
            recEmp.work_location,
            sysdate
        END IF;
      END IF; 
      CLOSE crEmp;
      -- Process next record
      iPos:=lIds.NEXT(iPos);
    END LOOP;
    lIds.DELETE;
  END;
END;Now create the three triggers calling the appropiate procedures.

Similar Messages

  • JDBC sender: after read insert records into another table

    Hi all,
    I send records from a SQL view (not a table) to RFC via proxy method.
    After reading a record from the view I would like to move this record to a database table called CHECKED. Can anyone provide me a solution for this or is this impossible. (there are 6 fields that have to be inserted in DB CHECKED after reading: admin, bukrs, dagbknr, bkstnr, datum, regel)
    Can I use an INSERT statement in my Update SQL Statement with variables or do I have to create an SP?
    Hope someone can help me out of here...
    Thanks in advance!
    Wouter.

    ur strucutre would of:
    <root>
    <Satement1>
    <TableName action=”INSERT”>
    <table>checked</table>
    <access>
    <admin>val</admin>
    <bukrs>val</bukrs>
    <dagbknr>val</dagbknr>
    <bkstnr>val</bkstnr>
    <datum>val</datum>
    <regel>val</regel>
    </access>
    </dbTableName>
    </StatementName1>
    </root>
    or u can use a SQL DML which wud pose a strucutre similar to
    <root>
      <stmt>
        <Customers action="SQL_DML">
          <access> INSERT CHECKED SET admin=’$admin$’, bukrs=’$bukrs$', dagbknr=’$dagbknr$’, bkstnr=’$bkstnr$', datum=’$datum$’, regel.=’$regel.$'
          </access>
        </Customers>
      </stmt>
    </root>
    for more inputs refer to <a href="/people/sap.user72/blog/2005/06/01/file-to-jdbc-adapter-using-sap-xi-30 link on jdbc</a>

  • Inserting records into a table with all caps

    Hello
    I have a procedure that inserts records into a table. How do I ensure that the text values inserted are recorded all capital letters into the table?
    Thanks.

    You can use UPPER(..) function in your insert statement, so that values are converted to UPPER, before insert.
    If you want to check at table level, you can achieve that by writting a before insert trigger and in that trigger check
    IF UPPER(:new.<col>) != :new.<col> THEN
    RAISE_APPLICATION_ERROR(-20101,'Error: Not all values are in upper case')
    END IF;

  • How to retrive one table records into another table by multiple records

    how to retrive table X records into another table Y by multiple records (means at once i want display 10 records) in form 6i .
    when i am written cursor it is ftching only one record.But i want to display all records at once.
    Declare
    Cursor cur_name is
    select PROTOCOL_NO,DOCNUM,SUBSETSN,REPEATSN,AESEQ,AETERM from coding_ae WHERE PROTOCOL_NO='KP229';
    Begin
    open cur_name;
    loop
    fetch cur_name into :PROTOCOL_NO,:DOCNUM,:SUBSETSN,:REPEATSN,:AESEQ,:AETERM;
    exit when cur_name%notfound;
    next_record;
    end loop;
    close cur_name;
    End;

    Hi,
    Make sure the cursor is in the detailed block. For that use 8GO_BLOCK* built-in. So the code will be
    Declare
    Cursor cur_name is
    select PROTOCOL_NO,DOCNUM,SUBSETSN,REPEATSN,AESEQ,AETERM from coding_ae;
    Begin
    GO_BLOCK('<detailed_block_name>');
    open cur_name;
    loop
    fetch cur_name into :PROTOCOL_NO,:DOCNUM,:SUBSETSN,:REPEATSN,:AESEQ,:AETERM;
    exit when cur_name%notfound;
    next_record;
    end loop;
    close cur_name;
    End;Regards,
    Manu.
    If my response or the response of another was helpful or Correct, please mark it accordingly

  • Using Crystal 2008 to insert records into a table

    Hi,
    We have a unique need to use Crystal to insert records into a table. We have managed to test a report that can write into a temporary table.  This is done by using sql command object  and uses  the following code :
    INSERT INTO TEMP_TABLE  (ORDERID)
    VALUES ({?orderid})   (-- where orderid a parameter).
    This test report asks for an order id and then inserts the record perfectly fine.
    Now moving on to the real report - This report basically prints orders in batches and we want to insert order id into a temporary table to ensure we don't print orders that were already printed. To do this we created a sub report "insert orders" that has the above insert command. The main report passes the orderid to subreport and the idea is that the subreport would insert each time an order is passed. So if main report printed 50 orders ids, the then it would do 50 inserts individually into the temp table. 
    This however is NOT working. The report runs fine but there is no insert.  Our hunch is that  Crystal is not committing after every order id is passed from the main report.  Not sure if we can set the AUTO COMMIT ON  as a default somewhere?
    Wondering if any one has attempted this or has any insights?
    Regards,
    Mohit.
    Environment is - Crystal 2008 and Oracle 11GR2, we are using Oracle drivers (and not odbc)

    Hmmm... I don't use Oracle but the syntax looks good...
    You've already tested it and I assume that you are using the same driver in the production report as you used in the test, so that shouldn't be an issue...
    how are you pulling the data? Is the final SELECT statement that pulls the report data in the same command as the INSERT script, or is the INSERT script in it's own command?
    The reason I ask... If you are trying to pass a multi-valued parameter to a command, it won't work. If you have the insert command as it's own command while the data is being pulled with linked tables or a separate command, it is possible that the report itself will execute as expected w/o passing a value to the insert script.
    If it's all in 1 command (as it should be), a bad parameter would fail in the final SELECT causing an error.
    Also... are rows null or empty string values being added to table when the report executes? This would be an indication that the command is being executed but isn't getting the parameter value.
    Jason

  • Can BO Enterprize SDK inserts records into user table

    From Infostore can we create a jsp script using Java SDK to inserts records into user table??
    Thanks
    Amar

    Hi Amar,
    I want to retrieve data/records from Infostore and insert into a user table using JSP script. Is it possible to do this?
    Infostore is a database used by BO Server. so any changes made in infostore through BO enterprise session is valid.
    Say u want to retrive on of report present in folder <my folder>.
    The you have to query for that. for eg.
    boinfostore.query("select * from ci_infoobjects where si_kind ='report' and si_foldername='my folder'");
    Create/add/insert any new information in infostore is done by functionalities provide by SDK.
    like adding the user or scheduling a report will add new object to infostore.
    If you directly access cms database and make any changes then , I am afraid you will end up with nightmare.
    So it is always recommneded to access infostore/ cms database only from bo session.
    For more information refer below link
    [http://devlibrary.businessobjects.com/BusinessObjectsXIR2SP2/en/devsuite.htm]
    then under Contents
    BusinessObjects Enterprise SDK >>  COM developer guide and API reference >> Query Language Reference
    do revert if any queries
    Thanks,
    Praveen.

  • Insert records into A table in Oracle from SAP

    Hello All,
    I want to know how can we insert a record into a table which is in another server say Oracle and this needs to be done everyday.
    For example, I have a record which gives the information whether the Daily Job has run Successfully or not. Now , I have to update this information in the Oracle table.

    refer amit perfect answer.
    Re: Need to put data in oracle table from sap.

  • How to insert records into the Table?

    Dear Sir,
    I'm new to JDeveloper. Now I managed to create a Frame in JDeveloper with many Text fields and a button. In the back end, I have a procedure to insert records to a table, to which I pass the values of the fields as parameters. Now I'm not getting the steps to call the PL/SQL Stored procedure when I click on the button. I'm using Oracle 9i JDeveloper version 9.0.3.1. and Oracle 9i Database.
    Please give me the complete steps to achieve my task - it is quite urgent.
    Thanking You in advance.
    Regards,
    Senthil .A. Perumal.

    The JDBC tutorial will show you how to call a stored procedure from Java:
    http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/basic.htm
    One more thing, why are you using such an old version of JDeveloper? any reason not to upgrade to the 10.1.3 version of JDeveloper?
    Also you might want to look into ADF and how it makes these type of database interactions easier.
    See this demo:
    http://www.oracle.com/technology/obe/obe1013jdev/adf_swing/master_detail_page_adfswing_bc.htm

  • Problem - Inserting Records into Hashed Tables

    Help for an ABAP Newbie...
    How do I insert records into a hashed table?
    I am trying the following, but get the error message,
    *You cannot use explicit or implicit index operations with types "HASHED TABLE" or "ANY TABLE".  "LT_UNIQUE_NAME_KEYS" has the type "HASHED TABLE".
    TYPES: BEGIN OF idline,
        id TYPE i,
        END OF idline.
      DATA: lt_unique_name_keys TYPE HASHED TABLE OF idline WITH UNIQUE KEY id,
            ls_unique_name_key LIKE LINE OF lt_unique_name_keys.
    " Create a record and attempt to insert it into the internal table.
    " Why does this cause a compilation error message?
    ls_unique_name_key-id = 1.
      INSERT ls_unique_name_key INTO lt_unique_name_keys.
    Thanks,
    Walter

    INSERT ls_unique_name_key INTO TABLE lt_unique_name_keys.

  • How to move milion of records into another table

    Hello, I would like to know if there is some way how to move large number of rows from one table into another.
    We have several tables storing runtime data. Data older then e.g. 10 days are moved into hitory tables. Currently we do this via pl/sql, but I was wondering if it is possible to do this somehow in SQL only (to make it faster).
    It is not possible to simply rename the tables, we need to move the data.
    Thanks for ideas.

    872553 wrote:
    Hello, I would like to know if there is some way how to move large number of rows from one table into another.
    We have several tables storing runtime data. Data older then e.g. 10 days are moved into hitory tables. Currently we do this via pl/sql, but I was wondering if it is possible to do this somehow in SQL only (to make it faster).
    It is not possible to simply rename the tables, we need to move the data.
    Thanks for ideas.To me looks like a Regular scheduled activity.
    Hence, using DBMS_SCHEDULER should be helpful.
    Create a Procedure to Copy the records from Transaction Table to History Table.
    create or replace procedure copyTransactionToHistory
    is
    begin
      insert /*+ append */ into history_table
      select column_list
        from transaction_table
       where transaction_date = trunc(sysdate) - 10;
      commit;
    end;
    Use DBMS_SCHEDULER to create Job with specified Time Interval (10 Days in your situation). More information and Examples are provided <a href="http://docs.oracle.com/cd/B28359_01/server.111/b28310/schedadmin006.htm#i1009099">Here</a>.There is also a possibilty of using NOLOGGING, but that will be recommended if the activity is not a regular scheduled activity and I do not think it would be a wise option to change the Table mode from LOGGING to NOLOGGING and vice-versa frequently.
    You might also consider options to improve the Data movement.
    1. Disabling Indexes/Constraints, if any, on History table.
    2. Using PARALLEL DML's option
    However, important information viz. your Oracle Version (Output of SELECT * FROM V$VERSION), Number of Records etc. are not mentioned which leaves us with no choice but to assume and suggest what we feel is best.
    Please read and post the information accordingly for us to help you. {message:id=9360002}

  • How to delete the Table Contents before inserting records into SQL table ?

    Hello Experts,
            I have a scenario where in I have to Pick up some records from SAP RFC & insert into SQL table.
            i know how to do this scenario but the proble with this is before inserting we first have to ZAP the SQL table & insert a new records. One more twist is The Triggering is happening from SAP side with Sender RFC. If this would have been from SQL Side i could have written a Stored Procedure/ Trigger & could have called this before the SENDER JDBC communciation channel picks up the Triggering event from SQL side.
    So how to do this scenarioin XI, First deleting all the Records of SQL table & then inserting the new reocrds. without using the BPM.
    Regards,
    Umesh

    hi umesh,
    you can achieve this by writing SQL query in message mapping level..
    refer this link:
    http://help.sap.com/saphelp_nw04/helpdata/en/b0/676b3c255b1475e10000000a114084/frameset.htm
    regards.

  • Efficient Way of Inserting records into multiple tables

    Hello everyone,
    Im creating an employee application using struts framework. One of the functions of the application is to create new employees. This will involve using one web form. Upon submitting this form, a record will be inserted into two separate tables. Im using a JavaBean (Not given here) between the JSP page and the Java file (Which is partly given below). Now this Java file does work (i.e. it does insert a record into two seperate tables).
    My question is, is there a more efficient way of doing the insert into multiple tables (in terms of performance) rather than the way I've done it as shown below? Please note, I am using database pooling and MySQL db. I thought about Batch processing but was having problems writing the code for it below.
    Any help would be appreciated.
    Assad
    package com.erp.ems.db;
    import com.erp.ems.entity.Employee;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.Collection;
    import java.util.ArrayList;
    public class EmployeeDAO {
         private Connection con;
         public EmployeeDAO(Connection con) {
              this.con = con;
         // METHOD FOR CREATING (INSERTING) A NEW EMPLOYEE
         public void create(Employee employee) throws CreateException {
              PreparedStatement psemployee = null;
              PreparedStatement psscheduleresource = null;
              String sqlemployee = "INSERT INTO employee (FIRSTNAME,SURNAME,GENDER) VALUES (?,?,?)";
              String sqlscheduleresource = "INSERT INTO scheduleresource (ITBCRATE,SKILLS) VALUES (?,?)";
              try {
                   if (con.isClosed()) {
                        throw new IllegalStateException("error.unexpected");
                            // Insert into employee table
                   psemployee = con.prepareStatement(sqlemployee);
                   psemployee.setString(1,employee.getFirstName());
                   psemployee.setString(2,employee.getSurname());
                   psemployee.setString(3,employee.getGender());
                            // Insert into scheduleresource table
                   psscheduleresource = con.prepareStatement(sqlscheduleresource);
                   psscheduleresource.setDouble(1,employee.getItbcRate());
                   psscheduleresource.setString(2,employee.getSkills());
                   if (psemployee.executeUpdate() != 1 && psscheduleresource.executeUpdate() != 1) {
                        throw new CreateException("error.create.employee");
              } catch (SQLException e) {
                   e.printStackTrace();
                   throw new RuntimeException("error.unexpected");
              } finally {
                   try {
                        if (psemployee != null && psscheduleresource != null)
                             psemployee.close();
                             psscheduleresource.close();
                   } catch (SQLException e) {
                        e.printStackTrace();
                        throw new RuntimeException("error.unexpected");
         }

    Hi ,
    U can use
    set Auto Commit function here ..
    let it be false first
    and when u do with u r all queries ..
    make it true
    this function take boolean values
    i e helful when u want record to be inserted in all or not at all..
    Hope it helps

  • Insert Records into database table.

    Hello Friends,
                         I am trying to insert set of records from an Internal table into Database table.
    INSERT SPFLI FROM TABLE ITAB ACCEPTING DUPLICATE KEYS.
    This is my statement. But It inserts only one record in to SPFLI table.
    Cheers
    Senthil

    Hi Sentil,
    USE THIS STATEMENT.
    MOVE-CORRESPONDING ITAB TO SPFLI.
    SPFLI-MANDT = SY-MANDT.
    MODIFY SPFLI.
    thy this....
    <b>reward if useful</b>
    regards,
    sunil kairam.

  • SBO2005SP01PL04: Inserting records into UDO - Tables

    Hi
    We need to fill up some values into UDO - tables. I know that there exists an method that uses a file at a specific place but our needs maybe need more flexibility because :
    - we will fill the values via Button that can be pressed whenever the user wants.
    - existing records with same "Code" shouldn't get overwritten.
    Thanks

    See Re: SBO2005SP01PL04: Copy UDO's of Type Masterdata from one DB to another

  • Inserting records into multiple tables

    Just thinking ahead, and trying to get my head around the
    next stage of my database project.
    At the moment I have the following tables :
    Candidates
    Candidate_ID (autonumber)
    Name (text)
    1, Iain
    2, Fi
    3, Rob
    Vacancies
    Vacancy_ID (autonumber)
    Vacancy (text)
    1, Cartographer
    2, Gardener
    3, Occupational therapist
    4, Web designer
    5, Recruitment manager
    Profiles
    Profile_ID (autonumber)
    Profile (text)
    1, Map making
    2, Web design
    3, Gardening
    4, Hand therapy
    5, Recruitment
    6, Aviation
    7, Sport
    8, Travel
    VacancyProfiles
    Vacancy_ID (number)
    Profile_ID (number)
    1,1
    1,2
    4,2
    2,3
    3,4
    5,5
    5,6
    CandidateProfiles
    Candidate_ID (number)
    Vacancy_ID (number)
    1,1
    1,2
    1,7
    1,8
    2,3
    2,4
    2,8
    3,5
    3,6
    3,7
    and from there created two queries
    CandidatesQuery
    SELECT Candidates.Candidate_ID, Candidates.Name,
    Profiles.Profile_ID, Profiles.Profile
    FROM Profiles INNER JOIN (Candidates INNER JOIN
    CandidateProfiles ON Candidates.Candidate_ID =
    CandidateProfiles.Candidate_ID) ON Profiles.Profile_ID =
    CandidateProfiles.ProfileID;
    1, Iain, 1, Map making
    1, Iain, 2, Web design
    1, Iain, 7, Sport
    1, Iain, 8, Travel
    2, Fi, 3, Gardening
    2, Fi, 4, Hand therapy
    2, Fi, 8, Travel
    3, Rob, 5, Recruitment
    3, Rob, 6, Aviation
    3, Rob, 7, Sport
    and
    Vacancies_Query
    SELECT Vacancies.Vacancy_ID, Vacancies.Vacancy,
    Profiles.Profile_ID, Profiles.Profile
    FROM Profiles INNER JOIN (Vacancies INNER JOIN
    VacancyProfiles ON Vacancies.Vacancy_ID =
    VacancyProfiles.VacancyID) ON Profiles.Profile_ID =
    VacancyProfiles.ProfileID;
    1, Cartographer, 1, Map making
    1, Cartographer, Web design
    2, Gardener, 3, Gardening
    3, Occupational therapist, 4, Hand therapy
    4, Web designer, 2, Web design
    5, Recruitment manager, 5, Recruitment
    5, Recruitment manager, 6, Aviation
    So from these, I have a Candidates page that is based on the
    Candidates table listing just ID, name and tel in a repeat region,
    with a link to a details page based on the CandidatesProfiles query
    above, and likewise with the Vacancies.
    I'm just wondering how this works with editing and adding
    records - as on those pages, I want to be able to add /edit fields
    from the Candidates and Vacancies tables, but also add/edit the
    profiles for each - do i just need my Add/Edit pages to be based on
    the same CandidatesProfiles and VacanciesProfiles query / SQL
    above?
    I get how the page retrieving the data can display the
    existing records, including multiple profiles for each in a repeat
    region - but am less sure about adding / editing multiple profiles?
    Or would it be a two step process - ie have a page to add a
    Candidate, and then have a page that displayed the Candidate's
    details with a subform where you could add/attach profiles to each
    Candidate?
    Hope that makes some sense, and someone can point me in the
    right direction.
    Cheers,
    Iain

    Thinking about it, would it be possible to have a list of
    checkboxes on the insert/edit page, with each asigned a Profile -
    so for example :
    if checkbox1 is checked, add Candidate1, Profile1
    if checkbox2 is checked, add Candidate2, Profile2
    etc?
    Iain

Maybe you are looking for