Looping through records without hardcoding column identifiers

Is it possible to call a nextval type function when looping through a recordset?
I have a cursor which fetches records into a %rowtype variable. However, I was wondering is it possible to go through each record without having to call the column name, but rather incrementally moving from record to record
i.e.
cursor x is
select a,b,c from d;
record x%rowtype;
open x;
loop
fetch x into record;
htp.p(x.nextval (or its equivalent));
exit when x%notfound;
end loop;
is this possible instead of
htp.p(x.a);
htp.p(x.b);
htp.p(x.c);
Thanks

You probably want to hard-code the column names in your code.
The alternative would be to use dynamic SQL and the DBMS_SQL package. That would drastically complicate the code, however, so it's generally not a great idea.
Justin

Similar Messages

  • Looping through records

    New to PL/SQL and wondered if you can simply loop through records in order to ouptut as single string in a file?
    DECLARE
    v_string_rec VARCHAR(4000);
    type v_cols is record;
    BEGIN
    FOR rec IN (SELECT * FROM PLAY_OWNER.STG_CUSTOMER)
    -- somehow need to get the single record into record var then loop through that?
    LOOP
    FOR i IN v_cols.FIRST .. v_cols.LAST
    LOOP
    v_string_rec := recs(i) || v_string_rec;
    END LOOP;
    DBMS_OUPTPUT.PUT_LINE (v_string_rec);
    -- UTL_FILE operations, insert rows
    END LOOP;
    END;
    Give me a slap by all means, as I say kind of new to this

    Just as a curiosity, using some xml capabilities we can obtain a strig concatenation of all columns of a given query this way:
    SQL> with t as
      2  (select xmltype(dbms_xmlgen.getxml(DBMS_XMLGEN.newContext('SELECT * FROM emp'))) doc
      3     from dual)
      4  select extract(column_value,'//text()') myrow
      5  from t, table(xmlsequence(extract(t.doc,'/ROWSET/ROW')));
    MYROW
    7369SMITHCLERK790217-12-198080020
    7499ALLENSALESMAN769820-02-1981160030030
    7521WARDSALESMAN769822-02-1981125050030
    7566JONESMANAGER783902-04-1981297520
    7654MARTINSALESMAN769828-09-19811250140030
    7698BLAKEMANAGER783901-05-1981285030
    7782CLARKMANAGER783909-06-1981245010
    7788SCOTTANALYST756619-04-1987300020
    7839KINGPRESIDENT17-11-1981500010
    7844TURNERSALESMAN769808-09-19811500030
    7876ADAMSCLERK778823-05-1987110020
    7900JAMESCLERK769803-12-198195030
    7902FORDANALYST756603-12-1981300020
    7934MILLERCLERK778223-01-1982130010
    14 rows selected.And all the single attribute values this way:
    SQL> with t as
      2  (select xmltype(dbms_xmlgen.getxml(DBMS_XMLGEN.newContext('SELECT * FROM emp'))) doc
      3     from dual)
      4  select extract(column_value,'//text()') attribute_value
      5  from (select column_value myrow
      6          from t, table(xmlsequence(extract(t.doc,'/ROWSET/ROW')))
      7        ) r, table(xmlsequence(extract(r.myrow,'/ROW/*')));
    ATTRIBUTE_VALUE
    7369
    SMITH
    CLERK
    7902
    17-12-1980
    800
    20
    7499
    ALLEN
    SALESMAN
    7698
    20-02-1981
    1600
    300
    30
    7521
    WARD
    SALESMAN
    7698
    22-02-1981
    1250
    500
    30
    7566
    JONES
    MANAGER
    7839
    02-04-1981
    2975
    20
    7654
    MARTIN
    SALESMAN
    7698
    28-09-1981
    1250
    1400
    30
    7698
    BLAKE
    MANAGER
    7839
    01-05-1981
    2850
    30
    7782
    CLARK
    MANAGER
    7839
    09-06-1981
    2450
    10
    7788
    SCOTT
    ANALYST
    7566
    19-04-1987
    3000
    20
    7839
    KING
    PRESIDENT
    17-11-1981
    5000
    10
    7844
    TURNER
    SALESMAN
    7698
    08-09-1981
    1500
    0
    30
    7876
    ADAMS
    CLERK
    7788
    23-05-1987
    1100
    20
    7900
    JAMES
    CLERK
    7698
    03-12-1981
    950
    30
    7902
    FORD
    ANALYST
    7566
    03-12-1981
    3000
    20
    7934
    MILLER
    CLERK
    7782
    23-01-1982
    1300
    10
    101 rows selected.Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/01/23/la-forza-del-foglio-di-calcolo-in-una-query-la-clausola-model/]

  • Trying to loop through records

    Hi
    I trying to loop through my records and write to a database each time, but my code only seems to write the first time through...
              //check for the stock levels...
              Iterator stockLevels = getItems().iterator();
              pstmt = dbConn.prepareStatement(sql_bundle.getString("findStock"));
              while (stockLevels.hasNext()) { 
                   CartItem stockL = (CartItem) stockLevels.next();
                   pstmt.setString(1, stockL.getProduct().getISBN());
                   ResultSet rscp = pstmt.executeQuery();
                   if(rscp.next()){
                        if (rscp.getInt("STOCK_LEVEL") > stockL.getQuantity()) {
                             int newAmount = rscp.getInt("STOCK_LEVEL") - stockL.getQuantity();
                             PreparedStatement pstmte = dbConn.prepareStatement(sql_bundle.getString("updateStock"));  
                             pstmte.setInt(1, newAmount);
                             pstmte.setString(2, stockL.getProduct().getISBN());
                             pstmte.executeUpdate();
                        } else {
                             cat.error("Right Bloddy mess");
                                 throw new Exception();
                   }else{ 
                        throw new Exception("No results from known good query.");
              pstmt.close();I get the following error in my browser:
    org.apache.jasper.JasperException
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
    and no errors when I compile using javac...
    Thanks

    excellent my looping is working...
    thanks

  • How to loop through records in the block

    Hello,
    I have 2 blocks one emp_control_block and the other one based on the emp. The emp control block basically has some search critieria which is then passed onto the emp block to execute the query. However, I don't want to show any emp block data until the user presses the search button in the control block then I automatically want to make visible the EMP block and also set the width of columns. Right now, in the properties I have not assigned any Canvas to the EMP Block
    Can anyone tell me How do I loop through the block and show the items/columns in a canvas that I have already created. Any example of the code would be really appreciated. Thanks

    Monica,
    I tried your code but I get NO NAVIGABLE ITEMS IN DESTINATION BLOCK error. In the property palette for the items in the EMP block I have assigned Null as Canvas because I want to programatically assign it to the emp_stack_canvas. How do I do that? Also I want to change the item width for each column to say a fixed width of 50.
    Thanks

  • Looping through records... LC 8.0

    Hi there
    It seems easy enough to get the first record from a DB into a Form - but for the life of me I cannot find a way to loop through all the records (like mail merge) and enter all the records?
    Could someone please point me in the right direction?
    Thanks

    Hi Paul
    That method would appear to be dependent upon a click method with buttons.
    Apart from the fact that it is time consuming, I can get the end result using .NET and iTextSharp (or ActivePDF Toolkit in asp.NET) to produce 'bulk' pdf documents by loading everything into a DataTable and running through a For loop for each row in the DataTable.
    These forms would be a 'one off' for each new Customer, with an average of 120 records, so was looking for a 'quick and dirty' approach - as you may gather we have LC but not used it very much at all, so perhaps I was missing something!

  • Looping through records in XML Variable !!

    Hi,
    I am getting no way how to do this. I am getting the below XML from a custom DSC component. Now I need to process it.
    <root>
        <records total_records="4">
            <record>
                <jobno>1122</jobno>
                <cust_name>Abhinav</cust_name>
                <email>[email protected]</email>
                <stat>1</stat>
            </record>
            <record>
                <jobno>2233</jobno>
                <cust_name>Doctor Dhober</cust_name>
                <email>[email protected]</email>
                <stat>0</stat>
            </record>
            <record>
                <jobno>4666</jobno>
                <cust_name>Vinau Dubey</cust_name>
                <email>[email protected]</email>
                <stat>1</stat>
            </record>
            <record>
                <jobno>7677</jobno>
                <cust_name>Nelesh Poda</cust_name>
                <email>[email protected]</email>
                <stat>0</stat>
            </record>
        </records>
    </root>
    Now I need to loop through every record & do some stuff for each one. In my process I have to send a mail to each of the user in the XML file. I tried it using SET VALUE's Node Set Functions, but not successful. Any help.
    Thanks.
    Abhinav

    Your xpath doesn't match your XML - you are missing the root node in your xpath expression:
    Expression: /process_data/myXML/records/record[1]/email
    should be:
               /process_data/myXML/root/records/record[1]/email
    When you build your loop there is one other thing to be careful of.  If you evaluate an xpath variable inside of another xpath expression, it gets inserted as a string.  This happens even if the variable is an integer.  For example:  If I have an integer variable counter which is set to 3 and evaluate:
         /process_data/myXML/root/records/record[/process_data/@counter]/email    The xpath expression will insert "3" (a string) and not an integer as you would expect.  The result will not be the third node. This can be a source of frustration and its hard to debug.
    Instead, use the number function inside the expression:
      /process_data/myXML/root/records/record[number(/process_data/@counter)]/email
    I've attached a sample process that shows this.

  • Problem while looping through record set and tem table for matching data

    hi I am using one record set and ane temp table and looping through both to find the match between dates.
    If date matches then it shud do some processing otherwise it will return default values(null values).
    FOR i IN student_rec .FIRST..student_rec .LAST          /*student_rec.school_date has 01-MAR-2012,02-MAR-2012,03-MAR-2012,04-MAR-2012,05-MAR-2012*/
    LOOP
    l_return_out.school_date := student_rec(i).school_date;
    l_return_out.marks_obtained := student_rec(i).marks_obtained;
    FOR i IN selected_dates .FIRST..selected_dates .LAST          /*selected_dates has 02-MAR-2012,03-MAR-2012,05-MAR-2012*/
    LOOP
    DBMS_OUTPUT.PUT_LINE(selected_dates(i));
    IF selected_dates(i)=student_rec(i).sett_date
    THEN
    EXIT;
    end if;
         ---------call procedure P1
    -----------get output as ret_val1               /*getting ret_val1 as 10 for 02-MAR-2012,03-MAR-2012,05-MAR-2012 */
         ----------call procedure P2
    ---------get ouput as ret_val2               /*getting ret_val1 as 20 for 02-MAR-2012,03-MAR-2012,05-MAR-2012 */
    if ret_val1>0 0r ret_val2>0
    then
    l_return_out.has_csts := yes;
    l_return_out.cst_present := 10;
    l_return_out.cst_absent := 20;
    else
    l_return_out.has_csts :=No;
    l_return_out.cst_present:= 0;
    l_return_out.cst_absent := 0;
    end if;
    end loop;
    l_return_out.has_cst := student_rec(i).has_csts;
    l_return_out.cst_missing := student_rec(i).cst_present;
    l_return_out.cst_existing := student_rec(i).cst_absent;
    PIPE ROW(l_return_out);
    END LOOP;
    RETURN ;
    I am expecting this as result
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          yes 10          20
    03-MAR-2012     40           yes 10          20
    04-MAR-2012     70          
    05-MAR-2012     60          yes 10          20
    but this as result
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          
    03-MAR-2012     40           
    04-MAR-2012     70          
    05-MAR-2012     60          
    Can anybody please highlight the mistake i am doing while processing the logic??
    Edited by: 942390 on Jul 13, 2012 8:44 PM
    Edited by: 942390 on Jul 13, 2012 8:45 PM

    I am getting a set values from a record set....student_rec
    and on pipelining this record set from 1st till last
    i am getting this
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          
    03-MAR-2012     40           
    04-MAR-2012     70          
    05-MAR-2012     60     
    so initially has_csts, cst_present and cst_absent is null for all dates.
    now have a temp table of selected_dates(which contains these dates 02-MAR-2012,03-MAR-2012,05-MAR-2012)
    now I am want to populate has_csts, cst_present and cst_absent with data only for those dates which is present in selected_dates temp table(02-MAR-2012,03-MAR-2012,05-MAR-2012) and that too has_csts, cst_present and cst_absent will be populated with some condition (based on the values from procedure got from P1 and P2).
    so want result set to look like
    school_date     marks_obtained     has_csts     cst_present cst_absent
    01-MAR-2012     20          
    02-MAR-2012     30          yes 10          20
    03-MAR-2012     40           yes 10          20
    04-MAR-2012     70          
    05-MAR-2012     60          yes 10          20
    so what could be the possible solution to obtained this....

  • How to loop through records in a block

    How do I get the count of records in a data block after the EXECUTE_QUERY?
    If I want to manually insert or update records into the table from the datablock how do I loop thru' records in the block.?
    Also for 'WHERE' clause of update statement is there anyway to tie up the rowid to the current row in the form.

    Use get_block_property('block',QUERY_HITS).
    For the second question :
    Set the properties of block to be INSERT_ALLOWED=FALSE,UPDATE_ALLOWED=FALSE, next do:
    go_block('block');
    first_record;
    set a local handler of errors
    loop
    next_record;
    end loop;
    when others then
    catch the error "Record must be inserted first...'
    For the third question set the DML Returning Value = Yes in property palette of the block and access the rowid as
    declare
    rowid_ rowid;
    begin
    rowid_:=:block.rowid;
    end;
    HTH

  • Loop through records in a table and update

    Hi there,
    Need some help here please. Sorry new to Oracle. I'm working with Oracle 10g.
    I have a table like this;
    ID Amount Date
    123 5000 Oct-07-2011
    123 null Oct-09-2011
    124 7000 Oct-14-2011
    124 null Oct-17-2011
    124 null Oct-24-2011
    What I'm trying to do here is loop thruogh the records and update the amount that's null with the previous amount with the same ID.
    Some sample code that I follow for this?
    Thanks very much for your help.

    maybe some of this example migth help.
    SQL> select id, amount, tdate
      2    from (select 123 id, 5000 amount, to_date('Oct-07-2011','mon-dd-rrrr') tdate from dual union all
      3          select 123 id, null amount, to_date('Oct-09-2011','mon-dd-rrrr') tdate from dual union all
      4          select 124 id, 7000 amount, to_date('Oct-14-2011','mon-dd-rrrr') tdate from dual union all
      5          select 124 id, null amount, to_date('Oct-17-2011','mon-dd-rrrr') tdate from dual union all
      6          select 124 id, null amount, to_date('Oct-24-2011','mon-dd-rrrr') tdate from dual union all
      7          select 124 id, 8000 amount, to_date('Oct-25-2011','mon-dd-rrrr') tdate from dual union all
      8          select 124 id, null amount, to_date('Oct-28-2011','mon-dd-rrrr') tdate from dual)
      9  order by id, tdate;
            ID     AMOUNT TDATE
           123       5000 07-Oct-11
           123            09-Oct-11
           124       7000 14-Oct-11
           124            17-Oct-11
           124            24-Oct-11
           124       8000 25-Oct-11
           124            28-Oct-11
    7 rows selected
    SQL>
    SQL> select id,
      2         last_value(amount ignore nulls) over (partition by id order by tdate) amount,
      3         tdate
      4    from (select 123 id, 5000 amount, to_date('Oct-07-2011','mon-dd-rrrr') tdate from dual union all
      5          select 123 id, null amount, to_date('Oct-09-2011','mon-dd-rrrr') tdate from dual union all
      6          select 124 id, 7000 amount, to_date('Oct-14-2011','mon-dd-rrrr') tdate from dual union all
      7          select 124 id, null amount, to_date('Oct-17-2011','mon-dd-rrrr') tdate from dual union all
      8          select 124 id, null amount, to_date('Oct-24-2011','mon-dd-rrrr') tdate from dual union all
      9          select 124 id, 8000 amount, to_date('Oct-25-2011','mon-dd-rrrr') tdate from dual union all
    10          select 124 id, null amount, to_date('Oct-28-2011','mon-dd-rrrr') tdate from dual)
    11  order by id, tdate;
            ID     AMOUNT TDATE
           123       5000 07-Oct-11
           123       5000 09-Oct-11
           124       7000 14-Oct-11
           124       7000 17-Oct-11
           124       7000 24-Oct-11
           124       8000 25-Oct-11
           124       8000 28-Oct-11
    7 rows selected
    SQL>

  • How to loop through a collection of records which is return value of func.

    Hi all.
    Have this situation:
    - Stored function (member of pkg procedure) that returns a collection of records.
    Package Spec:
    =========
    type tipo_pvt is table of s08_plan_venta_totalizado_r % rowtype;
    rc_pvt tipo_pvt;
    (s08_plan_venta_totalizado_r is a view).
    Package Body:
    =========
    select col1
    ,col2
    ,etc
    bulk collect into rc_pvt
    from s08_lista_precio_producto_r lpp
    ,s03_producto_r prd
    where condition;
    return rc_pvt;
    Once collection is loaded and returned (i know it loads records). I just want to loop through every record on a pl/sql procedure on the client (forms6i procedure), but it gives me the error: ORA-06531 Reference to uninitialized collection:
    On the forms6i client procedure i have something like:
    procedure p_carga_plan_venta_inv (p_id_plan_venta in number) is
    v_contador integer;
    v_mensaje varchar2(10);
    rc_pvt sk08_gestiona_plan_venta.tipo_pvt; (sk08_gestiona_plan_venta is package name)
    begin
         rc_pvt := sk08_gestiona_plan_venta.tipo_pvt();
         rc_pvt := sk08_gestiona_plan_venta.f_genera_plan_venta_inv (:pvv.lip_id_lista_precio
    ,:pvv.ems_id_sucursal
                                            ,:control4.v_metodo_calculo
    ,:pvv.unm_co_unidad_monetaria
    ,:pvp.fe_fin_periodo) ;
    -- previous statement dos not fail BUT THIS:
    message('rc_pvt.count= '||rc_pvt.count);pause;
    DOES FAIL
    end;
    So my question is : since i have already returned the collection, how come is not initialized....?
    Do i have to extend it first? In this case i have to return the number of records in the collection.....
    Look what happen when done from sqlplus:
    declare
    rc_pvt sk08_gestiona_plan_venta.tipo_pvt;
    begin
    rc_pvt := sk08_gestiona_plan_venta.tipo_pvt();
    rc_pvt :=
    sk08_gestiona_plan_venta.f_genera_plan_venta_inv (8713171
    ,null
    ,'m'
    ,'BS.F'
    ,to_date('28/02/2001','dd/mm/yyyy'));
    end;
    SQL> /
    Registros en la coleccion =6
    Procedimiento PL/SQL finalizado con éxito.
    SQL>
    I put a dbms_output.put_line on stored function .....
    Please help ....!
    Apparently it fails when calling the stored function:
    rc_pvt := sk08_gestiona_plan_venta.f_genera_plan_venta_inv (:pvv.lip_id_lista_precio
    ,:pvv.ems_id_sucursal
    ,:control4.v_metodo_calculo
    ,:pvv.unm_co_unidad_monetaria
    ,:pvp.fe_fin_periodo) ;
    I don't undestand since this function return the appropiate type. It seems the collection is empty, although having test that on sqlplus works ...
    rc_pvt := sk08_gestiona_plan_venta.f_genera_plan_venta_inv (:pvv.lip_id_lista_precio
    ,:pvv.ems_id_sucursal
    ,:control4.v_metodo_calculo
    ,:pvv.unm_co_unidad_monetaria
    ,:pvp.fe_fin_periodo) ;
    function f_genera_plan_venta_inv (p_id_lista_precio in number
    ,p_id_sucursal in number
    ,p_tipo_nivel_inv in varchar2
    ,p_co_unidad_monetaria in varchar2
    ,p_fe_fin_periodo in date) return tipo_pvt;
    for some reason it works on plus:
    SQL> declare
    2 rc_pvt sk08_gestiona_plan_venta.tipo_pvt;
    3 begin
    4 rc_pvt := sk08_gestiona_plan_venta.tipo_pvt();
    5 rc_pvt :=
    6 sk08_gestiona_plan_venta.f_genera_plan_venta_inv (8713171
    7 ,null
    8 ,'m'
    9 ,'BS.F'
    10 ,to_date('28/02/2001','dd/mm/yyyy'));
    11 --
    12 dbms_output.put_line('Registros en la coleccion = '||rc_pvt.count);
    13 for i in 1 .. rc_pvt.count loop
    14 --
    15 dbms_output.put_line('En '||i||rc_pvt(i).prd_co_producto);
    16 end loop;
    17 end;
    18 /
    Registros en la coleccion =6
    Registros en la coleccion = 6
    En 1PT.REF.PET.KO05
    En 2PT.REF.PET.LM15
    En 3PT.ALM.VDR.001
    En 4PT.REF.GRN.CN
    En 5PT.REF.GRN.KO
    En 6PT.REF.GRN.LM
    Procedimiento PL/SQL finalizado con éxito.
    Don't understand why it works on plus8 (same version that comes with 6i).
    Can't loop through records on forms...? WHY ...?
    Edited by: myluism on 02-abr-2012 14:40

    Forms 6i is an antique ... write your code to run on the server.
    Multiple examples of how to loop through an array loaded with bulk collect can be found here.
    http://www.morganslibrary.org/reference/array_processing.html
    The main library page is:
    http://www.morganslibrary.org/library.html

  • Iteration through records in E-Tester

    Hi,
    I am testing a web application and I would like to know if there is a way to iterate through records without logging in and logging out multiple times. Right now when I iterate , each ietration starts with login and ends with logout. I want to be able to iterate through just the business process multiple times and logout at the end.
    Can this be done in e-tester.
    Thanks.
    Message was edited by:
    user643041

    You can do this with Job Scheduler. You will have to break up the scripts into their component parts then run everything together in Job Scheduler.

  • How to loop through xml records from file without ROW , /ROW tags?

    I am using dbms_XMLSave.insertXML procedure to insert xml formated record from file. MY xmlformated records does not have open and close ROW tags. I have multiple records in the file.How can I loop through without <ROW>,</ROW> tags?

    I am using dbms_XMLSave.insertXML procedure to insert xml formated record from file. MY xmlformated records does not have open and close ROW tags. I have multiple records in the file.How can I loop through without <ROW>,</ROW> tags?

  • How do I loop through tables, not columns in a table?

    Sorry if this is a long one. My problem is actually quite simple. I am trying to write either an ad hoc PL/SQL block or a stored procedure to loop 18 times (thru 18 tables) and perform a SQL query on those tables, returning 18 resultsets. I would like the results to show up on the screen (or in a spool file, whatever).
    So far I have tried 3 different approaches, none of which have worked.
    1. I tried to assign the select query to a variable (qry) and use EXECUTE IMMEDIATE qry. This forced me thru a variety of errors to declare variables and assign the result to them--EXECUTE IMMEDIATE qry into nm0, nm1, nm2...
    The problem with that was the resultset returned more than the variable was built for as there might be no rows returned, or it might be a thousand rows of data. So I tried changing the variables to VARRAYS, but it gave me a type mismatch as the underlying columns were NUMBER and VARCHAR2.
    DECLARE
         ctr number;
         TYPE NUMLIST IS VARRAY (1000) OF NUMBER;
         TYPE VARLIST IS VARRAY (1000) OF VARCHAR2(15);
         nm0 NUMLIST NOT NULL DEFAULT 1;
         nm1 VARLIST;
         nm2 NUMLIST NOT NULL DEFAULT 1;
         nm3 VARLIST;
         nm17 NUMLIST NOT NULL DEFAULT 1;
         qry VARCHAR2(2000) := 'klx_uln_p000_cells';
    BEGIN
    FOR ctr IN 1..17 LOOP
         IF ctr &lt; 10 THEN
              qry := 'SELECT
              A.DIM_0_INDEX,
              S0.SYM_NAME,
              A.DIM_1_INDEX,
              S1.SYM_NAME,
              A.DIM_2_INDEX,
              S2.SYM_NAME,
              A.DIM_3_INDEX,
              S3.SYM_NAME,
              A.NUMERIC_VALUE,
              B.NUMERIC_VALUE
              FROM
              KHALIX.klx_uln_p00'||ctr||'_cells A,
              KHALIX.klx_ucn_p00'||ctr||'_cells B,
              KHALIX.KLX_MASTER_SYMBOL S0,
              KHALIX.KLX_MASTER_SYMBOL S1,
              KHALIX.KLX_MASTER_SYMBOL S7
              WHERE
              A.DIM_0_INDEX=B.DIM_0_INDEX AND
              A.DIM_1_INDEX=B.DIM_1_INDEX AND...
              A.DIM_7_INDEX=S7.SYM_INDEX';
         ELSE
              qry := 'SELECT
              A.DIM_0_INDEX...
              A.DIM_7_INDEX=S7.SYM_INDEX';
         END IF;
         BEGIN
         dbms_output.put_line('SELECT FOR KLX_ULN_P00'||ctr||'_CELLS');
         dbms_output.put_line(nm16);
         dbms_output.put_line(nm17);
         EXECUTE IMMEDIATE qry into nm0,nm1,nm2,nm3,nm4,nm5,nm6,nm7,nm8,nm9,nm10,nm11,nm12,nm13,nm14,nm15,nm16,nm17;
    --     dbms_output.put_line(qry);
         dbms_output.put_line(nm16);
         dbms_output.put_line(nm17);
         EXCEPTION
              WHEN NO_DATA_FOUND THEN
                   dbms_output.put_line('No data found for Query '||ctr);
         END;
    END LOOP;
    EXCEPTION
         WHEN NO_DATA_FOUND THEN
              dbms_output.put_line('No data found for Query '||ctr);
    END;
    2. So then I used REF CURSOR to create a stored procedure and return the values. That allowed me to run my query AND tokenize the tablenames with a counter so that it would loop through the different tables! However, I still could not get it to display the results without going to SQL Plus and typing 'print c;'.
    3. So, finally I tried to create a looping wrapper around the ref cursor to have some variable (ctr) increment so my query would get performed on table0_cells through table17_cells. This, too, did not work.
    If I manually go to SQL Plus and type:
    variable ctr number
    begin
    :ctr := 1;
    end;
    exec dupe_find(1,:c);
    it will execute for the first table (klx_uln_p001_cells) and I can then type 'print c' to see what was returned. But when I try putting this within a wrapper PL/SQL block with a Loop to make ctr go from 0 - 17 (to loop through table_names klx_uln_p000_cells to klx_uln_p017_cells), it does not work.
    Help! It should be very simple to loop through tables, shouldn't it? I just want a script that will loop through tables, perform a query on each table and display the results. For some reason, I can only find documentation examples on looping through columns that are all in the same table.
    Dave

    Here's a working example using your first strategy ...
    create table t1 (id number);
    create table t2 (id number);
    insert into t1 values (100);
    insert into t1 values (101);
    insert into t2 values (200);
    insert into t2 values (201);
    declare
    v_table_name user_tables.table_name%type;
    type ttab_id is table of t1.id%type index by binary_integer;
    tab_id ttab_id;
    begin
    for i in 1 .. 2 loop
    v_table_name := 't' || i;
    execute immediate 'select id from ' || v_table_name
    bulk collect into tab_id;
    dbms_output.put_line('query from ' || v_table_name);
    for j in 1 .. tab_id.count loop
    dbms_output.put_line(tab_id(j));
    end loop;
    end loop;
    end;
    There are many other ways to do this (especially if you need to do more than just print out the data).
    Richard

  • Insert Loop through a Report or Insert using a Column Link

    Hello!
    I think I have an easy one.
    I have created a site that tracks "issues" with the curriculum of a university's courses. If a curriculum developer sees something that must be updated, they use this site to log the "issue" so we have a running list of how the curriculum has changed for the particular course or courses. Some "issues" span multiple courses, so a table was created to allow the issue to be associated with as many courses as necessary.
    The "Courses" table holds a list of all courses at the university
    The "Issue_Courses" table combines the primary key for the "issue" and the "course" and creates the association between issues and courses.
    The page users use to create the associations has a report called "add_courses" which is searchable and filterable so the user can narrow down the list of courses they want to view (the list is well into the thousands), and this report contains a column with check boxes. This page also contains a hidden field containing the primary key for the issue, "p13_Issue_ID"
    I would like to create an insert statement that grabs the primary key for the issue from "p13_issue_ID" and loops through the report, inserting a new record for each checked box in the report. Any assistance would be great! Admittedly, my sql is pretty week.
    Another option that I think would work, if possible, would be to have a "column link" that simply runs the insert process by grabbing the issue primary key from "p13_issue_ID" and the course id from the report. Then, the user could simply click on an "Add" link or something similar on the report, which would run the insert statement, and basically create that association. Is this possible?
    Thanks in advance!
    Edited by: 846852 on Mar 23, 2011 3:12 PM
    Edited by: 846852 on Mar 23, 2011 3:14 PM

    Start with adding a checkbox column to the report in page (13 ??)
    select apex_item.checkbox(1,course_id) CHECK
           ,course_name
    FROM courses
    I assumed that course_id is the PK of the courses table , if not change the column names appropriately
    In report attributes of the "CHECK" column, change the column type to "*Standard Report Column*" (important).
    Now you should see a report with courses lists and checkboxes to choose them, You can also do the same with an interactive report(if you want to use it features to filter down records)
    Inorder to process the records create a PLSQL process that loops over the selected records(courses) and creates the relation in the Issue courses table using the hidden item and checked course primary key(course_id above)
    DECLARE
      ln_course_id NUMBER;
    BEGIN
      FOR 1 IN 1..APEX_APPLICATION.G_f01.COUNT
      LOOP
        ln_course_id := APEX_APPLICATION.G_f01(i);
        --Insert new relation using Issue Id and course ID
        INSERT INTO ISSUE_COURSES(course_id,issue_id) VALUES( ln_course_id,:P13_ISSUE_ID);
      END LOOP;
    END;If you have a submit/save button , make the process conditional for that button.

  • How to loop through SYS_REF cursor records

    Hello, I'm using the following oracle version
    PL/SQL Release 11.2.0.2.0 - Production
    I'd like to create an Oracle anonymous block which calls another procedureB. ProcedureB returns the result of a query in the form of a SYS_REF cursor. Once the result is returned into the anonymous block, I'd like to loop through specific columns of the result set. I've started with this, but it isn't right. Could you please let me know what I'm doing wrongly?
    create or replace procedure procedureRFHA(numIn IN number, cursorOUT OUT sys_refcursor) as
    begin
    open cursorOUT for
    select 'A' col1, 'B' col2
    from dual
    where 3 = numIn
    union all
    select 'C' col1, 'D' col2
    from dual
    where 3 = numIn;
    end;
    declare
    TYPE r_type IS RECORD (
    col1 VARCHAR2 (1),
    col2 VARCHAR2 (1)
    returnCursor sys_refcursor;
    begin
    procedureRFHA(3, returnCursor);
    LOOP
    FETCH returnCursor INTO r_type;
    dbms_output.put_line(r_type.col1);
    EXIT WHEN returnCursor%NOTFOUND;
    END LOOP;
    CLOSE returnCursor;
    end;

    Then please mark the question ANSWERED.

Maybe you are looking for

  • MC46 & MC50 Reports

    Hi Guru's Can any body tell me , what logic is the system considering to execute the reports MC46 (Slow Moving) and MC50 (Dead stock) In MC46 report system displaying 'Days Since Consumption" but when I cross check the last consumption date from MB51

  • Changing Date Format in ALV List for VKM1 transaction

    Hi All, I have to change date format to MM/DD/YY in the ALV list display of VKM1 transaction. There are user exits available. I am trying to use EDIT_MASK option of the field catalog.. Without changing the code, I give value as __:__:__ or MM/DD/YY i

  • Newbie Q?.. Opens in Tablet page on Desktop?

    Hey guys.. have just started playing with Muse.. Watched the Terry White tutorial.. Now in muse.. Made the 3 basic pages (all default settings) First for Desktop, then Tablet, then Phone.. Added 1 small line of text eg. "This is the desktop page!" et

  • How EKNUM is updated in Billing ?

    Hi I am creating a CR- sales order document type and then directly creation a Credit Memo ( G2) by doing VF01. The problem is in VBRK tbal EKNUM is blank. It means system is not recognising it as Foreign Trade data. I need to understand How this Fiel

  • Sending 2 messages from SAP but get 1 message in PI

    Hi all, This is a bit of a strange one but I have the situation where we send two idocs at the same time from a SAP ECC system to PI. The first idoc is processed but the second one just dissapears. Things I have checked: SMQ1/SMQ2 on both systems - n