Inserting rows in PL/SQl table

Hi,
I have a PL/SQl table which i populated through bulk collect and now i am trying to loop through the table (actually quite a few nested loops) ... Now inside one of my loops i might need to insert a new row by splitting field in the existing row in the table. Can I insert the row in the pl/sql table within the loop without affecting the 'FOR i IN tab.first..tab.last' loop ??
Also what would be the index of such a row inserted in the table. Can I access it with tab.last+1 (doesnt look like it can be done if i insert in the various levels of loops).
OR
If I insert the rows insde the nested loops , then I can access the new rows once I close all the loops and open a fresh loop ??. Will the new rows be at the last of the table.
Any help will be appreciated ...

user2309906 wrote:
Hi,
I have a PL/SQl table which i populated through bulk collect and now i am trying to loop through the table (actually quite a few nested loops) ... Now inside one of my loops i might need to insert a new row by splitting field in the existing row in the table. Can I insert the row in the pl/sql table within the loop without affecting the 'FOR i IN tab.first..tab.last' loop ??
Also what would be the index of such a row inserted in the table. Can I access it with tab.last+1 (doesnt look like it can be done if i insert in the various levels of loops).
OR
If I insert the rows insde the nested loops , then I can access the new rows once I close all the loops and open a fresh loop ??. Will the new rows be at the last of the table.
Any help will be appreciated ...With an associative array:
SQL> ed
Wrote file afiedt.buf
  1  declare
  2    type t_arr is table of varchar2(10) index by pls_integer;
  3    v_arr t_arr;
  4    v_cnt number := 0;
  5  begin
  6    -- populate the associative array
  7    for i in (select ename from emp)
  8    loop
  9      v_cnt := v_cnt + 1;
10      dbms_output.put_line('Populating: '||i.ename);
11      v_arr(v_cnt) := i.ename;
12    end loop;
13    -- now process the associative array
14    for i in v_arr.first .. v_arr.last
15    loop
16      dbms_output.put_line('Processing: '||i||':'||v_arr(i));
17      if v_arr(i) IN ('KING','TURNER','JAMES') then
18        v_arr(v_arr.last+1) := v_arr(i)||to_char(i);
19        dbms_output.put_line('Added: '||v_arr.last||':'||v_arr(i));
20      end if;
21    end loop;
22    -- now what's in the associative array?
23    for i in v_arr.first .. v_arr.last
24    loop
25      dbms_output.put_line('Result: '||i||':'||v_arr(i));
26    end loop;
27* end;
SQL> /
Populating: SMITH
Populating: ALLEN
Populating: WARD
Populating: JONES
Populating: MARTIN
Populating: BLAKE
Populating: CLARK
Populating: SCOTT
Populating: KING
Populating: TURNER
Populating: ADAMS
Populating: JAMES
Populating: FORD
Populating: MILLER
Processing: 1:SMITH
Processing: 2:ALLEN
Processing: 3:WARD
Processing: 4:JONES
Processing: 5:MARTIN
Processing: 6:BLAKE
Processing: 7:CLARK
Processing: 8:SCOTT
Processing: 9:KING
Added: 15:KING
Processing: 10:TURNER
Added: 16:TURNER
Processing: 11:ADAMS
Processing: 12:JAMES
Added: 17:JAMES
Processing: 13:FORD
Processing: 14:MILLER
Processing: 15:KING9
Processing: 16:TURNER10
Processing: 17:JAMES12
Result: 1:SMITH
Result: 2:ALLEN
Result: 3:WARD
Result: 4:JONES
Result: 5:MARTIN
Result: 6:BLAKE
Result: 7:CLARK
Result: 8:SCOTT
Result: 9:KING
Result: 10:TURNER
Result: 11:ADAMS
Result: 12:JAMES
Result: 13:FORD
Result: 14:MILLER
Result: 15:KING9
Result: 16:TURNER10
Result: 17:JAMES12
PL/SQL procedure successfully completed.With standard array (PL/SQL table):
SQL> ed
Wrote file afiedt.buf
  1  declare
  2    type t_arr is table of varchar2(10);
  3    v_arr t_arr;
  4    v_cnt number := 0;
  5  begin
  6    -- populate the pl/sql table
  7    select ename bulk collect into v_arr from emp;
  8    -- now process the pl/sql table
  9    for i in v_arr.first .. v_arr.last
