OPEN CURSOR approach- Performance

Hi All,
We have a requirement wherein we are using OPEN CURSOR and FETCH CURSOR in a ABAP Program (Function Module).
Any sample code related to CURSORs will be help full.
Is OPEN CURSOR method better in terms of performance compared to simple SELECT statements?
Any help regarding this will be highly appriciated.
Thanks in advance.

Hi Shilpa,
   Yes from performance perspective if you are reading a large chunk of data then the Open Cursor gives you better performance. You mak keep you mouse cursor on the word cursor and read help.
Sample Below:
DATA: BEGIN OF count_line,
        carrid TYPE spfli-carrid,
        count  TYPE i,
      END OF count_line,
      spfli_tab TYPE TABLE OF spfli.
DATA: dbcur1 TYPE cursor,
      dbcur2 TYPE cursor.
OPEN CURSOR dbcur1 FOR
  SELECT carrid count(*) AS count
         FROM spfli
         GROUP BY carrid
         ORDER BY carrid.
OPEN CURSOR dbcur2 FOR
  SELECT *
         FROM spfli
         ORDER BY carrid.
DO.
  FETCH NEXT CURSOR dbcur1 INTO count_line.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  FETCH NEXT CURSOR dbcur2
    INTO TABLE spfli_tab PACKAGE SIZE count_line-count.
ENDDO.
CLOSE CURSOR: dbcur1,
              dbcur2.
best regards,
Kazmi

