leak of open cursors

Hello.


I work with a (version 9.2.0.7) database which is accessed by a web applicattion which is at the origin of the leaks of sliders, I looked like a large part of the demand as I can and all statemtens and jdbc result sets appear to be properly closed.

I see that for a single session, increasing the number of open cursors, the application has restarted 3 days ago, but there is a session that has 100 open cursors rigth now, that means in a fortnight that he could reach the maximum number of open cursors.

I have no idea on how to find the sql code that could be responsible for this behavior.


I don't think that the following code is responsible for this beahviour, but maybe I'm wrong:
There is a stored procedure:
CREATE OR REPLACE FUNCTION REFLEX.DevuelveCursor(query in varchar2)
    RETURN SYS_REFCURSOR
AS
    c SYS_REFCURSOR;
BEGIN
    OPEN c FOR query;

    RETURN c;
END;
/
This procediure is called from jdbc in this way:
     /*************************** 
     Many lines of code follow here
     ***************************/      
      String queryCursor = "begin ? := DevuelveCursor(?); end;";
      cstmt = conexion.prepareCall(queryCursor);
      cstmt.registerOutParameter(1, OracleTypes.CURSOR);
      cstmt.setString(2, SentenciaContadores);
      cstmt.execute();

      rs = (ResultSet)cstmt.getObject(1);
     /*************************** 
     Many lines of code follow here
     ***************************/
      rs.close();
     /*************************** 
     Many lines of code foloow here
     ***************************/
     cstmt.close();
     /*************************** 
     Many lines of code follow here
     ***************************/
I wonder if only SYS_REFCURSOR is properly closed.



Thanks in advance.

Published by: fsanchezherrero on August 17, 2009 14:39

sybrand_b wrote:
Centinul,

I read it on Metalink. Do not add article, however.

The closest I can get to now of Note 62143.1, which States as soon as the maximum session_cached_cursors is reached, the 'old' cursors are automatically closed.

Dbms_sql sliders are a different beast, you must close the explicitlty when you hit an exception.

--------------
Sybrand Bakker
Senior Oracle DBA

Thank you very much!

Tags: Database

