Running queries against cursor results?

I'm running a cursor in a stored procedure, and the query itself is dependent on one of the parameters passed to the SP. So, for example:
create procedure annoying as
SQLString varchar2(50);
myCursor Types.cursorType; -- defined elsewhere in pkg.
begin
if parameter = 1 then SQLString = "select x,y from table1";
if parameter = 2 then SQLString = "select x,z from table2";
open myCursor for SQLString;
At this point, I need to run a further query against the result set from the cursor. I have no clue how to proceed with this. Am I barking up the wrong tree? Should I be looking for a different solution?

Instead of looping through a cursor and comparing the values of x, use the entire select statement that you would have used for the cursor as an inline view (select statement in the from clause) in your subsequent cursor and join via x. Please see the example below. You can continue this nesting for as many levels as required. For example, instead of opening the ref cursor for sqlstring2, you could use that as an inline view in another sqlstring3 and open the ref cursor for sqlstring3.
scott@ORA92> create or replace package types
  2  as
  3    type cursortype is ref cursor;
  4  end types;
  5  /
Package created.
scott@ORA92> show errors
No errors.
scott@ORA92> create or replace procedure annoying
  2    (parameter in  number,
  3       myCursor  out Types.cursortype)
  4  as
  5    SQLString  varchar2(50);
  6    sqlString2 varchar2(4000);
  7  begin
  8    if parameter = 1 then SQLString := 'select deptno x, dname y from dept';
  9    elsif parameter = 2 then SQLString := 'select deptno x,loc z from dept';
10    end if;
11    sqlstring2 := 'select e.empno, d.*
12                  from   emp e,
13                      (' || sqlstring || ') d -- inline view
14                  where e.deptno = d.x';
15    open myCursor for SQLString2;
16  end annoying;
17  /
Procedure created.
scott@ORA92> show errors
No errors.
scott@ORA92> variable g_ref refcursor
scott@ORA92> execute annoying (1, :g_ref)
PL/SQL procedure successfully completed.
scott@ORA92> print g_ref
     EMPNO          X Y
      7934         10 ACCOUNTING
      7839         10 ACCOUNTING
      7782         10 ACCOUNTING
      7902         20 RESEARCH
      7876         20 RESEARCH
      7788         20 RESEARCH
      7566         20 RESEARCH
      7369         20 RESEARCH
      7900         30 SALES
      7844         30 SALES
      7698         30 SALES
      7654         30 SALES
      7521         30 SALES
      7499         30 SALES
14 rows selected.
scott@ORA92> execute annoying (2, :g_ref)
PL/SQL procedure successfully completed.
scott@ORA92> print g_ref
     EMPNO          X Z
      7934         10 NEW YORK
      7839         10 NEW YORK
      7782         10 NEW YORK
      7902         20 DALLAS
      7876         20 DALLAS
      7788         20 DALLAS
      7566         20 DALLAS
      7369         20 DALLAS
      7900         30 CHICAGO
      7844         30 CHICAGO
      7698         30 CHICAGO
      7654         30 CHICAGO
      7521         30 CHICAGO
      7499         30 CHICAGO
14 rows selected.

