PL/SQL Cursor Help

I am trying to figure out how to get the following code to work.
I am using a cursor to run a SELECT statement with a group function. How do I get the information from the group function to print out with a dbms_output.put_line statement? Just for my knowledge, is there some way to reference the next/previous cursor field as part of the wf_country_spoken_rec variable?
DECLARE
CURSOR wf_country_spoken_cur IS SELECT c.country_name, COUNT(s.language_id)
FROM wf_countries c, wf_spoken_languages s
WHERE c.country_id = s.country_id
GROUP BY country_name
HAVING COUNT(s.language_id) > 6;
wf_rowcount INTEGER;
BEGIN
FOR wf_country_spoken_rec IN wf_country_spoken_cur
LOOP
DBMS_OUTPUT.PUT_LINE(wf_country_spoken_rec.country_name || ' ' || wf_country_spoken_rec.language_id);
wf_rowcount := wf_country_spoken_cur%ROWCOUNT;
END LOOP;
DBMS_OUTPUT.PUT_LINE(wf_rowcount);
END;
Thanks,
John

The only problem I think your code has is how it's referencing the language_id. If it suppose to print out the count of language_ids then you just need to add an alias to it. just like this:
DECLARE
    CURSOR wf_country_spoken_cur IS
        SELECT c.country_name,
               COUNT(s.language_id) language_id_cnt
          FROM wf_countries c,
               wf_spoken_languages s
         WHERE c.country_id = s.country_id
         GROUP BY country_name
        HAVING COUNT(s.language_id) > 6;
    wf_rowcount INTEGER;
BEGIN
    FOR wf_country_spoken_rec IN wf_country_spoken_cur
    LOOP
        DBMS_OUTPUT.PUT_LINE(wf_country_spoken_rec.country_name || ' ' || wf_country_spoken_rec.language_id_cnt);
        wf_rowcount := wf_country_spoken_cur%ROWCOUNT;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE(wf_rowcount);
END;
/

