Insert data from a table

<p style="margin-top: 0; margin-bottom: 0"><font face="Arial" size="2">Hi,</font></p>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Arial" size="2">I would
like to insert data in a table. The data are selected by a query. I wrote this
code but there is an error :</font></p>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New">
<font SIZE="2" COLOR="#0000f0">PROCEDURE</font><font SIZE="2"> </font>
<font SIZE="2" COLOR="#808000">GLMASTER_SAVE</font><font SIZE="2"> </font>
</font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">IS</font></p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" COLOR="#0000f0" face="Courier New">BEGIN</p>
</font>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
<font SIZE="2" COLOR="#0000f0">  INSERT</font><font SIZE="2"> </font>
<font SIZE="2" COLOR="#0000f0">INTO</font><font SIZE="2"> </font></font>
<font SIZE="2" COLOR="#808000"><font face="Courier New">GLMASTER_SAVE</font></p>
</font>
<p style="margin-top: 0; margin-bottom: 0">
<font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
</font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
</font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2">COMPANY</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
ACCT_UNIT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2"> ACCOUNT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
SUB_ACCOUNT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
ACTIVE_STATUS</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">)</font></p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
VALUES</p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
</font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
</font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">(SELECT</font><font SIZE="2">
</font><font SIZE="2">COMPANY</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
</font><font SIZE="2">ACCT_UNIT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
</font><font SIZE="2">ACCOUNT</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">,</font></font><font SIZE="2"><font SIZE="2" COLOR="#0000f0" face="Courier New">
</font></font><font face="Courier New"><font SIZE="2">SUB_ACCOUNT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
</font></font><font SIZE="2"><font face="Courier New">ACTIVE_STATUS</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
</font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
</font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
</font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">FROM</font><font SIZE="2">
</font></font><font SIZE="2"><font face="Courier New">GLMASTER</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
</font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">ORDER</font><font SIZE="2">
</font><font SIZE="2" COLOR="#0000f0">BY</font><font SIZE="2"> </font>
<font SIZE="2">COMPANY</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
</font><font SIZE="2">ACCT_UNIT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
</font><font SIZE="2">ACCOUNT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
</font><font SIZE="2">SUB_ACCOUNT</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">);</font></p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0">
<font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
</font></font><font SIZE="2" COLOR="#0000f0" face="Courier New">COMMIT;</p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" COLOR="#0000f0" face="Courier New">END;</p>
</font>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Arial" size="2">Do you
know why ?</font></p>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Arial" size="2">Thank you
for your help.</font></p>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<p style="margin-top: 0; margin-bottom: 0">
<font color="#008080" face="Arial" size="2"><i><b>Patrick</b></i></font></p>

try this:
  INSERT INTO GLMASTER_SAVE
    (COMPANY, ACCT_UNIT, ACCOUNT, SUB_ACCOUNT, ACTIVE_STATUS)
  SELECT COMPANY, ACCT_UNIT, ACCOUNT, SUB_ACCOUNT, ACTIVE_STATUS
       FROM GLMASTER
   ORDER BY COMPANY, ACCT_UNIT, ACCOUNT, SUB_ACCOUNT;you need not to include the VALUES
Message was edited by:
Warren Tolentino
sorry ps while posting this you had already posted your solution.