Similar Messages

  • Run queries against system tables for oracle BPEL processes

    I want to run queries against system tables for oracle BPEL processes. It is becoming very difficult for me to us EM as it is very slow,
    and not all the time, it is sufficient for our needs.
    We are doing load testing and we want find out info like how many requests came in and how many faulted and what time is taken by each request...
    So do any of you have the query that I can use and tables that I need to go against?

    Use the BPEL hydration database table "cube_instance".
    There should be plenty of example in the forum regarding this table.

  • Process to run queries against 0FIGL_V10

    Hi,
    I'm working on New GL Accounting and successfully populated data into 0FIGL_O10 then to 0FIGL_C10 and executed standard queries.
    My problem is with the virtual cube 0FIGL_V10 and it's standard queries.
    What is process i have to perform, before executing the standard queries aganist the virtual cube 0FIGL_V10 ?
    Thnaks in advance.
    Mr V

    Hi,
    Which are your problems? What do you mean by "process i have to perform"?
    you should just activate the virtual cube and querys. Then execute the querys.
    check this link:
    http://help.sap.com/saphelp_nw04/helpdata/en/c2/ed6840b151181ce10000000a1550b0/content.htm
    regards,
    Diego Lombardini

  • System process running queries every 25 seconds against SQL 2012 Developer Edition

    While debugging a long running stored procedure I wanted to include SP:stmtStarting and SP:stmtCompleted.
    I noticed that every 25 seconds I was getting multiple queries against every database on my local server like:
    select table_id, item_guid, oplsn_fseqno, oplsn_bOffset, oplsn_slotid
    from [dbname].[sys].[filetable_updates_random_number] with (readpast) order by table_id
    From different sid's each time.
    While searching I saw that sometimes this may had to do with always on availability or filestream support but this is not my case since I don't use any of these features. This is a single instance installation.
    The following queries return no rows.
    SELECT * FROM sys.filetables;
    GO
    SELECT * FROM sys.tables WHERE is_filetable = 1;
    GO
    @@version returns:
    Microsoft SQL Server 2012 (SP1) - 11.0.3401.0 (X64)
    Jan  9 2014 13:22:15
    Copyright (c) Microsoft Corporation
    Developer Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
    This may be useful but I also have SQL Server 2014 Developer Edition installed but also without always on availability / filestream enabled.

    Not yet, believe it or not, I've been working with them for nearly a month to try to figure this out.  Basically, what we found with our servers is that it's fine until it hits max memory or close to it.  When it hits max memory there
    should be the memory cleanup operations that occur, and when they start it just can't clean up the memory.  The memory cleanup operations just keep getting ran over and over which causes the high CPU to sit there even when users aren't on the system. 
    Eventually performance degrades and then eventually the SQL Server service runs out of available memory and the service restarts / crashes.  We (Microsoft) thinks they narrowed it down to 1 thing which is that it's a UserStore_SchemaMgr clerk
    which continues to grow and never shrinks.
    Here are a few things to try first:
    1) Make sure your databases are corruption free (do a DBCC CHECKDB) on all databases and make sure there is no corruption.  If there is then repair it and reboot the server.
    2) Install this hotfix (I'm doing this tonight, so I don't know if this fixes it yet, I have to do this off hours) 
    http://support2.microsoft.com/kb/2904100
    3) If no corruption exists from #1, run this: DBCC MEMORYSTATUS.  (Change the query type to have the results output as text from the top toolbar)  Then do Edit, Find and search for UserStore_SchemaMgr. 
    It's measured in KB, so you have to divide that number by 1024 for MB and 1024/1024 for GB.  In our case we have it going into the GB's.  I have a Windows 2008 R2 SQL Server that this runs at about 8 MB.  On our 2012 server it's running at
    15 GB.
    This is what we're trying to work on now.  If you don't mind, let me know what you find, because I've been spending a ton of time on this with them and I think it's a bug, however we are having a tough time finding it.
    Thanks.

  • Advice  on long running queries

    Hi all
    I am a junior dba and facing problem of log runninig queries. Can anyone help and let me know how to resolve the long running queries. I mean what should be the approach to findout out the problem.
    Please guide me.
    thanx
    Ajay

    >
    OK, so what about your buddy Jonathan Lewis who
    includes THREE hyperlinks in his sig line?
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    Author: Cost Based Oracle: Fundamentals
    http://www.jlcomp.demon.co.uk/cbo_book/ind_book.html
    The Co-operative Oracle Users' FAQ
    http://www.jlcomp.demon.co.uk/faq/ind_faq.html
    Tsk, tsk, the naughty little man is telling lies again.
    There's a search feature on the Oracle forum - it let's you search by user and ask for key words. I've searched against my identify looking for "ind_faq", and then for "cbo_book". It doesn't return any posts with that sig.
    And here's another thought: your comment about me being a buddy of Sybrand (who you were trying to claim did not exist just a few hours ago) reminded me that I have had reasons to criticise him in the recent past - for example Re: to_char and performance - and he managed to take it without descending into a hissy fit.
    And finally - a little logical error on your part. The fact that I know that Sybrand Bakker exists does not mean that he is a buddy of mine or that I am a buddy of his. After all, I know that you exist.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk

  • Multiple running queries at the same time

    Hi!
    I looked around (and RTM) for this but didn't find anything, so I'm asking here.
    I have quite a few long running queries (data loading and such things, warehousing stuff), and I need to be able to run multiple queries/statements at the same time. In TOAD I can do this, start a procedure and while it is running I can do SQL statements in another session tab (it supports threaded sessions - it starts queries in their own background thread/session).
    When I start a long running procedure or query in SQL Developer I can not do anything until the procedure execution finishes. Is there any way (setting/preference) to enable SQL Developer to be able to run multiple queries at the same time?
    I really would like to move away from TOAD, but this is a major showstopper for me.
    Thanx for any tips.
    Alex

    Hi!
    This post is going to be a little longer, but I have to clarify things out.
    I did not mean to throw any wild accusations, because I did my fair share of RTFM and searching the help. I can tell you that if you put any of these in the help search box:
    session
    non shared
    non-shared
    connection
    concurrent <- I guess this one should yeld something
    multiple
    spawn
    you won't find anything usefull, the article that comes closest, is this:
    "Sharing of Connections
    By default, each connection in SQL Developer is shared when possible. For example, if you open a table in the Connections navigator and two SQL Worksheets using the same connection, all three panes use one shared connection to the database. In this example, a commit operation in one SQL Worksheet commits across all three panes. If you want a dedicated session, you must duplicate your connection and give it another name. Sessions are shared by name, not connection information, so this new connection will be kept separate from the original."
    It does not mention any spawning of non-shared connections from the current one, nor it does mention using a accelerator key combo. But since there could be written something about it, I guess you could call it a documentation bug, because it does not provide any clue to this functionality. The help is definitely of no help in this case. As you can see, I do not throw accusations without trying to find out something first. I guess if someone is not as deep into SQL Developer as you are, there is no way for him/her to know this.
    OK, I tried your suggestion, and (sadly) it does not work as I suppose it should.
    Here's what I did:
    - start a new connection, and enter the following code in SQL Worksheet:
    declare
    j number;
    begin
    for i in 1..1000000
    LOOP
    j := sin(i);
    end LOOP;
    end;
    As you can see, it doesn't do much besides holding the connection busy for a while when executed.
    - start a new non-shared connection from the first one using CTRL-SHIFT-N (as you suggested) and put the following statement in the new SQL Worksheet (with "__1" appended to connection name)
    select sysdate from dual;
    - go to the first SQL Worksheet and execute the procedure
    - while the procedure is executing, go to the second SQL Worksheet and hit F9.
    The sysdate is returned as soon as the first SQL Worksheet finishes and not any sooner. It may run in separate session, but the result is not returned before the other session is finished doing what it is doing. I guess the correct behaviour would be to return the sysdate immediately.
    I verified this behaviour repeating it 3 times starting with a new instance of SQL Developer, each time connecting to another schema and spawning the new non-shared session. The database used was Oracle 10.2.0.3 EE on RHEL 4 UPD3.
    The concurrent execution lacks concurrency. The statements might be executed concurently on the database (i did not went the extra mile to verfiy this), but the returning of results is just not independent of other sessions. To the end user this is as much concurrent as it is serial execution.
    I hope developers get this issue straightened out soon, as I said, I'd love to move away from Toad, but I'll have to wait until they fix this out.
    Is there anything else that can be done to make it behave correctly?
    Kind regards
    Alex

  • Running out of cursors, memory and performance

    1. using xsql servlet .9.9.1 command-line with a query that involves cursor expressions, grouping and a join, i run into the following error:
    <ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00604: error occurred at recursive SQL level 1
    ORA-01000: maximum open cursors exceeded
    </ERROR>
    using a quick program with OracleXMLQuery from XSU 1.2, i get the same error with the same query.
    the database i'm testing is supposed to return 1 million+ rows; only 300 or so can be returned if i specify maxrows to be 300. anything beyond that gives me the cursor error.
    SQL*Plus handles the query just fine.
    2. if i take away the cursor expression in the query, and remove the maxrow spec, i get a java out of memory error.
    3. i can't enhance the performance via using OracleConnection object and wanting to use cursor expressions with XSU at the same time. i get a "protocol error" instead.
    So the questions are:
    1. how can i resolve the cursor issue for the result set size i'm trying to retrieve?
    2. how can i resolve the memory issue for the result set size i'm trying to retrieve? since XSU tries to load the entire result set into memory to build the DOM tree, is it possible to stream it out so that it doesn't have to be capped by memory limitations? if so, do you have sample code i can take a look at?
    3. is it possible to tune the oracle jdbc in conjunction of the use of XSU?
    null

    We are encountering the same problem. We are just inserting via http and no matter how we do things we end up running out of cursors. We are using the production version of the servlet. Have you been able to resolve your problem and do you know if there is a fix. Thanks for any information.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by alfred h:
    1. using xsql servlet .9.9.1 command-line with a query that involves cursor expressions, grouping and a join, i run into the following error:
    <ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00604: error occurred at recursive SQL level 1
    ORA-01000: maximum open cursors exceeded
    </ERROR>
    using a quick program with OracleXMLQuery from XSU 1.2, i get the same error with the same query.
    the database i'm testing is supposed to return 1 million+ rows; only 300 or so can be returned if i specify maxrows to be 300. anything beyond that gives me the cursor error.
    SQL*Plus handles the query just fine.
    2. if i take away the cursor expression in the query, and remove the maxrow spec, i get a java out of memory error.
    3. i can't enhance the performance via using OracleConnection object and wanting to use cursor expressions with XSU at the same time. i get a "protocol error" instead.
    So the questions are:
    1. how can i resolve the cursor issue for the result set size i'm trying to retrieve?
    2. how can i resolve the memory issue for the result set size i'm trying to retrieve? since XSU tries to load the entire result set into memory to build the DOM tree, is it possible to stream it out so that it doesn't have to be capped by memory limitations? if so, do you have sample code i can take a look at?
    3. is it possible to tune the oracle jdbc in conjunction of the use of XSU?
    <HR></BLOCKQUOTE>
    null

  • Help me to fix the error while running DBMaintain Against the Database Schema in ASE.

    Hi All,
    I am trying to install sybase mobiliser platform 5.1 SP 03.I am  referring the following guide
    http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01871.0513/pdf/Mobiliser_Platform_Installation_Guide_5.1…
    Now I have configured the ASE database server with default settings and now it is running fine.
    Now my concerns are as follows:
    1) I have executed the database schema (mobr5): 001_MONEY_drop_and_create_user.DDL with the help of linux command
    isql -Usa -SASE1 -Phello@123 -i/opt/sybase/db/sql/001_MONEY_drop_and_create_user.DDL -o/opt/sybase/ASE-15_0/install/ASE1.log
    How do I check the created database schema and user with default name 'mobr5'?
    2) While running DBMaintain Against the Database Schema, I have followed the steps mentioned in the guide and made the following changes in the file dbmaintain.properties.ase
    database.driverClassName=com.sybase.jdbc4.jdbc.SybDriver
    database.url=jdbc:sybase:Tds:ASE1:5000/mobr5
    database.userName=mobr5
    database.schemaNames=mobr5
    database.password=paybox
    #Must be set if the driver is not packaged inside the scriptarchive or is present on the classpath
    #e.g. /path/to/driver.jar
    #database.driverLocation=/path/to/jconnect.jar
    database.driverLocation=/opt/sybase/db/sql/com.sybase365.mobiliser.vanilla.standalone-5.1.3.RELEASE-scriptarchive-ase.jar
    database.driverLocation=/opt/sybase/db/sql/com.sybase365.mobiliser.vanilla.standalone-5.1.3.RELEASE-scriptarchive-ase-vanilla.jar
    When I execute the script archives ,
    java –jar /opt/sybase/db/sql/com.sybase365.mobiliser.vanilla.standalone-5.1.3.RELEASE-scriptarchive-ase-driverless.jar -c /opt/sybase/db/sql/dbmaintain.properties.ase
    java –jar com.sybase365.mobiliser.vanilla.standalone-5.1.3.RELEASE-scriptarchive-ase-vanilla-driverless.jar -c dbmaintain.properties.ase
    I get the following error:
    So please help me to resolve the issues.

    Hi All,
    Issue is resolved and database has been updated successfully..
    Error was in database .url field of dbmaintain.properties.ase file.
    I have changed the database.url field  from database.url=jdbc:sybase:Tds:ASE1:5000/mobr5
    to  database.url=jdbc:sybase:Tds:<Private IP of Linux instance>:5000/mobr5
    Note:- I am installing mobiliser platform on AWS cloud.So I have made use of Private IP address of AWS Linux instance.

  • How to get the list of long running queries

    hi,
         my requirement is to get the list of long running queries in bi and also what are the steps to reduce running time of quires.
    thanks.

    Hi Venkat,
    The statistics information will give you time the query takes while opening it
    For Eg,with BEx Analyzer,you have an option in Global Settings->Display Statistics.
    If you open a query from backend in Analyzer,and then click "Display Statistics",it will show the amount of time it takes to load it.
    Other than this there might be some tcodes available to read this value.
    Rgds,
    Murali

  • Stored procedure that returns a cursor (result set)

    Hi,
    We have a stored procedure that returns a cursor (result set) but when I compliled it and catalouged (introspected) it in the OBPM I got all the primitive type parameters (either IN or OUT) in the proc call except the cursor type (the result set) which is the out param of the stored proc.
    Any pointers please?
    Thanks

    Result set is of RowType and is not supported as a Stored Procedure as far as I know.
    HTH
    Sharma

  • EA2 : Cursor result support?

    I have been eagerly anticipating the release of 1.5 in the hope that cursor results would have support. I have been scouring the forums and have found mention of them but nowhere is there a definitive explanation of how to view the cursor results. Please bear in mind that we have strict controls over packages and schemas and the creating and compiling of "helper" procedures just to output cursor results is heavily frowned upon. Other than that I am a current PL/SQL Develper and am trying desperately to get off windows and onto Linux completely and your product has given me a glimpse of light at the end of the tunnel. Keep up the awesome work

    Okay guys, looks like we're getting our lines crossed. I am currently using PL/SQL developer and it has a very nice testing interface for procedures which return cursors as their results. You simply execute the procedure and then click on the cursor parameter and it opens up, as a table ( similar to the standard query results view ) and you can scroll through it as you would a normal query result.
    I am using 1.5 Early Adopter 2 (1.5.0.52.03).
    All I wanted to know is if there is/will be similar support for cursors in SQL Developer as there is in PL/SQL Developer, and if there already is ( and I mean built in support, not some workaround ) how to I get it/use it/see it??
    thanks
    Mark
    P.S. Still in awe of this free software...

  • Re: Probelems running queries in SQL Developer

    I used to be able to run queries in SQL developer without any problems but now I get the followin message whenever I try to run a query
    "Could not initialize class oracle.sql.CHAR"
    p.s. I also get this: "oracle.i18n.text.converter.CharacterConverterOGS.getInstance(I)Loracle/i18n/text/converter/CharacterConverter;"
    Edited by: user564155 on Jul 26, 2010 1:49 PM

    Might be corrupt settings; backup/delete the SQL Developer/systemXXX directory in the hidden Application Data under your Windows profile to reset your installation to defaults.
    Else, if you run from \sqldeveloper\bin\sqldeveloper.exe, what output do you get in the opened console when starting up and querying? This could help diagnosing the problem.
    Hope that helps,
    K.

  • Running queries coming from different systems

    Hello All
    I have a scenario,
    We are using BI version 7.0,
    The requirement is to  run queries in BEX analyzer coming from 2 different SaPBW systems.
    For example :
    We have two  BW systems A and B,
    In the First tab  we have query running based on the BW system A and in the second tab query running on Bw system B.
    When we try to run the second query in the second tab the first query vanishes,
    Can anybody help me, is it possible to run the 2 different queries from different systems???
    Regards,
    Ravi

    Hi Ravi,
    Even using RRI you will not be able to combine reports from different systems in single workbook. RRI is generally used for Summery to detail level reporting. In such scenarios from first report you click on particular characteristic and other details related to this characteristics are shown in different report coming from any other source.
    If you want this kind of report to run then either you will have to build a Virtual provider in one of the BI system making source as another system and then create a query and use it in same workbook.
    In this way your report might take some time to execute but you don't need to load all your data from one system to other.
    Regards,
    Durgesh.

  • Problem of using Run-chart in displaying result history of QM

    Hello all,
    I met a problem about the using of Run-chart in displaying result history of QM, normally, when you use this button to do a statistical chart for checking, the data would be displayed in the measure unit of Inspection Lot. What I want to know is whether there is way for me to change the measure unit from Inspection Lot number to another one (eg. batch number).
    Could anyone be appreciated to give me a short reply?
    Thanks & Best regards,
    Benny

    I think this is not possible
    Develop new program
    Use following Function module For Batch
    1.QRKS_CHARACTERISTIC
    Control chart for a characteristic
    2.QRKS_INSPECTION_LOT
    Control chart for a characteristic/inspection lot
    3.QRKS_MASTER_CHAR_MATERIAL
    Control chart for a master inspection characteristic/material
    4.QRKS_MASTER_CHARACTERISTIC
    Control chart for a master inspection characteristic
    5.QRKS_MATERIAL
    Control chart for a characteristic/material
    Regards
    Sanjay

  • Running Queries

    Hello All,
    I am faced with a peculiar situation.
    I am on BOXI3.1 SP2 with Windows Server 200R2 as OS and its  a clustered and distributed environment.
    I have a large number of reports which have multiple queries (which is quite natural).
    So when you open a report to refresh data interactively we generally click on "Run Queries" to refresh the entire report.
    But some of my over zealous users click on the dropdown and refresh only some of the queries and then start complaing that the report is not refreshing properly.
    So we decided to do something that they only see run queries not the individual ones. How can i resolve the situation.
    Earlier i thought I may change something on the XML and the dropdwon won't be visible but then I realised if i do that it will be applicable for all users. So we want it only for a certain group of users.
    Can anybody help ?
    Regards
    Sid

    Hi Sid,
    I don't think there is a way for you to do this in the out of the box product.  I think the easiest thing to do would be to put a big text box on the top of each report that states that the report requires ALL queries to be refreshed in order for it to show the correct data.
    This is really a user education piece and is not something that the security model accounts for.  In order for you to change this behavior based on groups, a right would have to be associated to that behavior and it doesn't appear that one exists at this point.
    Honestly, I think the easiest way to fix this is to have it stated on the report.  The next best way would be to have your users view instances of the document that has refreshed all the queries.  This limits the hits on your database and avoids this confusion.  You could remove the refresh rights for these groups and setup recurring schedules that they can view and work with, but cannot actually refresh the data on.
    I know this probably won't fit your scenario exactly, but just wanted to throw that out there.
    Jb