Similar Messages

  • SQL Cursors HELP  ASAP

    I need somebody to help me with sql cursors, in JSP.
    This is my peace of code what is wrong with it?
              Statement stmt = myConn.createStatement();
              stmt.executeQuery("BEGIN WORK");
              stmt.executeQuery("DECLARE item_cursor CURSOR FOR SELECT user_name FROM admin_info");
              stmt.executeQuery("FETCH 10 FROM item_cursor");
              ResultSet rs = stmt.getResultSet();
              while(rs.next()){
                   if(rs.getString(1) != null){
                        user_name = rs.getString(1).trim();
    %><P><%= user_name %></P><%
              stmt.executeQuery("CLOSE item_cursor");
              stmt.executeQuery("COMMIT WORK");
    and this is the error that a get: No results where returned by the query
    Please help anybody
    thanx guys

    If you are using ORACLE drivers and classes.
    This sample program shows Oracle JDBC REF CURSOR functionality, creating a PL/SQL package that includes a stored function that returns a REF CURSOR type. The sample retrieves the REF CURSOR into a result set object.
    * This sample shows how to call a PL/SQL function that opens
    * a cursor and get the cursor back as a Java ResultSet.
    import java.sql.*;
    import java.io.*;
    import oracle.jdbc.driver.*;
    class RefCursorExample
    public static void main (String args [])
    throws SQLException
    // Load the driver
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    // Connect to the database
    // You can put a database name after the @ sign in the connection URL.
    Connection conn =
    DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger");
    // Create the stored procedure
    init (conn);
    // Prepare a PL/SQL call
    CallableStatement call =
    conn.prepareCall ("{ ? = call java_refcursor.job_listing (?)}");
    // Find out all the SALES person
    call.registerOutParameter (1, OracleTypes.CURSOR);
    call.setString (2, "SALESMAN");
    call.execute ();
    ResultSet rset = (ResultSet)call.getObject (1);
    // Dump the cursor
    while (rset.next ())
    System.out.println (rset.getString ("ENAME"));
    // Close all the resources
    rset.close();
    call.close();
    conn.close();
    // Utility function to create the stored procedure
    static void init (Connection conn)
    throws SQLException
    Statement stmt = conn.createStatement ();
    stmt.execute ("create or replace package java_refcursor as " +
    " type myrctype is ref cursor return EMP%ROWTYPE; " +
    " function job_listing (j varchar2) return myrctype; " +
    "end java_refcursor;");
    stmt.execute ("create or replace package body java_refcursor as " +
    " function job_listing (j varchar2) return myrctype is " +
    " rc myrctype; " +
    " begin " +
    " open rc for select * from emp where job = j; " +
    " return rc; " +
    " end; " +
    "end java_refcursor;");
    stmt.close();

  • Need help on Dynamic SQL Cursor in Forms

    Hi All,
    I am trying to execute Dynamic SQL Cursor in forms using EXEC_SQL built in.
    I have a cursor for example:
    'select * from supplier where supplier = '||p_supplier||' and processing_order = '||p_order
    My code is
    cur_num := Exec_SQL.Open_cursor;
    sql_order := 'select * from supplier where supplier = '||p_supplier||' and processing_order = '||p_order;
    EXEC_SQL.PARSE(cursor_number, sql_order);
      EXEC_SQL.DEFINE_COLUMN(cur_num ,1,ln_Supp_Id);
      EXEC_SQL.DEFINE_COLUMN(cur_num ,2,ls_Suppl_Name,30);
    EXEC_SQL.DEFINE_COLUMN(cur_num ,24,ls_exchange,20);
      sql_count := EXEC_SQL.EXECUTE(cur_num );
      While EXEC_SQL.FETCH_ROWS(cur_num ) > 0 Loop
            EXEC_SQL.COLUMN_VALUE(cur_num ,1,ln_Supp_Id);
            EXEC_SQL.COLUMN_VALUE(cur_num ,2,ls_Suppl_Name);
            EXEC_SQL.COLUMN_VALUE(cur_num ,24,ls_exchange);
    End Loop;
    EXEC_SQL.CLOSE_CURSOR(cur_num );
    In this case I have to write 24 Define Columns and 24 Column value. Is there any way to assign them to %rowtype at one time as I need all coulmn of the table.
    I had similar case on multiple tables.
    Please help me
    Thanks,
    Maddy

    I need this dynamic sql because p_supplier and p_order values changes at run time
    I do not understand. Is this a simplified sample or the real thing? You do know that you can pass variables to cursors:
    cursor test is
    select * from supplier where supplier = p_supplier and processing_order = p_order;
    or does e.g. p_supplier hold other parts of the query?
    cheers

  • Help with "ORA-06511: PL/SQL: cursor already open"

    I've tried numerous variations on this piece of code and I always get the same result. I'm sure this is painfully obvious to an experienced PL/SQL person.
    Any help will be appreciated!
    Thank You!
    1 DECLARE
    2 CURSOR EMP_CURSOR IS SELECT last_name from employees;
    3 current_last_name varchar2(25);
    4 BEGIN
    5 IF EMP_CURSOR%ISOPEN
    6 THEN
    7 dbms_output.put_line ('cursor is already open');
    8 close EMP_CURSOR;
    9 END IF;
    10 dbms_output.put_line ('opening cursor');
    11 OPEN EMP_CURSOR;
    12 FOR item in EMP_CURSOR LOOP
    13 FETCH EMP_CURSOR INTO current_last_name;
    14 EXIT WHEN EMP_CURSOR%NOTFOUND;
    15 dbms_output.put_line (item.last_name);
    16 END LOOP;
    17 CLOSE EMP_CURSOR;
    18* END;
    19 /
    DECLARE
    ERROR at line 1:
    ORA-06511: PL/SQL: cursor already open
    ORA-06512: at line 2
    ORA-06512: at line 12

    Mathieu,
    Log in as anotherSchema and grant select on 'IDsTable' to the current user.
    SQL> r
      1  create or replace function f1(theID varchar2) return mytype pipelined is
      2  out varchar2(30);
      3  cursor myCursor (x varchar2) is select * from scott.emp where job=x;
      4  begin
      5  for rec in myCursor(theID) loop
      6  pipe row(rec.ename);
      7  end loop;
      8  return;
      9* end;
    Warning: Function created with compilation errors.
    SQL> show errors
    Errors for FUNCTION F1:
    LINE/COL ERROR
    3/33     PL/SQL: SQL Statement ignored
    3/53     PL/SQL: ORA-00942: table or view does not exist
    6/1      PL/SQL: Statement ignored
    6/10     PLS-00364: loop index variable 'REC' use is invalid
    SQL> connect scott
    Enter password: *****
    Connected.
    SQL> grant select on emp to testuser;
    Grant succeeded.
    SQL> connect testuser
    Enter password: ****
    Connected.
    SQL> create or replace function f1(theID varchar2) return mytype pipelined is
      2  out varchar2(30);
      3  cursor myCursor (x varchar2) is select * from scott.emp where job=x;
      4  begin
      5  for rec in myCursor(theID) loop
      6  pipe row(rec.ename);
      7  end loop;
      8  return;
      9  end;
    10  /
    Function created.
    SQL> disconnect
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.3.0 - Production
    SQL>

  • CR+LF Code at the end of each record selected in sql cursor

    i am selecting some data records in a sql cursor and writing it into a file using UTL_FILE.puT in a plsql procedure.
    at the end of select statement if i add ||chr(13||chr(10) iam getting CR+CR+LF code
    if i add only || chr(10) i am getting LF code.
    What i need is only CR+LF code. Kindly help to use any other commands.
    Thanks,
    Shivaji.
    Edited by: Shivaji M on Apr 22, 2010 12:11 AM
    Edited by: Shivaji M on Apr 22, 2010 12:36 AM

    It's in the book!
    "PUT_LINE terminates the line with the platform-specific line terminator character or characters."
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10577/u_file.htm#i997640

  • Building report from PL/SQL cursor

    Hello,
    is there any way to build APEX report using just PL/SQL cursor?
    I don't have grant to SELECT from views or tables, but I can use some functions returning row types and cursors. I know I can use them to build table from scratch with htp.p etc., but it’s not very nice. I want to do it using APEX reporting with filtering and pagination functionality.
    Is it possible?
    Regards,
    Przemek

    Apologies for the delay, I was out of the office.
    Below is a package serving as the basis for creating a view based on a pipelined function. The package is just a skeleton and will not compile in its current form, you will need to go through it filling in the blanks as described by the comments.
    If you want some control over what rows are returned by the view from a larger result set, use the set_parameters function in the WHERE clause, E.G.:
    select * from really_big_complicated_slow_view where 1 = view_pkg.set_parameters(something_that_reduces_the_view_result_set_size);
    Or, a more concrete example:
    select result_text from view_to_convert_to_csv where 1 = view_pkg.set_parameters(pi_table => 'my_table', pi_where = 'whatever');
    In the spirit of full disclosure, I got the idea for using the "set_parameters" function in the view WHERE clause from a post or blog somewhere a couple of years ago but have lost track of who actually deserves the credit for the good idea.
    -Tom
    create or replace package demo_vw as
    -- Package to serve as the basis for a view based on a function
    -- Customize this record so that it represents a row from this view...
    type row_type is record (
    -- record fields here
    type table_type is table of row_type;
    -- This function is used in the DDL to define the view, for example:
    -- create or replace view my_view (col1, col2, ..., colN) as
    -- select * from table(my_view_vw.get_view);
    function get_view
    return table_type
    pipelined;
    -- Customize this function header to accept the parameters for this view, if
    -- any. If this view does not require any parameters, the set_parameters
    -- function may be deleted.
    -- This function should always return 1 and is called as follows
    -- select <whatever>
    -- from my_view
    -- where 1 = my_view_vw.set_parameters(p1, p2, p3, ..., pN);
    function set_parameters (pi_whatever1 in whatever,
    pi_whateverN in whatever)
    return number;
    end demo_vw;
    show error package demo_vw
    create or replace package body demo_vw as
    -- Customize this list of private global variables to match the parameters
    -- required by the view. These variables are set, reset, and validated by
    -- set_parameters, reset_parameters, and valid_parameters respectively...
    g_var1 whatever;
    g_varN whatever;
    function set_parameters (pi_whatever1 in whatever,
    pi_whateverN in whatever)
    return number
    is
    -- Customize this function header to accept the parameters for this view, if
    -- any. If this view does not require any parameters, the set_parameters
    -- function may be deleted.
    -- This function should always return 1 and is called as follows
    -- select col1, col2, ..., colN
    -- from my_view
    -- where 1 = my_view_vw.set_parameters(p1, p2, p3, ..., pN);
    begin
    g_var1 := pi_whatever1;
    g_varN := pi_whateverN;
    return 1;
    end set_parameters;
    function valid_parameters
    return boolean
    is
    -- Customize...
    -- Assumes that set_parameters has been called to set the value of the view
    -- parameters.
    l_valid boolean := true;
    begin
    return l_valid;
    end valid_parameters;
    procedure reset_parameters
    is
    -- Customize...
    -- This is called at the end of the get_view function to reset the view
    -- parameters for the next caller.
    begin
    g_var1 := null;
    g_varN := null;
    end reset_parameters;
    function get_view
    return table_type
    pipelined
    is
    -- build and return each row for the view...
    l_row row_type;
    begin
    if valid_parameters then
    -- do your process to populate the l_row variable here...
    pipe row (l_row);
    end if;
    reset_parameters;
    exception
    when others then
    reset_parameters;
    raise;
    end get_view;
    end demo_vw;
    show error package body demo_vw
    create or replace view demo
    as
    select * from table(demo_vw.get_view);

  • Implicit PL/SQL cursors remain open, causing ORA-01000 (Client 9.2.0.1)

    Hello,
    since migrating our system from Oracle Client 9.0.X to 9.2.0.1 (Windows XP), i am encountering troubles when calling a stored procedure from a Cobol-Program:
    after a while i run into a 'Maximum open cursors exceeded'-message (ORA-01000)
    The stored procedure returns a cursor (ref_cursor)
    When Executing the stored procedure, there are actually 2 cursors involved, in fact the stored PL/SQL procedure implicitely opens a child-cursor when doing a select within the PL/SQL.
    After fetching the result and closing the cursor in my cobol-program, it correctly closes the cursor associated with the stored-procedure, but it does not close the cursor that was implicitely opened by oracle.
    After a while i am running into a Maximum open cursors message, because those cursors have not properly been closed.
    Here's a simple PL/SQL package that illustrates the problem:
    create or replace package scott.SCOTTS_PACKAGE is
    type ref_cursor IS REF CURSOR;
    function GET_EMP(EMP_IN CHAR) return ref_cursor;
    end SCOTTS_PACKAGE;
    create or replace package body scott.SCOTTS_PACKAGE is
    -- Function and procedure implementations
    function GET_EMP(EMP_IN CHAR) return ref_cursor is
    MyCurs ref_cursor;
    begin
    OPEN MyCurs FOR
    SELECT EMPNO ,
    ENAME ,
    JOB
    FROM SCOTT.EMP
    WHERE ENAME = EMP_IN;
    return(MyCurs);
    end;
    end SCOTTS_PACKAGE;
    Here are some exerpts from my cobol program:
    (The program iterates 100x through the section that executes the PL/SQL. After each iteration an additional open cursor remains in the database)
    003800 EXEC SQL BEGIN DECLARE SECTION END-EXEC.
    003900*
    004000 01 SQL-USERNAME PIC X(16) VARYING.
    004100 01 SQL-PASSWD PIC X(16) VARYING.
    004200 01 SQL-DBNAME PIC X(64) VARYING.
    004300 01 ORACLE.
    004700 02 ORA-CUR-EMP SQL-CURSOR.
    01 EMPREC.
    02 EMPREC-EMPNO PIC X(4).
    02 EMPREC-ENAME PIC X(10).
    02 EMPREC-JOB PIC X(9).
    005400 EXEC SQL END DECLARE SECTION END-EXEC.
    018400 PROCEDURE DIVISION.
    CONTINUE.
    018700 EXEC SQL
    018800 WHENEVER SQLERROR DO PERFORM SQL-ERROR
    018900 END-EXEC.
    019000*
    CONTINUE.
    019100 EXEC SQL
    019200 WHENEVER NOT FOUND DO PERFORM SQL-NOT-FOUND
    019300 END-EXEC.
    022400 EXEC SQL
    022500 ALLOCATE :ORA-CUR-EMP
    022600 END-EXEC
    PERFORM VARYING I FROM 1 BY 1 UNTIL I > 100
    ACCEPT DUMMY FROM TER
    IF DUMMY = "E"
    MOVE 100 TO I
    END-IF
    PERFORM GET-EMP
    ADD 1 TO I
    END-PERFORM
    119300 GET-EMP SECTION.
    119400************************
    119500 GAM0.
    MOVE SPACES TO EMPREC-EMPNO EMPREC-JOB
    MOVE "SMITH" TO EMPREC-ENAME
    120200 EXEC SQL AT SSSI EXECUTE
    120300 BEGIN
    120400 :ORA-CUR-EMP:=
    120500 SCOTT.SCOTTS_PACKAGE.GET_EMP(:EMPREC-ENAME );
    120900
    END;
    121000 END-EXEC
    121200 IF DB-ERR-CODE NOT = HIGH-VALUE
    121300 DISPLAY "CCSIFSO:GET-AUTRE-MATR:APPEL PERS... OK"
    121400 EXEC SQL
    121500 FETCH :ORA-CUR-EMP
    121600 INTO
    121700 :EMPREC-EMPNO,
    121800 :EMPREC-ENAME,
    121900 :EMPREC-JOB
    122400 END-EXEC
    122500 END-IF
    122600*
    122700 IF DB-ERR-CODE NOT = HIGH-VALUE
    122800 DISPLAY "CCSIFSO:GET-AUTRE-MATR:APPEL FETCH.. OK"
    123000 ELSE
    123100 MOVE LOW-VALUE TO DB-ERR-CODE
    123200 END-IF
    123300 EXEC SQL
    123400 CLOSE :ORA-CUR-EMP
    123500 END-EXEC
    123600 GA-EX.
    123700 EXIT.
    124000 SQL-NOT-FOUND SECTION.
    124100*----------------------
    124200 NF0.
    124300 DISPLAY "CCSIFSO:SQL-NOT-FOUND SECTION."
    124400 MOVE HIGH-VALUE TO DB-ERR-CODE.
    124500 NF-EX.
    124600 EXIT.
    124700*
    124800 SQL-ERROR SECTION.
    124900*-----------------
    125000 ER0.
    125200 EXEC SQL
    125300 WHENEVER SQLERROR CONTINUE
    125400 END-EXEC
    125700 MOVE HIGH-VALUE TO DB-ERR-CODE
    125800*
    126100 DISPLAY "ORACLE ERROR DETECTED: " SQLCODE UPON TER
    126200 DISPLAY SQLERRMC UPON TER
    126300*
    126400 EXEC SQL AT SSSI
    126500 ROLLBACK WORK
    126600 RELEASE
    126700 END-EXEC
    126800 DISPLAY "----------------------------" UPON TER
    126900 DISPLAY " ! ROLLBACK ET DISCONNECT ! " UPON TER
    127000 DISPLAY "----------------------------" UPON TER
    127200 CALL "PPTERMJ".
    127400 ER-EX.
    127500 EXIT.
    Finally here's an exerpt from V$OPEN_CURSOR, after a few iterations:
    1 begin :b1 := SCOTT . SCOTTS_PACKAGE . GET_EMP (:b2 ) ; END ;
    2 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    3 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    4 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    5 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    6 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    7 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    8 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    9 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    10 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    11 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    As you see, there is only 1 cursor starting with 'begin ... '
    but there are 10 implicit cursors 'SELECT EMPNO, ... ' that have not been properly closed, nor reused by ORACLE.
    In our old configuration (ORACLE CLient 9.0.X), you would only see:
    1 begin :b1 := SCOTT . SCOTTS_PACKAGE . GET_EMP (:b2 ) ; END ;
    2 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    meaning all the other cursors have properly been closed.
    As a conclusion: the program correctly closes the implicit cursors when using a 9.0 Client, wheras the implicit cursors remain open on Client 9.2.0.1 (Windows XP)
    The underlying database can be either 8.i or 9, the problem remains the same.
    Finally here's a small Delphi code, using ODAC-components, that somewhat illustrates the same problem:
    procedure TForm1.ExecProcClick(Sender: TObject);
    var I: INTEGER ;
    begin
    FOR I := 1 TO 5 DO
    BEGIN
    SP1.StoredProcName:='SCOTT.SCOTTS_PACKAGE.GET_EMP';
    SP1.Prepare;
    SP1.ParamByName('EMP_IN').AsString := 'SMITH';
    SP1.ExecProc;
    SP1.Next;
    SP1.Close;
    SP1.UnPrepare;
    END;
    end;
    After each call to 'PREPARE', an additional implicit cursor remains open on the database. (using Oracle Client 9.2.0.1)
    On our old system (Oracle Client 9.0 or 8.X), the same program would not generate accumulating open cursors on the database
    Any suggestions would be welcome,
    Claude

    Cobol.. been many years since I last even saw some Cobol source code. Invokes all kinds of memories. :-)
    Since you found the patch, the advice is superfluous, but works. Close the cursor at the PL/SQL side, e.g.
    create or replace procedure CloseRefCursor( cRefCursor TYPELIB.TRefCursor ) is
    begin
      close cRefCursor;
    exception when OTHERS then
      -- if the cursor is already gone, not a problem
      NULL;
    end;In Delphi for example, one can subclass the class used for ref cursor calls and add a call to the above PL/SQL proc in the destructor. Or add create a standard Cobol close ref cursor section that does similar.

  • Error while executing Procedure - ORA-06511: PL/SQL: cursor already open

    I have successfully compiled the following procedure but when I execute it, following error occurs, please adv.
    Thanks and Regards,
    Luqman
    create or replace
    procedure TESTKIBOR
    (contno in varchar)
    AS
    BEGIN
    DECLARE cursor c1 is
    SELECT * FROM KIBOR_SCHEDULE
    WHERE CN=contno;
    begin
    OPEN C1;
    FOR line IN c1 LOOP
    update kibor_schedule
    set lincome=line.Lincome,
    expo=line.eXPO,
    pport=line.pPORT
    where cn=line.cn
    and rno=line.rno;
    END LOOP;
    COMMIT;
    close c1;
    END;
    END TESTKIBOR;
    ERROR at line 1:
    ORA-06511: PL/SQL: cursor already open
    ORA-06512: at "MKTG.TESTKIBOR", line 6
    ORA-06512: at "MKTG.TESTKIBOR", line 10
    ORA-06512: at line 1

    Hi,
    CREATE OR REPLACE PROCEDURE Testkibor
         (contno  IN VARCHAR)
    AS
    BEGIN
      DECLARE
        CURSOR c1 IS
          SELECT *
          FROM   kibor_schedule
          WHERE  cn = contno;
      BEGIN
    --//    OPEN c1; --no need to open if using for loop
        FOR line IN c1 LOOP
          UPDATE kibor_schedule
          SET    lincome = line.lincome,
                 expo = line.expo,
                 pport = line.pport
          WHERE  cn = line.cn
                 AND rno = line.rno;
        END LOOP;
        COMMIT;
    --//     CLOSE c1; -- no need for loop  does it for you
      END;
    END testkibor;SS

  • Size of PL\SQL Cursor block

    I want to know the internal working of the PL\SQL Cursor. Lets start with a scenario.
         1) I have 3 table with 20 million records each.
         2) I am making a join out of them on a certain condition which gives me 60 million records, now I am putting them in a cursor.
    Questions :
         i) Can the Oracle PL\SQL Cursor is capable of holding that much records or there is any limit for it ?
         ii) If there is a limit for such block, then where can I find it and how can I set it ?
         3) If there is no such limit, then running such a query and holding all the data in the Cursor Block would degrade the performance. How Oracle handles such situations, It might be possible that Oracle only have the indexes of those records in the Cursor, but still it would be to time consuming to index 3 different table
    Kindly Inform me about this issue ....
    Thanks & regards
    - Nabil Shams

    1. Oracle PL/SQL cursor is just a handle to shared SQL area in Oracle SGA and as such does not consume an awful lot of memory (I would dare to say it consumes peanuts). What is more important it does not depend on number of rows you are going to fetch via cursor
    2. Therefore the answer to question 2 is NO
    3. Running the query could and would affect you in most unpleasnat ways if you tried to store results of the query in your process memory (PGA/UGA), or more specifically if you created PL/SQL indexed by table and tried to pack all 60000000 rows into it.
    If you fetch rows one by one, process the row, throw it away - then no problem... but what do you need to do it for?

  • Need a column based off a PL/SQL cursor, how to do this?

    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    With the Real Application Testing option
    JServer Release 9.2.0.8.0 - Production
    Report Builder 10.1.2.2.0
    ORACLE Server Release 10.1.0.5.0
    Oracle Procedure Builder 10.1.2.2.0
    Oracle ORACLE PL/SQL V10.1.0.5.0 - Production
    Oracle CORE     10.1.0.5.0     Production
    Hi,
    I am trying to create a fairly basic report but in the initial data model query, I have one column that is built based off of a PL/SQL cursor. How do I add this into my report? I have tried to create a function under Program Units and reference the function in my select statement for the data model however it keeps saying it is an invalid identifier, and I assume its looking in our database and not the function I created inside the report.
    This is what it looks like:
    SELECT   a.id,
             b.name,
             F_GET_GENERIC_NAME(b.code) "Generic Name",
             c.strength...and the function i want it to use in my report:
    FUNCTION F_GET_GENERIC_NAME (in_code varchar2) RETURN VARCHAR2 IS
    BEGIN
    DECLARE
    generic_name table.column%TYPE;
    CURSOR cs_get_generic_name IS
    SELECT /*+ USE_HASH (AR) */ desc
    FROM  a_ref AR, ai_ic AC    
    WHERE AC.code = in_code
    AND   AC.code = AR.code
    ORDER BY sort_nbr;
    BEGIN
           generic_name := '';
              FOR v_get_generic_name IN cs_get_generic_name
              LOOP
                 generic_name := generic_name || RTRIM(v_get_generic_name.desc)
                                     || '/' || ' ';
              END LOOP;
              generic_name := SUBSTR(generic_name, 1,(NVL(LENGTH(generic_name), 0) - 2));
    RETURN generic_name;
    END;
    END;
        Any suggestions? Should I just create the function in the database?

    I am trying to do it through a formula column but am encountering the following problem.
    I've created a formula column in my data model where I want the column to be (inside the group).
    Inside the PL/SQL for the column I reference the function that I had previously created with the following:
    function CF_Generic_nameFormula return Char is
    begin
         F_GET_GENERIC_NAME(:code);
    end;However it won't let me compile, giving the error that "F_GET_GENERIC_NAME is not a procedure or is undefined." Is there something else that I am missing?
    EDIT: Nevermind, i missed something simple like putting a return in front of the function call.
    Edited by: a small rabbit on Nov 3, 2009 10:43 AM
    Edited by: a small rabbit on Nov 3, 2009 10:44 AM

  • How to see pl/sql cursor in v$sql

    Hi All,
    I am trying to find how many child cursor will be created for select * into employee_rec from employees where employee_id = i however I couldn't find anything?
    Do I have to use execute immediate?
    Can't I measure PL/SQL cursors?
    set serveroutput on;
    declare
         employee_rec employees%rowtype;
    begin
         for i in 100..110
         loop
                select * into employee_rec from employees where employee_id = i;
                dbms_output.put_line(employee_rec.first_name);
         end loop;
    end;
    select sql_text, sql_ıd, versıon_count, hash_value from v$sqlarea where sql_text like 'select * into employee_rec from employees where employee_id%';
    <<No row returns>>
    select sql_text, sql_id, child_number, hash_value, plan_hash_value from v$sql where sql_text like 'select * into employee_rec from employees where employee_id%';
    <<No row returns>>
    Thanks in advance

    For example, I changed the code like the following
    I just would like the see the cursor (select * from employees where employee_id = emp_id;) you know what I mean?
    set serveroutput on;
    declare
    cursor my_c(emp_id number) is
    select * from employees where employee_id = emp_id;
    begin
         for i in 100..110
         loop
                for rec in my_c(i)
                loop
                  dbms_output.put_line(rec.first_name);
                end loop;
         end loop;
    end;
    Thanks

  • At what point is PL/SQL cursor data retrieved?

    Hi
    This may sound like a silly question but since I am not entirely sure, I thought I'd ask.
    In Oracle PL/SQL, do you know at what stage the query in a cursor is actually executed?
    Is it at the DECLARE stage or when you first OPEN / LOOP on it?
    I suspect upon the OPEN or the LOOP.
    I.e. if I had a cursor declared but did not loop (using FOR .. LOOP) through it for some hours, would the query results be as at the time of declare or as at the time of the OPEN / FOR...LOOP?
    E.g.
    CURSOR invoices
      IS
        SELECT invoice_number
        FROM unpaid_invoices
        WHERE due_date < TRUNC (SYSDATE)
    BEGIN
    -- Some time consuming processing that will take an hour
    -- Start Loop through cursor of invoices.
      <<overdue_invoices>>
      FOR inv IN invoices LOOP
    -- Some processing on the invoice
      END LOOP overdue_invoices;
    END;Would the cursor details for invoices be as at the CURSOR declaration or when the FOR inv... is reached?
    Thanks
    Martin

    When you use a for loop like that it implicitly opens the cursor at the start and closes it at the end of the loop.
    But the SQL query in that cursor is actually "run" when the first implicit or explicit fetch is issued, and retrieves new rows for every subsequent fetch.
    Of course, before rows can be retrieved there needs to be several other tasks.
    There's a good description of the steps of SQL processing in this part of the documentation.
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_sqlproc.htm
    PL/SQL implicitly declares a cursor for all SQL data manipulation statements, including queries that return only one row. For queries that return multiple rows, you can explicitly declare a cursor to process the rows individually.
    A cursor is a handle to a specific private SQL area. In other words, a cursor can be thought of as a name for a specific private SQL area. A PL/SQL cursor variable enables the retrieval of multiple rows from a stored subprogram.Edited by: fsitja on Dec 15, 2009 1:03 AM

  • SQL*Plus Help

    Hi! Does anyone know where i can download SQL*Plus Help? I need to get info on select syntax, sql built-in functions, etc..
    Thanks!

    hi
    you can proceed like this :
    go to the OTN
    the click on products.
    null

  • PL/SQL cursors vs. SQL*plus Select statement

    Hi folks, hope you're doing well,
    Here is a question that kept me wondering:
    Why would I use cursors when i can achieve the same thing with a SQL+ Select statement which is much easier to formulate than a cursor (e.g. you need no declaration, loops etc)?.
    Thanks so much,
    -a

    There is no such thing as a SQL*Plus SELECT statement. The SELECT command is part of the SQL Language - not part of the SQL*Plus (very limited small vocabulary) macro language.
    All SQL SELECTs (from client languages) winds up in the SQL Engine as SQL cursors. A SQL Cursor is basically the:
    - SQL source code
    - SQL "compiled" code (instructions on how to fetch the rows)
    On the client side, client cursors (not to be confused with SQL cursors) are used. A client cursor is created in the client language when it makes SQL calls via the database client driver (called the OCI/Oracle Call Interface for Oracle clients).
    Typically this is what a client does. It makes a connection to the database and gets a database handler in return. The database handler is the "communication channel" from the client to the db. In Oracle, the database handler in the client refers to the Oracle session (for that client) on db server.
    A SQL statement (source code) is used by the client. This can be a SELECT statement you type in at the SQL*Plus command line. It can be a SELECT statement for the PL/SQL cursor command in a stored procedure.
    The client creates a SQL handle for this SQL statement, by calling the Oracle client driver. Note that this SQL handle is a client handle - a client cursor for that SQL statement.
    E.g.
    a) sqlHandle = CreateSQL( databaseHandle, 'SELECT ... FROM ...')
    b) sqlHandle.Parse
    c) sqlHandle.Execute
    After the SQL handle (client cursor) has been executed, the client can fetch rows from it.
    This is what SQL*Plus does automatically for you, without you having to write the code to do it. SQL*Plus CONNECT command create a database connection handle. You enter a SELECT statement and SQL*Plus creates a SQL handle (client cursor), executes it, fetches from it, displays the rows, and closes the SQL handle when done.
    The same applies to PL/SQL. You can use a SELECT statement just like that in PL/SQL. E.g.
    declare
      i integer;
    begin
      select count(*) into i from emp where deptid = 123;
    end;This is called an implicit cursor. PL/SQL creates (just like SQL*Plus) an implicit client cursor. It creates and disposes of that client SQL handle for you - you do not need to do it.
    Or, you can create an explicit cursor. E.g. declare
      cursor c is select count(*) from emp where deptid = 123;
      i integer;
    begin
      open c;
      fetch c into i;
      close c;
    end;The question as to when to use implicit (client) cursors versus explicit (client) cursors depends on your requirements. Do you need to cycle through the results of the SQL? Etc.
    And keep in mind that in either case, the SQL Engine creates a SQL cursor anyway on its side.

  • How to install SQL*Plus help facilities and demos.

    Hi, everyone
    It appears error message say "failure to login" during SQL*Plus
    part of the Oracle8 full installation. I knew that system want
    to install SQL*Plus help and demos through logining one of
    dba account(maybe system user account). However, due to
    password's reason, can not log in SQL*Plus, so installer can't
    execute named pupbld.sql script, result in SQL*Plus help and
    demos can not be installed.
    Now, I am intend to install these stuff lonely.
    Could anyone help me? thank a lot.
    William
    null

    Hi,
    The pupbld.sql isn't the correct script to create the help
    facility, it just creates product and user profile tables.
    The help script is at $ORACLE_HOME/sqlplus/admin/help (run as
    system)
    cd $ORACLE_HOME/sqlplus/admin/help
    sqlplus system/<password> @helptbl
    sqlldr system/<password> control=plushelp.ctl
    sqlldr system/<password> control=plshelp.ctl
    sqlldr system/<password> control=sqlhelp.ctl
    sqlplus system/<password> @helpindx
    I think it is necessary to run the pupbld.sql script, without
    this script everyone who logins in oracle with sqlplus will see
    an error message, but... Run the script again:
    $ORACLE_HOME/sqlplus/admin/pupbld.sql
    Best regards,
    Ari
    William (guest) wrote:
    : Hi, everyone
    : It appears error message say "failure to login" during SQL*Plus
    : part of the Oracle8 full installation. I knew that system want
    : to install SQL*Plus help and demos through logining one of
    : dba account(maybe system user account). However, due to
    : password's reason, can not log in SQL*Plus, so installer can't
    : execute named pupbld.sql script, result in SQL*Plus help and
    : demos can not be installed.
    : Now, I am intend to install these stuff lonely.
    : Could anyone help me? thank a lot.
    : William
    null