10    loop
11      dbms_output.put_line('Processing: '||i||':'||v_arr(i));
12      if v_arr(i) = 'KING' then
13        v_arr.extend;
14        v_arr(v_arr.last) := 'PRESIDENT';
15      end if;
16    end loop;
17    -- now what's in the pl/sql table?
18    for i in v_arr.first .. v_arr.last
19    loop
20      dbms_output.put_line('Result: '||i||':'||v_arr(i));
21    end loop;
22* end;
SQL> /
Processing: 1:SMITH
Processing: 2:ALLEN
Processing: 3:WARD
Processing: 4:JONES
Processing: 5:MARTIN
Processing: 6:BLAKE
Processing: 7:CLARK
Processing: 8:SCOTT
Processing: 9:KING
Processing: 10:TURNER
Processing: 11:ADAMS
Processing: 12:JAMES
Processing: 13:FORD
Processing: 14:MILLER
Processing: 15:PRESIDENT
Result: 1:SMITH
Result: 2:ALLEN
Result: 3:WARD
Result: 4:JONES
Result: 5:MARTIN
Result: 6:BLAKE
Result: 7:CLARK
Result: 8:SCOTT
Result: 9:KING
Result: 10:TURNER
Result: 11:ADAMS
Result: 12:JAMES
Result: 13:FORD
Result: 14:MILLER
Result: 15:PRESIDENT
PL/SQL procedure successfully completed.
SQL>So, in answer to your questions...
Inserting additional rows in the array during the loop will effect the "last" value and alter the array. If you need to avoid this effect, store the "last" value in a variable and loop up to that value of the variable.
New rows will generally be additional rows on the end of the array unless you are using associative arrays which will then depend on how you reference the rows in the array.

