How to Populate a table type variable from a cursor

Hi
I have a stored procedure (P1) that returns a ref cursor as the output.
Another procedure (P2) receives this ref cursor (C).
In this procedure (P2), I want to do a Bulk Collect from this ref cursor (C) in
a table type variable that has been declared locally in the procedure P2. I have created appropriate Object Type and Table Types at the database level.
Please advise how to do it. I tried to do it in different ways, but was not able to do it - each time I faced incompatible data-type related issues.
Regards
Madhup

What I wrote was unclear. Syntactically it is valid and does something. But consider the advantage of a decent design.
SQL> create or replace procedure p1 (o out sys_refcursor) as
  2  begin
  3   open o for select * from emp;
  4  end p1;
  5  /
Procedure created.
SQL> create or replace procedure p2(i sys_refcursor) as
  2   type emp_tab is table of emp%rowtype;
  3   l_emp_tab emp_tab;
  4  begin
  5   fetch i bulk collect into l_emp_tab;
  6   close i;
  7  
  8   for i in 1..l_emp_tab.count loop
  9     NULL;
10   end loop;
11  end p2;
12  /
Procedure created.
SQL> CREATE OR REPLACE PROCEDURE p3 IS
  2 
  3  TYPE myarray IS TABLE OF emp%ROWTYPE;
  4  l_data myarray;
  5 
  6  CURSOR r IS
  7  SELECT * FROM emp;
  8 
  9  BEGIN
10    OPEN r;
11    LOOP
12      FETCH r BULK COLLECT INTO l_data;
13 
14      FOR j IN 1 .. l_data.COUNT
15      LOOP
16        NULL;
17      END LOOP;
18 
19      EXIT WHEN r%NOTFOUND;
20    END LOOP;
21    CLOSE r;
22  END p3;
23  /
Procedure created.
SQL> set serverout on
SQL> set timing on
SQL> declare
  2   r sys_refcursor;
  3  begin
  4    FOR i IN 1 .. 10000 LOOP
  5      p1(r);
  6      p2(r);
  7    END LOOP;
  8  end;
  9  /
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.71
SQL> begin
  2    FOR i IN 1 .. 10000 LOOP
  3      p3;
  4    END LOOP;
  5  end;
  6  /
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.21
SQL> Again sorry for being less than clear.

