Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
|
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2013, 04:22 PM
Registered User
 
Join Date: Jul 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How 2 point ref cursor to FOR Cursor loop results

Hi All,
It's really great to see every example under the sun found by google using DBMS_OUTPUT.PUTLINE() as the sole action taken on the results of each iteration of a loop, not too useful beyond the dev stage, though.
What I want is to simply report on the results of the LOOP below.
Each line sent to DBMS_OUTPUT should instead be in some form where I can point a single REF CURSOR to all of them. I simply need to output every line to a report on an ASP.NET web server. I want to do this the most efficient way possible. If that means inserting into a temp table, then selecting that resultset into a ref cursor, so be it. If not, please enlighten me. Thanks

DECLARE
vGroup NUMBER := 1;
vIter NUMBER :=1;

CURSOR cur IS
SELECT LID, SID, Cnt, Limits, Iter
FROM (
SELECT LID, SID, COUNT(*) OVER (PARTITION BY LID) Cnt, TRUNC(COUNT(*) OVER (PARTITION BY LID)/4)*4 Limits,
row_number() over (partition by LID order by SID desc) iter
FROM VW_TA
WHERE C0 > 0 AND C1 > 0 AND C2 > 0 AND C3 > 0 ORDER BY LID, SID DESC
) a WHERE ITER <= LIMITS;

BEGIN
FOR aRec IN cur
LOOP


DBMS_OUTPUT.PUT_LINE(aRec.LID || ', ' || aRec.SID || ', ' || aRec.Cnt || ', ' || aRec.Limits || ', ' || vGroup || ', ' || vIter);
IF (vIter = 4) THEN
vIter := 1;
vGroup := vGroup + 1;
ELSE
vIter := vIter +1;
END IF;
END LOOP;
END;
 
Old July 9th, 2013, 04:28 PM
Registered User
 
Join Date: Jul 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Reason why I am asking this is it seems the only way to get data from a stored procedure in oracle to a .NET dataset is via REF CURSOR. I am having a hard time figuring out how to get my resultant data into (or, view-able by) a ref cursor. If it were a simple select statement it wouldn't be an issue as I could then open the ref cursor for that select statement. Because I need to do some setting of variables in a for loop first, it is not a simple select statement.





Similar Threads
Thread Thread Starter Forum Replies Last Post
For loop with Floating Point Loop Counter - pp. 150 shivesh BOOK: Ivor Horton's Beginning Visual C++ 2010 1 March 28th, 2012 09:31 AM
Should I use a cursor? RobCarter SQL Server 2000 10 June 24th, 2011 09:25 AM
Problem with CURSOR FOR LOOP code_lover Oracle 12 April 9th, 2009 04:42 PM
Cursor results to Dataset NinaWilliam ADO.NET 0 November 27th, 2008 03:26 AM
Magnetic Cursor - Target Area Cursor? gcarcass .NET Framework 2.0 1 May 5th, 2008 07:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.