Similar Messages

  • Inserting data from  a table  to an XML file

    I want to insert the values from this xml file emp.xml into a table Employees :
    <EMPLOYEES>
    <EMP>
    <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAME>
    <JOB>CLERK</JOB>
    <HIREDATE>17-DEC-80</HIREDATE>
    <SAL>800</SAL>
    </EMP>
    <EMP>
    <EMPNO>7499</EMPNO>
    <ENAME>ALLEN</ENAME>
    <JOB>SALESMAN</JOB>
    <HIREDATE>20-FEB-81</HIREDATE>
    <SAL>1600</SAL>
    <COMM>300</COMM>
    </EMP>
    <EMP>
    </EMPLOYEES>
    and here is my Employee table in Oracle 9i database
    SQL> DESC EMPLOYEE;
    Name Null? Type
    EMPNO NUMBER
    EMPNAME VARCHAR2(10)
    JOB VARCHAR2(10)
    HIREDATE DATE
    SAL NUMBER
    After getting help from the members i was able to do the insert of data from the xml file to the table..how to do the insert of data from the table to the xml file.
    Regards,
    Renu

    Hello michaels , thank you for the solution, still i am having some problems
    Here is what i have done :
    1.
    SQL> CREATE DIRECTORY my_table_dir AS 'E:\table_files'
    2 ;
    Directory created.
    2.
    SQL> select * from myemp;
    ENAME
    SMITH
    ALLEN
    3.
    This is the content of the existing xml file saved in the directory E:\table_files as emp.xml
    <EMPLOYEES>
    <EMP>JIM</EMP>
    <EMP>RICK</EMP>
    </EMPLOYEES>
    4.
    Now i executed this code :
    declare
    emp_xml xmltype;
    begin
    select sys_xmlagg (column_value, sys.xmlformat ('EMPLOYEES')) emp_xml
    into emp_xml
    from table (xmlsequence (cursor (select *
    from myemp
    where ename in ('SMITH', 'ALLEN')),
    sys.xmlformat ('EMP')
    dbms_xslprocessor.clob2file (emp_xml.getclobval (), 'E:\table_files', 'emp.xml');
    end;
    And the Error i got is :
    declare
    ERROR at line 1:
    ORA-29280: invalid directory path
    ORA-06512: at "SYS.UTL_FILE", line 18
    ORA-06512: at "SYS.UTL_FILE", line 424
    ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 46
    ORA-06512: at line 12

  • Simple way to insert data from one table

    Hi,
    I need to know a simple way on how to transfer the data from one table to another....
    First table xx_inv_tab1 has three columns col1, col2, col3 and where as second table xx_inv_tab2 has five columns col1, col2, col3, col4, col5.
    Here col2, col3, col4 are the same columns as in table1 xx_inv_tab1...
    Now I want to transfer first table data in to second table .... first column of second table holds a sequence, followed by the first table three columns data and followed with col4 and col5 which will hold NULL values....
    In my scenario, I have 70 - 75 columns in my first table which I want to move to second table which three new columns (one is sequence and other two has null values)...
    Any ideas if we make it in a simplest way rather saying insert into xx_inv_tab2 (col1, col2, col3 ............................................. col75) values (seq, col1, col2..........................col75, null, null)
    Help Appreciated..
    Thanks

    Easy
    untested
    insert into xx_inv_tab2 t2 (col1,col2,col3,col4)
    select yourSequence.nextval, t1.col1, t1.col2, t1.col3
    from xx_inv_tab1 t1
    ;Note that col5 does not need to be used, since you want to fill it with NULL.
    USe excel or sql developer to write you a list of column names, if you are to lazy to write all 75 columns by yourself.
    What might also work:
    untested
    insert into xx_inv_tab2 t2
    select yourSequence.nextval, t1.*, null
    from xx_inv_tab1 t1
    ;Edited by: Sven W. on Aug 31, 2012 4:41 PM

  • [ECC6] Inserting data from internal table (deep structure) into db table

    Hi experts,
    I have a problem when inserting data from IT using deep structure into a database table. Please help:
    I have one database table with 2 columns ZTest (col1, col2). Col1 is key.
    In my program I have a deep structure t_screen using table type lvc_t_scol:
    In 4.6c systems, the INSERT statement works well but it does not work in ECC6 systems.
    DATA: BEGIN OF t_screen OCCURS 0,
            rec_count(3) TYPE n,
            col1 LIKE ZTest-col1,
            col2 LIKE ZTest-col2.
    DATA: ct TYPE lvc_t_scol.
    DATA: END   OF t_screen.
    t_screen-col1 = 'test1'.
    t_screen-col2 = 'test1'.
    APPEND t_screen.
    t_screen-col1 = 'test2'.
    t_screen-col2 = 'test2'.
    APPEND t_screen.
    INSERT ZTest FROM TABLE t_screen ACCEPTING DUPLICATE KEYS.
    Currently I have an idea using a temporary internal table with the same structure as ZTest. Use MOVE-CORRESPONDING statement to move data from t_screen table to temporary table before inserting --> It worked. But do you have any ideas without using temporary table?

    Hi
    There are a large number of stataments couldn't be supported in unicode system and so it doesn't allow to do it in ECC 6.
    U need to delete the deep structure from your defination:
    DATA: BEGIN OF t_screen OCCURS 0,
            rec_count(3) TYPE n,
            col1 LIKE ZTest-col1,
            col2 LIKE ZTest-col2.
    DATA: ct TYPE lvc_t_scol. "<-------- Error is here
    DATA: END   OF t_screen.
    So u need to use a structure like this to update your table:
    DATA: BEGIN OF T_ZTEST OCCURS 0,
            rec_count(3) TYPE n,
            col1 LIKE ZTest-col1,
            col2 LIKE ZTest-col2.
    DATA: END   OFT_ZTEST.
    Max

  • Inserting data from one table into another table using PL/SQL

    HI,
    I am trying to insert values from one table into another using PL procedure, the values I want to retrieve from the table riverside1 are charac_id and charac_type and insert these values into another table called riverside2 , the stored procedure zorgs_gorfs(x,y) accepts two parameters which are 2 charac_id's of d characters in riverside1 then using insert statements inserts these characters from riverside1 into riverside2.
    CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
         BEGIN
              INSERT INTO riverside2
                   (charac_id)
              VALUES
                   (x);
    INSERT INTO riverside2
                   (charac_id)
              VALUES
                   (y);
          END zorgs_gorfs;
    /This works but the problem im having is that when I also try to insert the charac_type as well as the charac_id it doesnt work below is the code:
    CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
         BEGIN
              INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id = x);
          END zorgs_gorfs;
    /can someone kindly sort me out

    modify this sql
    INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id = x);as
    INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id in ( x,y));But my suggestion would be consider revising your approach. It does not look that good.
    Thanks,
    karthick.

  • Inserting Data from one table to another.

    I running a procedure that loops through a cursor which is about 80,000 records(tableA) and I am trying to insert into another table(tableX) based on the data from tableA. I have error trapped the hell out of this and made sure I am covering any holes. When looping through the cursor, it insert only about 28,000 records and then exits the loop. I have debugged this problem 100 different ways and for the life of me I can not figure why it just craps out at about this many records. I actually located where the looping stops and took the next 5 records from tableA, and inserted them manually and they went through normally, which tells me that there should have been no reason why the executable statements exited the loop. I checked my space and I have more than enough. I have debugged the code many different ways, but still no luck. It always exits the procedure after inserting about 28,000 records. When I was debugging the code, I noticed that it would exit because one of my select into...statements was returning a NO_DATA_FOUND error, but I trapped that error, and assigned a value to that variable if it was null.
    I am really getting frustrated with this. Can anyone offer some suggestions or advice as to what I can do to acheive my goal?

    post the cursor , loop , definition.
    while you fire the cursor, on table A for
    insert in table X, what happens on A and X ?
    it tries to make a commit every 100/1000 time,
    until close the cursor.
    table definition X, is similar to A ?
    alert_$SID.log what says ?
    pasquale rago

  • Inserting data from one table to another in different format

    Hello,
    I would like to know what I am doing wrong with the following code when I write a data from one another to another table in a different format. I am now learning PL/SQL and am using this as
    a test problem.
    I have a table called students which has the following columns:
    SQL> desc student
    Name Null? Type
    ----------- ----------------STUDENT_ID NUMBER(10)
    COURSE VARCHAR2(10)
    CREDITS NUMBER(10)
    I have created another table called new_student which has the following structure:
    SQL> desc new_student
    Name Null? Type
    ----------------------------------------- -------- ------------- STUDENT_ID NUMBER(10)
    COURSE VARCHAR2(30)
    CREDITS VARCHAR2(10)
    The data in the student table is:
    SQL> select * from student;
    STUDENT_ID COURSE CREDITS
    1 Science 4
    1 History 3
    2 Science 4
    2 History 3
    2 Math 4
    3 Sociology 3
    3 Psycology 3
    I want to store the STUDENT table data in NEW_STUDENT table as:
    STUDENT ID COURSES CREDITS
    1 Science/History 4/3
    2 Science/History/Math 4/3/4
    3 Sociology/Psycology 3/3
    This is my code:
    DECLARE
    -- Get all the student IDs
    CURSOR studentlist_cursor IS select distinct student_id from student ORDER BY student_id;
    -- Get the information for each student ID
    CURSOR courses_cursor(nstudentid number) is select course, credits from student where student_id=nstudentid;
    nIndex     INTEGER;
    pltcourses     DBMS_SQL.VARCHAR2_TABLE;
    pltcredits     DBMS_SQL.NUMBER_TABLE;
    newcourses varchar2(50);
    newcredits varchar2(10);
    BEGIN
    FOR student_rec IN studentlist_cursor
    LOOP
    nIndex:=0;
    -- Loop through each student ID from student_rec to get the
    --courses and creditsstudent ID
    FOR courses_rec in courses_cursor(student_rec.student_id)
         LOOP
         nIndex:=nIndex+1;
         pltcourses(nIndex):=courses_rec.course;
    -- Store the course data for each student ID in newcourses
    -- while doing so check if it is null or put a '/' between each course
    loop
    if newcourses is null then
    newcourses:=pltcourses(nIndex);
    else
    newcourses:=newcourses||'/'||pltcourses(nIndex);
    end if;
    end loop;
         pltcredits(nIndex):=courses_rec.credits;
    --Store credits data in variable newcredits
    --If the newcredits is not null then put a '/' between each credits
    loop
    if newcredits is null then
    newcredits:=pltcredits(nIndex);
    else
    newcredits:=newcredits||'/'||pltcredits(nIndex);
    end if;
    end loop;
    -- Insert student id, newcourses, newcredits into NEW_STUDENT
    INSERT INTO NEW_STUDENT
    (student_id ,
    course,
    credits
    ) VALUES
    (student_rec.student_id,
    newcourses,
    newcredits
    COMMIT;
    -- come out of the student id record and go to the next student --id record
    END LOOP;
    -- come out of the loop
    END LOOP;
    END;
    While doing so I get an error message:
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at line 23.
    The error is at the line:
    newcourses:=newcourses||'/'||pltcourses(nIndex);
    Can anyone help me by pointing out where the mistake is?
    Thank you for reading this long mail.
    Thank you.
    Rama.

    Hi dude
    there is lot of error in ur pl/sql.
    and u have created table new_student with columns
    student_id number(10),
    courses varchar2(30),
    credits number(10).
    first u need to modify ur table.
    student_id number(10),
    courses varchar2(30),
    credits varchar2(10).
    Now i am writing whole pl/sql block for u. it will work fine.
    DECLARE
    CURSOR studentlist_cursor IS select distinct student_id from student ORDER BY student_id;
    CURSOR courses_cursor(nstudentid number) is select course, credits from student
    where student_id = nstudentid;
    nIndex INTEGER;
    pltcourses DBMS_SQL.VARCHAR2_TABLE;
    pltcredits DBMS_SQL.NUMBER_TABLE;
    newcourses varchar2(50);
    newcredits varchar2(10);
    BEGIN
    FOR student_rec IN studentlist_cursor
    LOOP
    nIndex:=0;
    newcourses := null;
    newcredits := null;
    FOR courses_rec in courses_cursor(student_rec.student_id)
    LOOP
    nIndex:=nIndex+1;
    pltcourses(nIndex):=courses_rec.course;
    if newcourses is null then
    newcourses:=pltcourses(nIndex);
    else
    newcourses:=newcourses||'/'||pltcourses(nIndex);
    end if;
    pltcredits(nIndex):=courses_rec.credits;
    if newcredits is null then
    newcredits:=pltcredits(nIndex);
    else
    newcredits:=newcredits||'/'||pltcredits(nIndex);
    end if;
    end loop;
    INSERT INTO NEW_STUDENT
    (student_id,
    course) VALUES
    (student_rec.student_id,
    newcourses);
    END LOOP;
    END;
    and please revert back
    Regards
    Anil

  • Inserting data from one table to another table....

    Hi DB Gurus,
    I have two table like table A in instance X and table B in instance Y. I want to insert data into table A from table B.If data in table B already exist in table A then that should not insert .if data In table B is not present in table A then that data should insert into table A.
    please help me to how insert this kind of data.I am trying to insert data by using "insert into" statement.Is it correct way or not. please let me know...
    Thanks in advance
    Best regards
    kumar

    Hey There,
    "I have two table like table A in instance X and table B in instance Y"
    Are these 2 instances sitting in the same db/rac.
    if so
    insert into x.a
    select * from y.b
    If the 2 instances are in different databases/racs then i think you can add a linked db into your script.- not 100% about that though.
    Dob

  • Insert data from one table to another.

    I have two tables - T1 & T2.
    T1 has columns A1,A2,A3,A4 (A1 & A2 are the primary keys)
    T2 has columns B1,B2,B3,B4 (B1 & B2 are the primary keys)
    I need to insert records from T1 to T2 with the conditions,
    - A1,A2,A3 will have the same record for the multiple records of A4.
    This is what I tried and got the error:-
    SQL> INSERT INTO nego_prop_supp (nps_supp_cd, nps_enq_no, nps_supp_resp, nps_cs_rank)
    2 SELECT DISTINCT tos_supp_code, tos_enq_no, tos_bid_seal_condn, csr_set_rank
    3 FROM tender_opening_supp, cs_rate
    4 WHERE tos_enq_no = '7211233E' AND
    5 tos_supp_code = csr_scd AND
    6 (tos_nature_of_bid = 'P' or tos_nature_of_bid = 'N') AND
    7 csr_set_rank IS NOT NULL;
    INSERT INTO nego_prop_supp (nps_supp_cd, nps_enq_no, nps_supp_resp, nps_cs_rank)
    ERROR at line 1:
    ORA-00001: unique constraint (DPURC.NEGO_PROP_SUPP_PK) violated
    You could understand that T1 consists (data from 'tender_opening_supp' & cs_rate), while T2 is nego_prop_supp.
    Pls. get me the soution for thi problem!!

    then this query
    SELECT DISTINCT tos_supp_code, tos_enq_no, tos_bid_seal_condn, csr_set_rank
    3 FROM tender_opening_supp, cs_rate
    4 WHERE tos_enq_no = '7211233E' AND
    5 tos_supp_code = csr_scd AND
    6 (tos_nature_of_bid = 'P' or tos_nature_of_bid = 'N') AND
    7 csr_set_rank IS NOT NULL
    8 and not exists (select nps_supp_cd from nego_prop_supp,tender_opening_supp where tos_supp_code
    = nps_supp_cd) ;
    have more than one tos_supp_code (the same any times) with any different value from tos_enq_no, tos_bid_seal_condn, csr_set_rank
    then anything is wrong or your key(on nego_prop_supp ) or the query retrieve rows that you not want
    the join is ok?
    why this join retrieve more than one value with the key of the other table? Do you need to filter any more? are you missing a filter?

  • Insert data from a table into 5 different tables

    My application has a data block than display information from another table. From this data block, the user has the option to select the records for upload. The information in the data block is used to insert data into 5 different tables. So if any exception occurs while inserting, the whole process should be rollback, but before this happen a record is inserting in a failed table indicated the reason of the failed.
    For this process I use the following commands:
    1.     sp_name := Get_Application_Property(SAVEPOINT_NAME);
    2.     INSERT DDL
    3.     INSERT DDL
    4.     INSERT DDL
    5.     INSERT DDL
    6.     INSERT DDL
    7.     If Other Exception then ISSUE_ROLLBACK(sp_name) Otherwise FORMS_DDL ('commit')
    The problem the previous insert(s) rollback
    Thanks,

    Hi,
    If you are using FORMS_DDL built-in to insert the data, then after each FORMS_DDL statement, you have to check the values of FORM_SUCCESS or FORM_FAILURE built-ins.
    FORMS_DDL('<insert_statement_1>');
    IF FORM_FAILURE THEN
    <the statement fails. so have to be rollbacked>
    END IF;
    FORMS_DDL('<insert_statement_2>');
    IF FORM_FAILURE THEN
    <the statement fails. so have to be rollbacked>
    END IF;Hope this helps.
    Regards,
    Manu.
    If my response or the response of another was helpful or Correct, please mark it accordingly

  • Insert data from internal table to ztable.

    Hello Expert,
    I have a ztable with a primary key, now i want to pass my data from the internal table to the ztable . I am using modify option to
    pass the data to the ztable but the problem is if the primary key value is same then its update the first record rather add one row in the zrable .But i want to push all the data what are available in the internal table though all the data are same. I even tried with Insert statement but its seems it doesnot work.
    Can you please advice me the right approach.
    Thanks.
    Satya

    Hi,
    It is all about the primary key fields of the database table.
    Example:
    You have a db table with following fields
    MANDT (primary key field)
    BUKRS (primary key field)
    BELNR (primary key field)
    GJAHR
    VBELN
    and it with same fields.
    MANDT BUKRS BELNR GJAHR VBELN
    120 0010 160000 2008 450000
    120 0010 160000 2007 450003
    120 0020 160000 2008 450000
    200 0010 160001 2008 450001
    200 0010 160001 2007 450001
    If you use INSERT statement, only 3 of these will be inserted into the database table, why?
    Because: Each database table must include one or a very small group of key fields that uniquely identify each table line by its value. These fields are known as the primary keys of the table.
    And as lines 1 and 2 / 4 and 5 have the same MANDT BUKRS and BELNR only one will be inserted into the table.
    If the database table is your own one, you will need to modify it so that it would work.
    Thankyou.
    Regards,
    Dhanalakshmi L

  • How to insert data from a table to database

    Hi all,
    My problem statement is that:
    I have jsp page, which has a table with some columns editable for inserting data. I am using MySql database.
    Now when I insert the data in the table and click submit button , the data entered must get stored in the database.
    If its a single data I can do it , but how to do for mulitple rows or columns.
    Please suggest me a solution
    Regards,
    Suraj

    i did one program similar to this requirement. when the rows and columns are fixed then what is the problem.
    use java script and capture all the values into an array and pass this to servlet and there call a method which will set
    the bean objects. or else no need to pick the array directly pass all the parameters and set the beans by retrieving these
    parameters(request.getParameter()).
    Diablo

  • Question in ABAP syntax, read & insert data from internal table, while loop

    Hi, SDN Fellow.
    I am from Java background and learnt ABAP, I don't usually write much ABAP code.
    I am trying to implement the following logic in a RFC now.
    I have one z-custom database table, the structure as the following:
    It has two columns, with these sample data.
    Says datable table is ZEMPMGRTAB.
    EmployeeID,ManagerID
    user10,user1
    user9,user1
    user8,user1
    user7,user2
    user6,user2
    user5,user2
    user4,user2
    user2,user1
    The logic is this:
    I have a input parameter, userid. I am using this parameter to have a select statement to query the record into export table,EXPTAB 'LIKE' table ZEMPMGRTAB.
    SELECT * FROM  ZEMPMGRTAB
      into table EXPTAB
       WHERE  EMPLOYEEID  = USERID.
    Say, my parameter value, USERID ='USER4'.
    Referring to the sample data above, I can get the record of this in my EXPTAB,
    EmployeeID,ManagerID
    user4,user2
    Now, I want to iterately use the EXPTABLE-ManagerID
    as the USERID input in SELECT statement, until it has no return result. Then, insert the new records in
    EXPTAB.
    In above new loop case, we will get this table content in EXPTAB,
    EmployeeID,ManagerID
    user4,user2
    user2,user1
    I kind of think of the pseudocode logic as below:
    (These may not be a valid ABAP code, so I need help to convert/correct them)
    DATA:
    IWA TYEP ZZEMPMGRTAB,
    ITAB
    HASHED TABLE OF ZZEMPMGRTAB
    WITH UNIQUE KEY EMPLOYEEID.
    SELECT * FROM  ZEMPMGRTAB
      into table ITAB
       WHERE  EMPLOYEEID  = USERID.
    *Question 1: I cannot insert a internal table to export table, it is *incompatible type, what is the alternative way fo this?
    *Question 2: How can I access thedata of the internal table like this,ITAB-MANAGERID? As if I can, I would do this:
    * IWA-EMPLOYEEE = ITAB-EMPLOYEEID. IWA-MANAGERID = IWA-MANAGERID. INSERT IWA INTO TABLE EXPTAB.
    * Question 3: Is the 'NE NULL' - 'not equal to NULL' is right syntax?
    IF ITAB NE NULL.
    INSERT ITAB INTO EXPTAB.
    ENDIF
    * Question 4: Is my WHILE loop setup right here? And are the syntax right?
    WHILE ITAB NE NULL.
    SELECT * FROM  ZEMPMGRTAB
      into table ITAB
       WHERE  EMPLOYEEID  = ITAB-MANAGERID.
    IF ITAB NE NULL.
    INSERT ITAB INTO EXPTAB.
    ENDIF
    REFRESH ITAB.
    ENDWHILE.
    Assume all the syntax and logic are right, I should get this result:
    EmployeeID,ManagerID
    user4,user2
    user2,user1
    If I have a new entry in datable table,ZEMPMGRTAB like this:
    user1,user0
    My pseudocode logic will get this result:
    EmployeeID,ManagerID
    user4,user2
    user2,user1
    user1,user0
    I truly appreciate if you can help me to validate the above syntax and pseudocode logic.
    Thanks in advance.
    KC

    Hi,
    FUNCTION ZGETSOMEINFO3.
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(USERID) TYPE  AWTXT
    *"     VALUE(FMTYPEID) TYPE  AWTXT
    *"  EXPORTING
    *"     VALUE(RETURN) TYPE  BAPIRETURN
    *"  TABLES
    *"      APPROVERT STRUCTURE  ZTAB_FMAPPROVER
    *"      ACTOWNERT STRUCTURE  ZTAB_FMACTOWNER
    DATA: T_RESULT TYPE STANDARD TABLE OF ZTAB_FMAPPROVER.
    **Question 1: For this line, I got an error says "Program ''USERID" *not found. Is the syntax right, as the USERID is a parameter for the function.
    perform add_line(USERID).
      ENDFUNCTION.
    form add_line using i_user type ZTAB_FMAPPROVER.EMPLOYEEID
                        changing T_RESULT TYPE ZTAB_FMAPPROVER.
    data: ls_row type ZTAB_FMAPPROVER.
    * Get record for i_user
    select single * into ls_row from ZTAB_FMAPPROVER
    where EmployeeID = i_user.
    if sy-subrc NE 0.
    * Do nothing, there is not manager for this employee
    else.
    * Store result
    QUESTION 2: I am still got stuck on this line of code. It still *says that "T_RESULT" is not an internal table "OCCURS n" *specification is missing. I thought the line: "T_RESULT TYPE *ZTAB_FMAPPROVER" means declare internal table, T_RESULT as type of ZTAB_FMAPPROVER". Am I understand it wrongly?
    append ls_row to t_result.
    * Call recursion
    perform add_line using ls_row-ManagerID
                              changing t_result.
    endif.
    endform.
    Thanks,
    KC

  • Insert data from source table to destination table dependning up on a criteria.once inserted delete from source table.

    HI,
    I have a source table with millions of records .I need to insert some of the data (depending on a condition) to a repository table.
    Once they are inserted they can be deleted from the source table.
    The deletion is taking a lot of time .
    I need to reduce the time to delete the records.
    ex:-  1 million records in 8 seconds.
    Had already used bulk collect and cursors but cannot succeed.
    Please suggest how to increase the performance.
    Thanks & Regards

    APPROACH 1:-
    CREATE OR REPLACE PROCEDURE SP_BC
    AS
    DETAILS_REC SOURCETBL%ROWTYPE;
    COUNTER NUMBER:=1;
    RCOUNT NUMBER:= 1;
    START_TIME PLS_INTEGER;
    END_TIME PLS_INTEGER;
    CURSOR C1 IS
    SELECT * FROM SOURCETBL WHERE DOJ<SYDATE;
    BEGIN
    START_TIME := DBMS_UTILITY.GET_TIME;
        DBMS_OUTPUT.PUT_LINE(START_TIME/100);
        OPEN C1;
        LOOP
        FETCH C1 INTO DETAILS_ROW;
        EXIT WHEN  C1%NOTFOUND;
               BEGIN
                EXIT WHEN COUNTER >10000;
                INSERT INTO DESTINATIONTBL VALUES DETAILS_REC;
                IF SQL%FOUND THEN
                    DELETE FROM SOURCETABLE WHERE ID= DETAILS_REC.ID;
                  COUNTER:=COUNTER+1;
            END IF; 
        COMMIT;
            END;
         COUNTER:=1;
        END LOOP;
        COMMIT;
    END;
    APPROACH 2:-
        CREATE OR REPLACE PROCEDURE SP_BC1
    IS
    TYPE T_DET IS TABLE OF SOURCETBL%ROWTYPE;
    T_REC T_DET;
    BEGIN   
        SELECT *  BULK COLLECT INTO T_REC FROM SOURCETBL
         WHERE NAME=@NAME;
        FOR I IN  T_REC .FIRST ..T_REC .LAST
           LOOP
             INSERT INTO DESTINATIONTBL VALUES T_REC (I);
          IF SQL%FOUND THEN
          DELETE FROM SOURCETBL WHERE ID =
           WHERE ID = T_REC (I).ID;  
           END IF; 
           EXIT WHEN T_REC=0;
        END LOOP;
        COMMIT;
    END;
    APPROACH 3:-
    CREATE OR REPLACE PROCEDURE SP_BC2
    AS
    TYPE REC_TYPE IS TABLE OF SOURCETBL%ROWTYPE ;
    DETAILS_ROW REC_TYPE;
    CURSOR C1 IS
    SELECT * FROM
         SOURCETBL WHERE END<SYSDATE;
        BEGIN
        OPEN C1;
        LOOP
        FETCH C1 BULK COLLECT INTO DETAILS_ROW LIMIT 999;
        FORALL I IN 1..DETAILS_ROW.COUNT
                  /* A BATCH OF 999 RECORDS WILL BE CONSIDERED FOR DATA MOVEMENT*/
    INSERT INTO DESTINATIONTBL VALUES DETAILS_ROW(I);
    --            IF SQL%FOUND  THEN
    --                DELETE from SOURCETBL WHERE ID IN DETAILS_ROW(I).ID;
    --           END IF;
            EXIT WHEN  C1%NOTFOUND; 
        COMMIT;   
        END LOOP;
        COMMIT;
    3rd approach seems better but i have an issue with referring the fileds of a record type.

  • How to insert data from a table into itself if they don't already exist meeting a certain condition

    First, let me apologize as I did not write/design this mess, just inherited this terrible design and legacy application!
    I have table of companies and a table of suppliers with various attributes and of them being a bit column of is_public.  The public suppliers then need to be inserted into the table as suppliers for the other suppliers.
    As an example, in the company table company 'PUB01' is flagged as a public supplier (Company.IS_PUBLIC_SUPPLIER = 1).  Therefore in the Suppliers table I need to insert a row for each each of PUB01's suppliers in that same table to all the other suppliers
    in that table if they do not already exist as follows:
    Here is a sample of the table structure:
    CREATE TABLE [dbo].[COMPANY](
    [COMPANY_ID] [nvarchar](15) NOT NULL,
    [COMPANY_NAME] [nvarchar](100) NOT NULL,
    [IS_PUBLIC_SUPPLIER] bit NOT NULL,
     CONSTRAINT [PK_COMPANIES] PRIMARY KEY CLUSTERED 
    [COMPANY_ID] ASC
    ) ON [PRIMARY]
    GO
    CREATE TABLE [dbo].[SUPPLIERS](
    [SUPPLIER_ID] [int] IDENTITY(1,1) NOT NULL,
    [COMPANY_ID] [nvarchar](15) NOT NULL,
    [SUPPLIER_NAME] [nvarchar](100) NOT NULL,
    [PUBLIC_SUPPLIER_ID] [int] NULL,
     CONSTRAINT [PK_SUPPLIER_MASTER] PRIMARY KEY CLUSTERED 
    [SUPPLIER_ID] ASC
    GO
    Thanks!

    Thanks Visakh!  Will that work if some have already been inserted previously?
    Yes
    but if you want to exclude them use this
    INSERT INTO Suppliers(Company_ID,Supplier_Name,PUblic_Supplier_ID)
    SELECT s1.Company_ID,
    s2.Supplier_Name,
    s2.Supplier_ID
    FROM Suppliers s1
    CROSS JOIN Suppliers s2
    WHERE EXISTS(
    SELECT 1
    FROM Company
    WHERE Company_ID = s2.Company_ID
    AND IS_PUBLIC_SUPPLIER = 1
    AND s1.COMPANY_ID <> s2.COMPANY_ID
    AND NOT EXISTS (SELECT 1
    FROM Suppliers
    WHERE Company_ID = s1.Company_ID
    AND Supplier_Name = s2.Supplier_Name
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

Maybe you are looking for