Maybe you are looking for

  • 64-Bit OS' no longer work on GT780DXR

    Hi there, Hopefully someone can help point me toward what might be going on here; basically the other day when turning my laptop on, it made it to the Windows 7 loading screen (with the rotating coloured balls), before suddenly crashing out and BSOD'

  • Shutter count question

    Does anyone in the forum know how I can determine the shutter count I have logged on my T3i? The camera is still going strong without any problems at all (except for a few dead pixels that appear as tiny red spots in some images). I am mostly just cu

  • IMac CRT Video

    Just wanna know if there is a need for a graphics accelerator or driver for an iMac G3 display. Here are my display properties. ATY,Rage128VR: Chipset Model: ATY,Rage128VR Type: Display Bus: AGP VRAM (Total): 8 MB Vendor: ATI (0x1002) Device ID: 0x52

  • Does anybody know how to make a selection in Photoshop Elements 13 without having the width / height box drag from the cursor?

    I've recently upgraded from Photoshop Elements 10 to Photoshop Elements 13 and the selection tool dragging this little box behind it whenever I make a selection or move a selection is highly irritating. I tried to google for how to not have it shown

  • Why gnome-ppp establish mobile broadband connection,not networkmanager

    I am using usb radio modem AirPlus MCD-650 on my summer cottage and trying to setup internet. I have both Ununtu and Archlinux partitions, but prefer to use Arch, because my computer is too old for heavy Ubuntu OS. There is no problem to connect to i