Cursor result count
Hi,
I've a staging table with one column
result_id :100,101,102 etc
I need to query another table say stage2 which consists of many columns including result_id
so If I found result id in stage 2 then I want to update that table flag enable_flag=y and give a count in a log file say : no of records updated
If I won't find id in table2 , I've to move on with other ids by putting a message in a log file says :'This id has no value in stage2'
and provide count :no of ids don't have any value:
Any simple and efficent way of doing this ?
Thanks,
Kiran
>
say in stage1 If I've an id 191 which is not there in stage 2 Then I need to put that in logifile
>
Are you saying that if IDs 191, 192 and 193 are not in the stage 2 table you need to log a separate count for each ID?
If so then you should add a query to Solomon's code that executes before the UPDATE statement.
The query would get IDs from STAGE1 and a count of the number of those IDs that are in STAGE2. You would use these results to do the logging that you want to do. Then you would do the update shown in Solomon's code.
SELECT S1.RESULT_ID, COUNT(S1.RESULT_ID) ID_COUNT
FROM STAGE1 S1, STAGE2 S2
WHERE S1.RESULT_ID (+) = S2.RESULT_ID
GROUP BY S1.RESULT_IDThe result set records with a count of zero are the IDs that are not in the STAGE2 table. The other records have the count of how many records will get updated.
You can use the above query as a cursor to do logging.
Similar Messages
-
How to get total number of result count for particular key on cluster
Hi-
My application requirement is client side require only limited number of data for 'Search Key' form total records found in cluster. Also i need 'total number of result count' for that key present on the custer.
To get subset of record i'm using IndexAwarefilter and returning only limited set each individual node. though i get total number of records present on the individual node, it is not possible to return this count to client form IndexAwarefilter (filter return only Binary set).
Is there anyway i can get this number (total result size) on client side without returning whole chunk of data?
Thanks in advance.
Prashantuser11100190 wrote:
Hi,
Thanks for suggesting a soultion, it works well.
But apart from the count (cardinality), the client also expects the actual results. In this case, it seems that the filter will be executed twice (once for counting, then once again for generating actual resultset)
Actually, we need to perform the paging. In order to achieve paging in efficient manner we need that filter returns only the PAGESIZE records and it also returns the total 'count' that meets the criteria.
If you want to do paging, you can use the LimitFilter class.
If you want to have paging AND total number of results, then at the moment you have to use two passes if you want to use out-of-the-box features because LimitFilter does not return the total number of results (which by the way may change between two page retrieval).
What we currently do is, the filter puts the total count in a static variable and but returns only the first N records. The aggregator then clubs these info into a single list and returns to the client. (The List returned by aggregator contains a special entry representing the count).
This is not really a good idea because if you have more than one user doing this operation then you will have problems storing more than one values in a single static variable and you used a cache service with a thread-pool (thread-count set to larger than one).
We assume that the aggregator will execute immediately after the filter on the same node, this way aggregator will always read the count set by the filter.
You can't assume this if you have multiple client threads doing the same kind of filtering operation and you have a thread-pool configured for the cache service.
Please tell us if our approach will always work, and whether it will be efficient as compared to using Count class which requires executing filter twice.
No it won't if you used a thread-pool. Also, it might happen that Coherence will execute the filtering and the aggregation from the same client thread multiple times on the same node if some partitions were newly moved to the node which already executed the filtering+aggregation once. I don't know anything which would even prevent this being executed on a separate thread concurrently.
The following solution may be working, but I can't fully recommend it as it may leak memory depending on how exactly the filtering and aggregation is implemented (if it is possible that a filtering pass is done but the corresponding aggregation is not executed on the node because of some partitions moved away).
At sending the cache.aggregate(Filter, EntryAggregator) call you should specify a unique key for each such filtering operation to both the filter and the aggregator.
On the storage node you should have a static HashMap.
The filter should do the following two steps while being synchronized on the HashMap.
1. Ensure that a ConcurrentLinkedQueue object exists in a HashMap keyed by that unique key, and
2. Enqueue the total number count you want to pass to the aggregator into that queue.
The parallel aggregator should do the following two steps while being synchronized on the HashMap.
1. Dequeue a single element from the queue, and return it as a partial total count.
2. If the queue is now empty, then remove it from the HashMap.
The parallel aggregator should return the popped number as a partial total count as part of the partial result.
The client side of the parallel aware aggregator should sum the total counts in the partial result.
Since the enqueueing and dequeueing may be interleaved from multiple threads, it may be possible that the partial total count returned in a result does not correspond to the data in the partial result, so you should not base anything on that assumption.
Once again, that approach may leak memory based on how Coherence is internally implemented, so I can't recommend this approach but it may work.
Another thought is that since returning entire cached values from an aggregation is more expensive than filtering (you have to deserialize and reserialize objects), you may still be better off by running a separate count and filter pass from the client, since for that you may not need to deserialize entries at all, so the cost on the server may be lower.
Best regards,
Robert -
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?
ThanksResult 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... -
How to get Result Count Content By Search Webpart (ContentBySearchWebPart)?
I'm writing a webpart that extends the out of the box ContentBySearchWebPart.
Does any one know how to get the search result count from this webpart?
I did not find any property?Hi
Thanks but you are referring to the "Search Webpart". I am referring to the "Content Search" or often called "Content by Search" which is different. It's the one under Content Rollup.
Although very similar they're not - Content Search WP doesn't have that property.
What I am really after is to hide the whole webpart if there are no results coming back. I tried to figure it out and even write a jQuery that would search for the text "There are no results" message which comes from the webpart when result count=0
and hide the parent webpart that way. There will be a short flash once the page loads rendering the webpart for a split second and then disappear by jQuery - which is not great UI experience.
There is this property: "ShouldHideControlWhenEmpty" but it doesn't do anything when there are no results. The webpart is still visible. Webpart has a the Title and the Border around it so when there are no results the title and the border show
up with no results. Like I said I want to hide the whole thing in that case.
So I thought I could extend the OOTB ContentBySearchWebPart and get a hold of some kind property that would get me the result count. If the results count is 0 simply I would hide the webpart server side.
Thoughts? -
How to determine the cursor record count before the "open cursor"?
Is it possible to determine the record count of an explicit cursor without running a count()? Say, my cursor definition is something like this,
CURSOR cur_vehicle
IS
SELECT os.order_id, os.order_item, vs.part_id
vs.part_num,
vs.iso_num,
vs.model_yr
vs.dealer_cde,
vs.cust_cde,
px.plant_cd
FROM parts_source vs,
orders_source os,
plant_tbl_crossref px
wHERE os.order_id = vs.order_id
AND vs.part_id = os.part_id
AND vs.plant_cde = px.plant_cde
ORDER BY os.order_id;
I want to log the count of records returned by the above cursor prior to the first fetch, without running a count(1) for the query in cursor select.
I know adding " Count(1) over(order by null) " in the cursor SELECT will bring it. But that does not help me log the record count to some log file or table before opening the cursor for processing.
To conclude, my objective is to update the record count of cursor in some table before processingsarvan wrote:
Is it possible to determine the record count of an explicit cursor without running a count()?
..snipped..No. The only way to do it correctly is inside that select.
Each select is a consistent read. Which means that if this is done as 2 select statements, the 1st select can see a different version of the data than the 2nd select statement. does. So if you want a count and that to be consistent and on the same version of the data than the select, it has to be done as part of the select.
Also consider what a cursor is. It is not a result set of sorts that is created in memory upfront - with a convenient interface that tells you the size/number of rows of that result set.
A cursor is basically a program that reads database data as input and produce output. A fetch from a cursor is an instruction for this program to execute and output data.
There's no data set that is created by the cursor from which the count can be determined. The cursor program does have state variables - like +%RowCount+ that specifies how many rows the cursor has thus far output. And you need to run that cursor to the end (no more output) in order to determine the total number of rows output by the cursor. -
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. -
Restricting on a cursor result
Task:
1. I would like to make reports for a system.
2. I want to make the reports with an out sys_refcursor
3. I want to pass in some cursor with ids, to restrict report.
So here's the code I got so far:
procedure customer_status_distribution(c_universe sys_refcursor,
t_result out sys_refcursor) is
v_table_of_number table_of_number;
begin
fetch c_universe bulk collect
into v_table_of_number;
open t_result for with a as(
select column_value column_value
from table(cast(v_table_of_number as table_of_number)))
select t.alder, count(*)
from customer_aggregation t
where customer_id in(select column_value from a)
group by t.alder;
end;
c_universe is containing just numbers of course.
The problem with this is that it doesn't use the index on customer_aggregation.customer_id column.
I can add /*+RULE*/ and it uses the index, but I do not want that, since the actual reports are quite more complex, and will use different technuiqes for optimizing.
exists() clause does not use index.
/*+ index(customer_aggregation name_of_index)*/ doesn't do it.
Am I going about this the wrong way? Any ideas?Following code:
fetch c_universe bulk collect
into v_table_of_number;
open t_result for
select t.alder, count(*)
from customer_aggregation t
where exists(select * from table(cast(v_table_of_number as table_of_number)) where column_value = t.customer_id)
group by t.alder;
gives:
SELECT STATEMENT 12176732
SORT GROUP BY 12176732 1 9
NESTED LOOPS SEMI 12176729 1 9
TABLE ACCESS FULL -> CUSTOMER_AGGREGATION 1457 1521909 13697181
COLLECTION ITERATOR PICKLER FETCH
Rewrite using in:
fetch c_universe bulk collect
into v_table_of_number;
open t_result for
select t.alder, count(*)
from customer_aggregation t
where t.customer_id in(select column_value from table(cast(v_table_of_number as table_of_number)))
group by t.alder;
gives:
SELECT STATEMENT 12176732
SORT GROUP BY 12176732 1 9
NESTED LOOPS SEMI 12176729 1 9
TABLE ACCESS FULL -> CUSTOMER_AGGREGATION 1457 1521909 13697181
COLLECTION ITERATOR PICKLER FETCH
Rewrite to use hints and "in":
fetch c_universe bulk collect
into v_table_of_number;
open t_result for
select /*+index(t PK_AGGR_CUSTOMER_ID)*/ t.alder, count(*)
from customer_aggregation t
where t.customer_id in(select column_value from table(cast(v_table_of_number as table_of_number)))
group by t.alder;
end;
gives:
SELECT STATEMENT 12211234
SORT GROUP BY 12211234 1 9
NESTED LOOPS SEMI 12211231 1 9
TABLE ACCESS BY INDEX ROWID -> CUSTOMER_AGGREGATION 35959 1521909 13697181
INDEX FULL SCAN -> PK_AGGR_CUSTOMER_ID 11354 1521909
COLLECTION ITERATOR PICKLER FETCH
Rewrite using index hint and "exists":
fetch c_universe bulk collect
into v_table_of_number;
open t_result for
select /*+index(t PK_AGGR_CUSTOMER_ID)*/ t.alder, count(*)
from customer_aggregation t
where exists(select column_value from table(cast(v_table_of_number as table_of_number)) where column_value = t.customer_id)
group by t.alder;
gives:
SELECT STATEMENT 12211234
SORT GROUP BY 12211234 1 9
NESTED LOOPS SEMI 12211231 1 9
TABLE ACCESS BY INDEX ROWID -> CUSTOMER_AGGREGATION 35959 1521909 13697181
INDEX FULL SCAN -> PK_AGGR_CUSTOMER_ID 11354 1521909
COLLECTION ITERATOR PICKLER FETCH
Finally, what I want is (explain plan wise):
the code posted using a tmp_numbers table:
which gives:
SELECT STATEMENT 10
SORT GROUP BY 10 1 22
TABLE ACCESS BY INDEX ROWID -> CUSTOMER_AGGREGATION 3 1 9
NESTED LOOPS 8 1 22
SORT UNIQUE
TABLE ACCESS FULL -> TMP_NUMBERS 2 1 13
INDEX RANGE SCAN -> PK_AGGR_CUSTOMER_ID (1) 2 1
Suggestions? -
Is it possible to ref cursor(result set) as in parameter to procedure/funct
Hi,
I am getting a resultset/ref cursor from the Java side to the procedure/function as in parameter. Is this possible in oracle 10g.
If yes can body send the links/suggestions describing some examples.
Thanks,I am getting a resultset/ref cursor from the Java
side to the procedure/function as in parameter. Is
this possible in oracle 10g. It is possible, but it sounds like you have your application design entirely backwards.
A ref cursor is designed to be used to pass a result set from a stored procedure to a client or calling application.
So while you could use a screwdriver to hammer in a nail, you probably would not want to. -
Total Results Count in search results page
Hi,
I am working on a website.If we search for a particular object in search box(like:pen,pencil,box).It should give me the total count of those particular object
with its details .
I tried in several ways to get the total count,but it displaying only the total of the display range items.
Thanks,turns out that the LiveLink Security Trimmer was causing this issue. It comes along the installation of OpenText AGA for SharePoint. As we don't crawl any LiveLink sources, we got rid of it, restarted the Search Host Controller and it works fine now.
Diary of a SharePoint Consultant
MCT, MCPD SharePoint 2010 -
Why use exchange ews api "GetRoomLists" result count zero
In this feature . i must get the room list.
I have two questions:
first one :
this is my c# code.
static ExchangeService service = Service.ConnectToService(UserDataFromConsole.GetUserData(), new TraceListener());
var zz = service.GetRoomLists();
validation code use microsoft's example <Exchange 2013 101 Code Samples>
But the zz item count is zero..
I'm sure that my office 365 have three rooms and the outlook client can use those room item to create the meeting..
second :
i want get some room's meeting .
who to do that?
Ths....The AddressList's you see in the GAL in Outlook or OWA aren't the same thing as RoomList's these need to be created as there are none by default. To create a roomlist you need to use the Exchange Management Shell New-DistributionList cmdlet and the -RoomList
switch eg
http://blogs.technet.com/b/educloud/archive/2011/11/07/get-a-room-enable-room-finder-with-room-list-distribution-groups.aspx
Cheers
Glen -
Newbie Q: Limiting the result count
Hi,
I wanted to know if there is any other way to limit the result set other than using this:
SELECT * FROM (select display_url, rownum as r from table_name) where r <= 10;
Its a times like these that mysql looks so easy to use with its LIMIT feature.
thanksHi,
SELECT display_url
FROM table_name
SAMPLE (5);will returns about 5% of the rows you would get without the SAMPLE clause. Don't expect exactly 5%.
Unlike the ROWNUM technique, this will produce a random sampling.
For details, see the [SQL Language Reference man ual|http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_10002.htm#sthref9780]. -
Stop Query if it does not match with Condtions & Control the result count
Dear All,
I have requirement in my Environment, I have to stop the Queries which compromises these conditions
1. If Query is running more than specified threshold (if it running more than 2 mins).
2. If Query is fetching huge data (rows more than 1000 for example)
Please note we have done enough study on resource governor, it works on compile time, we need to control the queries during run time. Also resource governor does not restrict the resources if they are free.
Answers are appreciated.Hello,
I would not advise you to do such things in your environment.2 mins is very less time how could you be so sure a 2 min query is bad. And your second point is totally baseless it wouldtake a query a fraction of secondto read 1000 rows.My answer would be please
dont implement.
If you want to test below query might achieve the first requirement, I have not tested it please treat this query as hint and optimize or add anything if required.
If you schedule this query through agent for every 2 mins or 5 mins .It can achieve.But some query takes more time to rollback than to finish scheduling this would lead to unstable environment
USE MASTER
IF EXISTS (SELECT * FROM TEMPDB.SYS.ALL_OBJECTS WHERE NAME LIKE '#KILL_CONNECTION')
BEGIN
DROP TABLE #KILL_CONNECTION
END
CREATE TABLE #KILL_CONNECTION
SESSION_ID INT
,TOTAL_ELAPSED_TIME BIGINT
,START_TIME DATETIME
INSERT INTO #KILL_CONNECTION
SELECT
SESSION_ID
,TOTAL_ELAPSED_TIME
,START_TIME
FROM SYS.DM_EXEC_REQUESTS
WHERE TOTAL_ELAPSED_TIME > 7200 AND SESSION_ID > 50
DECLARE @SESSION_ID BIGINT
DECLARE @CMD VARCHAR(1000)
DECLARE KILL_CONNECTION CURSOR FOR
SELECT SESSION_ID
FROM #KILL_CONNECTION
OPEN KILL_CONNECTION
FETCH NEXT FROM KILL_CONNECTION INTO @SESSION_ID
WHILE @@FETCH_STATUS = 0
BEGIN
SET @CMD = 'KILL ' + @SESSION_ID
EXECUTE (@CMD)
END
CLOSE KILL_CONNECTION
DEALLOCATE KILL_CONNECTION godrop table #Kill_connection
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers -
Procedure output cursor result insert to new table
Hi all,
Is there has any method to complete following task,
CREATE OR REPLACE
PROCEDURE sp1(
cv_1 OUT sys_refcursor)
AS
BEGIN
OPEN cv_1 FOR SELECT OBJECT_NAME FROM USER_OBJECTS;
END;
CREATE TABLE TEST1(OBJECT_NAME VARCHAR2(100));
var cv_1 refcursor;
INSERT INTO TEST1(OBJECT_NAME)
EXEC sp1(:cv_1);
Note: need solution apart from insert records to above table with-inside the procedure.
Thanks
Tharindu DhaneenjaYour code will not work anyway. You need to go through the SQL and PL/SQL basics again. It's always better to use pure SQL (if possible) instead of PL/SQL. You can try to insert using something like
INSERT INTO TEST1 SELECT OBJECT_NAME FROM USER_OBJECTS; -
Hello,
I want to find the total amount of rows present in my cursor result,
is there any way how I can find this?
I need it because I have to do an extra operation in the last result of my cursor.
Thanks in advanceHi,
Use BULK COLLEC to fetch your records in collection then use
collection_name.COUNT
for Example::
~
"afiedt.buf" 13 lines, 247 characters
1 DECLARE
2 TYPE emp_rec IS TABLE OF EMP%ROWTYPE;
3 v_arr emp_rec;
4 CURSOR emp_cur is SELECT * FROM EMP;
5 BEGIN
6 open emp_Cur;
7 LOOP
8 FETCH emp_cur BULK COLLECT INTO v_arr;
9 dbms_output.put_line(v_arr.COUNT);
10 EXIT WHEN emp_cur%NOTFOUND;
11 END LOOP;
12* END;
SQL>/
PL/SQL procedure successfully completed.
SQL>set serveroutput on
SQL>/
17
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL>SELECT count(*) FROM EMP;
COUNT(*)
17
1 row selected.
SQL>Regards
Maybe you are looking for
-
I get an error (2131) message on my Dell Vistro 1700 windows 7 computer when trying to burn a CD
-
Upon restart, doesn't automatically connect to wi-fi
Since upgrading to 10.7, every time I restart my iMac (Intel, 3.06 GHz, 12 GB RAM, late October 2009 model) it doesn't automatically connect to my home's wi-fi. I have to go into the wi-fi menu in the menubar and select my network. Anybody else havin
-
Which AIR SDK versions will run which iOS versions
Where can I find information about which AIR SDKs can target each version of iOS. Specifically, we are updating our app from AIR SDK 3.4 to the current 3.7; however, we aren't sure which versions of iOS the new SDK will work with. There is an air faq
-
hi my location is Chile .. I would comment as follows: Within what is the batch management in SAP Business One, specifically when it is done out of a product, you can view the lots available and implement a self-selection button. This button takes lo
-
I purchased the movie Veronica Mars. It shows in my purchases but it does not show in my library. When I check for downloads available it says that I have downloaded all purchases in my account but this one is not there. So frustrated with this wh