Inserting values from a PL SQL table to a database table

Hi,
Here is my dilemma.
I have values inserted to a pl sql table which I have gathered from a web page. Now I need to add these same values to a database table. I see the values as 1-'AA', 2='BB' etc.
I use the following code to insert to a outside table in the database and it seems to be crashing.
for i in app_table.first .. app_table.last loop
r_convention(i).priority_country_code:=app_table(i);
insert into test_countries
values (test_seq,tion(i).r_convention(i).priority_country_code);
commit;
end loop;
WHen I run this code I see the values. But it goes to the first value and then crashes and does not go through the
rest of the values. What am I missing here?
Thanks!

Hi,
Why can't you directly insert into the table from the object type....
for i in app_table.first .. app_table.last loop
r_convention(i).priority_country_code:=app_table(i);
insert into test_countries
values (test_seq,app_table(i));
commit;
end loop;Can you give me your complete code, so that we can have a better picture..
Edited by: plsql dev on Sep 10, 2010 10:14 PM

Similar Messages

  • 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

  • Insert and update tables from SQL server to oracle database tables

    Hi,
    I am having problem while update data from sql server to oracle database tables.
    I am doing one way insert +updates that is from SQL Server tables ==> Oracle database tables
    I am using tools Sql server Integration service. I can insert data from sql server to oracle but update can't. Please help me how can I update + insert from sql server to oracle database tables easily.
    Thanks in advance.

    Hi,
    What about using Oracle SQL Developer for migration
    http://www.oracle.com/technetwork/database/migration/sqlserver-095136.html
    HTH

  • 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

  • Pass a value from a PL/SQL function to a javascript (html header) ? ?

    Hey Guys,
    Have a question regarding how to pass a value from a PL/SQL function to a javascript in the HTML Header.
    I have created a PL/SQL function in my database, which does looping.
    The reason for this is:  On my apex page when the user selects a code, it should display(or highlight buttons) the different project id's present for that particular code.
    example= code 1
    has project id's = 5, 6, 7
    code 2
    has project id's = 7,8
    Thank you for your Help or Suggestions
    Jesh
    The PL/SQL function :
    CREATE OR REPLACE FUNCTION contact_details(ACT_CODE1 IN NUMBER) RETURN VARCHAR2 IS
    Project_codes varchar2(10);
    CURSOR contact_cur IS
    SELECT ACT_CODE,PROJECT_ID
    FROM ACTASQ.ASQ_CONTACT where ACT_CODE = ACT_CODE1;
    currec contact_cur%rowtype;
    NAME: contact_details
    PURPOSE:
    REVISIONS:
    Ver Date Author Description
    1.0 6/25/2009 1. Created this function.
    BEGIN
    FOR currec in contact_cur LOOP
         dbms_output.put_line(currec.PROJECT_ID || '|');
         Project_codes := currec.PROJECT_ID|| '|' ||Project_codes;
    END LOOP;
    RETURN Project_codes;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END contact_details;
    /

    Jesh:
    I have made the following modifications to your app to get it to work as I thing you need it to.
    1) Changed the source for the HTML Buttons Region(note use of id vs name for the Buttons)
    <script>
    function hilitebtn(val) {
    //gray buttons
    $x('graduate').style.backgroundColor='gray'
    $x('distance').style.backgroundColor='gray'
    $x('career').style.backgroundColor='gray'
    $x('photo').style.backgroundColor='gray'
    //AJAX call to get project-ids
    var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=GETPROJECTS',0);
    get.addParam('x01',val)
    gReturn = get.get();
    var arr=gReturn.split(':');  //dump into array
    get = null;
    for (i=0;i<arr.length;i++) {
    // alert('val=' + arr);
    if ( arr[i]==5)
    $x('graduate').style.backgroundColor='red';
    if ( arr[i]==6)
    $x('distance').style.backgroundColor='red';
    if ( arr[i]==7)
    $x('career').style.backgroundColor='red';
    if ( arr[i]==8)
    $x('photo').style.backgroundColor='red';
    </script>
    <table cellpadding='0' cellspacing='0' border='0'>
    <tr><td>
    <input type='button' id='graduate' value='Graduate'>
    </td>
    <td>
    <input type='button' id='distance' value='Distance'>
    </td>
    <td>
    <input type='button' id='career' value='Career/Tech'>
    </td>
    <td>
    <input type='button' id='photo' value='Photos'>
    </td>
    </tr></table>
    2) Defined the application process  GETPROJECTS as DECLARE
    IDS varchar2(1000);
    l_act_code varchar2(100) :=4;
    begin
    IDS:='';
    l_act_code := wwv_flow.g_x01;
    for x in(
    SELECT ACT_CODE,PROJECT_ID
    FROM ASQ_CONTACT
    where ACT_CODE = l_act_code)
    LOOP
    IDS := IDS || X.PROJECT_ID|| ':' ;
    END LOOP;
    HTP.PRN(IDS);
    END;
    3) Changed the 'onchange' event-handler on p1_act_code to be 'onchange=hilitebtn(this.value)'
    4) Added the JS to the HTML Page Footer <script>
    hilitebtn($v('P1_ACT_CODE'));
    </SCRIPT>

  • Inserting Data from Oracle to SQL Server on the Real Time Basis.

    Hi Everyone,
    I need to insert data from Oracle to SQL Server on the Real Time basis, we have to fetch data from oracle approx 20 tables, and each table has more than 30 Fields. I need to fetch data in every 15 mins.
    I have created a job using SQL SERVER Agent by writing insert queries for all the tables with conditions that no rows will be inserted which is already in SQL. note that this job is taking only 1 min to execute.
    But in this way our SQL Server getting hanged and it giving problems to other application running in the SQL SERVER.
    So i m requesting all of you that what is the best way to insert huge amount of data on the real time basis.
    Thanx in Advance.

    1) Create Linked server 
    2) insert data using openquery  and set job in sql agent
    3) run job after 15 minutes

  • How to check  if all values from a dataset  has come to  an internal table

    How to check  if all values from a dataset  has come to  an internal table ?

    Hi,
    After OPEN DATASET statement check if sy-subrc = 0 if its success then proceed with split statement and save the dataset values into a internal table and while debugging the internal table you will find that whether all values get into internal table.
    Checking sy-subrc after OPEN DATASET statement is must to fill up the values in the internal table.
    For e.g.
    OPEN DATASET p_inpfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.
      IF sy-subrc NE 0.
        WRITE :/ 'No such input file' .
        EXIT.
      ELSE.
    READ DATASET p_inpfile INTO loc_string.
          IF sy-subrc NE 0.
            EXIT.
          ELSE.
            CLEAR loc2.
    *Spliting fields in the file-
            REPLACE ALL OCCURRENCES OF '#' IN wa_string WITH ' '.
           SPLIT wa_string AT const INTO loc2-pernr
                                           loc2-werks
                                           loc2-persk 
                                           loc2-vdsk1.
    Hope you get some idea.
    Thanks,
    Sakthi C

  • How to insert data from access to sql server ?

    How to insert data from access to sql server ?
    Please help me
    thanks

    phamtrungkien wrote:
    How to insert data from access to sql server by JAVA?The first four words of my last post:
    masijade wrote:
    JDBC with two connectionsGet a resultset from the jdbc-odbc bridge access connection, cycle through it and add batch insert commands to the jdbc connection to sql server. Give it a try and if the code has an error, then post your code ans ask a question.
    The real question, though, is why you think it absolutely necessary to use Java for this.

  • To replace values of one of the field in the database table

    How to replace values of one of the field in the database table with a new values? Pls help to solve

    Hi
    You can use the UPDATE command to update one of the field value in a table
    see the UPDATE syntax and use it
    but in real time you should not do like this
    Regards
    Anji

  • Error binding table components with database tables

    Hi, when i try to bind table components with database tables y receive this error
    java.lang.NullPointerException
         at com.sun.sql.rowset.CachedRowSetXImpl.initMetaData(CachedRowSetXImpl.java:861)
         at com.sun.sql.rowset.CachedRowSetXImpl.getMetaData(CachedRowSetXImpl.java:2336)
         at com.sun.data.provider.impl.CachedRowSetDataProvider.getMetaData(CachedRowSetDataProvider.java:1317)
         at com.sun.data.provider.impl.CachedRowSetDataProvider.getFieldKeys(CachedRowSetDataProvider.java:489)
         at com.sun.rave.web.ui.component.table.TableRowGroupDesignState.resetTableColumns(TableRowGroupDesignState.java:261)
         at com.sun.rave.web.ui.component.table.TableRowGroupDesignState.setDataProviderBean(TableRowGroupDesignState.java:163)
         at com.sun.rave.web.ui.component.table.TableDesignState.setDataProviderBean(TableDesignState.java:250)
         at com.sun.rave.web.ui.component.TableDesignInfo.linkBeans(TableDesignInfo.java:162)
         at com.sun.rave.insync.models.FacesModel.linkBeans(FacesModel.java:1042)
         at com.sun.rave.designer.DndHandler.processLinks(DndHandler.java:2126)
         at com.sun.rave.designer.DndHandler.importBean(DndHandler.java:880)
         at com.sun.rave.designer.DndHandler.importItem(DndHandler.java:702)
         at com.sun.rave.designer.DndHandler.importDataDelayed(DndHandler.java:376)
         at com.sun.rave.designer.DndHandler.access$000(DndHandler.java:114)
    [catch] at com.sun.rave.designer.DndHandler$1.run(DndHandler.java:298)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

    There are a thing that I don't undertand. When I try to bind samples database table (Travel, for example) to table components, there are no errors. But when I try to bind table component with my remote postgresql database table, yes...the table component disappear and only a "Table" string is displayed....this error is because I use remote database?? Or because it's PostgreSQL??
    Thanks.

  • 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+".

  • 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;

  • 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;

  • 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

  • Inserting data from Oracle to SQL Server 2008

    Hi All,
    I am using oracle 9.2.0.7 and SQL server 2008 in windows server 2003 operating system.
    My requirment is like below.
    1) I would liek to insert data from the Oracle database to SQL Server.
    For the above requirement we have created the ODBC, then configure the listener file, tns file, and created the db link. This part is working fine as I am able to select the data from the SQL Server.
    But when I am inserting the record from the oracle database to the SQL Server I am getting the error, (ORA-00904) Here oracle can not identified the column name.
    My insert statement is like below.
    insert into test@SQLTEST (name, fullname)
    values ('Oracle', 'Oracle server data');
    Test is the SQL server table name and sqltest is the db link name.
    If I am select the data
    select * from test@SQLTEST from Oralce I am getting the data properly.
    Thanks,
    SUN
    Edited by: User SUN@ on Jun 9, 2010 5:49 PM

    Hi,
    I modify the column name as "f_name" and "l_name";
    Still I am getting the same error;
    Thanks,
    SUN

