Open cursor query - oracle 10g

Could anyone tell me which is the right query for fetching open cursor:
1.
select max(a.value) as highest_open_cur,s.sid, s.username, oc.sql_text, s.logon_time, s.status, s.machine
from v$sesstat a, v$statname b, v$parameter p, v$session s, v$open_cursor oc
where a.statistic# = b.statistic#
and b.name = 'opened cursors current'
and p.name= 'open_cursors'
and username in ('USER_ID')
and s.sid = a.sid
-- and s.status <> 'KILLED'
and oc.sid = s.sid
group by s.sid,s.username, oc.sql_text, s.logon_time, s.status, s.machine
order by s.logon_time desc
2.
SELECT user_name,sid,sql_text,count(1) total,sysdate snap_time
FROM v$open_cursor
WHERE user_name IN ('USER_ID')
GROUP BY user_name,sid,sql_text
HAVING count(1)>0;
The issue is inthe secind query we have had hardly any open cursors and from the first query we are getting quiet a lot.
Would like someone to explain me the the interpretation of both the queries.
Does Oracle 10g has a different interpretation of these tables.
How should we be reading the open cursors? and
Does anyone feel there is a better way to check for open cursors ?

...etc...
How should we be reading the open cursors? and
Does anyone feel there is a better way to check for
open cursors ?Forget cursors, if your purpose is to do some kind of research for performance tuning, just generate either the Enterprise Manager ASH or ADDM reports.