Similar Messages

  • Auto create request by reading a row in MS SQL table?

    Auto create request by reading a row in MS SQL table?
    If all required data for a particular request type were included in a row of a MS SQL db table (staging table), could a request be created using a db adaptor?  Or is web services the only option to auto create a request?

    By definition, a DB adapter is part of ServiceLink and ServiceLink handles task-level integration, ie, it can externalize a task that's in a request that already exists. Web Services is the only option to create a new request.

  • Compare 2 tables and insert rows missing in each table.

    I have a tough situation. I have two exact tables- one online and one offline database. I know that there are missing rows of data from each table, so I need to make a comparison of one table and insert rows that do not exist. I was thinking to try this, but it took over 3 hours to run and did not return anything:
    insert into t
    select * from t a
    where not exists (select * from [email protected] b
    where a.col1 != b.col1
    and a.col2 != b.col2
    and a.col3 != b.col3);
    and it goes on for another 7columns.
    The trouble I have is to include a date clause so that the query can be broken down into running only a few months of data comparisions at a time- the records go back 4 years to compare. Also is there a way to write this so that it will query both tables at the same time in order to speed things up- or is one table at a time the best advice? Each table has over 100 million records to compare, that's why I was hoping to use a date criteria since one column is date.
    Let me know what you advise to make this work, I hope I was on the right track.

    Not sure if the MINUS operator will perform better with your data set but;
    SQL> create table t1 (some_id number, some_date date)
    Table created.
    SQL> create table t2 (some_id number, some_date date)
    Table created.
    SQL> insert into t1 values (1, trunc(sysdate))
    1 row created.
    SQL> insert into t1 values (2, trunc(sysdate-5))
    1 row created.
    SQL> insert into t1 values (4, trunc(sysdate-90))
    1 row created.
    SQL> insert into t2 values (1, trunc(sysdate))
    1 row created.
    SQL> insert into t2 values (3, trunc(sysdate-10))
    1 row created.
    SQL> insert into t2 values (5, trunc(sysdate-100))
    1 row created.
    SQL> select * from t1
       SOME_ID SOME_DAT
             1 07-07-30
             2 07-07-25
             4 07-05-01
    3 rows selected.
    SQL> select * from t2
       SOME_ID SOME_DAT
             1 07-07-30
             3 07-07-20
             5 07-04-21
    3 rows selected.
    SQL> insert into t1 (
       select some_id, some_date from t2 where some_date between sysdate-50 and sysdate
       minus
       select some_id, some_date from t1 where some_date between sysdate-50 and sysdate)
    1 row created.
    SQL> insert into t2 (
       select some_id, some_date from t1 where some_date between sysdate-50 and sysdate
       minus
       select some_id, some_date from t2 where some_date between sysdate-50 and sysdate)
    1 row created.
    SQL> select * from t1
       SOME_ID SOME_DAT
             1 07-07-30
             2 07-07-25
             4 07-05-01
             3 07-07-20
    4 rows selected.
    SQL> select * from t2
       SOME_ID SOME_DAT
             1 07-07-30
             3 07-07-20
             5 07-04-21
             2 07-07-25
    4 rows selected.

  • Programming insert row VO,but inner-table no data show?

    We have Master-Detail-Detail ViewObject,when programming insert row three ViewObject,why inner-table UI no data show?
    [Source Code ZIP files|http://docs.google.com/leaf?id=0B1l5uiKPTIr_ZTQwYTQ1MTMtZWFlMS00YWQ1LWFiZWQtYzNmODIwNDRlZWJk&hl=zh_TW]
    1.SmpTest0PG.xml click button.
    2.SmpTest0CO.java call MyTestAMImpl.java create Method insert row three ViewObject.
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    if (pageContext.getParameter("Test") != null)
    String key = "1";
    Serializable aserializable1[] = { key };
    String quote_id = (String)am.invokeMethod("create", aserializable1);
    if (!quote_id.equals(null))
    pageContext.setForwardURL("OA.jsp?page=/smp/oracle/apps/pos/test/webui/SmpTestPG&Key="+key,
    null,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    null,
    null,
    true, // Retain AM
    OAWebBeanConstants.ADD_BREAD_CRUMB_YES,
    OAWebBeanConstants.IGNORE_MESSAGES);
    3.SmpTest0CO.java Forward SmpTestPG.xml.
    4.SmpTestPG.xml Show Data.
    MyTestAMImpl.java
    public String create(String key)
    int vendor_id = 0;
    String vendor_name = null;
    int contact_id = 0;
    int site_id = 0;
    String quote_id = null;
    OADBTransaction trx = (OADBTransaction)((OAApplicationModuleImpl)this).getDBTransaction();
    SmpPoHdVOImpl hdvo = getSmpPoHdVO();
    SmpPoDlVOImpl dlvo = getSmpPoDlVO();
    SmpPoDkVOImpl shvo = getSmpPoDkVO();
    if (!hdvo.isPreparedForExecution())
    hdvo.setWhereClause("1 = 0");
    hdvo.setMaxFetchSize(0);
    hdvo.executeQuery();
    if (!dlvo.isPreparedForExecution())
    dlvo.setWhereClause("1 = 0");
    dlvo.setMaxFetchSize(0);
    dlvo.executeQuery();
    if (!shvo.isPreparedForExecution())
    shvo.setWhereClause("1 = 0");
    shvo.setMaxFetchSize(0);
    shvo.executeQuery();
    String s = key;
    Serializable aserializable[] = { s };
    SmpViewPoHdVOImpl quhdvo = getSmpViewPoHdVO();
    if(quhdvo != null)
    quhdvo.invokeMethod("initQuery", aserializable);
    SmpViewPoDlVOImpl qudlvo = getSmpViewPoDlVO();
    // insert hd
    quhdvo.setRangeSize(-1);
    Row quhdrow[] = quhdvo.getAllRowsInRange();
    for(int i = 0; quhdrow != null && i < quhdrow.length; i++)
    Row hdrow = hdvo.createRow();
    hdrow.setAttribute("DocNum","200");
    hdvo.insertRow(hdrow);
    hdrow.setNewRowState(Row.STATUS_NEW);
    quote_id = hdrow.getAttribute("HEADER_ID").toString();
    // insert dl
    RowIterator dlIter = (RowIterator)quhdrow.getAttribute("SmpViewPoDlVO");
    dlIter.setRangeSize(-1);
    Row qudlrow[] = dlIter.getAllRowsInRange();
    int line_seq = 0;
    for(int j = 0; qudlrow != null && j < qudlrow.length; j++)
    Row dlrow = dlvo.createRow();
    line_seq ++;
    dlrow.setAttribute("LineNum",String.valueOf(line_seq));
    dlrow.setAttribute("ItemNo",qudlrow[j].getAttribute("ItemNo"));
    dlrow.setAttribute("Qty",qudlrow[j].getAttribute("Qty"));
    dlvo.insertRow(dlrow);
    dlrow.setNewRowState(Row.STATUS_NEW);
    // insert shipment
    RowIterator shipIter = (RowIterator)qudlrow[j].getAttribute("SmpViewPoDkVO");
    shipIter.setRangeSize(-1);
    Row shipRow[] = shipIter.getAllRowsInRange();
    int ship_seq = 0;
    for(int k = 0; shipRow != null && k < shipRow.length; k++)
    ship_seq ++;
    Row shrow = shvo.createRow();
    shrow.setAttribute("ShipmentNum",String.valueOf(ship_seq));
    shrow.setAttribute("Qty",shipRow[k].getAttribute("Qty"));
    shvo.insertRow(shrow);
    shrow.setNewRowState(Row.STATUS_NEW);
    return quote_id;
    Edited by: Tony_Huang on Apr 10, 2010 3:59 PM

    public class SmpTestCO extends OAControllerImpl
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    OATableBean oatablebean = (OATableBean)webBean.findChildRecursive("SmpPoDlVORN");
    OATableBean oatablebean1 = (OATableBean)webBean.findChildRecursive("SmpPoDkVORN");
    if (oatablebean != null)
    oatablebean.setAttributeValue(UIConstants.ALL_DETAILS_ENABLED_ATTR, ((Object) (Boolean.TRUE)));
    oatablebean.setAttributeValue(OAWebBeanConstants.VIEW_LINK_NAME, "SmpPoDlDkVL1");
    if (oatablebean1 != null)
    oatablebean1.setAttributeValue(OAWebBeanConstants.VIEW_LINK_NAME, "SmpPoDlDkVL1");
    oatablebean1.setInsertable(true);
    oatablebean1.setAutoInsertion(true);
    }

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

  • Loop Cursor Fetch Insert Rows Into Global Temporay Table

    Hi friends,
    I want to know there where is the problem in my this query
    cursor c1 is select empno
    from scott.emp;
    b number;
    begin
    open c1;
         loop
         fetch c1 into b;
         exit when c1%notfound;
    insert into scheema.a1
    (a)
    values
    (b);
    commit;
         end loop;
         close c1;
    end;
    There is no any error displaying while proceeding this query but the table a1 which is (Global temporary table with ON COMMIT PRESERVE ROWS option enabled) does not gets any records. Kindly let me know the problem.
    Regards.

    Are you sure that the query returns date? Are you checking the table via the same session?
    SQL> create global temporary table a1 (
      a  number)
      on commit preserve rows
    Table created.
    SQL> declare
       cursor c1 is select empno
          from scott.emp;
       b number;
    begin
       open c1;
       loop
          fetch c1 into b;
          exit when c1%notfound;
          insert into a1
          (a)
          values
          (b);
          commit;
       end loop;
       close c1;
    end;
    PL/SQL procedure successfully completed.
    SQL> select * from a1
             A
          7369
          7499
          7521
          7566
          7654
          7698
          7782
          7788
          7839
          7844
          7876
          7900
          7902
          7934
    14 rows selected.

  • Inserting rows using pl sql

    Hi all,
    I created one tabale to inserting some numbers
    create table loc_number (c1 number);
    now i want to insert 10 rows into this table using pl sql.
    How can i do that using pl sql?

    Hi,
    Yes it is possible.
    Why do you want to use loops here ?
    (I'm assuming, you need this for practice purpose)
    begin
    for i in 1..10
    loop
       insert into loc_number
           values (i);
    end loop;
    commit;
    end;

  • Problems trying to insert rows from PL/SQL procedure with existing seq..

    hello. please help me.
    i have a button that is calling an anonymous PL/SQL block and i am struggling with inserting records automatically when this button is clicked. an ordinary before insert DB trigger is launched:
    reate or replace TRIGGER "SPECSYS"."BI_SPEC_INSTRUCTS"
    before insert on "SPEC_INSTRUCTS"
    for each row
    begin
    if :NEW."ID" is null then
    select "SPEC_INSTRUCTS_SEQ".nextval into :NEW."ID" from dual;
    end if;
    end;
    in my PL/SQL I am trying to create a record automatically. stupid question that this undoubtedly is, how do i do this? if i leave the sequence column = null surely the trigger should take care of inserting the sequence into this column automatically?
    i have tried making the sequence column = null, leaving it out altogether (ie specifying all colums except this one on the insert statement) but with no success!

    this is not the problem!

  • Inserting rows in a database table using JDBC

    Hi,
    I am trying to insert a row in a table using the follwing code:
    String Query_String = "Insert into Table_Name (Field_1, Field_2, Field_3)" +
    "Values (Value_1, Value_2, Value_3)";
    stmt.executeUpdate (Query_String);
    Field_1 is a Date field, Field_2 is a String, and Field_3 is an integer.
    Any of the fields could be null. If the user does not enter a value for any
    one of these fields what would be the values for
    Value_1, Value_2, or Value3 in the Query_String?
    Thanks.

    Hi,
    I am trying to insert a row in a table using the
    follwing code:
    String Query_String = "Insert into Table_Name
    (Field_1, Field_2, Field_3)" +
    "Values (Value_1,
    "Values (Value_1, Value_2, Value_3)";
    stmt.executeUpdate (Query_String);
    Field_1 is a Date field, Field_2 is a String, and
    Field_3 is an integer.
    Any of the fields could be null. If the user does not
    enter a value for any
    one of these fields what would be the values for
    Value_1, Value_2, or Value3 in the Query_String?
    Thanks.Keep in mind that each database server probably has their own way of storing date values. For now, I'm going to assume that you're going to be using MySQL.
    // Initialize variables to null
    String Value_1 = "";
    String Value_2 = "";
    String Value_3 = "";
    try
    // Get Date
    Date date = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Value_1 = dateFormat.format(date);
    // Get String value
    Value_2 = "some string";
    // Get Integer value
    Value_3 = String.valueOf("2");
    String query = INSERT INTO T_NAME VALUES('" + Value_1 +"', '" + Value_2 + "', '" + Value_3 + "');
    int iUpdated = stmt.executeUpdate(query);
    catch(Exception e)
    // Catch Code
    System.out.println("Number of records updated: " + iUpdated);
    This will just enter empty string values if the strings are empty.
    Is this what you wanted to know?
    If not, provide a bit more information and I'll try to help as best as I can

  • Inserting Rows in an Editable Table

    Application Focus: JSF with ADF/BC.
    watching Steve Muench´s Screencast on "Creating an Editable Table with a Dropdown List in Each Row" i was inspired to add a functionality to add rows.
    Lets say i have an Employee and Departments table. If i want to add three new employees in the employee editable table - that wont work - it seems that adding rows aint that simple, cause it seems not possible to commit more than one row at a time
    what i did according to forum posts and how-to´s:
    1. dropped "insert" from data control palette
    2. altered binding to from create to "CreateInsert"
    works ok, but if i press the button twice (3x, 4x) the new rows are shown, but if i commit them, only one is in the database?
    Any tips on that would be appreciated.

    I'm trying to a similar thing, create an input screen that allows you to add muliple rows at the same time some rows having a drop down list. I've read the following How to which lets me edit multiple rows but if I add a create button or a CreateInsert button it doesnt seem to give me rows to create.
    How To Create Multi Row Edit Forms in a JSP Page with Oracle JDeveloper 10g
    http://www.oracle.com/technology/products/jdev/tips/mills/JSP_Multi_Row_Edits.html

  • Timeout when inserting row in a locked table

    How can I set the timeout before an INSERT statement fails with error ORA-02049 (timeout: distributed transaction waiting for lock) when the entire table has been lock with LOCK TABLE .
    Documentation says to modify DISTRIBUTED_LOCK_TIMEOUT parameter, but it is obsolete in Oracle 8i.
    Any idea ???

    You could set an alarm() in a signal. Then on return (for whatever reason) you clear the alarm, inspect the return code of the sql execute call and determine what happened (i.e. did the transaction completed or did the alarm get you).
    Hope it helps.
    -Lou
    [email protected]
    How can I set the timeout before an INSERT statement fails with error ORA-02049 (timeout: distributed transaction waiting for lock) when the entire table has been lock with LOCK TABLE .
    Documentation says to modify DISTRIBUTED_LOCK_TIMEOUT parameter, but it is obsolete in Oracle 8i.
    Any idea ???

  • How to fetch rows from PL/SQL table(Collections)

    Hi,
    I retrived rows from the table and stored in to table type.
    Now I want fetch these rows and display on the screen. Pls guide me.
    following code is my code:
    DECLARE
    type t1 is table of emp%rowtype index by binary_integer;
    var1 t1;
    v_counter number:=0;
    BEGIN
    select * bulk collect into var1 from emp;
    for vr in var1.first..var1.last
    loop
    dbms_output.put_line(var1(1)); --Got an Error Here. Acually I don't Know how to  fetch.
    update dept set deptno=var1.deptno --Here also Error occured.
    end loop;
    END;

    Fetching rows to display them is a task for the client tool. You need to define a ref cursor therefore.
    If you just want to play around, here we go
    SQL> DECLARE
      2    type t1 is table of emp%rowtype index by binary_integer;
      3    var1 t1;
      4    v_counter number:=0;
      5  BEGIN
      6    select * bulk collect into var1 from emp;
      7    for vr in 1..var1.count loop
      8      dbms_output.put_line(var1(vr).ename);
      9      update dept set deptno=var1.deptno Here also Error occured.
    10    end loop;
    11  END;
    12  /
    SCOTT
    ADAMS
    PL/SQL procedure successfully completed.
    SQL>

  • Insert row wherever within a table?

    Can it be done? Looking to add and delete rows wherever needed within a table. Currently, it only allows me to add or remove either the very first row or the very last; not those in-between. My users constantly request the ability to insert where needed (like word and excel) and I'm stumped on how to work it out.

    1. Cell options
    2. Cell options!
    You probably have too much space inside the top and bottom edges of each cell. Select the entire table and select Cell Options (from the Table menu or from your friendly right click pop-up menu). A relatively safe value for Top and Bottom distance is 1 mm.
    You can see the grid lines either because you have Show Frame Edges on (they should be thin and blue), or, more likely, because the ID import doesn't honor the Excel settings and puts the lines there by itself. If your lines are blue and thin, don't worry; they're just there to help you. Select Preview mode and they will disappear (just as text frame edges, guidelines, etc.). If the lines are black and thick, select the entire table and use the Cell options to switch them off. Just select either 0 pt thickness or a [None] line color.

  • 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

  • QUERY FOR INSERT INTO  SQL TABLE

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

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

Maybe you are looking for

  • Is anyone having issues with Windows 8 phones not loading mobile versions of websites?

    I was just wondering if anyone with a Windows phone is having problems loading the mobile site version of a Muse site when viewed on the phone? or if there is a known bug or incompatability?

  • Outlook 2007/Adobe 9 Converting Folders to PDF

    I have converted several email folders in Outlook 2007 to PDF so that I can delete the folders from my outlook but have them saved in client folders.  When I try to access these saved pdf emails on my computer, I get the error message that "There was

  • Internal order derivation from SO to PR

    Hello all, I have created a sales order, by giving CO object as Internal order. When I am creating purchase requisition with reference to sales order, it is not picking internal order, it is picking only profit center. How to customize in order to de

  • Re:Bi content reports

    Hi expert, This is pradeep.in my project my client required sd,mm and fico reports are in excel format ofter then the client decision take place .please give me those reports please .my id [email protected] Thanks & Regards, Pradeep kandepu Edited by

  • Can I set up my mac Keyboard in windows 7 with a dongle bluethooth?

    my pc computer does not have bluetooth! I had a dongle bluethooth USB and i trying to use my mac keayboard!