Inserting values from a cursor to a table

Hi,
I need to insert the values from a cursor into a table,this i the part of code which trieds to do it...i get error stating "select stmt missing"...pls help out...
OPEN  p_cursor for V_SQLSTATEMENT;
        ---for i in p_cursor
        LOOP
          FETCH p_cursor INTO v_cursor_type;      
          insert into TEMPCHARTVALUES(HOP,AMOUNT,EFFECTIVE_FROM,EFFECTIVE_TO,CURRENCY)
               values (v_cursor_type.PMC1_HOP_CODE,
                     v_cursor_type.PMC1_Amount,
                     v_cursor_type.PMC1_EFFECTIVE_FROM,
                     v_cursor_type.PMC1_EFFECTIVE_UPTO,
                     v_cursor_type.PMC1_CURRENCY);
                                                       --dbms_output.put_line(v_cursor_type.KEYCODE1);
          EXIT WHEN p_cursor%ROWCOUNT = v_REC_COUNT;
          end loop;

Hi, here it is..
create or replace
procedure  prm_sp_charts_db (P_CURSOR OUT SYS_REFCURSOR,CHARTCode VARCHAR,tablename varchar)
IS
v_COUNT varchar2(200);
v_REC_COUNT NUMBER;
V_SQLSTATEMENT VARCHAR2(2000);
v_cursor_type  TEMPCHARTVALUES%ROWTYPE;
    begin
     v_COUNT:='SELECT COUNT(*) FROM PRM_M_Chart_' || CHARTCode;
     execute immediate v_COUNT into v_REC_COUNT;
     V_SQLSTATEMENT := 'SELECT ';
     V_SQLSTATEMENT := V_SQLSTATEMENT || 'PMC' || CHARTCode || '_F1_CODE Keycode1,';
      open  P_CURSOR for select column_name from  user_tab_columns where table_name=tablename and column_name='PMC' || CHARTCode || '_F2_CODE';
      IF P_CURSOR%FOUND then
      V_SQLSTATEMENT := V_SQLSTATEMENT || 'PMC' || CHARTCode || '_F2_CODE Keycode2,';
      else
      V_SQLSTATEMENT := V_SQLSTATEMENT || '0,';
      END IF;
      open  P_CURSOR for select column_name from  user_tab_columns where table_name=tablename and column_name='PMC' || CHARTCode || '_F3_CODE';
      IF P_CURSOR%FOUND then
      V_SQLSTATEMENT := V_SQLSTATEMENT || 'PMC' || CHARTCode || '_F3_CODE Keycode3,';
      else
      V_SQLSTATEMENT := V_SQLSTATEMENT || '0,';
      END IF;
       open  P_CURSOR for select column_name from  user_tab_columns where table_name=tablename and column_name='PMC' || CHARTCode || '_F4_CODE';
      IF P_CURSOR%FOUND then
      V_SQLSTATEMENT := V_SQLSTATEMENT || 'PMC' || CHARTCode || '_F4_CODE Keycode4,';
      else
      V_SQLSTATEMENT := V_SQLSTATEMENT || '0,';
      END IF;
      open  P_CURSOR for select column_name from  user_tab_columns where table_name=tablename and column_name='PMC' || CHARTCode || '_F5_CODE';
      IF P_CURSOR%FOUND then
      V_SQLSTATEMENT := V_SQLSTATEMENT || 'PMC' || CHARTCode || '_F5_CODE Keycode5,';
      else
      V_SQLSTATEMENT := V_SQLSTATEMENT || '0,';
      END IF;
      --open  P_CURSOR for select column_name from  user_tab_columns where table_name=tablename and column_name='PMC' || CHARTCode || '_F6_CODE';
      IF P_CURSOR%FOUND then
      V_SQLSTATEMENT := V_SQLSTATEMENT || 'PMC' || CHARTCode || '_F6_CODE Keycode6,';
      else
      V_SQLSTATEMENT := V_SQLSTATEMENT || '0,';
      END IF;
      --open  P_CURSOR for select column_name from  user_tab_columns where table_name=tablename and column_name='PMC' || CHARTCode || '_F7_CODE';
      IF P_CURSOR%FOUND then
      V_SQLSTATEMENT := V_SQLSTATEMENT || 'PMC' || CHARTCode || '_F7_CODE Keycode7,';
      else
      V_SQLSTATEMENT := V_SQLSTATEMENT || '0,';
      END IF;
      --open  P_CURSOR for select column_name from  user_tab_columns where table_name=tablename and column_name='PMC' || CHARTCode || '_F8_CODE';
      IF P_CURSOR%FOUND then
      V_SQLSTATEMENT := V_SQLSTATEMENT || 'PMC' || CHARTCode || '_F8_CODE Keycode8,';
      else
      V_SQLSTATEMENT := V_SQLSTATEMENT || '0,';
      END IF;
      --open  P_CURSOR for select column_name from  user_tab_columns where table_name=tablename and column_name='PMC' || CHARTCode || '_F9_CODE';
      IF P_CURSOR%FOUND then
      V_SQLSTATEMENT := V_SQLSTATEMENT || 'PMC' || CHARTCode || '_F9_CODE Keycode9,';
      else
      V_SQLSTATEMENT := V_SQLSTATEMENT || '0,';
      END IF;
      --open  P_CURSOR for select column_name from  user_tab_columns where table_name=tablename and column_name='PMC' || CHARTCode || '_F10_CODE';
      IF P_CURSOR%FOUND then
      V_SQLSTATEMENT := V_SQLSTATEMENT || 'PMC' || CHARTCode || '_F10_CODE Keycode10,';
      else
      V_SQLSTATEMENT := V_SQLSTATEMENT || '0,';
      END IF;
      V_SQLSTATEMENT := V_SQLSTATEMENT ||'PMC' || CHARTCode || '_HOP_CODE HOPCode,PMC' || CHARTCode || '_AMOUNT ,PMC'|| CHARTCode || '_EFFECTIVE_FROM Effective_From,PMC' || CHARTCode || '_EFFECTIVE_UPTO Effective_Upto,PMC' || CHARTCode || '_CURRENCY Currency FROM PRM_M_CHART_' || CHARTCode ;
      DBMS_OUTPUT.PUT_LINE(V_SQLSTATEMENT);
       OPEN  p_cursor for V_SQLSTATEMENT;
        ---for i in p_cursor
        LOOP
          FETCH p_cursor INTO v_cursor_type;      
          insert into TEMPCHARTVALUES(HOP,AMOUNT,EFFECTIVE_FROM,EFFECTIVE_TO,CURRENCY)
               values (v_cursor_type.PMC1_HOP_CODE,
                     v_cursor_type.PMC1_Amount,
                     v_cursor_type.PMC1_EFFECTIVE_FROM,
                     v_cursor_type.PMC1_EFFECTIVE_UPTO,
                     v_cursor_type.PMC1_CURRENCY);
                                                       --dbms_output.put_line(v_cursor_type.KEYCODE1);
          EXIT WHEN p_cursor%ROWCOUNT = v_REC_COUNT;
          end loop;