Maybe you are looking for

  • "cacheHostInfo is null" and Add-SPDistributedCacheServiceInstance : Object reference not set to an instance of an object.

    I am working on a standalone install Sharepoint 2013 (no Active Directory). I found newsfeed feature is not available and checked Distributed Cache service is stopped. When start it "cacheHostInfo is null" is returned. I checked the Windows service "

  • Selection from a Maintenance View

    Hi,     I have to fetch data from a view, unfotunately that view is a mainteance view. Is there any other way to select/fetch data from that view in my report program ? Regards, Bharath Mohan B

  • Need suggestion on indexes

    I want to create some indexes on following table in Oracle 10G database. Table --> RegionalOrders Columns --> TenorderID -- PrimaryKey custid number(6) -- ForegionKey Empid number(6)-- ForegionKey Region (char(4)) -- ForegionKey Tencon varchar(20), T

  • BP telephone Search using wildcards (IC Winclient)

    I'm unable to search business partners by telephone number using wildcards (*) because I get the error message "enter a country to do the search using wildcards". How can I include a default country and state on the html template of the BP Search? I´

  • Differences between oraxsl output and XMLLoder transformation

    Following the ch14 deptempdepend example in Steves book, the data loads ok. However if I use oraxsl to transform the data into the canoconial rowset format using java oracle.xml.parser.v2.oraxsl deptempdepend.xml deptempdepend.xsl out.xml I get the r