Query of Query(cursor)
Hi all,
I want to implement something like "query of queries" in Oracle with the help of CURSORS.
Is it possible to use a cursor in the from clause of a query?
Please help me....
Thanking u all in advance...
Regards,
Aswathy.
> But can i know if this can be done with CURSORS.
A cursor is not a data set or result set - it is not a copy of rows (or row identifiers) in memory.
A cursor is (SQL) program parsed & compiled into an execution plan. This contains the instructions to fetch the applicable rows.
A FETCH from a cursor is an instruction to Oracle to execute that SQL program to return the next rows (or rows in the case of a bulk fetch).
It seems to me that you are thinking of row-by-row processing - which is why you want a query of a query and use a cursor for that.
Row-by-row processing is also aptly named slow-by-slow processing.
The correct approach is to think data sets. And write queries to deal with data sets. And yes, you can create a data set using SQL and re-use it with the WITH syntax.
For example (and a very poor example as analytical SQL should be used instead, but the intention is simply to show you how the WITH syntax works):
with MY_DATA_SET as(
select
col1,
col2,
col3
from table1
where <some conditions & filters>
select
'MAX C1' as NAME,
max(col1)
from my_data_set
union all
select
'MAX C2' as NAME,
max(col2)
from my_data_set
union all
select
'C1=C2' as NAME,
count(*)
from my_data_set
where c1 = c2
<etc>
You can create multiple "data sets" like this and join them, further refine them, etc. Just remember to aim to write minimal SQL code... the less code there is, the less complexity, the less work to do (usually) and the better the likelihood of good performance and scalability.
Similar Messages
-
Hi all,
I am trying see if we can use LINQ like functionality to query a ref cursor resultset. I have about 50 procedures( as part of 12 packages) which send the ref cursor output to a front end application when called individually. Now I need to create a procedure to get only specified records from each of these 50 ref cursors and output it to another ref curosr.
In other words how can I use the following
select col_2 from pkg_abc.pro_ref_cursor_out(arg1, arg2...) where col_1 = 'X':I am not inclined to use a fetch as I foresee performance issues?
Thanks@ Tubby. Here is what I am looking to do. Let us say I have two packages as below each with one ref cursor. In reality there are about 15 packages and 50 procedures and hence 50 ref cursors.
CREATE OR REPLACE PACKAGE pkg_1
IS
TYPE resultset_typ IS REF CURSOR;
PROCEDURE pro_1 (
i_region IN VARCHAR2,
o_resultset OUT resultset_typ, -- 'recordset' output
END pkg_1;
CREATE OR REPLACE PACKAGE BODY pkg_1
IS
PROCEDURE pro_1 (
i_region IN VARCHAR2,
o_resultset OUT resultset_typ,
IS
BEGIN
OPEN o_resultset FOR
SELECT 'employees' AS person_type, employee_name FROM tbl_employees WHERE region = i_region;
END;
END pro_1;
END pkg_1;
CREATE OR REPLACE PACKAGE pkg_2
IS
TYPE resultset_typ IS REF CURSOR;
PROCEDURE pro_2 (
i_region IN VARCHAR2,
o_resultset OUT resultset_typ, -- 'recordset' output
END pkg_2;
CREATE OR REPLACE PACKAGE BODY pkg_2
IS
PROCEDURE pro_2 (
i_region IN VARCHAR2,
o_resultset OUT resultset_typ,
IS
BEGIN
OPEN o_resultset FOR
SELECT 'customers' AS person_type, customer_name FROM tbl_customers WHERE region = i_region;
END;
END pro_2;
END pkg_2;Currenlty the front end app calls these packages individually when required. But I want to create an additional package as follows so that I dont have to write the underlying queries again.
CREATE OR REPLACE PACKAGE pkg_3
IS
TYPE resultset_typ IS REF CURSOR;
PROCEDURE pro_3 (
i_region IN VARCHAR2,
i_name IN VARCHAR2,
o_resultset OUT resultset_typ, -- 'recordset' output
END pkg_3;
CREATE OR REPLACE PACKAGE BODY pkg_3
IS
PROCEDURE pro_3 (
i_region IN VARCHAR2,
i_name IN VARCHAR2,
o_resultset OUT resultset_typ,
IS
BEGIN
OPEN o_resultset FOR
SELECT * FROM pkg_1.pro_1(i_region) WHERE employee_name = i_name
UNION ALL
SELECT * FROM pkg_2.pro_2(i_region) WHERE customer_name = i_name
END;
END pro_3;
END pkg_3; -
[Help] statement.executeQuery(query) opens MULTIPLE cursors
Hey everyone,
I'm having a real hard time finding anything about this on the net so I've turned here. When we call:
resultSet = statement.executeQuery(query)
from a servlet for some reason that one executeQuery opens anywhere from 9-12 cursors in our oracle DB. All the executeQuery documentation I could find just said it should open 1 cursor for that particular ResultSet. query is a fairly simple SQL statement, it searches multiple tables but that doesn't explain why it should open so many cursors.
On a side note the resultSet and statement are global to the method and are closed in the finally block, no SQLExceptions are thrown further adding to my confusion.
If anyone has seen something like this where executing 1 query opens multiple cursors please let me know any information you might have.
Thanks in advance
-DaveHi Dave
I had a similar problem using the Oracle 8i, but my query was a more complicated than yours and opened a lot of cursors.
The answer is to close every ResultSet and the Statement:
while (xxResult.next()){ ... }
xxResult.close();
xxResult.getStatement().close();
This worked for me,
Good luck,
Daniel. -
Link Query and Ref Cursor Query
Hi all!!
How can I link Query and Ref Cursor Query??
I mean, How can I pass input parameters to the PL/SQL procedure if they are not User parameters but they come from another table??
Thanks a lot
F.I have searched the forum and this is the closest to my problem.
Just started using ref cursors in my reports.
The problem I am running into is that I have two ref cursor queries in my report - they each contain a column named seq_no which forms a join (in the database) .
My report returns the correct number of records in each query, but I can't find a way to enforce the join. I've tried all the methods I can think of including combining the results into one query.
The IDE won't let me join on a column and when I join on the group (which I make only contain the seq_no fields) that join is ignored.
Can anyone help me on this? -
Want to edit existing query in query designer..
hi friends..
i have created the new query in query designer...
after opening that new query using query designer , i have a list of default values right hand side and then am placing the cursor on one default value which i have created now , at right most side we have general , display , hierarchy , planning , advance tabs
in the hierarchy tab i have an option called values of poseted nodes...what does it mean? except my newly created deafult value..all other fileds are checked with option called Values of posted node -->always show
for my newly created deafult value is having like " values of posted nodes --> can not determine defalut value
so now i want to change the above option to -->always show...but the hierarchy tab is totally disabled how can i enabled that tab? and change?
please help me...
thanks in aadvance..
regards
anandHi,
We are faced same problem that time we raised the sap note they provided below programme
ANALYZE_RSZ_TABLES once we run this programme after that we find some error.
Please check using this programme.
Thanks and Regards,
Venkat. -
Error while accessing Query using Query Analyzer
dear experts...
while accesiing the query using query analayzer...
we are getting below error...
What has happened?
URL http://xxx.xxx.xxx.xx:XXXX/irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2fcom.sap.pct!2fplatform_add_ons!2fcom.sap.ip.bi!2fiViews!2fcom.sap.ip.bi.bex call was terminated because the corresponding service is not available.
Note
The termination occurred in system BI1 with error code 404 and for the reason Not found.
The selected virtual host was 0 .
What can I do?
Please select a valid URL.
If you do not yet have a user ID, contact your system administrator.
ErrorCode:ICF-NF-http-c:001-u:ANAND-l:E-i:PSRCCPRDA003_BI1_00-v:0-s:404-r:Notfound
HTTP 404 - Not found
Your SAP Internet Communication Framework Team
thanks for helping me...
anandHi friends,,
instead of getting the link like
http://128.222.125.57:9000/sap/bw/bex?cmd=ldoc&infocube=ZMC_SRH1&query=AGINGV21A&sap-language=EN(working link)
am getting below link...which is getting an error....
http://128.222.125.57:9000/sap/bw/://:/irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2fcom.sap.pct!2fplatform_add_ons!2fcom.sap.ip.bi!2fiViews!2fcom.sap.ip.bi.bex?QUERY=AGINGV21A
above marked is the unwanted thing so how can i change my link in query designer???
please suggest me firneds -
Unable to create new query using query manager
Hi friends,
I have been trying to create a query using query manager for couple of hours but still not able to.I am following the instructions given in oracle Peopletools 8.52 : Peoplesoft query
Chapter - creating new queries.
Below are the steps I am going through to create new query:
Step - I open the component Reporting Tools-> Query->Query Manager , I don't get the tabbed pages one for search an existing query and another for create new query.
Please follow this link to see how the page is displayed in first step:
http://uploadpic.org/v.php?img=EvMvVAXX1E
Step 2 - When I click on create new query link, I am redirected to a page where it asks for record name to add in the query. But, even this page is not displayed as how it supposed to be
http://uploadpic.org/v.php?img=GzHh3f6krU
Step 3 - Following the above step, when I click on Person record to add into my query I am asked to select the fields that I want to display in the output.
But I somehow do not get the proper tabbed pages where individual pages are there to add the attributes to complete the query like adding multiple records, fields, query, expressions, prompt...etc
http://uploadpic.org/v.php?img=Wbbla3Q3jE
I am neither able to select multiple records in my query nor able to customize my query to get the desired results.
Below is the query that I want to create using query manager:
SELECT P.EMPLID,P.BIRTHDATE, N.NAME, A.ADDRESS1, A.ADDRESS2, A.CITY
FROM PS_PERSON P, PS_NAMES N, PS_ADDRESSES A
WHERE P.EMPLID = N.EMPLID AND
N.EMPLID = A.EMPLID AND
P.BIRTHDATE BETWEEN to_date('1990/1/1','yyyy/mm/dd') and to_date('1991/1/1','yyyy/mm/dd');Hi,
As I cannot access your screenshot by the blocking of company firewall rules.
I'm guessing currently you are using PT 8.52.00 version, correct?
This should be a bug, that you need to apply the 8.52.0X patch, not sure which patch fix this, you can apply the latest one to solve this issue for no tab page of query manager. (PT 8.52.06)
Hope this helps.
Thanks,
Saxon SI -
Using NVL in Query of Query resulting in error
I'm still using CF8 and Oracle 11G back-end.
When I use NVL in the query of query I got error....Can't I use NVL to check on null value? Please help
Here is my codes:
<cfquery name="GetC2" datasource="#Trim(application.OracDSN)#">
SELECT CamID2, rel2_2,p_ln2,p_fn2,ins,l_year
FROM prt_temp
WHERE Ins = 'CC'
AND l_year = '1481'
AND NVL(Child_LN2,' ') <> ' '
AND NVL(Child_FN2,' ') <> ' '
</cfquery>
<cfif GetC2.Recordcount NEQ 0>
<cfquery name="CheckRel2C2" dbtype="QUERY">
SELECT CamID2, rel2_2
FROM GetC2
WHERE NVL(Rel2_2,' ') <> ' '
AND NVL(p_ln2,' ') = ' '
AND NVL(p_fn2,' ') = ' '
AND Ins = 'CC'
AND l_year = '1481'
</cfquery>
</cfif>
The error:
Error Executing Database Query.
Query Of Queries syntax error.
Encountered "NVL ( Rel2_2 ,. Incorrect conditional expression, Expected one of [like|null|between|in|comparison] condition,NVL is an Oracle function, and is not available in ColdFusion Query of Query. If you are trying to check for null values, then use IS NULL or IS NOT NULL. So
WHERE NVL(Rel2_2,' ') <> ' '
AND NVL(p_ln2,' ') = ' '
AND NVL(p_fn2,' ') = ' '
becomes
WHERE Rel2_2 IS NOT NULL
AND p_ln2 IS NULL
AND p_fn2 IS NULL
-Carl V. -
I'm creating an image gallery. My database has about 1000
records with 10 column.
Now I'm realising there's a lot of trips to the database.
Would it be better that when I init my app I store the "get all"
query and query that from that point? Or is the difference in
performance of querying a query as a oppose to a database not worth
it?
If you say I should query the query, how many records would
be too much to hold in memory.
Thanksquote:
Originally posted by:
dandev
I'm creating an image gallery. My database has about 1000
records with 10 column.
Now I'm realising there's a lot of trips to the database.
Would it be better that when I init my app I store the "get all"
query and query that from that point? Or is the difference in
performance of querying a query as a oppose to a database not worth
it?
If you say I should query the query, how many records would
be too much to hold in memory.
Thanks
It would be better to just select the records you need. -
How to extract the Physical Query(database Query)
Hi ,
How to extract the Physical Query(database Query) from obiee which was fired in obiee
Regards
RangaHi Ranganath,
Have a look the following links.
Setting Logging level:
http://gerardnico.com/wiki/dat/obiee/loglevel
How to see physical query:
http://gerardnico.com/wiki/dat/obiee/manage_session_log
If you are new to OBIEE, spend some hours on the following blog to learn from basics to advanced level.
http://gerardnico.com/wiki/
http://obiee101.blogspot.com/
http://www.rittmanmead.com/blog/
Hope it helps you.
Regards,
Kalyan Chukkapalli
http://123obi.com -
Hey All
How I can run query from Query Manager from addon level?
regards
Krzysztof SalaHi Krzysztof,
There is no object in the SDK to access and execute the queries programmatically so you have to use the UI to simulate the user opening and selecting the query (ie activate the menu object for the query you want to run, populate any parameters then click on the OK button to execute the query). It's a bit of a messy solution but it can work ok.
The alternative is to execute your query from within your add-on and display the results in a new form. This form can just have a matrix and an OK button so it's very easy to create (via Screenpainter or at runtime).
Hope this helps,
Owen -
Please suggest a select query / sub query with out using any subprograms or
source table: Three columns ORIGIN, DESTINATION,MILES
Origin Destination Miles
Sydney Melbourne 1000
Perth Adelaide 3000
Canberra Melbounre 700
Melbourne Sydney 1000
Brisbane Sydney 1000
Perth Darwin 4000
Sydney Brisbane 1000
out put :Three columns ORIGIN, DESTINATION,MILES
Duplicate routes are to be ignored so the output is
Origin Destination Miles
Sydney Melbourne 1000
Perth Adelaide 3000
Canberra Melbounre 700
Brisbane Sydney 1000
Perth Darwin 4000
Please suggest a select query / sub query with out using any subprograms or functions/pkgs to get the out put table.Hi,
user9368047 wrote:
... Please suggest a select query / sub query with out using any subprograms or functions/pkgs to get the out put table.Why? If the most efficient way to get the results you want involves using a function, why wouldn't you use it?
Here's one way, without any functions:
SELECT a.*
FROM source_table a
LEFT OUTER JOIN source_table b ON a.origin = b.destination
AND a.destination = b.origin
AND a.miles = b.miles
WHERE b.origin > a.origin -- Not b.origin > b.origin
OR b.origin IS NULL
;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test this.
Edited by: Frank Kulash on Nov 6, 2012 7:39 PM
Corrected WHERE clause after MLVrown (below) -
What is wrong with this query of query... Basically it seems like the "IF" logic in the select statement isn't looking at the current results, but instead the first line of the AllCategories() query. Any ideas would be much appreciated.
<cffunction name="getCategoryDetail" returntype="query" >
<cfargument name="CategoryID" default="">
<cfset AllCategories = Application.Celerant.QueriesCached.getAllCategories()>
<cfquery name="CategoryDetail" dbtype="query" >
SELECT
<cfif AllCategories.typ eq 'EMPTY'>
'DEPT' as ThisLevel,
AllCategories.Dept as ThisName
<cfelseif AllCategories.subtyp_1 eq 'EMPTY'>
'TYP' as ThisLevel,
AllCategories.typ as ThisName
<cfelseif AllCategories.subtyp_2 eq 'EMPTY'>
'SUBTYP_1' as ThisLevel,
AllCategories.subtyp_1 as ThisName
<cfelseif AllCategories.subtyp_3 eq 'EMPTY'>
'SUBTYP_2' as ThisLevel,
AllCategories.subtyp_1 as ThisName
<cfelse>
'SUBTYP_3' as ThisLevel,
AllCategories.subtyp_1 as ThisName
</cfif>
FROM
AllCategories
WHERE
AllCategories.web_taxonomy_id = #arguments.CategoryID#
</cfquery>
<cfreturn CategoryDetail>
</cffunction>Basically it
seems like the "IF" logic in the select statement isn't
looking at the current results, but instead the first line
of the AllCategories() query.
That is exactly what is happening. The IF is not evaluated within the QoQ. It is evaluated once, before the QoQ executes, using the values in the first record of the query.
QoQ are very limited. AFAIK they and do not support that kind of logic. So you must loop through the query, one row at a time, and calculate the desired values. -
Query of query with left outer join
Hi,
I cannot use joins in query of query, I try the old method using the ( + ) but no luck "Query Of Queries syntax error. Encountered ( + )."
Here is an example of my query code:
select p.part_id, s.supplier_name, s.second_name
from part p, supplier s
where p.supplier_id = s.supplier_id ( + )
and p.second_id = s.second_id ( + );
PART SUPPLIER_NAME SECOND_NAME
P1 Supplier#1 A
P2 Supplier#2
P3
P4
How can I do the same in query of query syntax?
Thanks!I found a solution:
http://www.bealearts.co.uk/blog/2007/06/20/how-to-do-an-outer-join-in-query-of-queries/
I am not sure about my second condition. i create the join query for the empty columns.
select part.part_id, supplier.supplier_name, supplier.second_name
from part, supplier
where part.supplier_id = supplier.supplier_id
and supplier.second_id is null
union
select part.part_id, supplier.supplier_name, supplier.second_name
from part, supplier
where part.supplier_id = supplier.supplier_id
and part.second_id = supplier.second_id
union
select part.part_id, joinQuery.supplier_name, joinQuery.second_name
from part, joinQuery
where part.supplier_id not in (#ValueList(supplier.supplier_id)#)
Can anyone check and let me know if this is correct?
My final result have one less row from parts table.
Thanks -
How to implement enter-query , execute-query in Apex Forms
Hi,
I am new to Oracle Application Express. I want to know what is the equivalent of ENTER-QUERY and EXECUTE-QUERY features of Oracle Forms in Oracle APEX? I saw a lot of documentation, but everywhere I found that APEX forms only have 3 database actions, (1) INSERT (2) UPDATE & (3) DELETE.
Does anybody know how we can do QUERY in APEX Forms? (like we do in Oracle Developer Forms).
Thanks in advance.Oracle APEX is a web/ stateless environment. So you do not have the same functionality/ features as in a Oracle Forms environment which is session/state oriented.
You can however achieve functionality similar to Enter Query / Execute Query through other means.
The easiest is to use the Forms with Report wizard. It creates 2 pages, the first one is a report and the other a Form. Clicking on the Report rows takes you to the Form page in Edit mode where as the the Create button takes you to the Form in Insert mode.
If you want to have the enter-query / execute query on a single page it will require significant effort and skills. Try it when you have acquired some more skills in Apex.
In APEX , like any other web application, you have to think in the web paradigm and not client-server. Even Forms 11g is essentially client-server like and is session oriented through the forms applet.
Regards, -
Query or query view in webtemplate
Hi guys,
I am working with one webtemplate and related queries/query views.we have different strategy for changing if its query or queryview thats been used in template.
1.How can I find if its Queries or Queryviews that been used for my dataproviders in my webtemplate?I am working with WAD3.5
2.Whats the difference between a query and a query view?what difference does it make if we use query or queryview while building and using a webtemplate?
Thanks alot.
P Olinhi
you should first understand that Query view is nothing but a modified view of the Query. You run a query, do some filtering, navigation or do some changes to the look and then save it as a query view. so the answers would be
1. You open the data provider at the bottom of your webtemplate and there you can see if the data provider is a Query or a view (from the radio buttons)
2. it makes no difference whether u use a Query or query view in a web template. It is up to you to decide in what format you want to see the web report. If you want the web report to display the report in the format of the Query, then you would use Query as data provider. If you have to show the web report in the format of the Query view, then you would use Query view as the data provider.
thanks
Maybe you are looking for
-
Error in migration of portal ..while importing
hi all, iam trying to migrate portal 3.0.9.8.0 from a 9.0.1.2 database to another 9.0.1.2 database. i have exported all the required users successfully. then i created the required tables spaces and users in the target database. while importing users
-
I have a makbook pro, running with Leopard (10.5.8). I know that I missed both Lion and Snow Leopard and want to know the best way to upgrade. Do I need to buy both in addition to Mountain Lion? Will my computer even run Mountain Lion? I need ste
-
Where do I purchase single user copy of Intel build Mac OS X Tiger?
Hi, I am planning to reinstall my intel Macbook pro, and I bought a copy of Mac OS X tiger from campus store today. I did not mention that I have needed an intel build, thought Apple would put intel and powerpc build together. Obviously I was wrong.
-
Routines for table 56 and D1555
Dear All, We are in implementation of IS-Oil-Downstream. Need your help on the follwoing items. 1.0 There are couple of products whcih are subjected to aromatic conversion. e.g. Benzene. for thsi product we use the Table D1555 for correcting the v
-
Why is it difficult to install new fonts ?
I have been trying to install several different fonts for various applications. Upon doing some redearch there seemed to be an issue because I was trying to install .ttf files after being unzipped. Now a little further down the track I have discover