Similar Messages

  • Open connections query - Oracle 10g

    How do I get the number of connections opened by a specific user to oracle 10g db ?
    Can someone help me with the query / tables to query for the same.

    Thejas wrote:
    How do I get the number of connections opened by a specific user to oracle 10g db ?
    Can someone help me with the query / tables to query for the same.select count(*) from v$session where username = <sepcific_user>
    Reading documentation is always a suggestion.
    Regards

  • Viewer leaving open cursors in Oracle

    We are using the JRC to display reports in our software. We are running jboss-4.2.0 as our application server. The backend could be either SQL Server or Oracle. For Oracle we are using the oracle.jdbc.driver.OracleDriver driver. The reports are set up using a JDBC (JNDI) connection. Generally we have it working ok but in Oracle the JRC is leaving open cursors leading to  ORA-01000: MAXIMUM OPEN CURSORS EXCEEDED. I have found that a new cursor is opened when the data source is changed in the following code snippet
    Iterator tableIT = tableNames.iterator();
    while (tableIT.hasNext()) {
      ITable oldTable = (ITable)tableIT.next();
      ITable table = (ITable) ((IClone)oldTable).clone(true);
      table.setQualifiedName(table.getName());
      clientDoc.getDatabaseController().setTableLocation(oldTable, table);
    When we hit the last line in this loop, a new cursor is opened in Oracle so if a report has 10 tables, I get 10 cursors opened. I know that I need to close the cursors somehow but nothing I do seems to make a difference. After my processHttpRequest call to the viewer I added:
    crystalReportPageViewer.getReportSource().dispose();
    clientDoc.getReportSource().dispose();
    The code definately executes but the the number of open cursors in Oracle does not change. I am at a loss.

    A couple more things to think about then.
    1.  When you go through your loop to set your table location, you are using the clone method to create a new table and then pass that table to the report.  Cloning tables is no longer necessary with the JRC.  We do know that a fix was provided for the JRC SDK, however this fix would probably not have been applied to the clone method since it has been deprecated.
    I have attached a sample that shows the new methodology for setting table location; very similar, just not using clone anymore.
    2.  When you want to destroy any connections that the ReportClientDocument has made, you will need to call .close() on this object.  This can be done in conjunction with the viewer.dispose().  One thing to note is that if you call the .close() method, it will need to be done as the user is closing the browser, or you will not have access to your report object when you have it open in the HTML Viewer.

  • Error in Cursors in Oracle 10g

    We have a VB program that is running a procedure with a cursor like this:
    cursor cleo is select * from tabla1 where campo1='valor1';
    leer cleo%rowtype;
    begin
    open cleo;
    loop
    fetch cleo into leer;
    exit when cleo%notfound;
    end loop;
    close cleo;
    end
    Then return rows that not are part of the set given by the select statement.
    The problem is given randomly when running the VB program, instead if run the same statement in sqlplus it works fine.
    The program works fine against an Oracle 8 database, the error appears against an Oracle 10g database
    null

    the code to execute is:
    create or replace procedure cpc_jz_aux (dirname varchar2, plan varchar2, error out varchar2) is
    file_write sys.utl_file.file_type;
    cursor cleo is select *
    from oper.plan_hidro_et_per_cpcs
    where id_plan = plan
    and id_etapa = 1 order by id_hidro,id_per;
    leer cleo%rowtype;
    BEGIN
    error:=NULL;
    if sys.utl_file.is_open(file_write) then
    sys.utl_file.fclose(file_write);
    end if;
    file_write := sys.utl_file.fopen(dirname,'cpc_jt3.dat','w');
         open cleo;
         loop
              fetch cleo into leer;
              exit when cleo%notfound;
              sys.utl_file.put_line(file_write,leer.id_hidro||','||leer.id_per||','||
                   nvl(leer.ymin,0)||','||nvl(leer.ymax,0)||','||nvl(leer.zmin,0)||
                        ','||nvl(leer.zmax,0));
         end loop;
         close cleo;
         sys.utl_file.fclose(file_write);
    exception
    when others then
    dbms_output.put_line('error:'||sqlcode||' '||sqlerrm);
    error := sqlerrm;
    if sys.utl_file.is_open(file_write) then
    sys.utl_file.fclose(file_write);
    end if;
    raise;
    end cpc_jz_aux;
    Message was edited by:
    jpastro

  • Cursors in Oracle 10g XE stored procedures

    I want to use a cursor in a stored procedure. I saw many examples on the net but none of them seem to work in Oracle 10g Express Edition.
    I am new to Oracle and any solution relevant to Oracle 10g XE is highly appreciated.
    Yosief Kesete

    Dear user!
    Simple error. Try that:
    CREATE OR REPLACE PROCEDURE "employeesgetlist
      p_FIRST_NAME IN VARCHAR2,
      returnValue OUT SYS_REFCURSOR
    IS
      p_EMPLOYEE_ID NUMBER;
      CURSOR C1 IS
      SELECT employee_id
      FROM employees
      WHERE first_name = p_FIRST_NAME;
    BEGIN
      BEGIN
        -- OPEN A PREVIOUSLY DECLARED CURSOR
        OPEN C1;
        LOOP
          FETCH C1 INTO p_EMPLOYEE_ID;
          EXIT WHEN C1%NOTFOUND;
        END LOOP;
         -- CLOSE THE CURSOR
        CLOSE C1;
      END;
      OPEN returnValue FOR
      SELECT * FROM employees
      WHERE employee_id = p_EMPLOYEE_ID;
    END;
    {code}
    Yours sincerely
    Florian W.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Maximum Open Cursors Exceeded - Oracle & Java

    I am using NetBeans ( Forte 5) for developing an application with Oracle Database. My application makes use of executeUpdate, executeQuery statements inorder to access Database.
    After few insertions and deletions of data through the host language( Java), my application stops working. It gives out the error.
    java.sql.SQLException: ORA-01000: maximum open cursors exceeded[/b
    Is this the problem with Forte or Oracle. I am using Oracle in a network in which i have got a tablespace in the Database server.
    How to tackle this problem.

    I am using 3 methods preparedStatements
    1. execute - returns boolean
    2. executeQuery - returns ResultSet
    3. executeUpdate - returns int
    I am closing the ResultSet object returned by executeQuery using
    close() method.
    Is this the correct way to close the open cursor.
    I access the table attributes using a rs.getString(colNum) and
    rs.getInt(colNum)
    Even then i am getting the maximum open cursors exceeded message.
    Will Oracle open a cursor for execute and executeUpdate which is not returning a ResultSet object .
    If Oracle opens a cursor for these two methods, how should i close the open cursor.

  • LRM -00109:could not open parameter file Oracle 10g in Solaris 10

    Hallo! I have just installed Oracle 10g in Solaris 10.When I logged into sqlplus / as sysdba if found that I was connected to an idle instance. When I tried to startup open the db, the following error appeared
    Connected to an idle instance.
    SQL> startup open;
    ORA-01078: failure in processing system parameters
    LRM-00109: could not open parameter file '/export/home/oracle/product/10.2.0/db_1/dbs/initsolaris.ora'
    My pfile has the name init.ora and not initsolaris.ora.How can I change the settings to make the Oracle database start via pfile init.ora.
    Eventually,I would like the db to read the spfile spfileorcl.ora during the startup.How can I achieve this?
    Thanks

    4joey1 wrote:
    Hallo! I have just installed Oracle 10g in Solaris 10.When I logged into sqlplus / as sysdba if found that I was connected to an idle instance. When I tried to startup open the db, the following error appeared
    Connected to an idle instance.
    SQL> startup open;
    ORA-01078: failure in processing system parameters
    LRM-00109: could not open parameter file '/export/home/oracle/product/10.2.0/db_1/dbs/initsolaris.ora'
    My pfile has the name init.ora and not initsolaris.ora.How can I change the settings to make the Oracle database start via pfile init.ora.
    By default, oracle will look first for a spfile named "spfile<ORACLE_SID>.ora". Lacking that, it will try to find "init<ORACLE_SID>).ora.
    Eventually,I would like the db to read the spfile spfileorcl.ora during the startup.How can I achieve this?
    Once you have started the db (I believe a startup nomount will be sufficient) you can issue CREATE SPFILE ... Details are in the fine SQL Reference manual found at tahiti.oracle.com
    BTW, "open" is the default behavior of "startup", so no need to specify it. A simple "startup" does the same thing.
    Thanks

  • SQL Query (Oracle 10g)

    Hi All,
    Please find the following requirement.
    Requirement -
    There are 2 standalone database named database A and
    database B used by 2 separate application. Database A
    has schema S1 and Database B has schema S2.
    Schema S1 has around 40 master tables which get updated
    very frequently. This 40 tables are also present in S2
    also.
    We want the both the 40 tables to be in sync every
    hourly or half any hour.
    eg. If records are added/updated deleted in S1.emp then
    same should be done in S2.emp and visa versa also.
    We dont want to use dblink,materialised views or
    scripts. Is there any feature in Oracle 10G like
    replication or Streams where in this can be done.
    Incase if are not able to replicate both ways then at
    least one way can we replicate ? like any records are
    added/updated deleted in S1.emp then same should be done
    in S2.emp and similarly in the other 39 tables.
    Thank you
    Message was edited by:
    User71408

    Can anyone provide a SQl query to create a
    schema/user named 'test' with username as 'system'
    and password as 'manager'system user is created during database creation, it's internal Oracle admin user that shouldn't be used as schema holder.
    In Oracle database, Oracle user is schema holder there's no seperate schema name to be defined other than username.

  • Copy and open Command in Oracle 10g Linux (Minut, Ubuntu)

    Dear All;
    I am facing one problem we used to copy any document and for open any document in WINDOWS
    Host('CMD /C COPY '||'"'||:Old_Doc||'"'||' X:\03\03\'||:New_Doc);
    Client_Host('Cmd /C Start '||'X:\03\03\'||:New_Doc);
    But these commands not running in Linux. Please provide me any solution that will help me to copy and open any kind of document in oracle 10g in Linux. I am waiting of your positive response. thx.

    I am not using any thing istead of HOST command, I dn't know any thing similier about HOST command. When I run this in Linux then it give me error message. I think there is something like HOST command in Linux but........ is it??

  • Maximum Open Cursors Exceeded - Oracle 9 & Java Web Server 6.1

    We are facing this problem - maximum open cursors exceeded after migrating our application to Sun Java System Web Server 6.1
    We were not facing this problem with our earlier web server
    Can anybody let us know - is there any setting we need to do to avoid this.
    The current setting for this attribute in the database is quite huge - close to 2000
    One of the "webservd" sessions, (web server user) exceeded this value

    See my reply in your duplicated post:
    http://swforum.sun.com/jive/thread.jspa?threadID=57989&messageID=220483#220483

  • Select on Cursor in oracle 10g

    Hi Experts ,
    I have a cursor which selects the data from another source.
    Now I am having a problem with this cursor because i cannot put any where condition as it takes huge time to retrive the data (data's are retrived from views)
    The "select *  from Source" works fine as it takes less  time.
    Now how can I filter the cursor  (select *  from Source ) and load the data into table ?
    can I use "select col from curosr where  cond= 'something' ?"

    You don't understand what a cursor is.
    You do not 'get data into a cursor'.  A cursor is not a result set of data.  A cursor is just a pointer to a query that data is fetched through.
    What you have shown there is a PL/SQL cursor declaration.  At that point is has not done anything except declare the definition of the cursor.  It hasn't even been opened or executed against the database, let alone any data fetched.
    How are you measuring that the query is 'fast' when you query it without conditions compared to 'slow' when you query it with conditions.
    It's possible that you don't have the correct indexes for your query filtering conditions etc. but as we don't have your database version, tables, data etc. we cannot see to help.
    I see you obviously didn't read the first FAQ about how to post your information.
    Maybe you'll bother to read this FAQ instead:  Re: 3. How to improve the performance of my query? / My query is running slow.
    which links to two threads describing what information you need to provide for tuning help.
    I can't see how you would improve performance by trying to filter your data after querying more than you need, so I think you're looking for a solution before you even know what the problem is.

  • Cursor in ORACLE FORMS 10g/6i

    Dear All Seniors
    Please tell me with complete example about CURSORS in ORACLE 10g/ 6i.
    i.e
    -> declaration
    ->opening
    -> fetching
    -> close etc
    Shall be very thankfull to him.
    thanks in advance
    yassen

    Here is an example
    DECLARE
         /* cursor declaration */
         CURSOR C IS
         SELECT  EMP_MST.EMP_ID,EMP_MST.EMP_DESIG_ID,     
         EMP_MST.EMP_CODE, EMP_MST.EMP_NAME,
         DESIG_MST.DESIG_NAME,EMP_MST.EMP_MIN_DOLLAR,EMP_MST.EMP_GROSS_SAL,  EMP_MST.EMP_BASIC,
         EMP_MST.EMP_MOBILE_BILL,EMP_MST.EMP_TA,EMP_MST.EMP_FES_BONUS
         FROM EMP_MST, DEPT_MST,DESIG_MST
         WHERE NVL(EMP_MST.EMP_QUIT, 0) = 0
         AND EMP_MST.EMP_CID_ID=:GLOBAL.GUNIT_ID
         AND EMP_MST.EMP_DEPT_ID=:GLOBAL.GDEPT_ID
         AND EMP_MST.EMP_DEPT_ID=DEPT_MST.DEPT_ID
         AND EMP_MST.EMP_DESIG_ID=DESIG_MST.DESIG_ID
         AND EMP_MST.EMP_SAL_TYPE=1
         ORDER BY EMP_MST.EMP_CODE;
         ALT NUMBER;
         R C%ROWTYPE;
         N NUMBER;
         errnum NUMBER       := ERROR_CODE;
      V_COUNT NUMBER;
      SD_COUNT NUMBER;
         V_ADD_AMT NUMBER;
         V_ADD_DEDUCT NUMBER;
         V_SAL_ADD_AMT NUMBER;
    BEGIN     
         SELECT COUNT(SD_EMP_ID) INTO SD_COUNT
         FROM SALARY_DTL,SALARY_MST
         WHERE SALARY_DTL.SD_SM_ID=SALARY_MST.SM_ID
         AND SALARY_MST.SM_MONTH=:SALARY_MST.SM_MONTH;
    /*cursor open*/
         OPEN C;
         --=================
           IF errnum = 40508 THEN    
                ALT:=SHOW_ALERT('DUP_MYD');
                RAISE Form_Trigger_Failure;
           END IF;      
         --================     
              GO_BLOCK('SALARY_DTL');     
              IF SD_COUNT=0 THEN
              FIRST_RECORD;
              ELSE
                   LAST_RECORD;
                   NEXT_RECORD;
              END IF;
         LOOP
          FETCH C INTO R;               ----cursor fetch/read
          EXIT WHEN C%NOTFOUND;     
          :SALARY_DTL.SD_EMP_ID:=R.EMP_ID;         --- data assign...
          :SALARY_DTL.SD_DESIG_ID:=R.EMP_DESIG_ID;     
          :SALARY_DTL.TXT_EMP_CODE:=R.EMP_CODE;     
          :SALARY_DTL.TXT_NAME:=R.EMP_NAME;     
          :SALARY_DTL.TXT_DESIG:=R.DESIG_NAME;
          :SALARY_DTL.SD_OLD_GROSS_SAL:=R.EMP_GROSS_SAL;
          :SALARY_DTL.SD_GROSS_SAL:=ROUND(R.EMP_MIN_DOLLAR*:SALARY_MST.SM_DOLLAR_RATE);
    --      :SALARY_DTL.SD_ORG_BASIC:=R.EMP_BASIC;     
          :SALARY_DTL.SD_ORG_BASIC:=ROUND(:SALARY_DTL.SD_GROSS_SAL*60/100);
          :SALARY_DTL.SD_MOBILE_BILL:=R.EMP_MOBILE_BILL;     
          IF NVL(:SM_BONUS_MONTH,0) =1 THEN
               :SALARY_DTL.SD_FES_BONUS:=R.EMP_FES_BONUS;     
          ELSE
               :SALARY_DTL.SD_FES_BONUS:=NULL;
          END IF;
          NEXT_RECORD;     
         END LOOP;
         PREVIOUS_RECORD;
         CLOSE C;
    END;Hope this helps..

  • Confused about Open Cursors :(

    Hi all,
    i need some clarification on this issue, i've read throught the documentation and i'm a bit confused.
    I'm using 10.1.0.2
    select sum(value)
    from v$statname sn,
    v$sesstat st,
    v$session s
    where sn.statistic# = st.statistic#
    and st.sid = s.sid
    and sn.name = 'session cursor cache count'
    The result of the above query is 4926, meaning i have 4926 CLOSED cursors in the session cursor cache.
    select count(1)
    from v$open_cursor
    The result of the above query is 16968, meaning i have 16968 cached cursors
    So there are two distinct cursor Caches ?
    now lets look at other statistic
    select sum(value)
    from v$statname sn,
    v$sesstat st,
    v$session s
    where sn.statistic# = st.statistic#
    and st.sid = s.sid
    and sn.name = 'opened cursors current'
    this one gives me 12212 , so i have 12212 opened cursors (NOT CACHED , REALLY OPENED CURSORS ...is this correct???)
    I suspect that my applications are not closing resultsets (java build application, deployed in oracle application server, database connections in pooled connection) ... so i'm trying to help my developers to find the potencial bug in application.
    How can i get the SQL from OPEN cursors ???
    V$open_cursor gives me SQL from CLOSED cached cursors ...
    Best Regards
    Rui Madaleno

    Hi,
    >>this one gives me 12212 , so i have 12212 opened cursors (NOT CACHED , REALLY OPENED CURSORS ...is this correct???)
    For your instance, yes because you use the sum(value) aggregate function. But I think that the best is get this value per session.
    select count(1) from v$open_cursor
    v$open_cursor shows cached cursors, not currently open cursors, by session. If you're wondering how many cursors a session has open, don't look in v$open_cursor. It shows the cursors in the session cursor cache for each session, not cursors that are actually open. To monitor open cursors, query v$sesstat where name='opened cursors current'. This will give the number of currently opened cursors, by session:
    select a.value, s.username, s.sid, s.serial#
    from v$sesstat a, v$statname b, v$session s
    where a.statistic# = b.statistic#  and s.sid=a.sid
    and b.name = 'opened cursors current';
    >>I suspect that my applications are not closing resultsets (java build application, deployed in oracle application server, database connections in pooled connection)
    In this case, you need to monitor you application. If want, you can use the OEM Database Console and go to [Top Sessions | Session Details] link, or to use this SQL above.
    By the way, do you are getting ORA-1000 errors ?
    If so, set the OPEN_CURSORS parameter high enough that you never get an ORA-1000 during normal operations.
    Cheers

  • Rep-0756 problem facing while opening the report in 10g

    Hi,
    I am facing problem while opening RDF in oracle 10g.
    I follow the next steps.
    1. Open the RDF in 10g.
    2. Open the PLL in report builder and compile that PLL and save in same path where report located.
    3. reattach the library with RDF.
    4. Close the RDF
    5. Reopen the RDF and facing the error.
    6. REP-0756- unable to open attached............
    7. I set the report_path in Registry also where PLL exists
    Please give me the solution for this problem
    Waiting for quick reply.
    ashok

    Thank you fs,
    I am also facing the similar issue in reports 10g, I am keeping the .pll file in my local machine say c:\me\reports\xyz.pll. When I am opening this pll, I am getting the error REP-0756 though the path 'c:\me\reports\' is added to the REPORTS_PATH. Your suggestion resolved the issue.
    Many thanks,
    Lokesh.

  • Open cursors problem- j2ee + oracle 10g

    Hi,
    I am using EJB on sunOne application server 8.1., Oracle 10g DB.
    EJB container connects to Oracle DB through a set of connection pools.
    BMP for all entity beans.
    I have about 160 PL/SQL functions that make up the business logic of the online application. everytime the application runs, I get an increasing number of open cursors, including some of the ones that are explicitly closed within PL/SQL (inspection with sys.v_$open_cursor).
    I made sure all CallableStatements, PreparedStatements, RecordSets within the beans are closed and set to NULL. All PL/SQL functions use explicit cursors, so every select statement is managed within a cursor which is explicitly closed when the function finishes with it.
    From v$open_cursor, I identified the sessions with the cursors still open, and issued (ALTER SYSTEM KILL SESSION �sid, #serial�) for each of the sessions (this is done via a PL/SQL function for all inactive sessions).
    These sessions have state INACTIVE, and wait_class IDLE. This has Killed all sessions, but I was not able to use the application anymore. I suspect by killing those sessions we have also caused the connections between EJB container and the Oracle DB. The only way to use the application now is to stop and restart the sunONE domain � this is very inconvenient.
    Has anyone encountered a similar problem? any suggestions to reduce or eliminate the open cursors number? Please help.
    Thank you all

    Maybe you can try to have a smaller steady-pool-size and idle-timeout-in-millis for your connection pools.
    Also, if that's at all possible, have smaller number of connection pools being shared by more apps.
    Just my 2c.
    thanks.

Maybe you are looking for

  • USB API?  Solaris 8 or in 9?

    I am looking for any information on the USB api for Solaris. In the early docs on Solaris 8, it was mentioned that the api would be in a future release, but I cannot find it. Does anyone have information about its inclusion (or exclusion) in Solaris

  • How do you make fonts back to default size in Firefox 24? They are blown way too big.

    Since upgrading to Firefox 22 and 24, the font size has been extremely huge. The only way to make it smaller is ctrl - , but when I go to other sites the fonts are normal size. I want to be able to get the default size font on the Firefox 24. I've be

  • How do i find out if my one year warrenty will cover replacing the earphone jack?

    Nomatter what I do only one earphone works with all headphones, when i put the headphones in another device both works. My wanenty does not expire until next febuary, but i keep trying to look and see if it is covered but i cannot find it in the text

  • How do i add bullet points to a pdf

    How do i add bullet points to a pdf?

  • Create Number range

    I have to create a number range for OM ids . OM ids will be assigned to organistion units .  OM ids will be unique and cannot be assigned to more then one org units . Please tell me the steps to create Number range which should start with 10000 till