Similar Messages

  • Avg number of open cursors per session

    We've been noticing a large number of open cursors open per session in our database, these users being Oracle Forms users. There are quite a few 'bells & whistles' in this vendor-supplied application with many round trips to the database. The warning we were receiving was induced by an alert that we had set up within OEM.
    It got me wondering then, what a large number of cursors per process really was. We're seeing between 10-80 open cursors. The init parm OPEN_CURSORS has a default value of 50 upon installation (which is per session), so the max of 80 doesn't seem too much higher.
    Are we really experiencing a large # of open cursors per session? Does someone have a means of estimating the max # of cursors that one would expect based upon CPU & memory resources? I can't find anything in the documentation.
    Thanks,
    Chuck

    There is an OPEN_CURSORS parameter in the init.ora file,
    I want to know the impact of number of open cursors on performance
    (ie., how many open cursors would be appropriate for an instance)There shouldn't be a performance issue here. The value needs to be set based on how many open cursors you want to allow simultaneously. If you set the value too low, applications will get the "too many cursors open" error when they try to open a new cursor. If you're not having problems, or if you don't know how many open cursors you're likely to have, I wouldn't change this parameter.
    Justin

  • Number of open cursors

    I'm working on debugging some code and trying to monitor some of things that are happening at runtime. One of the things that would be useful is if I could monitor the number of open cursors on a connection.
    I've done my searching and can't seem to find anything of the sort Connection.getOpenCursorCount().... is there such a method or anything related?

    There's nothing generic like this, every possible approach that I know of is implementation-specific, either Java-side or DB-side.
    The Java-side approach is to attempt to track ResultSets through their life-cycle, as a rough proxy for cursors; this usually relies on wrapped RSs or a vendor-specific driver feature, and is sometimes not a good solution for running down certain types of resource leaks.
    On the DB side, some DBs have some visibility into open cursors through some sort of vendor-specific API.
    For example, on Oracle, there is the system view V$OPEN_CURSOR that can be queried for some information related to open cursors, often in conjuction with info ftom V$SESSION and V$SQL, V$SQL_AREA or V$SQL_TEXT. IMPORTANT NOTE: this view is actually a view on internal Oracle memory structures. While you can query it like any normal view or table, it is changing constantly, with internal per-row consistancy guaranteed by latches (locks on memory). Complex queries against internal views (such as self-joins or complex aggregations) can interact with the latches very badly; the queries may take many hours to complete and consume massive amounts of CPU while doing so. If you need to perform a complex analysis, don't do it on the live view; create a snapshot of the view and use that, for example:
    CREATE TABLE SNAP_OPEN_CURSORS as
    SELECT * FROM V$OPEN_CURSORS(Note that in a RAC or OPS Oracle cluster, the V$ views only report on the instance you're connected to; there are analogous GV$ views that report on all available instances, and have an added INST_ID column identifying the source instance, when relevant).

  • Oracle and "Maximum open cursors exceeded"

    Hi,
    I am using Weblogic 7.0sp2 with Oracle 9.2.0. Since we are using manual JTA
    transactions and the 9.2 drivers are buggy in that respect, we are using the
    9.0.1 thin drivers delivered with weblogic.
    The problem I have is that after a while, we get the now classic "Maximum open
    cursors exceeded" error on connections from our connection pool (used through
    a
    TX datasource). I have of course checked all our JDBC code and it is fine. We
    do not leave any statement/connection open. In fact, I am certain that the
    problem is not caused by our applicative code.
    The reason I am so positive is that the numbers of open (cached) cursors is
    growing, even though there is no activity on our application (I mean no
    activity at all). The number of cursors is regurlarly increasing by one
    every 5 minutes until it reaches the maximum allowed for a session.
    I have listed the statements corresponding to the opened cursors (they
    do not belong to our code, as you might have guessed):
    SELECT sysdate, user from dual
    select longdbcs from javasnm$ where short = :1
    select longname from javasnm$ where short = :1
    As you can see, there are only three different statements. You can get
    the statements from the system view v$open_cursor for a given session
    but it will only give one row per different statement. If you want to know
    the # of opened cursors in your cursor, use v$sesstat with statistic# = 3
    (opened cursor current).
    I suspect something is wrong in the connection testing done by weblogic
    for the pool (I have activated test on reserved connections and test table
    name is "dual") that leaves a resultset/statement behind. What is weird
    though is that the refresh period is still 0 (not 5 minutes as you would
    expect from the cursor growth rate...).
    I would not say that it is an Oracle bug (as stated in some BEA FAQ I read)
    since our application JDBC code does not exhibit the same problem. The
    problem appeared with recent version of WebLogic for which the session
    cursor cache is enabled, I suppose for performance reasons - this
    is set by isssuing "ALTER SESSION SET SESSION_CACHED_CURSORS = ...".
    Talking about this, does anybody know to which value WebLogic sets this
    parameter when intializing the connection (this is neither
    documented/configurable)?
    Up to now, I have come up with possibly two workarounds, neither of which
    is satisfying:
    - resetting the pool from time to time
    - issuing "ALTER SESSION SET SESSION_CACHED_CURSORS = 0" when I get a
    connection from the pool. I have not tested this one personally (read
    in a newsgroup that someone else did successfully) but it is supposed
    to reset the cursor cache that is causing the trouble.
    Any help will be greatly appreciated,
    Regards,
    Thierry.

    Thierry Rouget wrote:
    Hi,
    I am using Weblogic 7.0sp2 with Oracle 9.2.0. Since we are using manual JTA
    transactions and the 9.2 drivers are buggy in that respect, we are using the
    9.0.1 thin drivers delivered with weblogic.
    The problem I have is that after a while, we get the now classic "Maximum open
    cursors exceeded" error on connections from our connection pool (used through
    a
    TX datasource). I have of course checked all our JDBC code and it is fine. We
    do not leave any statement/connection open. In fact, I am certain that the
    problem is not caused by our applicative code.
    The reason I am so positive is that the numbers of open (cached) cursors is
    growing, even though there is no activity on our application (I mean no
    activity at all). The number of cursors is regurlarly increasing by one
    every 5 minutes until it reaches the maximum allowed for a session.
    I have listed the statements corresponding to the opened cursors (they
    do not belong to our code, as you might have guessed):
    SELECT sysdate, user from dual
    select longdbcs from javasnm$ where short = :1
    select longname from javasnm$ where short = :1
    As you can see, there are only three different statements. You can get
    the statements from the system view v$open_cursor for a given session
    but it will only give one row per different statement. If you want to know
    the # of opened cursors in your cursor, use v$sesstat with statistic# = 3
    (opened cursor current).
    I suspect something is wrong in the connection testing done by weblogic
    for the pool (I have activated test on reserved connections and test table
    name is "dual") that leaves a resultset/statement behind. What is weird
    though is that the refresh period is still 0 (not 5 minutes as you would
    expect from the cursor growth rate...).
    I would not say that it is an Oracle bug (as stated in some BEA FAQ I read)
    since our application JDBC code does not exhibit the same problem. The
    problem appeared with recent version of WebLogic for which the session
    cursor cache is enabled, I suppose for performance reasons - this
    is set by isssuing "ALTER SESSION SET SESSION_CACHED_CURSORS = ...".
    Talking about this, does anybody know to which value WebLogic sets this
    parameter when intializing the connection (this is neither
    documented/configurable)?
    Up to now, I have come up with possibly two workarounds, neither of which
    is satisfying:
    - resetting the pool from time to time
    - issuing "ALTER SESSION SET SESSION_CACHED_CURSORS = 0" when I get a
    connection from the pool. I have not tested this one personally (read
    in a newsgroup that someone else did successfully) but it is supposed
    to reset the cursor cache that is causing the trouble.
    Any help will be greatly appreciated,
    Regards,
    Thierry.Hi. We don't make those queries either. I suspect they are internal to the
    oracle driver. One thing you can try is to set the size of the pool's
    statement cache to zero. Oracle will retain cursors for every statement we
    cache. The alternative is also to tell the DBMS to allow a given session
    more cursors.
    Joe

  • Open cursors are NOT closed only by closing the ResultSet or Statement

    I've realised that the open cursors are only closed by closing the connection.
    In my example code I have for-loop with a vector of table-names. For every table-name I start a query to retrieve metainformation (row-size, column-names). Although I close the ResultSet (which automatically closes the PreparedStatement/Statement) I reached after the 150th loop a max-cursor-exception (ora-01000) ?!
    It seems that there is only the workaround to close and re-open the connection at the end of the for-loop. Which is performance-side pretty bad :-(.
    Is there really no other solution?
    Besides: does anyone know WHY the statement.close() also closes the ResultSet?? I think this is a bad design (hence to tight dependency between both classes). What if the garbage collector closes the statement (and hence to the JDOC the statement.close()-method also closes the ResultSet)? For example if a method uses a local Statement and returns a ResultSet (and the Statement-garbage is collected), then the ResultSet would cause an exception?!
    Thanks for the help in advance
    Tai

    I've realised that the open cursors are only closed by
    closing the connection.Or by closing the Statement!
    In my example code I have for-loop with a vector of
    table-names. For every table-name I start a query to
    retrieve metainformation (row-size, column-names).
    Although I close the ResultSet (which automatically
    closes the PreparedStatement/Statement) I reached
    after the 150th loop a max-cursor-exception
    (ora-01000) ?!Closing the ResutSet does not automatically close the PreparedStatement/Statement.
    >
    It seems that there is only the workaround to close
    and re-open the connection at the end of the for-loop.
    Which is performance-side pretty bad :-(.
    Is there really no other solution?
    Just explicitly close the PreparedStatement/Statement!
    Besides: does anyone know WHY the statement.close()
    also closes the ResultSet?? You need to think of a resultset as a live connection to the database.
    Consider SELECT * FROM ABIGTABLE, it would be inefficient to populate the Resultset with all of the rows (could even eat up all memory) so the first n rows are returned ( n = Statement.getFetchSize() ) and the next n rows are returned as needed.
    I think this is a bad
    design (hence to tight dependency between both
    classes). What if the garbage collector closes the
    statement (and hence to the JDOC the
    statement.close()-method also closes the ResultSet)?
    For example if a method uses a local Statement and
    returns a ResultSet (and the Statement-garbage is
    collected), then the ResultSet would cause an
    exception?!You should use a statment and resultset, read all your data into a collection or a CachedRowSet (http://www.javaworld.com/javaworld/jw-02-2001/jw-0202-cachedrow.html) then close the statment as soon as possible. Never return a resultset form your data tier: that is tight coupling between the tiers of your application!

  • More on "maximum open cursors exceeded"

    It seems a lot of people have been seeing this error message, but reading through the posts on the topic hasn't given me any new insight on the problem. Here's an account of my particular situation:
    I am using the XSQL servlet, v.1.0.0.0 with the thin jdbc driver v.1.x. The servlet is running within an Apache server (1.3.12) on a Linux box, and the Oracle database (8.1.5) is located on a Solaris 2.6 machine.
    The servlet accepts HTTP connections, performs the corresponding SQL queries and returns the output from the database to the HTTP client. Here's a simple example:
    (Sorry about potential bad line breaks.)
    client request:
    % telnet xsql-host.some.domain 80
    Trying xxx.xxx.xxx.xxx
    Connected to xsql-host.some.domain.
    GET /xsql/test/listall.xsql
    <server response here>
    listall.xsql:
    <?xml version="1.0"?>
    <page connection="boss" xmlns:xsql="urn:oracle-xsql">
    <accounts>
    <xsql:query tag-case="lower" rowset-element="" row-element="accountinfo">
    select * from test
    </xsql:query>
    </accounts>
    </page>
    Very simple stuff indeed. Now, this has worked perfectly for 3 weeks or so. During this period, the xsql servlet has been stopped and restarted numerous times and the machine hosting the database has been rebooted at least three times. Then, for no apparent reason (as nothing had changed in the setup described above), I started getting "maximum open cursors exceeded" on every request. Since then, I have been unable to get the system working as it had up until now. I haven't restarted the database and I would like to avoid doing so, because that would not be a valid solution for us if the problem reappeared in production. The maximum open cursors setting in Oracle should be correct, since things were running smoothly before.
    From what I can see, the problem could be with the servlet not closing its cursors. One post mentioned that it did, but I would appreciate it if this could be double-checked. Considering the database is the only portion of the system which has been kept running for extended periods of time, it seems to me that this might indeed be the problem.
    Confirmation, workarounds, suggestions, patches, or a consolation box of chocolates would all be appreciated.
    Thanks,
    - Fad
    ([email protected])
    null

    Check which process is making all the cursors on which database. If it is your procedure, try explicitly closing the cursors. I think the cursors are only implicitely closed after the transaction is ended. If you loop and open a cursor within the loop, that might be the problem.
    I also had this problem with Java working over a JDBC connection some time ago on a 815 database. If I recall correctly, that was caused by the JDBC driver and fixed by replacing it with a JDBC driver of 9i.
    The following script is what I used previously in a program that can draw a graph from the results. It is ugly, but does the job.
    Hope this helps,
    L.
    select
      'max cursors',
      to_number(value)
    from
      v$parameter
    where
      name = 'open_cursors'
    union
    select
      substr(lower(username),1,10)||'('||substr(to_char(ses.sid)||','
      ||to_char(serial#),1,9)||')',
      s.value
    from
      v$sesstat s,
      v$statname n,
      v$session ses
    where
    s.statistic#=n.statistic#
    and ses.sid=s.sid
    and n.name like '%cursor%'
    and n.name like '%current%'
    and not (ses.sid between 1 and 6)

  • PreparedStatement and open cursors

    Hi,
    i write an application where it is necessary to get a lot of preparedStatements in one connection. The preparedStatements are used
    only once and they are closed after the usage. But it seems to me that this close
    has no effect. Depending on the value in open cursors the error ORA - 01000 raises and it is not possible to get another preparedStatement without closing and opening the connection. But that increases the runtime to much and the application is a performance-critical application.
    Does anyone have an idea how to solve the problem?
    Thanks

    >
    Any thoughts what could be the problem. Only time I ever got them was because the result set, statement, connection wasn't being closed or wasn't being closed in the correct order.

  • TOO many OPEN CURSORS during loop of INSERT's

    Running ODP.NET beta2 (can't move up yet but will do that soon)
    I don't think it is related with ODP itself but probably on how .Net works with cursors. We have a for/next loop that executes INSERT INTO xxx VALUES (:a,:b,:c)
    statements. Apparently, when monitoring v$sysstat (current open cursors) we see these raising with 1 INSERT = 1 cursor. If subsequently we try to perform another action, we get max cursors exceeded. We allready set open_cursor = 1000, but the number of inserts can be very high. Is there a way to release these cursors (already wrote oDataAdaptor.dispose, oCmd.dispose but this does not help.
    Is it normal that each INSERT has it's own cursor ? they all have the same hashvalue in v$open_cursor. They seem to be released after a while, especially when moving to another asp.net page, but it's not clear when that happens and if it is possible to force the release of the (implicit?) cursors faster.
    Below is a snippet of the code, I unrolled a couple of function-calls into the code so this is just an example, not sure it will run without errors like this, but the idea should be clear (the code looks rather complex for what it does but the unrolled functions make the code more generic and we have a database-independend datalayer):
    Try
    ' Set the Base Delete statement
    lBaseSql = _
    "INSERT INTO atable(col1,col2,col3) " & _
    "VALUES(:col1,:col2,:col3)"
    ' Initialize a transaction
    lTransaction = oConnection.BeginTransaction()
    ' Create the parameter collection, containing for each
    ' row in the list the arguments
    For Each lDataRow In aList.Rows
    lOracleParamters = New OracleParameterCollection()
    lOracleParameter = New OracleParameter("luserid", OracleDbType.Varchar2,
    _ CType(aCol1, Object))
    lOracleParamters.Add(lOracleParameter)
    lOracleParameter = New OracleParameter("part_no", OracleDbType.Varchar2, _
    CType(lDataRow.Item("col2"), Object))
    lOracleParamters.Add(lOracleParameter)
    lOracleParameter = New OracleParameter("revision", OracleDbType.Int32, _
    CType(lDataRow.Item("col3"), Object))
    lOracleParamters.Add(lOracleParameter)
    ' Execute the Statement;
    ' If the execution fails because the row already exists,
    ' then the insert should be considered as succesfull.
    Try
    Dim aCommand As New OracleCommand()
    Dim retval As Integer
    'associate the aConnection with the aCommand
    aCommand.Connection = oConnection
    'set the aCommand text (stored procedure name or SQL statement)
    aCommand.CommandText = lBaseSQL
    'set the aCommand type
    aCommand.CommandType = CommandType.Text
    'attach the aCommand parameters if they are provided
    If Not (lOracleParameters Is Nothing) Then
    Dim lParameter As OracleParameter
    For Each lParameter In lOracleParameters
    'check for derived output value with no value assigned
    If lParameter.Direction = ParameterDirection.InputOutput _
    And lParameter.Value Is Nothing Then
    lParameter.Value = Nothing
    End If
    aCommand.Parameters.Add(lParameter)
    Next lParameter
    End If
    Return
    ' finally, execute the aCommand.
    retval = cmd.ExecuteNonQuery()
    ' detach the OracleParameters from the aCommand object,
    ' so they can be used again
    cmd.Parameters.Clear()
    Catch ex As Exception
    Dim lErrorMsg As String
    lErrorMsg = ex.ToString
    If Not lTransaction Is Nothing Then
    lTransaction.Rollback()
    End If
    End Try
    Next
    lTransaction.Commit()
    Catch ex As Exception
    lTransaction.Rollback()
    Throw New DLDataException(aConnection, ex)
    End Try

    I have run into this problem as well. To my mind
    Phillip's solution will work but seems completey unnecessary. This is work the provider itself should be managing.
    I've done extensive testing with both ODP and OracleClient. Here is one of the scenarios: In a tight loop of 10,000 records, each of which is either going to be inserted or updated via a stored procedure call, the ODP provider throws the "too many cursor errors at around the 800th iteration. With over 300 cursors being open. The exact same code with OracleClient as the provider never throws an error and opens up 40+ cursors during execution.
    The applicaation I have updates a Oracle8i database from a DB2 database. There are over 30 tables being updated in near real time. Reusing the command object is not an option and adding all the code Phillip did for each call seems highly unnecessary. I say Oracle needs to fix this problem. As much as I hate to say it the microsoft provider seems superior at this point.

  • Maximum open cursors in SQLJ, ORA-01000

    Hello,
    Can someone please help me with the following: I have a java application that does 7000 insert statements, but I get ORA-01000 after only 200-300 inserts. The error message is:
    Exception: java.sql.SQLException: ORA-01000: maximum open cursors exceeded
    A simplified version of my insert in sqlj:
    try {
         #sql [_ctx] {
              insert into TABLE_X
              ( name, addr ) values
              (:m_name,m_addr)
    } catch(SQLException e){
              m_mgr.GetErrorLog().logError("Critical",
         "Failed to insert user into TABLE_X","","Program aborting","?",e );
              m_mgr.SystemErrorExit();
    1. The only answers I can find in the forums is either to increase max open cursors in inti.ora, or to close your statements correctly. I'v tried increasing max open cursors but this does not help..(its not a very god approach anyway), and I can't see why I should close my statements from SQLJ: This error did not occur in the same application on a different platform 10 months ago.
    2. Could it have something to do with the thin driver version I'm using. Either in JDev or in the database. I use JDev 903 (on win 2000) and a 8.1.7.4 database (on solaris).
    3. I tried using oci8 connectoin, but could not get it working. Using oci8 i got the error
    java.lang.UnsatisfiedLinkError: no ocijdbc9 in java.library.path
    Feedback appreciated.
    /Anders

    For oci to work you should have Oracle or SQL client installed on your machine.
    You should also have ORACLE_HOME\bin in you path.
    ocijdbc9.dll is available in the above directory.
    Chandar

  • Maximum open cursors exceeded when inserting to a remote db

    I receive the error:
    ORA-01000: maximum open cursors exceeded
    ORA-02063: preceding line
    from ONTARIO
    (where ONTARIO is my remote db) when I am performing inserts from a pl/sql procedure to the remote db. I am performing two inserts from inside pl/sql and then issuing an explicit commit. I checked the open_cursors init param on both the local db and remote db and it was set to 300. I bumped up the remote db init param to 600. I was able to perform more inserts but still received this error.
    I thought implicit cursors close themselves, especially after a commit. Do I need to do something special to close the cursors on the remote machine?
    Thanks for your time...

    Check which process is making all the cursors on which database. If it is your procedure, try explicitly closing the cursors. I think the cursors are only implicitely closed after the transaction is ended. If you loop and open a cursor within the loop, that might be the problem.
    I also had this problem with Java working over a JDBC connection some time ago on a 815 database. If I recall correctly, that was caused by the JDBC driver and fixed by replacing it with a JDBC driver of 9i.
    The following script is what I used previously in a program that can draw a graph from the results. It is ugly, but does the job.
    Hope this helps,
    L.
    select
      'max cursors',
      to_number(value)
    from
      v$parameter
    where
      name = 'open_cursors'
    union
    select
      substr(lower(username),1,10)||'('||substr(to_char(ses.sid)||','
      ||to_char(serial#),1,9)||')',
      s.value
    from
      v$sesstat s,
      v$statname n,
      v$session ses
    where
    s.statistic#=n.statistic#
    and ses.sid=s.sid
    and n.name like '%cursor%'
    and n.name like '%current%'
    and not (ses.sid between 1 and 6)

  • Monitroing maximum open cursors

    Hei experts!
    How can I get the information about the all the curently opened connections and cursors? We have this 'maximum open cursor exceeded' problem very often.
    Although I know I can raise the open cursor amount in init.ora, still I want to trace who is connecting to database and how many curcors caused by that connection.
    By the way, the query
    select a.value, b.name from v$mystat a, v$statname b
    where a.statistic# = b.statistic# and a.statistic#= 3;
    doesn't really show me the actua opened cursors(because it always show only 1 open cursor which is caused just by this select statement).
    Any information is appreciated,
    Thanks in advance,
    Chen Zhao

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Koshal Patibandla ([email protected]):
    Set the paramater open_cursor to as high as possible. There is absolutely no performance overhead.
    <HR></BLOCKQUOTE>
    Yea, of course if you have enough memory

  • SELECT DISTINCT With OPEN cursor FOR

    Hello.
    I have the following procedure. All it does is open a cursor for an SQL string passed into it, and return the open cursor.
    PROCEDURE sp_execute_dynamic (hold_input_string IN CLOB,
    hold_cursor OUT hold_cursor_type) IS
    BEGIN
    OPEN hold_cursor FOR TO_CHAR(hold_input_string);
    END sp_execute_dynamic;
    It works fine except when I perform SELECT DISTINCT. I get the following error.
    SQL> declare
    2 TYPE hold_cursor_type IS REF CURSOR;
    3 hold_cursor hold_cursor_type;
    4 hold_object_name VARCHAR2(1024);
    5 hold_object_type VARCHAR2(1024);
    6 begin
    7 dynamic_sql_pkg.sp_execute_dynamic('select distinct object_name from user_objects where object_
    name in (''PLAN_TABLE'',''DBA_OBJECTS'')',hold_cursor);
    8 loop
    9 fetch hold_cursor into hold_object_name, hold_object_type;
    10 exit when hold_cursor%NOTFOUND;
    11 dbms_output.put_line('Object Name = '||hold_object_name||' Object Type = '||hold_object_type);
    12 end loop;
    13 end;
    14 /
    declare
    ERROR at line 1:
    ORA-01007: variable not in select list
    ORA-06512: at line 9
    It does the same thing with SELECT UNIQUE or SELECT with a GROUP BY. Can anyone tell me why this happens and what I could to to work around it?
    Thanks
    Chris

    see at line 7 you are selecting only one column and at line 9you are fetching into two variables
    7 dynamic_sql_pkg.sp_execute_dynamic('select distinct object_name from user_objects where object_
    name in (''PLAN_TABLE'',''DBA_OBJECTS'')',hold_cursor);
    8 loop
    9 fetch hold_cursor into hold_object_name, hold_object_type;
    HTH

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

  • SYS_REFCURSOR, open cursor

    I have a function that is returning an address.
    CREATE OR REPLACE FUNCTION GetAnyRows_01(p_paid IN NUMBER)
    RETURN SYS_REFCURSOR
    AS
       rc SYS_REFCURSOR;
    BEGIN
         OPEN rc FOR SELECT ans_strasse_pf, ans_plz, ans_ort
                    FROM anschriften
                    where ans_pa_pa_id = p_paid;
        RETURN rc;
    END;
    /The third column of my select statement contains the function, which is returning a ref
    cursor construct.
    SQL> select pa_pa_id Nr#,
      2         pa_geschlecht mw, 
      3         GetAnyRows_01(pa_pa_id) address
      4  from partners
      5  where pa_pa_id in (20,46)
      6  order by 1
      7  /
           NR# M ADDRESS
            20 m CURSOR STATEMENT : 3
    CURSOR STATEMENT : 3
    ANS_STRASSE_PF                           ANS_P ANS_ORT
    Peterstreet 46                           20566 Hamburg
            46 m CURSOR STATEMENT : 3
    CURSOR STATEMENT : 3
    ANS_STRASSE_PF                           ANS_P ANS_ORT
    Dragon Heart 1                           97745 Munich
    SQL> First if want to know, if this okay, programming a SYS_REFCURSOR for solving this problem?
    What do you think about it?
    ~
    With the following statement I must get at about 16.000 rows, but I get an error :-(
    SQL> select pa_pa_id Nr#,
      2         pa_geschlecht mw, 
      3         GetAnyRows_01(pa_pa_id) address
      4  from partners
      5  --where pa_pa_id in (20,46)
      6  order by 1
      7  /
           GetAnyRows_01(pa_pa_id) address
    FEHLER in Zeile 3:
    ORA-01000: maximum open cursors exceeded
    ORA-06512: in "MAD.GETANYROWS_01", Line 14
    SQL> I have checked the open cursor of my session:
    SQL> SELECT o.sid, s.username, substr(machine,1,32), count(*)
      2  FROM v$open_cursor o, v$session s
      3  WHERE o.sid = s.sid
      4  GROUP BY o.sid, s.username, machine
      5  HAVING COUNT(*) > 1
      6  ORDER BY count(*) desc;
           SID USERNAME                       SUBSTR(MACHINE,1,32)               COUNT(*)
           146 MAD                            bello                                   557Does anybody have an idea?

    I have checked the open cursor of my session:
    SQL> SELECT o.sid, s.username, substr(machine,1,32),
    count(*)
    2  FROM v$open_cursor o, v$session s
    3  WHERE o.sid = s.sid
    4  GROUP BY o.sid, s.username, machine
    5  HAVING COUNT(*) > 1
    6  ORDER BY count(*) desc;
    SID USERNAME
    SUBSTR(MACHINE,1,32)
    COUNT(*)
    146 MAD                            bello
    557This proves nothing as the cursors may have been closed after the SQL finished.
    The problem is that for each row of data you are opening a ref cursor, but these opened cursors are not being closed for each row.
    Can you not just join to the address table that is in the function and retrieve the data as an additional column? It doesn't really seem like you need to use a function in this case.
    Also bear in mind that calling user defined functions from within SQL causes a performance issue when dealing with lots of rows of data due to the context switching between SQL and PL/SQL that has to take place.
    If you can do it just in SQL then do that. Ony resort to PL/SQL when absolutely necessary.

  • Recommended OPEN CURSORS setting for Oracle serving a web app

    G'day
    Hopefully Phil is still lurking here, so might see this.  Or anyone else that knows about Oracle.
    I've always thought the default for "maximum pooled statements" setting for an Oracle DSN - which is 300 - is way too low to be sensible for a web app (which, let's face it, any CF DSN is going to be used for!).  I usually find I end up with it up around 1000-2000, depending on the sizeof the app, and how busy it is.
    I'm adequate with monkeying around with Oracle, and have needed to do a moderate bit of that sort of thing in our dev environment, but I am by no means a DBA, so it's all very seat-of-the-pants.
    So I'm keen to know what other people have their maximum pooled statements / open cursors setting set to for their Oracle-driven web sites/apps.
    One of the reasons I'm asking is that I wonder if it might be worth while to suggest the default for CF9 is upped to 1000 or so..?
    Thoughts / comment?
    Adam

    I personally would not set the limit any higher than 300, and I'd consider keeping it even lower.
    Each pooled query / open connection is imposing resource-burdens on both the CF and the Oracle servers by creating what might be thought of as "a very crowded restaurant."  Most of them are just standing around, but they nevertheless are occupying the restaurant, and the potential exists that every one of them might try to order a burger-and-fries at exactly the same time.
    The "number of pooled statements" should be such that your SQL-server can actually handle that number of simultaneous requests, both in terms of active searches and of maintaining the still-open result sets.  Beyond that point, incoming web requests should be forced to wait.  Set an "occupancy limit" to your proverbial restaurant such that everyone could come in and be timely served at the same time.
    Categorically, if you plot out response-time graphs about such things (SQL servers, virtual memory subsystems, and so on), they exhibit a fairly-linear performance curve up to a point, after which "the elbow- or knee-point is reached" and beyond that point it becomes exponential in a very, very bad way.  I saw this happen in a batch-processing subsystem long ago on a very small mainframe:  (yeah, I'm makin' these numbers up...)
    Number of Jobs at Once
    Completion Time per Job
    1
    30 seconds
    3
    40 seconds
    8
    9 minutes
    12
    4.5 hours
    It was just-about that bad.  And what I did to (dramatically...) address the problem was to impose simultaneous-job limits on that subsystem.  As long as the number of simultaneous jobs was constrained to "less than 3 at a time," a workload of 12 jobs could be reliably completed in (4 * 40) seconds, whereas if all 12 jobs tried to run at once, the computer would have reason to file a lawsuit for abuse.

Maybe you are looking for

  • How to Hide a User?

    I'm trying to create an admin user without having the account showing on the login screen. I came across this article: How to hide a user account in OS X - Apple Support Which says to enter the following into the Terminal (when using Yosemite): sudo

  • PSE 10 Liquify filter

    Can not view image at full size when in liquify.  e.g. the image is much smaller when you select liquify and when you enlarge it it pixelates.  Is there a adjust or is something wrong with my Elements? Thanks!

  • Forte Bug 22023 .

    Ivor Vaz@SUNLIFE 08-11-97 12:57 PM Hello, Does anybody know of a work-around for using MS-SQL stored procedures with complex select statements to build cursors in forte ? I have to use a select statement that contains a union. When I do an OpenCursor

  • User Exists  for  MIRO /FB03   transaction

    Hi, Our requirement is to capture the PO text in MIRO posting document (FB03) I have tried the following - I made use of SAP enhancement LMR1M004 and user exit EXIT_SAPLMRMP_004 to populate the BSEG_SGTXT. What i observed are - - When you create the

  • 2008R2 Server Image to Different Backup Server

    We are considering imaging our current 2008R2 HP server with NovaBackup Business Essentials. This will allow us to restore to different hardware in case the primary server goes down for an extended time. - are there issues with this? - will 2008/r2 r