﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server Newbies  / RE:- HELP! Cursor results displayed in table / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 03:06:11 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: RE:- HELP! Cursor results displayed in table</title><link>http://www.sqlservercentral.com/Forums/Topic1379317-1291-1.aspx</link><description>[quote][b]Eugene Elutin (11/2/2012)[/b][hr][quote][b]Sean Lange (10/31/2012)[/b][hr][quote][b]Mackers (10/31/2012)[/b][hr]Hi Chris,The SQL is quite hard to read (and I have never come across case statements &amp; cursors used like that before) but rather than using a cursor couldn't you write this as a SQL statement doing outer joins on the tables to achieve the same results?To be honest I only every really use cursors for breaking large transactions into smaller ones (inserting data per month etc).  In answer to your question I guess you could insert you results into a temp table than report from that(?)Mack[/quote]Next time you feel you need a cursor for this type of an operation, start a new post on SSC. From the description I doubt you need a cursor for that type of thing either. :-P[/quote]Unlike to SQL Server, ORACLE cursors usually do not have performance problems. However, I've seen few cases where rewriting CURSORS into set-based queries did bring some performance benefits even in Oracle.[/quote]To wit, Oracle can't return the results of SELECT to a GUI and unless MS came up with a really improved drive, you have to build a "Reference Cursor" for that.  Most people simplify that problem by including the stored procedures in a PACKAGE that contains a "global reference cursor".</description><pubDate>Fri, 02 Nov 2012 18:42:08 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: RE:- HELP! Cursor results displayed in table</title><link>http://www.sqlservercentral.com/Forums/Topic1379317-1291-1.aspx</link><description>[quote][b]Sean Lange (10/31/2012)[/b][hr][quote][b]Mackers (10/31/2012)[/b][hr]Hi Chris,The SQL is quite hard to read (and I have never come across case statements &amp; cursors used like that before) but rather than using a cursor couldn't you write this as a SQL statement doing outer joins on the tables to achieve the same results?To be honest I only every really use cursors for breaking large transactions into smaller ones (inserting data per month etc).  In answer to your question I guess you could insert you results into a temp table than report from that(?)Mack[/quote]Next time you feel you need a cursor for this type of an operation, start a new post on SSC. From the description I doubt you need a cursor for that type of thing either. :-P[/quote]Unlike to SQL Server, ORACLE cursors usually do not have performance problems. However, I've seen few cases where rewriting CURSORS into set-based queries did bring some performance benefits even in Oracle.</description><pubDate>Fri, 02 Nov 2012 05:31:27 GMT</pubDate><dc:creator>Eugene Elutin</dc:creator></item><item><title>RE: RE:- HELP! Cursor results displayed in table</title><link>http://www.sqlservercentral.com/Forums/Topic1379317-1291-1.aspx</link><description>[quote][b]Mackers (10/31/2012)[/b][hr]Hi Chris,The SQL is quite hard to read (and I have never come across case statements &amp; cursors used like that before) but rather than using a cursor couldn't you write this as a SQL statement doing outer joins on the tables to achieve the same results?To be honest I only every really use cursors for breaking large transactions into smaller ones (inserting data per month etc).  In answer to your question I guess you could insert you results into a temp table than report from that(?)Mack[/quote]Next time you feel you need a cursor for this type of an operation, start a new post on SSC. From the description I doubt you need a cursor for that type of thing either. :-P</description><pubDate>Wed, 31 Oct 2012 08:23:59 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: RE:- HELP! Cursor results displayed in table</title><link>http://www.sqlservercentral.com/Forums/Topic1379317-1291-1.aspx</link><description>[quote][b]christopher.grant (10/31/2012)[/b][hr]I have the following code below that prints a set of results to screen using put_line but I need to display the results as a table. Is it possible to do this or can someone suggest another better way of acheiving this. Any help would be appreciated. If any more detail is required please ask.[/quote]This isn't sql server code, this is Oracle code. You will find far more help on an Oracle forum. This forum is dedicated to SQL Server.</description><pubDate>Wed, 31 Oct 2012 08:22:24 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: RE:- HELP! Cursor results displayed in table</title><link>http://www.sqlservercentral.com/Forums/Topic1379317-1291-1.aspx</link><description>Thanks for your reply.You have answered another question I had inadvertently. I thought this statement was over complicated and that using joins to achieve the same results would be a better option. I think I will just start from scratch with this one.Chris :-)</description><pubDate>Wed, 31 Oct 2012 08:22:20 GMT</pubDate><dc:creator>christopher.grant</dc:creator></item><item><title>RE: RE:- HELP! Cursor results displayed in table</title><link>http://www.sqlservercentral.com/Forums/Topic1379317-1291-1.aspx</link><description>Hi Chris,The SQL is quite hard to read (and I have never come across case statements &amp; cursors used like that before) but rather than using a cursor couldn't you write this as a SQL statement doing outer joins on the tables to achieve the same results?To be honest I only every really use cursors for breaking large transactions into smaller ones (inserting data per month etc).  In answer to your question I guess you could insert you results into a temp table than report from that(?)Mack</description><pubDate>Wed, 31 Oct 2012 08:16:33 GMT</pubDate><dc:creator>Mackers</dc:creator></item><item><title>RE:- HELP! Cursor results displayed in table</title><link>http://www.sqlservercentral.com/Forums/Topic1379317-1291-1.aspx</link><description>I have the following code below that prints a set of results to screen using put_line but I need to display the results as a table. Is it possible to do this or can someone suggest another better way of acheiving this. Any help would be appreciated. If any more detail is required please ask.WHENEVER sqlerror exit failureset   linesize 300set   feed offset   serveroutput onset   verify offset   trimspool onset   termout offspool ss.txtDECLARE-- CURSORS        CURSOR C1 IS        select location_name, address from location where location_name like 'HOR%';        CURSOR C2 IS        SELECT OPERATOR_CLASS FROM OPERATOR_CLASS_DFN where STATUS = 0 and OPERATOR_CLASS NOT IN ('Analyst','DCC','Viewer','Incident Updater','Schedule Creator');        CURSOR C3 (s_client VARCHAR2, s_operator_class VARCHAR2) IS                SELECT CLIENT                from CONNECTION_OPERATOR_CLASS                where client = s_client                and for_operator_class = s_operator_class                and ALLOW_OR_DENY = 'DENY'                and status = 0;            -- VARIABLESv_location_name     location.LOCATION_NAME%TYPE;v_address              location.ADDRESS%TYPE;v_operator_class    operator_class_dfn.OPERATOR_CLASS%TYPE;s_client                  connection_operator_class.CLIENT%TYPE;s_operator_class    connection_operator_class.FOR_OPERATOR_CLASS%TYPE;r_client                  connection_operator_class.CLIENT%TYPE;-- MAIN BODYBEGIN        OPEN C1;                LOOP                FETCH C1 into v_location_name, v_address;                EXIT WHEN C1%NOTFOUND;                OPEN C2;                        LOOP                        FETCH C2 into v_operator_class;                        EXIT WHEN C2%NOTFOUND;                        OPEN C3 (v_location_name,v_operator_class);                        r_client := NULL;                                FETCH C3 into r_client;                                IF r_client IS NULL                                THEN                                        dbms_output.put_line ('NOT FOUND :'||v_location_name||'|'||v_address||'|'||v_operator_class||'|');                                END IF;                        CLOSE C3;                        END LOOP;                CLOSE C2;                END LOOP;        CLOSE C1;END;/exit;</description><pubDate>Wed, 31 Oct 2012 07:53:29 GMT</pubDate><dc:creator>christopher.grant</dc:creator></item></channel></rss>