end prm_sp_charts_db;

Similar Messages

  • How to insert values from different region into one table

    Hi everyone
    I have created a page which contains 4 html regions like region1,region 2 ...region 4
    in region 1 i created 2 text items like (emp_name,emp_id).
    in region 2 i created 2 date fields (start_date,end_date).
    In region3 i created a tabular form which contains(job , hire_date).
    in region 4 i created a textfield (%of Hike)
    So i want to create a button(submit) .when i press the button it will insert all the informations provided by the user in different regions will be inserted to a table called employee_information.
    Can i do this?
    If it is possible please tell me how to do this
    if not then tell me any alternative solution.
    Thanks,
    Regards,
    Sabyasachi

    Sabyasachi wrote:
    Hi fac586
    Can you please tell me step by step how to do it or can you please make an example in apex.oracle.com and give me the credentials so that i can know clarify my doubts.1. Create a Form using a Wizard. This will create the items and processes necessary to retrieve data from, and perform DML on, the table. The items will be contained in a single default region.
    2. Create custom HTML regions on page.
    3. Move items and buttons from the default region created by the Form Wizard by changing the Region value in the "Displayed" section of the item attributes page, or Page Items page; or reassign items to regions using the Reassign Region Items page.

  • How can I insert values from table object into a regular table

    I have a table named "ITEM", an object "T_ITEM_OBJ", a table object "ITEM_TBL" and a stored procedure as below.
    CREATE TABLE ITEM
    ITEMID VARCHAR2(10) NOT NULL,
    PRODUCTID VARCHAR2(10) NOT NULL,
    LISTPRICE NUMBER(10,2),
    UNITCOST NUMBER(10,2),
    SUPPLIER INTEGER,
    STATUS VARCHAR2(2),
    ATTR1 VARCHAR2(80),
    ATTR2 VARCHAR2(80),
    ATTR3 VARCHAR2(80),
    ATTR4 VARCHAR2(80),
    ATTR5 VARCHAR2(80)
    TYPE T_ITEM_OBJ AS OBJECT
    ITEMID VARCHAR2(10),
    PRODUCTID VARCHAR2(10),
    LISTPRICE NUMBER(10,2),
    UNITCOST NUMBER(10,2),
    SUPPLIER INTEGER,
    STATUS VARCHAR2(2),
    ATTR1 VARCHAR2(80),
    ATTR2 VARCHAR2(80),
    ATTR3 VARCHAR2(80),
    ATTR4 VARCHAR2(80),
    ATTR5 VARCHAR2(80)
    TYPE ITEM_TBL AS TABLE OF T_ITEM_OBJ;
    PROCEDURE InsertItemByObj(p_item_tbl IN ITEM_TBL, p_Count OUT PLS_INTEGER);
    When I pass values from my java code through JDBC to this store procedure, how can I insert values from the "p_item_tbl" table object into ITEM table?
    In the stored procedure, I wrote the code as below but it doesn't work at all even I can see values if I use something like p_item_tbl(1).itemid. How can I fix the problem?
    INSERT INTO ITEM
    ITEMID,
    PRODUCTID,
    LISTPRICE,
    UNITCOST,
    STATUS,
    SUPPLIER,
    ATTR1
    ) SELECT ITEMID, PRODUCTID, LISTPRICE,
    UNITCOST, STATUS, SUPPLIER, ATTR1
    FROM TABLE( CAST(p_item_tbl AS ITEM_TBL) ) it
    WHERE it.ITEMID != NULL;
    COMMIT;
    Also, how can I count the number of objects in the table object p_item_tbl? and how can I use whole-loop or for-loop to retrieve values from the table object?
    Thanks.

    Sigh. I answered this in your other How can I convert table object into table record format?.
    Please do not open multiple threads. It just confuses people and makes the trreads hard to follow. Also, please remember we are not Oracle employees, we are all volunteers here. We answer questions if we can, when we can. There is no SLA so please be patient.
    Thank you for your future co-operation.
    Cheers, APC

  • While inserting values from a xml file into the database.

    Dear Forum Members,
    While using Samp10.java (given in XSU!2_ver1_2_1/oracleXSU12/Sample)for inserting values from xml file Sampdoc.xml into database table xmltest_tab1,the error shown below appears on the DOS prompt.
    The code for sam10 is:
    import oracle.xml.sql.dml.*;
    import java.sql.*;
    import oracle.jdbc.driver.*;
    import oracle.jdbc.*;
    import java.net.*;
    public class samp10
    public static void main(String args[]) throws SQLException
    String tabName = "xmltest_tab1";
    String fileName = "sampdoc.xml";
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn=DriverManager.getConnection("jdbc:odbc:BookingSealinerScott","scott","tiger");
    OracleXMLSave sav = new OracleXMLSave(conn, tabName);
    URL url = sav.createURL(fileName);
    int rowCount = sav.insertXML(url);
    System.out.println(" successfully inserted "+rowCount+
    " rows into "+ tabName);
    conn.close();
    }catch (Exception e){e.printStackTrace();}
    The Structure of Sampdoc.xml is:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW num="1">
    <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAME>
    <JOB>CLERK</JOB>
    </ROW>
    <ROW num="2">
    <EMPNO>7499</EMPNO>
    <ENAME>ALLEN</ENAME>
    <JOB>SALESMAN</JOB>
    </ROW>
    <ROW num="3">
    <EMPNO>7521</EMPNO>
    <ENAME>WARD</ENAME>
    <JOB>SALESMAN</JOB>
    </ROW>
    </ROWSET>
    Description of table xmltest_tab1 is:
    SQL> desc xmltest_tab1;
    Name Null? Type
    EMPNO NUMBER(4)
    ENAME CHAR(10)
    JOB VARCHAR2(9)
    Error Displayed is:
    A nonfatal internal JIT (3.00.078(x)) error 'Structured Exception(c0000005)' has
    occurred in :
    'oracle/xml/sql/dml/OracleXMLSave.cleanLobList ()V': Interpreting method.
    Please report this error in detail to http://java.sun.com/cgi-bin/bugreport.cgi
    oracle.xml.sql.OracleXMLSQLException: sun.jdbc.odbc.JdbcOdbcConnection
    at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:1967)
    at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:1880)
    at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1013)
    at samp10.main(samp10.java:36)
    Press any key to continue . . .
    Please send me the solution as soon as possible.
    Thanks,
    Waiting for your Reply,
    Bye,
    Vineet Choudhary
    Email id: [email protected]
    null

    Go and read about JDBC. You need to know some basics before asking such a st&*id questions.
    Paul

  • Copying value from one cursor to another

    Hi,
    I have a problem while copying values from one cursor to another cursor.
    The code looks like below.
    PROCEDURE XYZ
                TransactionResultSet OUT NOCOPY types.ref_cursor,
    IS
                temp_cursor types.ref_cursor;
                wip_rec types.ref_cursor;
    BEGIN
    DECLARE
                    CURSOR temp_cursor IS
                SELECT ...........
    END;
    BEGIN     
        FOR wip_rec IN temp_cursor
        LOOP
        update tinsagr set something
        where {the condition}
            IF SQL%ROWCOUNT = 0 THEN
      dbms_output.put_line('this is test ');
            Fetch wip_rec into TransactionResultSet;
         END IF;
       END LOOP;so basically i want to iterate the "temp_cursor" and depending on the values i get it from here i shall update a table. Actually i want to exclude few records from "temp_cursor" and add it/copy rest of the records to "TransactionResultSet"
    That means say initially " temp_cursor" has 100 records and i updated 5 records in a table and same number of records should be excluded and rest should be added to the output cursor TransactionResultSet.
    How do i achieve it?
    while saving i am getting
    (1): PLS-00456: item 'WIP_REC' is not a cursor.
    Do any one has any idea what to do in such scenario?

    There are options like....
    SQL> CREATE OR REPLACE TYPE emp_obj AS OBJECT (ename VARCHAR2(50), dept NUMBER);
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_tbl IS TABLE OF emp_obj;
      2  /
    Type created.
    SQL> set serverou on
    SP2-0158: unknown SET option "serverou"
    SQL> set serverout on
    SQL> DECLARE
      2    rc      sys_refcursor;
      3    v_ename emp.ename%TYPE;
      4    v_dept  emp.deptno%TYPE;
      5    ---End Of Local Varriable Declaration
      6    --Procedire declaration !
      7    PROCEDURE TEST_CUR(pi_out_ref_cur IN OUT sys_refcursor) IS
      8      emp_rec emp_tbl;
      9    BEGIN
    10      /* This BULK COLLECT can be done with explicit cursor,Ref Cursor
    11      with some simple modification, Here I have used implicit cursor! */
    12      SELECT emp_obj(ename, deptno) --Casting as the object
    13      BULK COLLECT
    14        INTO emp_rec
    15        FROM emp
    16       WHERE deptno = 10;
    17   
    18      dbms_output.put_line('Records selected are:');
    19      FOR i in 1 .. emp_rec.COUNT LOOP
    20        dbms_output.put_line(emp_rec(i).ename || '--' || emp_rec(i).dept);
    21      END LOOP;
    22      --Now we are filtering the record and may be doing some operation with each record.
    23      FOR i in 1 .. emp_rec.COUNT LOOP
    24        IF emp_rec(i).ename = 'KING' THEN
    25          --You can change this IF according to your need.
    26          emp_rec.DELETE(i);
    27        END IF;
    28      END LOOP;
    29      OPEN pi_out_ref_cur FOR
    30        SELECT * FROM TABLE(emp_rec); --Using the TYPE AS table.
    31    END TEST_CUR;
    32    /* Main execution or procedure calling section*/
    33  BEGIN
    34    --Actual calling
    35    TEST_CUR(rc);
    36    dbms_output.new_line;
    37    dbms_output.put_line('Now in Ref Cursor');
    38    dbms_output.put_line('****************');
    39    LOOP
    40      FETCH rc
    41        INTO v_ename, v_dept;
    42      dbms_output.put_line(v_ename || '--' || v_dept);
    43      EXIT WHEN rc%NOTFOUND;
    44    END LOOP;
    45 
    46  END;
    47  /
    Records selected are:
    CLARK--10
    KING--10
    MILLER--10
    Now in Ref Cursor
    CLARK--10
    MILLER--10
    MILLER--10
    PL/SQL procedure successfully completed.
    SQL>

  • How to retrieve the max value from a cursor in procedure

    Hi,
    In a procedure, I defined a cursor:
    cursor c_emp is select empno, ename, salary from emp where ename like 'J%';
    but in the body part, I need to retrieve the max(salary) from the cursor.
    could you please tell me how I can get the max value from the cursor in the procedure.
    Thanks,
    Paul

    Here is one sample but you should just get the max directly. Using bulk processing should be a last resort.
    DECLARE
      CURSOR c1 IS (SELECT * FROM emp where sal is not null);
      TYPE typ_tbl IS TABLE OF c1%rowtype;
      v typ_tbl;
      max_sal number;
    BEGIN
      OPEN c1;
      max_sal := -9999999999999;
      LOOP                                                 --Loop added
        FETCH c1 BULK COLLECT INTO v LIMIT 3; -- process 3 records at a time
            -- process the records
           DBMS_OUTPUT.PUT_LINE('Processing ' || v.COUNT || ' records.');
            FOR i IN v.first..v.last LOOP
                 if v(i).sal > max_sal then
                   max_sal := v(i).sal;
                 end if;
                DBMS_OUTPUT.PUT_LINE(v(i).empno);
            END LOOP; 
        EXIT WHEN c1%NOTFOUND;
      END LOOP;
      DBMS_OUTPUT.PUT_LINE('Max salary was: ' || max_sal);
    END;
    Processing 3 records.
    7369
    7499
    7521
    Processing 3 records.
    7566
    7654
    7698
    Processing 3 records.
    7782
    7788
    7839
    Processing 3 records.
    7844
    7876
    7900
    Processing 2 records.
    7902
    7934
    Max salary was: 5000

  • Inserting data from jsp form to multiple tables !

    Hi,
    I want to insert data from jsp form to two tables
    tables are
    (1) Form
    formId (PK)
    deptName
    (2) Data
    formId (FK)
    sNo
    description
    itemCode
    and the problem is that i want to save information form a jsp form to above two tables and i have only one form.
    so how do i insert data from a jsp form to multiple tables.

    You already know what your form in the jsp will be and what fields they are. You also already know what your database looks like. Using one form, you should be able to break the data down, and give it certain ids and/or names, so that when the form is submitted, you retrieve the correct values corresponding to a specific field and insert it.
    Unless there is something else I am not catching, this seems pretty straight forward.

  • *Urgent*How to insert data from MS SQL to the table that create at the adobe form?

    Hi,
    I'm using Adobe life cycle designer 8 to do my interactive form. I would like to ask how to insert data from MS SQL to the table that i have created in my adobe interactive form?
    I really need the information ASAP as i need to hand in my project by next week... i really appreciate any one who reply this post.
    Thanks

    Tou need to do a couple of things
    1. On the Essbase server, set up an odbc system connection to your MySQL database
    2. In the load rule , go to the file menu and select open SQL data source and in the data source put in your SQL statement . A couple of hints. Where it says Select, don't put in the word select and where it say from don't put in from. The system adds them for you. The easiest way ti enter a SQL statement is to do it all in the select area So if your SQL would normanlly say select * from mytable just enter the code as * from mytable in the select area
    The click ol/retrieve and enter in your connection info. Itshould bring data back into the load rule. Save the load rule and use it

  • Insert records from report program into R3 table

    Hi
    I wanted to insert records from report program into R3 table.
    here is my code
    data : itab type standard table of zemp initial size 10 with header line.
    itab-EMPNO = '012'.
    itab-ENAME = 'XXXX'.
    itab-JOB = 'XXXX'.
    APPEND itab.
    insert ztable from table itab.
    but i am getting the following error
    the type of the data base table and work area/internal table "ITAB" are no unicode-converible.
    how can I insert records from report program into R3 table
    should I have to write move corresponding
    pls guide
    thanks
    manian

    Hi,
    itab-EMPNO = '012'.
    itab-ENAME = 'XXXX'.
    itab-JOB = 'XXXX'.
    APPEND itab.
    insert ztable from table itab.
    Do one thing
    Data : itab type table of ztable with header line.
    itab-EMPNO = '012'.
    itab-ENAME = 'XXXX'.
    itab-JOB = 'XXXX'.
    APPEND itab.
    insert ztable from table itab.
    error will resolve, then try to make structure similar to ZTABLE

  • How to pick max value from a column of a table using cursor and iteration

    Hello Everybody
    I have a table loan_detail
    and a column in it loan_amount
    now i want to pick values from this table using cursor and then by using iteration i want to pick max value from it using that cursor
    here is my table
    LOAN_AMOUNT
    100
    200
    300
    400
    500
    5600
    700i was able to do it using simple loop concepts but when i was trying to do this by using cursor i was not able to do it .
    Regards
    Peeyush

    SQL> SELECT MAX(sal) Highest_Sal,MIN(sal) Lowest_Sal FROM emp;
    HIGHEST_SAL LOWEST_SAL
           5000        800
    SQL> set serverout on
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := counter;
    10      counter := counter + 1;
    11    END LOOP;
    12    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    13    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    14  END;
    15  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Even smaller
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := 1;
    10    END LOOP;
    11    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    12    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    13  END;
    14  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Edited by: Saubhik on Jan 5, 2011 4:41 PM

  • Logic for inserting values from Pl/sql table

    Hi I'm using Forms 6i and db 10.2.0.1.0
    I am reading an xml file using text_io, and extracting the contents to Pl/sql table.
    Suppose, the xml
    <?xml version="1.0" encoding="UTF-8" ?>
      <XML>
      <File name="S2_240463.201002170044.Z">
      <BookingEnvelope>
      <SenderID>KNPROD</SenderID>
      <ReceiverID>NVOCC</ReceiverID>
      <Password>TradingPartners</Password>
      </BookingEnvelope>
    </File>
    </XML>From this xml, i'm extracting contents to a table of records, say bk_arr, which look like
    Tag                             Val
    File name                     S2_240463.201002170044.Z
    SenderID                     KNPROD
    ReceiverID                   NVOCC
    Password                     TradingPartnersAnd now from this i've to insert into table, say bk_det .
    The tag may come in different order, sometimes some additional tags may also come in between,
    So i cannot access it sequentially and insert like
    Insert into bk_det(file,sndr,rcvr,pswd) values(bk_arr(1).val,bk_arr(2).val....)
    The tag name is constant ir for sender id, it will always be SenderID , not something like sndrid or sndid etc..
    So if i've to insert to senderid column, then i've to match the tag = SenderID, and take the value at that index in the array.
    How best i can do this?
    Thanks

    I am referring to how you are parsing the XML - as you can extract values from the XML by element name. And as the name is known, it's associated value can be inserted easily.
    Basic example:
    SQL> with XML_DATA as(
      2          select
      3                  xmltype(
      4  '<?xml version="1.0" encoding="UTF-8" ?>
      5  <XML>
      6          <File name="S2_240463.201002170044.Z">
      7                  <BookingEnvelope>
      8                          <SenderID>KNPROD</SenderID>
      9                          <ReceiverID>NVOCC</ReceiverID>
    10                          <Password>TradingPartners</Password>
    11                  </BookingEnvelope>
    12          </File>
    13  </XML>'         )       as XML_DOM
    14          from    dual
    15  )
    16  select
    17          extractValue( xml_dom, '/XML/File/@name' )                      as FILENAME,
    18          extractValue( xml_dom, '/XML/File/BookingEnvelope/SenderID' )   as SENDER_ID,
    19          extractValue( xml_dom, '/XML/File/BookingEnvelope/ReceiverID' ) as RECEIVER_ID,
    20          extractValue( xml_dom, '/XML/File/BookingEnvelope/Password' )   as PASSWORD
    21  from       xml_data
    22  /
    FILENAME                  SENDER_ID  RECEIVER_I PASSWORD
    S2_240463.201002170044.Z  KNPROD     NVOCC      TradingPartners
    SQL> Now this approach can be used as follows:
      create or replace procedure AddFile( xml varchar2 ) is
    begin
            insert into foo_files(
                    filename,
                    sender_id,
                    receiver_id,
                    password
            with XML_DATA as(
                    select
                            xmltype( xml ) as XML_DOM
                    from    dual
            select
                    extractValue( xml_dom, '/XML/File/@name' ),
                    extractValue( xml_dom, '/XML/File/BookingEnvelope/SenderID' ),
                    extractValue( xml_dom, '/XML/File/BookingEnvelope/ReceiverID' ),
                    extractValue( xml_dom, '/XML/File/BookingEnvelope/Password' )
            from    xml_data;
    end;
    /No need for a fantasy called PL/SQL "+tables+".

  • Can't insert recors fetched by cursor in the table

    HI
    i am fetching records from my table total_budget.All the fetched records are displayed in a tabular data block(data block name is forecast_result).Now i want to insert these record fetched by cursor in my table forecast_resul which is empty.how can i do it.I am sending the code if any one can help............
    When i execute this code it give me error unable to insert(FRM-40508) .I have carefully checked table columns names and their data types.All r fine but i dont know y it is not working.Here is the code
    DECLARE
    cursor c1 IS
    SELECT ministry_id,fiscal_year ,t_amount
    FROM total_budget
    WHERE ministry_id=:global.var11 AND (fiscal_year BETWEEN :syear and :eyear);
    BEGIN
    T_XSUMX := 0;
         OPEN C1;
         X:=1;
         SUMX := 0; SUMY := 0; SUMXY:=0; SUMX2 := 0;
         go_block('forecast_result');
         first_record;
         LOOP
              FETCH C1 INTO Y1,Y2,Y;
              EXIT WHEN C1%NOTFOUND;
              SUMY := SUMY +Y;
              XY := X*Y;
              X2 := X*X;
              SUMX := SUMX + X;
    SUMXY := SUMXY + XY;
              SUMX2 := SUMX2 + X2;
                   :forecast_result.ministry_id:=Y1;
                   :forecast_result.fiscal_year:=Y2;
              :forecast_result.t_amount:=Y;
         NEXT_RECORD;
              X := X + 1;
         END LOOP;
         close C1;
    z:=X-2;
         X_BAR := z;
         X := z+1;
         T_XSUMX := X * SUMX;
         T_SUMY := SUMY * SUMX;
         T_SUMX := SUMX * SUMX;
         T_SUMXY := SUMXY * X;
         T_SUMX2 := SUMX2 * X;
         R1 := T_SUMY - T_SUMXY;
         R2 := T_SUMX - T_SUMX2;
         B := ROUND(R1/R2,1);
         A := ROUND((T_SUMXY -(T_SUMX2*B))/T_XSUMX,1);
         Y_BAR := A+(B*X_BAR);
    :forecast_result.ministry_id:=Y1;
    :forecast_result.fiscal_year:=Y2;
    :forecast_result.t_amount:=Y_BAR;
    next_record;
         insert into forecast_result
         values(:forecast_result.ministry_id,:forecast_result.fiscal_year,:forecast_result.t_amount);
         commit;
    END;
    Can anyone tell me wat i am doing wrong
    looking for instant reply
    nida

    Hi alma,
    Plz u dnt wrt babytalk rr SMS-language -> mi! Becoz mi don lejk dat.
    I suppose that your data block "forecast_result" are based on the table of the same name. Otherwise this may be the cause of some of your trouble.
    Your code would properly work better like this:
    DECLARE
      X NUMBER(38);
      SUMX NUMBER(38);
      SUMY NUMBER(38);
      Y NUMBER(38) ;
      Y1 varchar2(10);
      Y2 varchar2(10);
      X2 NUMBER(38);
      XY NUMBER(38);
      SUMXY NUMBER(38);
      SUMX2 NUMBER(38);
      X_BAR NUMBER(38);
      Y_BAR NUMBER(38);
      T_SUMY NUMBER(38);
      T_SUMX NUMBER(38);
      T_SUMXY NUMBER(38);
      T_SUMX2 NUMBER(38);
      T_XSUMX NUMBER(38);
      R1 NUMBER(38);
      R2 NUMBER(38);
      A NUMBER(38);
      z number(38);
      B NUMBER(38);
      final number(38);
      -- Just curious, where does :syear and :eyear come from ??
      cursor c1 IS
       SELECT ministry_id, fiscal_year, t_amount
        FROM total_budget
       WHERE ministry_id=:global.var11
         AND (fiscal_year BETWEEN :syear and :eyear);
    BEGIN
      T_XSUMX := 0;
      X:=1;
      SUMX := 0;
      SUMY := 0;
      SUMXY:=0;
      SUMX2 := 0;
      go_block('forecast_result');
      -- If you're making this dynamically, then clear the block to start with.
      clear_block(NO_COMMIT);
      first_record;
      OPEN C1;
      LOOP
        FETCH C1 INTO Y1, Y2, Y;
        EXIT WHEN C1%NOTFOUND;
        SUMY := SUMY + Y;
        XY := X*Y;
        X2 := X*X;
        SUMX := SUMX + X;
        SUMXY := SUMXY + XY;
        SUMX2 := SUMX2 + X2;
        :forecast_result.ministry_id := Y1;
        :forecast_result.fiscal_year := Y2;
        :forecast_result.t_amount := Y;
        -- NO, this will not work. You have to CREATE the record. You only get the
        -- first record for "free". Next_Record moves to allready existing records.
        -- NEXT_RECORD;
        Create_Record;
        X := X + 1;
      END LOOP;
      close C1;
      z := X - 2;
      X_BAR := z;
      X := z + 1;
      T_XSUMX := X * SUMX;
      T_SUMY := SUMY * SUMX;
      T_SUMX := SUMX * SUMX;
      T_SUMXY := SUMXY * X;
      T_SUMX2 := SUMX2 * X;
      R1 := T_SUMY - T_SUMXY;
      R2 := T_SUMX - T_SUMX2;
      B := ROUND(R1/R2,1);
      A := ROUND((T_SUMXY -(T_SUMX2*B))/T_XSUMX,1);
      Y_BAR := A+(B*X_BAR);
      -- What are you doing here ?? This is weird. The population of the records are done in
      -- the loop ! You don't have to add anything here.
      -- :forecast_result.ministry_id:=Y1;
      -- :forecast_result.fiscal_year:=Y2;
      -- :forecast_result.t_amount:=Y_BAR;
      -- Since your data block (hopefully) are based on the table of the same name, you DON'T
      -- need to do this. You just have to press the commit button (or F10 or the floppy disk
      -- icon or what-ever).
      -- insert into forecast_result
      -- values(:forecast_result.ministry_id,:forecast_result.fiscal_year,:forecast_result.t_amount);
      -- commit;
    END;

  • PL/SQL 10g - Cannot Insert Values from PL/SQL

    Hi People,
    BACKGROUND (if required):
    I'm trying to write a message threading algorithm for uni, I believe it works so far, it's just matching the subjects at the moment I want to expand it to include email addresses but that will be at a later date.
    A brief run down, at the moment, a user can generate a list of email addresses to filter the corpus with, these are then inserted (via Java) into the table Sender. These addresses are then used in an IF statement, however they are only used if the table sender is populated. The messges that are identified as threads have their Message ID inserted into another table but they also have their values printed to the DBMS output.
    QUESTION:
    What I need help with is although the values print out to the DBMS Output after a great deal of time, normally after the DBMS buffer has maxed out (thus the statement ends in error). The values printed are not inserted into the table.
    Any help on solving this or optimising if would be greatly appreciated, I'm new to PL/SQL i'm afraid so it's probably a really messy statement.
    If this is a badly worded question and I need to supply more information then I gladly will, however i'm not 100% on what information is relevant at the moment.
    Below is the statement in question.
    Thanks and Regards,
    K
    LOOP
    IF sender_cur1%FOUND THEN
    IF sub_One = Sub_two and sub_One_MID != sub_Two_MID and Sub_One_Sender = send_user_cur THEN
    INSERT INTO MATCHING_SUB (MID) VALUES (sub_Two_MID);
    dbms_output.put_line('MID is: ' || sub_Two_MID);
    END IF;
    ELSE
    IF sub_One = Sub_two and sub_One_MID != sub_Two_MID THEN
    INSERT INTO MATCHING_SUB (MID) VALUES (sub_Two_MID);
    dbms_output.put_line('MID is: ' || sub_Two_MID);
    END IF;
    END IF;
    Edited by: user8967525 on 01-Mar-2010 07:27
    Edited by: user8967525 on 01-Mar-2010 08:08

    cd,
    I will most certainly try.
    I have a table of emails that I am attempting to thread by means of comparing the subjects together (for now). However ultimately I want to be able to bring in the recipients as well. However this can be ignored for now.
    The main variables from the Messages table are:
    MID(number) - 0 - 245000
    SENDER(VARCHAR) - Email Address
    SUBJECT_CLN6 - VARCAHR - Cleaned email subject.
    I am creating two instancs of a cursor that contains the subjects and MID's from Messages. I am then looping through cur1 comparing the value against all values in cur2, this continues until all values in cur1 have been compared against cur2. I use the MID to ensure that I am not comparing the same Message. Furthermore I am also filtering the Emails by Sender (if the table has been populated by the user, via a java applet, otherwise if just uses the subject). The variable Send_User_Cur takes takes its values from the Table called Sender, whilst sub_one_sender takes its values from the column Sender in Messages.
    The proposed output of this at the moment is to just have the MID's (and later all the relevant columns, however just for now MID) of all the threaded emails, inserted into the table MATCH_THREAD, such that they can be called upon later for further processing and most likely called from a java applet at some point as well.
    I've pasted the entire code below. I understand that it looks a bit messy on the preview and for that I apologise.
    Thanks all!
    Kev
    DECLARE
    CURSOR sub_cur1 IS
    SELECT MID, Sender, trim(subject_cln6) from MESSAGES;
    sub_One MESSAGES.subject_cln6%TYPE;
    sub_One_MID MESSAGES.MID%type;
    sub_One_Sender MESSAGES.SENDER%type;
    CURSOR sub_cur2 IS
    SELECT MID, trim(subject_cln6) from Messages;
    sub_Two MESSAGES.subject_cln6%TYPE;
    sub_Two_MID MESSAGES.MID%type;
    CURSOR sender_cur1 IS
    SELECT SENDER_ID FROM SENDER;
    Send_User_Cur SENDER.SENDER_ID%type;
    counter number := 0;
    MID_t MESSAGES.MID%TYPE;
    i number := 0;
    j number := 0;
    BEGIN
    SELECT count(subject) INTO counter
    FROM MESSAGES;
    OPEN sub_cur1;
    OPEN sub_cur2;
    OPEN sender_cur1;
    FETCH sub_cur1 INTO sub_One_MID, Sub_One_Sender, Sub_One;
    FETCH sender_cur1 INTO Send_User_Cur;
    WHILE sub_cur1%FOUND
    LOOP
    IF sub_cur2%ISOPEN THEN
    FETCH sub_cur2 INTO sub_Two_MID, SUB_Two;
    dbms_output.put_line('OPEN');
    ELSE
    OPEN sub_cur2;
    FETCH sub_cur2 INTO sub_Two_MID, SUB_Two;
    --dbms_output.put_line('OPENED and FETCHED');
    END IF;
    LOOP
    IF sender_cur1%FOUND THEN
    IF sub_One = Sub_two and sub_One_MID != sub_Two_MID and Sub_One_Sender = send_user_cur THEN
    INSERT INTO MATCH_THREAD (MID) VALUES (sub_Two_MID);
    commit;
    END IF;
    ELSE
    IF sub_One = Sub_two and sub_One_MID != sub_Two_MID THEN
    INSERT INTO MATCH_THREAD (MID) VALUES (sub_Two_MID);
    commit;
    END IF;
    END IF;
    FETCH sub_cur2 INTO sub_Two_MID, SUB_Two;
    i := i + 1;
    EXIT WHEN i = counter;
    END LOOP;
    CLOSE sub_cur2;
    FETCH sub_cur1 INTO sub_One_MID, Sub_One_Sender, SUB_One;
    i := 0;
    dbms_output.put_line('sub_One_MID: ' || sub_one_mid);
    END LOOP;
    CLOSE sub_cur1;
    CLOSE sub_cur2;
    END;

  • Insert values from more than one select query

    Hi all, I've a simple question:
    I need to insert values into a table from two select statements.
    There's what I need to accomplish:
    I need to monitor the cursors opened on a database, so:
    I created the following table:
    O_CURSORS
    Cols: TOTAL (Number 5), USER (VARCHAR2 20), DATE (TIMESTAMP)
    I think some query like the following should work, but unfortunately, it doesn't.
    insert into O_CURSORS (total,user,date)
    values (
    (select a.value, s.username from v$sesstat a, v$statname b, v$session s where a.statistic# = b.statistic#  and s.sid=a.sid and b.name = 'session cursor cache count'),
    (select sysdate from dual)
    )This statement is not working, the message is
    "Not enough values"
    If I modify the statement as follows, it works fine
    insert into O_CURSORS (total,user)
    (select a.value, s.username from v$sesstat a, v$statname b, v$session s where a.statistic# = b.statistic#  and s.sid=a.sid and b.name = 'session cursor cache count'),
    )Any advice would be very appreciated!
    Thanks in advance.

    You don't have to select sysdate from dual; it can be a part of any select statement. Just include sysdate in your first query:
    INSERT INTO O_CURSORS (total,user,date)
    SELECT a.value, s.username, SYSDATE
    FROM v$sesstat a,  v$statname b,   v$session s
    WHERE a.statistic# = b.statistic#
      AND s.sid=a.sid and b.name = 'session cursor cache count'You'll note also that I elimiated the VALUES keyword, and just used a SQL statement to satisfy the INSERT statement.
    Edited by: user13640471 on Feb 21, 2011 1:17 PM
    Edited by: user13640471 on Feb 21, 2011 1:18 PM

  • Insert records from user form to multiple tables in same database

    Hi Experts, I need your help. I have a form that has multiple text fields that I need to insert the records to their each respective table. For example: The first name field needs to go the the name table, address goes to a seperate table, phone goes to a seperate table and so on.
    Is this possible to do?
    Thanks Much
    Sham

    The same for ASP, JSP or PHP.  Just the code syntax is different for each language.  Are you using MySQL, Access or ?
    In any case, create the three recordsets on the database and use insert queries.  If you don't know what one is, google insert query and you will see the syntax. 
    Here is a good example out on the web
    http://www.stardeveloper.com/articles/display.html?article=2000032601&page=1
    In your case you would get the values for the inserts from the form data and only need to open the database connection once.
    Good luck.
    Walt
    B & B Photography

Maybe you are looking for