Similar Messages

  • How to insert into table type variables

    hi all,
    how to assingn values to table type variable, i am getting error.
    declare
    dept1 dept%rowtype;
    begin
    dept1:=(100,'SHIPPING','HYDERABAD');
    end;
    ERROR at line 4:
    ORA-06550: line 4, column 8:
    PLS-00382: expression is of wrong type
    regards,
    Sri Ram.

    You can do like this
    declare
      dept1 dept%rowtype;
    begin
      dept1.deptno := 10;
      dept1.dname := 'IT';
    end;
    /

  • How to pass table type variable into function from SQL*PLUS ?

    How to pass a table type variable from sql*plus prompt into a function ?
    Thanx in advance.

    Krishna,
    Do you mean like this?SQL> DECLARE
      2      TYPE t_tbl IS TABLE OF VARCHAR2(20);
      3      l_sample_tbl           t_tbl;
      4
      5      FUNCTION print_contents ( p_tbl IN t_tbl )
      6      RETURN VARCHAR2
      7      IS
      8          l_string            VARCHAR2(1000);
      9      BEGIN
    10          FOR i IN 1..p_tbl.COUNT LOOP
    11              IF (i = 1) THEN
    12                  l_string := p_tbl(i);
    13              ELSE
    14                  l_string := l_string || ', ' || p_tbl(i);
    15              END IF;
    16          END LOOP;
    17          RETURN (l_string);
    18      END print_contents;
    19
    20  BEGIN
    21      l_sample_tbl := t_tbl();
    22      l_sample_tbl.EXTEND;
    23      l_sample_tbl(1) := 'one';
    24      l_sample_tbl.EXTEND;
    25      l_sample_tbl(2) := 'two';
    26      l_sample_tbl.EXTEND;
    27      l_sample_tbl(3) := 'three';
    28      l_sample_tbl.EXTEND;
    29      l_sample_tbl(4) := 'four';
    30      l_sample_tbl.EXTEND;
    31      l_sample_tbl(5) := 'five';
    32      DBMS_OUTPUT.PUT_LINE(print_contents(l_sample_tbl));
    33  END;
    34  /
    one, two, three, four, five
    PL/SQL procedure successfully completed.
    SQL> HTH,
    T.

  • How to populate a table based on a row selection from another table.

    Hi, i just started to use ADF BC and Faces. Could some one help me or point me a solution on the following scenario .
    By using a search component , a table is being displayed as a search result. If i select any row in the resulted table , i need to populate an another table at the bottom of the same page from another view. These two tables are related by primary key . May i know how to populate a table based on a row selection from another table. Thanks
    ganesh

    I understand your requirement and the tutorial doesn't talk about Association between the views so that you can create a Master-Detail or in DB parlance, a Parent-Child relationship.
    I will assume that we are dealing with two entities here: Department and Employees where a particular Department has many Employees and hence a Parent-Child relationship.
    Firstly, you need to create an Association between the two Entities - Department and Employees. You can do that by right clicking on the model's entity and then associating the two entities with the appropriate key say, DepartmentId.
    Once you have done that, you need to link the two entities in the View section with this Association that you created. Then go to AppModule and make sure that in the Available View Objects: 'EmployeesView' appears under 'DepartmentView' as "EmployeesView via <link you created>". Shuttle the 'DepartmentView' to the right, Data Model and then shuttle
    "EmployeesView via <link you created>" to the right, Data Model under 'DepartmentView'.
    This will then be reflected in your Data Controls. After that, you simply would have to drag this View into your page as a Master-Detail form...and then when you run this page, any row selected in the Master table, would display the data in the Detail table.
    Also, refer to this link: [Master-Detail|http://baigsorcl.blogspot.com/2010/03/creating-master-detail-form-in-adf.html]
    Hope this helps.

  • How to Populate Internal table data to Table Control in a Report Program

    Dear All,
           How to Populate Internal table data to Table Control in a Report Program? It is a pure report program with out any Module pool coding involved, which is just used to display data. Till now it is being displayed in a report. Now the user wants the data to be displayed in a table control. Could someone tell me how to go about with this.
    Thanks in Advance,
    Joseph Reddy

    If you want to use a table control, you will need to create a screen.
    In your report....
    start-of-selection.
    perform get_data.  " Get all your data here
    call screen 100. " Now present to the user.
    Double click on the "100" in your call screen statement.  This will forward navigate you to the screen.  If you have not created it yet, it will ask you if you want to create it, say yes.  Go into screen painter or layout of the screen.  Use the table control wizard to help you along the process.  It will write the code for you.  Since it is an output only table control, it will be really easy with not a lot of code. 
    A better way to present the data to the user would be to give it in a ALV grid.  If you want to go that way, it is a lot easier.  Here is a sample of the ALV function module.  You don't even have to create a screen.
    report zrich_0004
           no standard page heading.
    type-pools slis.
    data: fieldcat type slis_t_fieldcat_alv.
    data: begin of imara occurs 0,
          matnr type mara-matnr,
          maktx type makt-maktx,
          end of imara.
    * Selection Screen
    selection-screen begin of block b1 with frame title text-001 .
    select-options: s_matnr for imara-matnr .
    selection-screen end of block b1.
    start-of-selection.
      perform get_data.
      perform write_report.
    *  Get_Data
    form get_data.
      select  mara~matnr makt~maktx
                into corresponding fields of table imara
                  from mara
                   inner join makt
                     on mara~matnr = makt~matnr
                        where mara~matnr in s_matnr
                          and makt~spras = sy-langu.
    endform.
    *  WRITE_REPORT
    form write_report.
      perform build_field_catalog.
    * CALL ABAP LIST VIEWER (ALV)
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                it_fieldcat = fieldcat
           tables
                t_outtab    = imara.
    endform.
    * BUILD_FIELD_CATALOG
    form build_field_catalog.
      data: fc_tmp type slis_t_fieldcat_alv with header line.
      clear: fieldcat. refresh: fieldcat.
      clear: fc_tmp.
      fc_tmp-reptext_ddic    = 'Material Number'.
      fc_tmp-fieldname  = 'MATNR'.
      fc_tmp-tabname   = 'IMARA'.
      fc_tmp-outputlen  = '18'.
      fc_tmp-col_pos    = 2.
      append fc_tmp to fieldcat.
      clear: fc_tmp.
      fc_tmp-reptext_ddic    = 'Material'.
      fc_tmp-fieldname  = 'MAKTX'.
      fc_tmp-tabname   = 'IMARA'.
      fc_tmp-outputlen  = '40'.
      fc_tmp-col_pos    = 3.
      append fc_tmp to fieldcat.
    endform.
    Regards,
    Rich Heilman

  • How to Populate a table in PL/SQL

    Hi Every1,
    please clarify me How to Populate a table in PL/SQL,Thanx in advance...
    Thanks & Regards,
    Ram Nainar S

    Not possible. SQL is used to populate tables - it is the language that interacts (CRUD) Oracle data in tables. Not PL/SQL.
    So even when using PL/SQL, you still need to use SQL. Thus "populating" a table is no different than using SQL or using SQL (from inside PL/SQL).

  • How to insert a table with variable rows in smart form

    Hi all,
    How to insert a table with variable rows in smart form?
    Any help would be appreciated.
    Regards,
    Mahesh.

    Hi,
    Right click the mouse->create->table
    If you want 5 columns, you need to declare 5 cells in one line type of the table
    Click on Table -> Details, then do the following
    Line Type 1 2 3 4 5
    L1 2mm 3mm etc
    Here specify the width of the columns as many as you want..
    then in the header/main area of the table, click create Table Line, Rowtype is L1, automatically 5 cells will come,In each cell create a text element, display the variable to be printed there.

  • Trying to populate a table with data from WebRowset

    Hi,
    I want to be able to populate my tables with data from WebRowsets that have been saved to files. Everything goes good until I get to acceptChanges(). At which point I get a NullPointerException.
    Here's the code...
    WebRowSet wrs = new WebRowSetImpl();
    FileReader reader = new FileReader(inputFile);
    wrs.readXml(reader);
    wrs.beforeFirst();
    CachedRowSet crs = new CachedRowSetImpl();
    crs.setSyncProvider("com.sun.rowset.providers.RIXMLProvider");
    crs.populate(wrs);
    crs.beforeFirst();
    crs.acceptChanges(con);
    Results in...
    java.lang.NullPointerException
    at com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:867)
    at com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:919)
    I'm using Java 1.5_02. I looked at the source code for CachedRowSetImpl, and the only thing I could think of is that maybe "provider.getRowSetWriter()" in the following snippet is returning null....
    public void setSyncProvider(String s)
    throws SQLException
    provider = SyncFactory.getInstance(s);
    rowSetReader = provider.getRowSetReader();
    rowSetWriter = (TransactionalWriter)provider.getRowSetWriter();
    Any ideas?? Thanks!

    I have the same problem after setting com.sun.rowset.providers.RIXMLProvider.
    Looks like a bug to me.
    By the way, why are you creating a new CachedRowSet and populate it with a WebRowset (which extends CachedRowSet)?

  • Select values from table%ROWTYPE variable into a cursor

    I have a stored procedure which has an OUT parameter of table1%ROWTYPE.
    In future we might have to add more OUT parameters of table2%ROWTYPE etc. But at any point of time only one will have values.
    So instead of having table%ROWTYPE as OUT parameter, can I send these single row ( with variable values) in a cursor, so that declaration part atleast will not change.
    Is it possible to select values from table%ROWTYPE variable into a cursor.
    cursorOUT IS
    SELECT * FROM varREC;
    where varREC is table.ROWTYPE variable.
    Or which is the better solution in this situation.
    Thanks.

    SQL> var a refcursor
    SQL> declare
      2   bb emp%ROWTYPE;
      3  begin
      4   select * into bb from emp where rownum = 1;
      5   open :a for select bb.ename ename, bb.empno empno from dual;
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    SQL> print a
    ENAME                                 EMPNO
    SMITH                                  7369Rgds.

  • Populate SQL table with data from Oracle DB in ODI

    Hi,
    I am trying to populate a source SQL table with fields from an Oracle db in ODI. I am trying to perform this using a procedure and I am am getting the following error:
    ODI-1226: Step PROC_1_Contract_Sls_Person_Lookup fails after 1 attempt(s).
    ODI-1232: Procedure PROC_1_Contract_Sls_Person_Lookup execution fails.
    ODI-1228: Task PROC_1_Contract_Sls_Person_Lookup (Procedure) fails on the target MICROSOFT_SQL_SERVER connection Phys_HypCMSDatamart.
    Caused By: weblogic.jdbc.sqlserverbase.ddc: [FMWGEN][SQLServer JDBC Driver][SQLServer]Invalid object name 'C2C_APP.CON_V'.
    My question is what is the best method to populate SQL db with data from an Oracle db? Using a procedure? A specific LKM?
    I found threads referring to using an LKM to populate Oracle tables with data from a SQL table....but nothing for the opposite.
    Any information would help.
    thanks,
    Eric

    Hi Eric,
    If using an Interface, I would recommend the LKM SQL to MSSQL (BULK) knowledge module. This will unload the data from Oracle into a file, then bulk load the staging db on the target using a BULK INSERT.
    Regards,
    Michael Rainey

  • How to populate internal table( varaible of ABAP table type) in Excel VBA?

    Hi,
    I am trying to update a database table from excel using a VBA Macro.
    I am able to connect to SAP and able to read data from SAP using a RFC. Similarly after updating certain values, i want to update a table in SAP.
    Below are the steps I am doing  apart from basic settings.
    Getting the reference of the SAP TABLE type from RFC fucntion module
    ' Call RFC
    Set MyFunc = R3.Add("UPDATE_TVARVC_VIA_RFC")
    ' Get reference and Values TVARVC
    Set oParam4 = MyFunc.Tables("TVARVC")   
       2. Loop over the active cells and populate oParam4
              " add values as below
        oParam4.Rows.Add
        oParam4.Value(1, "NAME") = ..................
        oParam4.Value(1, "TYPE") = ..................
        oParam4.Value(1, "NUMB") = ..................
      Do it for all columns in the table line.
    My query is how to identify active cells and make the above code dynamic in step 2.
    Thanks in Advance,
    Best,
    Aneel

    Hi Aneel,
    You can try the following:
    e.g.
    for j = 1 to ActiveCell.SpecialCells(11).Column
      oParam4.Rows.Add
      if j=1 then oParam4.Value(j, "NAME") = ActiveSheet.Cells(1,j).Value
      if j=2 then oParam4.Value(j, "TYPE")  = ActiveSheet.Cells(1,j).Value
      if j=3 then oParam4.Value(j, "NUMB") = ActiveSheet.Cells(1,j).Value
    next j
    Regards,
    ScriptMan

  • How to populate a table in the html page from the java script

    Hi all,
    I have doubt in populating a table in the html page. my application is as follows
    I have a html page in which i have a combo box and a table following the combo box.
    i have to populate the table depending on the item selected in the combo box.
    for this i am using javascript to get the value of combo box onClick
    then i have to call some function thru jsp to get the data and then i have to populate the table with thst into from java script
    how can i do this, i.e populating html table from java script
    Thanks in advance
    satya

    Hi Mihai,
    You can populate data in DO_INIT_CONTEXT method of ur impl class in your Z component.
    data:
    lv_struct_ref type ref to YOUR_STRUCTURE,
    lv_value_node type ref to cl_bsp_wd_value_node,
    lv_bo_coll type ref to if_bol_bo_col.
    Data: current type ref to if_bol_bo_property_access.
    data: dref type ref to data.
    data: lv_guid_h type crmt_object_guid.
    data: lt_attr type table of YOUR_STRUCTURE.
    data: ls_attr type YOUR_STRUCTURE.
    data: lr_entity type ref to cl_crm_bol_entity.
    create object lv_bo_coll type cl_crm_bol_bo_col.
    lt_attr is ur internal table.
    Loop at lt_attr into ls_attr.
      create data lv_struct_ref.
      create object lv_value_node
           exporting
                iv_data_ref = lv_struct_ref.
    call method lv_value_node->if_bol_bo_property_access~set_property
    exporting
    iv_attr_name = 'YOURFIELDNAME1'
    iv_value = ls_attr-firstname.
    call method lv_value_node->if_bol_bo_property_access~set_property
    exporting
    iv_attr_name = ' YOURFIELDNAME2'
    iv_value = ls_attr-lastname.
    lv_bo_coll->add( lv_value_node ).
    typed_context->YOURCONTEXTNODE->set_collection( lv_bo_coll ).
    endloop.
    Regards,
    Raghu

  • How to populate a Table from a WebApplication JSF from a MySQL database

    Hi,
    I'm trying to populate a table on a WebApplication JSF. I don't know how the table can be filled with informations from a MySQL database.
    Please show me the way.

    In the future, JSF related questions should be posted in a forum devoted to JSF: [http://forums.sun.com/forum.jspa?forumID=427].
    Regarding to your question, you may find this article useful: [http://balusc.blogspot.com/2006/06/using-datatables.html].

  • How to populate a Row type data?

    Hello All,
    Looking for a BAPI to change PO's I found the BAPI called by the Massive change of PO's.
    I am in 4.6B so I do not have access to BAPI_CHANGE_PO.
    I tested BAPI MASS_CHANGE_PURCHASE_ORD directly in SE37 and I know how to fill the tables to make it work for my Purposes.
    Here it is the problem.
    I do not know how to fill the import parameter SELDATA from my code.  I know the values I need to populate, but I do not know how to pass them to this kind of parameter. 
    This import parameter is ROW Type.  Two of the fields have like a little table inside.
    Does any body have worked with this kind of data?
    Thank you in advance.
    MAC.

    Hi MAC,
    Declare the following variables
    DATA: IT_SELTAB TYPE MASS_TABDATA,
              WA_SELTAB TYPE MASS_WA_TABDATA,
              IT_KEYFIELDNAMES TYPE MASS_FIELDTAB,
              WA_KEYFIELDNAMES TYPE DDOBJNAME,
              IT_FIELDNAMES TYPE MASS_FIELDTAB,
              WA_FIELDNAMES TYPE DDOBJNAME,
              IT_NEWSEGMENTS TYPE MASS_NEWSEGMENTS,
              WA_NEWSEGMENTS LIKE LINE OF IT_NEWSEGMENTS,
    Now fill your data in the work areas first and
    then append the WA_ to their respective tables
    WA_KEYFIELDNAMES = 'KeyFieldNameXYZ'.
    WA_FIELDNAMES = 'FieldNameABC'.
    WA_NEWSEGMENTS = 123.
    APPEND WA_KEYFIELDNAMES TO IT_KEYFIELDNAMES.
    APPEND WA_FIELDNAMES TO IT_FIELDNAMES.
    APPEND WA_NEWSEGMENTS TO IT_NEWSEGMENTS.
    WA_SELTAB-KEYFIELDNAMES = IT_KEYFIELDNAMES.
    WA_SELTAB-FIELDNAMES = IT_FIELDNAMES.
    WA_SELTAB-NEWSEGMENTS = IT_NEWSEGMENTS.
    APPEND WA_SELTAB TO IT_SELTAB.
    The above code can be modified to be used in loops to fill data for multiple lines.
    Please reward points if this helps.
    Regards,
    Prabhas.

  • How to use Oracle Table Type values in Select Statement.

    Hi,
    I am fetching initial set of values into Oracle Table of Records Type and want to use list of values in the Select statement.
    For example, try something like the following:
    TYPE t_record IS RECORD (
    ID TABLEA.ID%type,
    NO TABLEA.NO%type,
    v_record t_record;
    TYPE t_table IS TABLE OF v_record%TYPE;
    v_table t_table;
    -- Code to populate the values in v_table here.
    SELEC ID,NO, BULK COLLECT INTO <some other table variabes here> FROM TABLEA
    WHERE ID IN v_table(i).ID;
    I want to know how to use the values from Oracle Table Type in the Select Statement.

    Something like this:
    create or replace type t_record as  object (
    id number,
    no number
    CREATE or replace type t_table AS TABLE OF t_record;
    set serveroutput on
    declare
      v_table t_table := t_table();
      v_t1 t_table := t_table();
    begin
      v_table.extend(1);
      v_table(1).ID := 1;
      v_table(1).No := 10;
      v_table.extend(1);
      v_table(2).ID := 2;
      v_table(2).ID := 20;
      SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
      from TableA
      FROM TABLEA
      WHERE ID IN (select t.ID from table(v_Table) t);
      for i in 1..v_t1.count loop
        dbms_output.put_line(v_t1(i).ID);
        dbms_output.put_line(v_t1(i).No);
      end loop;
    end;
    /Untested!
    P;
    Edited by: bluefrog on Mar 5, 2010 5:08 PM

Maybe you are looking for