Maybe you are looking for

  • IPad 3G no longer detected by iTunes (Win Vista), only charging when battery V. Low

    This appears to be a software issue: my iPad 3G (32GB) is not detected by iTunes (yet my iPhone is), nor by Windows Vista.  Furthermore, it does not charge from the wall charger until it shuts down in low battery, and only charges to 2%, after which

  • Mail Backup: On My Mac

    Hi I was wondering if there is a way that I can save ON MY MAC section from my Mail? I'm using Lion OS. Thanks

  • Quiz result not showing up in Edge

    Hi there Edgers Really hoping someone can help me out with this problem. I've used Redesigns code(Seen Below) to design a quiz in Animate. I have two problems, when the first question is answered, it skips to the 3rd question instead of the 2nd. I am

  • How to make sure an applet runs with Java 5?

    Hi all, First let me say thanks for all the help in the past. You've help me go from noob to intermediate noob. I've just about finished my first applet game which can be checked out here . Now I've been reading about problems with mac and 1.6. (note

  • Can I remove a CD Rom from one Mac pro and re-install it in another mac pro

    One mac pro, my computer has a CD ROM that doesn't open and my brother's old Mac Pro has a CD ROM that still opens and closes how easy would it be for me to remove the CD ROM from my brother's old Mac Pro and re-install it in my Mac Pro