Similar Questions

  • ORA - 00604:Maximum open cursors...

    Hello

    I made my DB installation / configuration and everything. When I access request through the DB, I get the following error.

    ORA - 00604:Maximum open cursors...

    My open_cursors value of V$ PARAMETER is 300. Kindly guide me on this to solve this problem.

    refer
    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14237/initparams138.htm

  • java.sql.SQLException: ORA-01000: maximum open cursors exceeded.

    Hello

    We use otralce 10g I am see this error in the production of the java application, we close the connections but some how this issue getting not resolved.

    There are towing applications.

    request 1 and application2 refer to the same database read/write

    Hello

    If the application opens cursors repetedly without closing them.
    (I don't argue that you must always close the sliders, but rather that you should not open them more than once)

    You can find that a series of sessions open cursors

    select * from v$sesstat where statistic# = 3 order by value desc;
    

    This will give you the session with more open cursors. This lets you know what cursors are opened then:

    select sid,sql_text, count(*) from sys.v_$open_cursor group by sid,sql_text order by 3 desc;
    

    BTW, what do you mean by the close connections? I hope that you are not opening and closing of connections, whenever you need it?

    Concerning
    Peter

  • Windows does not correctly - open cursor freezes and gets to abnormal termination

    Cursor freezes. Then I can just turn off the computer at the tower. Windows then reopen correctly. Sometimes I'm asked to select 'normally open', sometimes prompted to opt for the option "repair". Sometimes takes up to 15 attempts before getting the chance.  Then the process repeats itself afterwards. There is nothing wrong with the cursor. Help!

    The best way to combat the freeze is to be patient and select Ctrl + Shift + Esc to bring up the Task Manager. Click on the Applications tab, place the cursor on a running application, and then click end task. Be patient as the task manager should have priority over a problenmatic that runs application. It usually does, but he needs time. If you continue to use the Power On / Off button you will make things worse.

    Can you identify which application is causing the problem?

    What anti-virus program do you use?

    The amount of RAM is installed?

    You authorize chkdsk to run until the end, when the computer does not start normally? You must allow running chkdsk.

    Event Viewer reports

    1. normally, when an error occurs on your computer looking in Event Viewer should be your starting point to find a solution. More related system errors are recorded and get an exact copy of the relevant report is important. Unfortunately, is not easy to understand reports and most of the users computer need help with their interpretation. I have to say later interpretation.

    2 Event Viewer includes three main newspapers of Windows. Here's the Application, security, and system. For purposes of troubleshooting system is by far the most important.

    3. to access the system log, select Start, Control Panel, administrative tools, Event Viewer, in the list on the left of the window select Windows and the system logs. Place the cursor on the system, right click and select filter current log. Check the front of the error and click OK and see you only reports errors. Click the Date and time column header to sort. You may need to click a second time to see the last report above.

    4. a tip for posting copies of error reports! Run Event Viewer and double-click the error you want to copy. Click the copy button to place a copy in the Clipboard and close Event Viewer. Now start your message and paste it into the body of the message. Make sure that it is the first dough right out of the event viewer.

    5. He cautioned against three types of reports, information, and reports errors. In most situations, it is the error reports that offer the best information but sometimes WARNING reports provide useful clues.

    6. all reports have stamps date and hour and when troubleshooting, it is important to focus on the latest reports. Reports of studies from the point when the computer is started, and then check if a similar report appeared in the previous session. If errors do not repeat investigation as to why they happen is wasted effort.

    7. in the individual reports the most important information is the event ID and Source such as these help when looking for help on the internet. The description is just as important and copy the exact text to use as search criteria greatly helps achieve better results when using Google. Not paraphrase descriptions when other people asking for help.

  • open cursor and drop table

    Hello

    How does this work?

    Session 1: Session 2:


    SQL > create table t (x number);

    Table created.

    SQL > insert into t values (1);

    1 line of creation.

    SQL > insert into t values (2);

    1 line of creation.

    SQL > commit;

    Validation complete.

    SQL > start

    2 for f in (select * from t) loop

    3 dbms_output.put_line(sysdate||) e '|| f.x);

    4 dbms_lock.sleep (60);

    5 end of loop;

    6 end;

    7.


    SQL > drop table t;

    Deleted table.

    SQL > select sysdate to double;

    13:58:45

    13:58:34 1

    13:59:34 2


    The table has been deleted, but the line is always returned once the table is deleted. With the help of OPEN and FETCH has the same


    declare
    cursor c is select * from t;
    r t % rowtype;
    Start
    Open c;
    extract the c in r;
    dbms_output.put_line(sysdate||) e '|| r.x);
    DBMS_LOCK. Sleep (60);
    extract the c in r;
    dbms_output.put_line(sysdate||) e '|| r.x);
    end;
    /

    Is this a bug? I could even reproduce it with 1 million rows. Shouldn't this ORA-01001 invalid cursor return?


    Start
    for f in (select * from t) loop
    If f.x in (1,10,100,1000,10000,100000,1000000) then

    dbms_output.put_line(sysdate||) e '|| f.x);

    DBMS_LOCK. Sleep (5);

    end if;
    end loop;
    end;
    /

    Thank you

    Laurent

    PS: It boils down to having no consistency to the DICTIONARY level... which is ugly

    Huh? The dictionary makes perfect sense.

    Any query cursor / who uses the data dictionary will get the correct results.

    If the cursor that you use should the data dictionary, it will get the correct results - he'll notice the table disappeared and will throw an exception.

    Your 'problem' manifests only for a SELECT query. Change the cursor in UPDATES and you can't delete the table.

    SQL > drop table t;

    drop table t

    *

    ERROR on line 1:

    ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired

    Even if you remove a line in this loop.

    https://docs.Oracle.com/CD/B28359_01/server.111/b28318/consist.htm#i8841

    As a request enters the implementation phase, change current system (SNA) number is determined. Figure 13-1, this system change number is 10023. As data blocks are read in the name of the query, only the blocks that are written with the observed SNA are used.

    When the cursor is opened that the SNA is determined, the data file header is read and Oracle knows where the first measure.

    The cursor can read this measure without the need of the data dictionary. So if you drop the table in another session your cursor can continue to read this measure.

    It is ONLY when the next measurement is necessary that Oracle uses the dictionary of data and notice that the table has been deleted.

    https://docs.Oracle.com/CD/B28359_01/server.111/b28318/logical.htm

    A scope is a number of blocks of contiguous data allocated for storing a specific type of information.

    The cursor can keep accessing the measure, and all these "contiguous data blocks" because he knows where the measurement begins and how many blocks there.

    So if 'million' lines fits into this extent (s) the query will keep trucking.

    It may take even more to see the missing table if a path to the index is used as the index blocks are pointers to the previous index block. These pointers can span extensions - you can read an entire table once it has been abandoned if the cursor is using the index to find all data or all the blocks table as long as the extensions/blocks being read have not been replaced or reallocated.

    It is therefore a problem for SOME ONLY.

  • Max open cursor

    Hi all

    In my 9i database I get open_cursors = 4000, and in the last days some sessions reached this value for cursor open.
    I questioned the v$ open_cursor for one of the sid and I discovered more than 2000 slider are all about this selection:

    Here are just a few...

    SADDR ADDRESS HASH_VALUE, SQL_TEXT SQL_ID
    ---------------- -------------------- ---------- ------------- --------------------------------------------------
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ
    000000056B260B68 0000000559E57208 a7kknct5skbd7 1267281319 CHOOSE ID_ARCHIVIO_SEQ. NEXTVAL FROM DUAL AS SEQ


    as you can see it select is exactly the same, so why the cursor are not shared?

    TK!

    Luca

    user11181920 wrote:

    as you can see it select is exactly the same, so why the cursor are not shared?

    because your program does not close the cursor.
    Can you identify a program that issues that SQL?
    If you can, look at how the cursor is open, and is closed after use.

    I agree - it's a good candidate.
    I used to see this quite frequently in programming Java in particular with previous versions of Oracle. A Java class has been used for a slight stain but the cursor was not closed at the end of the appeal of Java. The java object should be discarded and eventually cleaned up memory, but the database (and session in memory) don't know that the memory of java had disappeared. The result was a single slider, which is held in the SGA (v$ sql), but several pointers to this slider which is held in memory of session (v$ open_cursor).

    (Note - I can use the Java terminology incorrectly in the descriptions above, but I hope that the concept is clear).
    (Note: it is possible to reproduce this in PL/SQL very easily, but pl/sql tends to clean itself up automatically)

    Concerning
    Jonathan Lewis

  • ORA-01000: Maximum open cursors exceeded when you copy of database

    Hi all

    We are trying to use SQL Developer to export data from an Oracle database and import it into another. The function 'Copy of database' looks like it works pretty well, but unfortunately to halfway through the transfer, we get a lot of these errors:

    23 STAGE_SINET_PROG_TYPE inserted rows in s 0ms
    Impossible to perform the batch insert.
    ORA-00604: an error has occurred at the SQL level 1 recursive
    ORA-01000: cursors open maximum exceeded

    Impossible to perform the batch insert.
    ORA-00604: an error has occurred at the SQL level 1 recursive
    ORA-01000: cursors open maximum exceeded

    Impossible to perform the batch insert.
    ORA-01000: cursors open maximum exceeded

    Impossible to perform the batch insert.
    ORA-01000: cursors open maximum exceeded

    Impossible to perform the batch insert.
    ORA-01000: cursors open maximum exceeded

    Impossible to perform the batch insert.
    ORA-01000: cursors open maximum exceeded

    Leaving incomplete transfer. Is this a bug in SQL Developer, or y at - there a way around this? I've seen a few references to the DBA can change an option on our server, but as this is a shared database is not an option for us.

    Why must SQL Developer sliders so much anyway?

    Thank you
    Adam.

    Bug in the line of code under development.

  • Procedural problem - open cursor for SQL

    in my form, I added a procedure. It works fine in SQL, but when I try to run form it gives an error.
    Code of procedure: -.
    PROCEDURE Proc_Purchase_all IS
    BEGIN
      --------------------------------
      declare
         v_sql varchar2(4000);
         v_user varchar2(30);
         v_sep varchar2(20);
         v_cur SYS_REFCURSOR;
       pur_rec    purchase%ROWTYPE;
       begin
         for u in (SELECT * FROM ALL_TABLES WHERE OWNER LIKE 'BMP%' and table_name ='PURCHASE') loop
           v_sql := v_sql || v_sep || 'SELECT * from '||u.owner||'.purchase';
          v_sep := ' UNION ALL ';
        end loop;
        open v_cur for v_sql;
      Loop
      Fetch v_cur into pur_rec;
      Exit when v_cur%NOTFOUND;
      --DBMS_OUTPUT.PUT_LINE (PUR_REC.S_CODE||' '||Pur_rec.s_name);
      End Loop;
        close v_cur;
     end; 
      
      -------------------------------
    END;
    Error line
    Open the v_cur for v_sql; *
    Error: -.
    Has met the "V_SQL" symbol to one of the following conditions.
    Select
    Has met with the symbol of the END to one of the following conditions.
    Start the function outer package pragma procedure

    Just take a look at the forms online help located here: http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=0

    Search after exec_sql or populate_group

    as for the procedure of database... I'm sure you know how to create a database procedure, not you? Create a procedure for data base and place the logic of your first approach (as you say it worked in SQL * more) and call this procedure of forms. But if you need to process your results (if you do are specific forms) you will certainly stick to one of the first 2 methods.

    see you soon

  • Open cursors

    Hello

    How is-open_cursors parameter affect in RAC environment. Assuming that I give a value of 400. Each node takes 200 each assigned either randomly or a total of 400 and it's.

    How about you change the setting. What I have to change it separately in the nodes, or simply the "alter system set open_cursors = 500 scope = both" will do.

    Hello

    This setting is per session and by each jurisdiction as well.

    See on http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams138.htm#REFRN10137

    to change in all cases, regardless if you're using spfile shared for all instances follow these steps:

    SQL > alter system set open_cursors = 100 scope = the two sid = *.

    See you soon,.

    Rodrigo Mufalani
    http://www.mrdba.com.br/mufalani

  • How to view the external cursor opened in a session

    Hi all
    Is there a way to display a cursor open external in a session? Suppose if I want to check if there is a public and open cursor that has been defined in a package, how can I do? I try to play with v$ open_cursor, but I can't make sense.

    Best regards
    Val

    Valerie Debonair wrote:
    I want to test a lifetime of a cursor in a session. I don't want to interrogate another session but the same session where the open cursor.

    This probably more experimentation rather than useful in the real world. Suppose I have a package that sets a public cursor (as defined in the package spec) but for reasons of bad programming practice, the cursor is not closed and remains in session until the end view of v$ open_cursor can you tell me if an open cursor exists in the session?

    How do you know if this open cursor has been consumed (not more data), or not? It might be half an hour old, but still perfectly valid (if using the snapshot has not expired).

    I wouldn't say a cursor that was opened for x times a problem. The problem is to have multiple copies of the same open cursor - like which indicates a cursor leak.

    Anyway, you can watch the view V$ OPEN_CURSORS performance virtual - but in my test below, that time is is filled not doing a calculation of time would not work. You can continue this and dig deeper into the data dictionary (and the behavior of the Oracle) to determine if your needs can be met.

    SQL> --// package defines a static session PL/SQL cursor
    SQL> create or replace package FooLib as
      2
      3          cursor c is select object_name from user_objects;
      4
      5  end;
      6  /
    
    Package created.
    
    SQL>  --// open the cursor
    SQL> begin
      2          open fooLib.c;
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> --// do at least one fetch making sure that the cursor has been "touched"
    SQL> declare
      2          s       varchar2(30);
      3  begin
      4          fetch fooLib.c into s;
      5          DBMS_OUTPUT.put_line( s );
      6  end;
      7  /
    SYSLIB
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL> --// the data in v$open_cursor for the PL/SQL cursors we have opened in our session
    SQL> select
      2          c.sid,
      3          c.user_name,
      4          c.cursor_type,
      5          c.last_sql_active_time,
      6          t.sql_text
      7  from       v$sqltext t,
      8          v$open_cursor c
      9  where      c.address = t.address
     10  and        c.hash_value =  t.hash_value
     11  and        c.sid = (select sid from v$session where audsid =SYS_CONTEXT('userenv','sessionid') )
     12  and        c.cursor_type = 'OPEN-PL/SQL';
    
           SID USER_NAME  CURSOR_TYPE          LAST_SQL_ACTIVE_TIME SQL_TEXT
    ---------- ---------- -------------------- -------------------- ----------------------------------------------------------------
            25 BILLY      OPEN-PL/SQL                               SELECT OBJECT_NAME FROM USER_OBJECTS
    
    SQL>
    SQL>
    SQL> begin
      2          close fooLib.c;
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL>  --// cursor should now be gone as it was closed
    SQL> select
      2          c.sid,
      3          c.user_name,
      4          c.cursor_type,
      5          c.last_sql_active_time,
      6          t.sql_text
      7  from       v$sqltext t,
      8          v$open_cursor c
      9  where      c.address = t.address
     10  and        c.hash_value =  t.hash_value
     11  and        c.sid = (select sid from v$session where audsid =SYS_CONTEXT('userenv','sessionid') )
     12  and        c.cursor_type = 'OPEN-PL/SQL';
    
    no rows selected
    
    SQL> 
    
  • Open the cursor Question

    Hello

    Declare

    Cursor c

    is

    Select * from...

    Cursor c1

    is

    Select * from...

    Begin

    OPEN C;

    Loop

    Fetch c

    IN one;

    FETCH c1

    IN b;

    End loop;

    End;

    If I write as above on the right error ora-01001?

    I love below cannot?

    Declare

    Cursor c

    is

    Select * from...

    Cursor c1

    is

    Select * from...

    Begin

    OPEN C;

    OPEN c1;  ---????

    Loop

    Fetch c

    IN one;

    FETCH c1

    IN b;

    End loop;

    End;

    The code of follow through logically.

    First, you open two separated/not related sliders. (p.s. calling c1 and c_1 does not help you read what is happening - give meaningful names of things)

    You then in a loop.

    You get the first record of "c1".

    You retrieve the first recording of 'c_1 '.

    If you get a recording of "c1" (which you did the first time) then you are perpetuating and print the details of the employee him.

    If you get a recording of 'c_1' (which you did the first time) then you are perpetuating and print details of her Department.

    you loop around back.

    You retrieve the next record in "c1".

    You retrieve the next record in 'c_1 '.

    If you get a recording of "c1" (makes you this second time) then you perpetuate and print the details of the employee him.

    You will find then that 'c_1' did not return a second record for departments (because the query retrieves only one record for the Department 10), so that you leave the loop.

    Then, you close the sliders.

    That's how it works, but I doubt that's what you really wanted to.

    The number of times will make you a loop around the data depends on of what that either the query returns the least number of rows, in this case the request of the Prosecutor, which is only to recover 1.  By chance looking for employees first if you get 2 of them, but you will never get beyond this amount.

    So, of course, you can open the two sliders together if you want and close them together if you want... but you have to separate the curls as they are independent of each other:

    SQL > declare
    2 v_empno emp.empno%TYPE;
    3 v_deptno emp.deptno%TYPE;
    4 d_deptno dept.deptno%TYPE;
    5 c_emp cursor is
    6. Select empno,
    DeptNo 7
    8 of the emp
    9 where deptno = 10;
    10 c_dept of cursor is
    11. Select deptno separate
    12 of the Department
    13 where deptno = 10;
    14 start
    15 open c_emp;
    16 open c_dept;
    17 loop
    18 extract c_emp in v_empno, v_deptno;
    19 when out c_emp % notfound;
    20 dbms_output.put_line (' employee Details: ' | v_empno |) » '|| v_deptno);
    21 end of loop;
    22
    23 loop
    24 extract c_dept in d_deptno;
    25 exit when c_dept % notfound;


    26 dbms_output.put_line (' Department Details: ' | d_deptno);
    27 end of loop;
    28 close c_emp;
    29 close c_dept;
    30 end;
    31.
    Employee details: 7782 10
    Employee details: 7839 10
    Employee details: 7934 10
    Details of the Department: 10

    However, it is not advisable, you open cursors before using them and leaving them open after using them.

    Best practice would be...

    SQL > declare
    2 v_empno emp.empno%TYPE;
    3 v_deptno emp.deptno%TYPE;
    4 d_deptno dept.deptno%TYPE;
    5 c_emp cursor is
    6. Select empno,
    DeptNo 7
    8 of the emp
    9 where deptno = 10;
    10 c_dept of cursor is
    11. Select deptno separate
    12 of the Department
    13 where deptno = 10;
    14 start
    15 open c_emp;
    loop 16
    17 get c_emp in v_empno, v_deptno;
    18 when out c_emp % notfound;
    19 dbms_output.put_line (' employee Details: ' | v_empno |) » '|| v_deptno);
    20 end of loop;
    21 close c_emp;
    22
    23 open c_dept;
    24 loop
    25 extract c_dept in d_deptno;
    26 exit when c_dept % notfound;
    27 dbms_output.put_line (' Department Details: ' | d_deptno);
    28 end of loop;
    29 close c_dept;
    30 end;
    31.
    Employee details: 7782 10
    Employee details: 7839 10
    Employee details: 7934 10
    Details of the Department: 10

    Of course, if the sliders are linked (i.e. you want to get the Department information about the current employee you are looking at) then you need to do as I showed in my first answer.

  • Open with the cursor

    Greetings-

    I have a block of code on a report in the grid control, and it works well.
    What bothers me is that I need to specify the parameter in the
    Open the cursor so many times. I know that there is an easier way.
    Here is a simple example of this article:


    T1d: = sysdate - 90

    my_str: = ' select * from my_table where collection_timestamp
    between: 1 and (: 1 + 1)';

    my_cursor cursor open for my_str using t1d, t1d.

    However - in my code I use this about 24 times. Any help would be appreciated.

    Thank you

    Brian

    Rate the original question when you asked it... However, it is possible to 'normalise' your bind variables in the query using subquery factoring for example

    declare
      dt1    date;
      my_str varchar2(32767);
    begin
      dt1 := sysdate - 90;
      my_str := 'with t as (select :1 as dt from dual)
                 select *
                 from my_table, t
                 where collection_timestamp between t.dt and (t.dt + 1)';
    
      open cursor my_cursor for my_str using dt1;
      ..
    

    If you are linking to the weighted subquery just inside, and then this subquery is used throughout the application to provide the values.

  • Getting error - ORA-06511: PL/SQL: cursor already opened

    I have the following code for an Apex (Application Express) project I'm developing.

    declare
    mail_id varchar2 (100);
    number of min_skill_cnt;
    skill_cde varchar2 (30);
    number of total_leave;
    number of toal_emp;

    CUR cursor is
    Select S_EMP_EMAIL
    from EMP_SKILLS_INFO where SKILLCODE = 'MGR' and S_EMP_EMAIL = lower(:APP_USER);


    cursor minskill is
    Select skill_code, MINRQMT_AM
    of skills_code_info
    where skill_code in (select skillcode from the emp_skills_info where S_EMP_EMAIL = lower (:APP_USER));

    cursor leavecnt (v_skill IN VARCHAR2) is
    Select count (*) in emp_leave_info
    where leave_date =: P24_LEAVE_DATE
    and emp_email IN (select S_EMP_EMAIL from the EMP_SKILLS_INFO where SKILLCODE = v_skill);


    cursor empcnt (v_skills IN VARCHAR2) is
    Select count (*) in EMP_SKILLS_INFO
    where SKILLCODE = v_skills;

    Start

    Open the heart;

    Open minskill;

    LOOP
    extract the minskill in skill_cde min_skill_cnt;
    When the output minskill % NOTFOUND;

    Open leavecnt (skill_cde);
    extract the leavecnt in total_leave;

    Open empcnt (skill_cde);
    extract the empcnt in toal_emp;

    IF toal_emp-total_leave < min_skill_cnt

    then

    () apex_mail. Send
    p_to = >: APP_USER,.
    P_FROM = > '[email protected] ',.
    p_cc = > NULL,
    p_body = > ' * this is a system generated message, please do not respond to this *' |
    Chr (10) | UTL_TCP. CRLF. "Please consider the skills as ' |: APP_USER |' on leave ' |"

    Chr (10) | UTL_TCP. CRLF. "Thank you,.
    p_subj = > 'Alert code skills');

    end if;

    END LOOP;

    close empcnt;
    close leavecnt;
    close minskill;
    close cur;

    end;

    =======================
    Ideally this should send an email to managers when a particular skill runs short when the employee is requesting authorization.
    I am getting an error that cursor is already open when I run this code. I don't know what cursor or where it sits open cursor command.

    All entries will be appreciated.

    You open cursors leavecnt and empcnt in a loop without closing. Second iteration of loop will obviously trigger the cursor is already open.

    SY.

  • Same mistake again - ORA-06511: PL/SQL: cursor already opened

    Hello

    Even if I close the cursor, I get the following error "ORA-06511-6511: PL/SQL: cursor already opened. Please can you give your suggestion.

    CUR CURSOR IS
    JULIE name FROM test;

    BEGIN

    IF heart % ISOPEN THEN
    CLOSE cur
    END IF;

    Heart OPEN;

    FOR my heart IN cuv
    LOOP
    -sql statements
    END LOOP;

    END;

    Published by: AravindhK on December 6, 2011 13:56

    Do not open cursors when you write

    For  in 
    loop
    
    SQL> Declare
    CURSOR cur IS
    SELECT 1 A FROM dual;
    BEGIN
    IF cur%ISOPEN THEN
    CLOSE cur;
    END IF;
    --OPEN cur;
    DBMS_OUTPUT.PUT_LINE('Cursor opened by for');
    FOR cuv IN cur
    LOOP
    DBMS_OUTPUT.PUT_LINE(cuv.A);
    END LOOP;
    END;
    
    Cursor opened by for
    1
    
    PL/SQL procedure successfully completed.
    
  • Folders of bookmarks in Safari in the Favorites bar not open click when you access one after another

    Question: The records of Safari bookmarks in the bookmarks bar not open click when you access one after another

    Diagnostic steps:

    (1) create 2 or more folders in the bookmarks with the individual sites in their breast.  (Examples of folder name: career, finances and health)

    (2) safari > display > display favorite bar. All the Favorites should be visible in the main window of Safari with all these files

    3) click on the folder named career and then go directly to Finance. (the record finance should open with a single click)

    (4) or try to open the folder of health directly after clicking on career record. The health record is expected to open in one click. This does not currently happen

    Currently, 2 click are required to open a folder in the Favorites bar. To activate the button and the second displays the Web sites it contains.

    It is annoying and seems as if the browser is obsolete.

    If opening cursor hover is not what apple wants for these records, we are fine with it. But the least we should do, it's that these files opens in one click.

    Thank you.

    Send feedback to Apple. They will not respond, but at least know that there is a problem. If enough people send feedback, it can become the problem solved as soon as possible.

    Your comments

Maybe you are looking for