Cursor%ROWCOUNT

I understand I can use cursor%ROWCOUNT to count the number of rows in a cursor. How do I have a loop that loop all the way till the cursor's rowcount is at its last row?

for tha use cursor%NOTFOUND.
Once you fetch you can check
IF cursor%NOTFOUND THEN
EXIT;
END IF;
rowcount cant be used to find the last record as it just a count that has how many records fetched till now from a cursor
SQL> declare
  2     cursor c is select * from dual connect by level <= 5;
  3     l varchar2(1);
  4  begin
  5     open c;
  6     loop
  7             fetch c into l;
  8             dbms_output.put_line(c%rowcount);
  9             exit when c%notfound;
10     end loop;
11     close c;
12  end;
13  /
1
2
3
4
5
5
PL/SQL procedure successfully completed.Thanks,
Karthick.
Edited by: Karthick_Arp on Sep 4, 2008 5:07 AM

Similar Messages

  • Cursor%ROWCOUNT at start of cursor?

    I want show the number of records pulled from the database in a report at the top of it.
    E.g.
    500 students match your request:
    /* The students details here */
    It seems ROWCOUNT increments each time just like a counter, is there a way to get the total number of rows returned at the start of the cursor.

    Hi,
    one way could to execute a COUNT(*) query before you execute the query which returns the data (not a efficient way). Which reporting tool you are using may be they have a knowing the count of records received.
    thanks

  • Getting cursor rowcount before fetching?

    Just checking if this is do-able? Is there a way to find the total number of rows selected by a cursor after opening it, but before fetching anything?
    I know the cursor attribute %rowcount returns the number of records fetched so far (although I don't see this as very useful if there's no way to first find out how many rows there are in total).
    From what I've read in the docs it isn't possible, but just checking if anyone has found a way, or there's some deep, hidden, undocumented built-in somewhere that I can probe to get what I want. :o)
    After the cursor is opened, the sql has been executed and the result set generated.. I don't see why Oracle couldn't report how many rows are in the result set before all the rows are fetched??
    thanks in advance.

    BluShadow wrote:
    Mahanam wrote:
    The ROWCOUNT attribute doesn't give the real row count until you have iterated through the entire cursor.Yes it does give the real row count, because it's the rows that have been fetched, not the complete rows that will be fetched.What I meant was :
    Until all rows are not fetched, we will not be able to know "row count", that is at the time we opened the cursor, by using rowcount attribute. My mistake I did not clearly mention.
    In other words, you should avoid relying on this attribute to tell you how many rows are in a cursor after it is opened.There are never any rows "in" a cursor. A cursor does not store data.Yes, cursor does not store data, but when cursor is opened, there may be rows to process. Please correct me if I am wrong.

  • REF Cursor Rowcount

    I need to get the rowcount for the refcursor before fetching the data itself.
    Please let me know how to get the same.
    Example:
    Open X FOR Query
    var:= x%rowcount
    Once this executed i am getting the value var is 0 but it's retriving some rows to java environment.

    PL/SQL 101 : Understanding Ref Cursors

  • Looping through a cursor (newbie)

    I am trying to construct a dynamic insert statement. I am retrieving (using a select) the column names from one of my tables into a cursor. I would now like to loop through the cursor and extract the column names. Is there anyway to loop through the cursor like you can normally do as below:
    for i = 0 to cursor%rowcount
    tempstring = tempstring + ',' + cursor.i; (something along these lines)
    end for
    and then do 'insert into tablename (' || tempstring
    Am I making sense?

    There are several methods to process cursors and you can easily find them
    here.
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/01_oview.htm#740
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/06_ora.htm#36656
    And before trying to use dynamic sql it would be better to think would you really
    need it...
    Rgds.

  • CURSOR%NOTFOUND vs no more records to process;

    how can I differentiate between the above ? I have a cursor that selects data based on a condtion. If the condition is not met and I get CURSOR%NOTFOUND is true I want to handle this in one way while still being able to handle no more rows to process.
    hope my question is clear
    thanks
    Message was edited by:
    aanton

    That means, if cursor%rowcount > 0 then you have found at least one record. If there was no record found at all, cursor%rowcount is 0.
    SQL> get t
      1  declare
      2    cursor c1 is select dummy from dual where 1 = 1;
      3    cursor c2 is select dummy from dual where 1 = 0;
      4    l_res  varchar2(10);
      5  begin
      6    open c1;
      7    fetch c1 into l_res;
      8    if c1%notfound then dbms_output.put_line ( 'c1: not found, c1%rowcount: ' || c1%rowcount );
      9    else                dbms_output.put_line ( 'c1: found,     c1%rowcount: ' || c1%rowcount );
    10    end if;
    11    fetch c1 into l_res;
    12    if c1%notfound then dbms_output.put_line ( 'c1: not found, c1%rowcount: ' || c1%rowcount );
    13    else                dbms_output.put_line ( 'c1: found,     c1%rowcount: ' || c1%rowcount );
    14    end if;
    15    close c1;
    16    open c2;
    17    fetch c2 into l_res;
    18    if c2%notfound then dbms_output.put_line ( 'c2: not found, c2%rowcount: ' || c2%rowcount );
    19    else                dbms_output.put_line ( 'c2: found,     c2%rowcount: ' || c2%rowcount );
    20    end if;
    21    close c2;
    22* end;
    SQL> /
    c1: found,     c1%rowcount: 1
    c1: not found, c1%rowcount: 1
    c2: not found, c2%rowcount: 0
    PL/SQL procedure successfully completed.
    SQL>

  • Update a column for every 2000 records in the table

    The table has 50,000 records. I want to update the process_id every 2000 rows. For example, 1 for the 1st 2000 rows, 2 for the next 2000 rows, 3 for the next 2000 rows, and etc. Is there a quick way to do it?
    Thanks much

    hey <[email protected]>
    Two ways of doing this...
    First: PL/SQL
    By declaring a cursor on the table and using the cursor%rowcount method to update your field..something like this...
    Declare
    Begin
    For rno in MyCursor
    Loop
    update <tablename> set process_id = lv_pid where rowid = rno.rowid
    If mod(MyCur%rowcount,2000) = 0 then
    lv_pid = lv_pid + 1;
    End If;
    End Loop;
    End
    I am sorry if u already knew this :-) !!
    Second: SQL
    let u know once (if)i crack it :-( !!
    Goodluck...
    Vasudev

  • Collections and counts

    Greetings!
    I have a procedure in the following format:
    PROCEDURE test as
    type p1 is table of number;
    tab_t1 p1;
    cursor c1 is
    (select ....... from table1);
    begin
    open c1;
    loop
    fetch c1 BULK COLLECT INTO tab_t1... limit 1000;
    FORALL i in 1..tab_t1.count
    insert into table2 values tab_t1(i);
    commit;
    exit when c1%notfound;
    end loop;
    msg := 'Count of records inserted ' || to_char(sql%rowcount);
    test_util.write_to_log (handle, msg);
    close c1;
    commit;
    end;
    My question is where should the sql%rowcount be when we use collections (after closing the cursor or before end loop or ..), to capture count of all the records that have been inserted so far. Thank you,
    Lakshmi
    Message was edited by:
    user6773

    Ramana:
    There is one major difference betqween your version and Adrian's accumulating SQL%ROWCOUNT for each of the INSERTS. Adrian uses a count of 0 in the collection to exit, and you are using cursr%NOTFOUND.
    I created two procedures, one p based on your logic, and a second p1 based on Adrians. I also set the limit to something less than the number of records in the table, and not an even multiple of the number of records. so, the procedures are:
    CREATE or replace PROCEDURE p AS
       TYPE array_tp IS TABLE OF t%ROWTYPE;
       l_array array_tp;
       CURSOR c IS
          SELECT * FROM t;
       l_cnt1 NUMBER := 0;
       l_cnt2 NUMBER := 0;
       l_cnt3 NUMBER := 0;
    BEGIN
       OPEN c;
       LOOP
          FETCH c BULK COLLECT INTO l_array LIMIT 9;
          l_cnt1 := c%ROWCOUNT;
          FORALL i IN 1 .. l_array.COUNT
             INSERT INTO t1 VALUES l_array(i);
          EXIT WHEN c%NOTFOUND;
          l_cnt2 := l_cnt2 + SQL%rowcount;
       END LOOP;
       l_cnt3 := c%ROWCOUNT;
       CLOSE c;
       DBMS_OUTPUT.Put_Line('Cursor rowcount after fetch gives: '||l_cnt1);
       DBMS_OUTPUT.Put_Line('Accumulate sql rowcount after insert gives: '||l_cnt2);
       DBMS_OUTPUT.Put_Line('Cursor rowcount before close gives: '||l_cnt3);
    END;
    CREATE or replace PROCEDURE p1 AS
       TYPE array_tp IS TABLE OF t%ROWTYPE;
       l_array array_tp;
       CURSOR c IS
          SELECT * FROM t;
       l_cnt1 NUMBER :=0;
       l_cnt2 NUMBER :=0;
       l_cnt3 NUMBER :=0;
    BEGIN
       OPEN c;
       LOOP
          FETCH c BULK COLLECT INTO l_array LIMIT 9;
          EXIT WHEN l_array.COUNT = 0;
          l_cnt1 := c%ROWCOUNT;
          FORALL i IN 1 .. l_array.COUNT
             INSERT INTO t1 VALUES l_array(i);
          l_cnt2 := l_cnt2 + SQL%rowcount;
       END LOOP;
       l_cnt3 := c%ROWCOUNT;
       CLOSE c;
       DBMS_OUTPUT.Put_Line('Cursor rowcount after fetch gives: '||l_cnt1);
       DBMS_OUTPUT.Put_Line('Accumulate sql rowcount after insert gives: '||l_cnt2);
       DBMS_OUTPUT.Put_Line('Cursor rowcount before close gives: '||l_cnt3);
    END;Note that the line l_cnt3 := c%ROWCOUNT after the LOOP but before closing the cursor would be my preference as a way to get the count if you really needed it. Now running both I get:
    SQL> SELECT COUNT(*) FROM t;
      COUNT(*)
            40
    SQL> SELECT COUNT(*) FROM t1;
      COUNT(*)
             0
    SQL> exec p
    Cursor rowcount after fetch gives: 40
    Accumulate sql rowcount after insert gives: 36
    Cursor rowcount before close gives: 40
    PL/SQL procedure successfully completed.
    SQL> SELECT COUNT(*) FROM t1;
      COUNT(*)
            40
    SQL> ROLLBACK;
    SQL> exec p1;
    Cursor rowcount after fetch gives: 40
    Accumulate sql rowcount after insert gives: 40
    Cursor rowcount before close gives: 40
    PL/SQL procedure successfully completed.
    SQL> SELECT COUNT(*) FROM t1;
      COUNT(*)
            40You version using SQL%ROWCOUNT misses the last partial set of rows because c%NOTFOUND is TRUE after fetching the last 4 rows from the table, so you exit the loop prior to accumulating. Moving the EXIT WHEN after assigning SQL%ROWCOUNT would give the correct results.
    John

  • Record Count + Resultset

    Hi All,
    I am executing a query in back and returning ref cursor to front end. Before returning recordset, I am doing record count. If record count is more then max record count defined, then I do not return any recordset.
    Now the problem is that I have to execute this query twice, once for counting and another for fetching. This increases my response time. I tried to get Cursor%ROWCOUNT after fetching, so that I can get total time during fetch itself, but it shows 1 as it always fetch single record at time.
    Is there any way through which I can execute query once and get records as well as its count.
    Thanks,
    Danish

    When you OPEN a cursor the SQL statement associated with it is executed. i.e. Oracle allocates the required resources for that statement and also identifies the rows that needs to be processes.
    Thats all happens when you issue OPEN. The records are not fetched.
    ROWCOUNT is a pseudocolumn that only indicates how many rows are fetched currently. So initially it will be zero. So it will give the total count only when you finish fetching all the rows.
    So as far now i dont see any other option other than querying the table for COUNT to get the count of rows.

  • PL/SQL Cursor-attribute %ROWCOUNT

    Hi to everybody,
    I have a question regrading to Cursor attributes.
    I'm written a funtion(you can see the code below) with REF CURSOR as its Return value.
    Now I want to use the Cursor Attribute ROWCOUNT to check out how many rows the function gives back, but I always become 0.
    The funtion itself work without any problems except for the ROWCOUNT Attribute which gives always 0 back.
    Can somebody told me what I make wrong????
    Thanxxx
    Schoeib Amin
    Create or Replace Function PIFS.indizierteWerte_fr_test
    (match IN string,
    Dauer IN number)
    return
    types.cursorType --Package where I defined a REF CURSOR TYPE
    AS
    Rate1 number;
    match_ VARCHAR2(15);
    c_cursor types.cursorType;
    Anfangsdatum date;
    jetziges_datum date;
    Anzahl number;
    BEGIN
    match_:=match;
    Anfangsdatum:=gebe_anfangsdatum(Dauer);
    jetziges_Datum:=sysdate;
    Rate1:=berechne_fr(match_,Anfangsdatum);
    OPEN c_cursor FOR
    Select
    (fr.indiziert)*Rate1 INDIZIERT,fr.DATUM
    from
    fondsreihe fr
    where
    fr.match=match_
    and fr.Datum between Anfangsdatum and to_char(jetziges_Datum,'DD.MM.YYYY') order by fr.DATUM;
    anzahl:=c_cursor%ROWCOUNT;
    dbms_output.put_line(anzahl);
    return c_cursor;
    END indizierteWerte_fr_test;

    Schoeib: Your function is defined as returning a REF CURSOR, there fore it must return a REF CURSOR. You cannot assign a number to a REF CURSOR variable to get sround this. If all you want to do in your function is get the number of rows returned by the dursor, then change the return type of the function to NUMBER, then iterate through the cursor to get the row count.
    Gavin: Unfortunately, there is no way to get the number of rows returned from a statement without executing the statement. If you are using the Cost Based Optimizer, and all tables in the query are correctly (i.e. recently) analyzed, and you have also analysed the columns, then the Explain plan would give a reasonable (but no guarantees) extimate of the number of rows the query will return.

  • Help me show rowcount of a cursor on forms canvas,,

    i mean..
    The program unit is not in the forms application but in the oracle server side.
    i need to show a cursor's rowcount on forms canvas
    while a cursor is running loop in the program unit in real-time..
    so i used the when-timer-expired trigger that reads a data(related record count from some table) every 1second.
    i hoped that the timer trigger synchrozes with the server program unit.
    but there was only one time event when the server program unit has finished.
    How can i resolve the problem..??

    duplicate
    i try to display a number of executed record on the forms screen.
    Please do not create a new thread for the same problem.

  • Dynamic sql and ref cursors URGENT!!

    Hi,
    I'm using a long to build a dynamic sql statement. This is limited by about 32k. This is too short for my statement.
    The query results in a ref cursor.
    Does anyone have an idea to create larger statement or to couple ref cursors, so I can execute the statement a couple of times and as an result I still have one ref cursor.
    Example:
    /* Determine if project is main project, then select all subprojects */
    for i in isMainProject loop
    if i.belongstoprojectno is null then
    for i in ProjectSubNumbers loop
    if ProjectSubNumbers%rowcount=1 then
    SqlStatement := InitialStatement || i.projectno;
    else
    SqlStatement := SqlStatement || PartialStatement || i.projectno;
    end if;
    end loop;
    else
    for i in ProjectNumber loop
    if ProjectNumber%rowcount=1 then
    SqlStatement := InitialStatement || i.projectno;
    else
    SqlStatement := SqlStatement || PartialStatement || i.projectno;
    end if;
    end loop;
    end if;
    end loop;
    /* Open ref cursor */
    open sql_output for SqlStatement;
    Thanks in advance,
    Jeroen Muis
    KCI Datasystems BV
    mailto:[email protected]

    Example for 'dynamic' ref cursor - dynamic WHERE
    (note that Reports need 'static' ref cursor type
    for building Report Layout):
    1. Stored package
    CREATE OR REPLACE PACKAGE report_dynamic IS
    TYPE type_ref_cur_sta IS REF CURSOR RETURN dept%ROWTYPE; -- for Report Layout only
    TYPE type_ref_cur_dyn IS REF CURSOR;
    FUNCTION func_dyn (p_where VARCHAR2) RETURN type_ref_cur_dyn;
    END;
    CREATE OR REPLACE PACKAGE BODY report_dynamic IS
    FUNCTION func_dyn (p_where VARCHAR2) RETURN type_ref_cur_dyn IS
    ref_cur_dyn type_ref_cur_dyn;
    BEGIN
    OPEN ref_cur_dyn FOR
    'SELECT * FROM dept WHERE ' | | NVL (p_where, '1 = 1');
    RETURN ref_cur_dyn;
    END;
    END;
    2. Query PL/SQL in Reports
    function QR_1RefCurQuery return report_dynamic.type_ref_cur_sta is
    begin
    return report_dynamic.func_dyn (:p_where);
    end;
    Regards
    Zlatko Sirotic
    null

  • Difference between implicit cursor and explicit cursor.

    hi all,
    i have used explicit cursor, i know the way of using implicit cursor, but i don't what the difference between both.
    Is they both are different. if yes y? which cursor is most reliable to use.
    please tell me..
    Thanks..

    OK,
    1- An IMPLICIT cursor is automatically declared by Oracle every time an SQL statement is executed The user will not be aware of this happening and will not be able to control or process
    the information in an implicit cursor.
    Example:
    SET SERVEROUTPUT ON
    BEGIN
    UPDATE Customers
    SET Cust_name = 'B'
    WHERE Cust_name LIKE 'B%';
    DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
    END;
    2- An EXPLICIT cursor is defined by the program for any query that returns more than one row of data.
    That means the programmer has declared the cursor within the PL/SQL code block. This declaration allows for the application to sequentially process each row of data as it is returned by the cursor.
    Example :
    DECLARE
    CURSOR C_MyCursor IS
    SELECT *
    FROM bookings
    WHERE Cust_no = 701;
    see this post
    http://comsci.liu.edu/~vasilaky/db2/cursors.htm :-)

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

  • Copying value from one cursor to another

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

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

Maybe you are looking for

  • Report Painter -  Report not displaying all values

    Hi All, We are executing a report for Manufacturing variances by Product group which is created through report painter. In the output of the report in rows product wise data is displayed and columns are volume, price .. are there. Out of 8 products d

  • How to convert a sample from labview 5.1 to labview8.0

    I have a sample from the manifacture which was programmed using the labview5.1 but now I use use the labview8.05 . Can anybody help me to convert the sample from labview5.1 to labview8.05 , thanks Solved! Go to Solution. Attachments: CaryExample.vi ‏

  • Image Resolution for Printing Photos

    I am not sure if the resolution/files size requirements are the same for both inkjets (e.g. Epson) and taking your camera's SD card to a local self-serve kiosk (e.g. CVS). I have been taking photos at the larger file size with my Canon Powershot and

  • Trouble exporting anamorphic material

    So I'm simple trying to export a quicktime from an dv-pal anamorphic sequence and everytime I do it comes up as 4:3 frame size. I use the 'Current Settings' tab and failing that tried dv-pal anamorphic both exporting out as 4:3. I probably not doing

  • ITunes cannot see Apple TV

    I'm having a bummer of a time getting iTunes to see my Apple TV. I am using a MacBook Pro with OS 10.4.9 and have iTunes 7.1.1 installed. I verified by running software update. My router is an Airport Extreme 802.11N base station. I've tried my mac w