Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 18th, 2006, 06:43 PM
merl merl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 merl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 34 sec
Reputation Power: 7
Error in cursor when adding another cursor

Sorry the title could not be more informative. I have a weird error where a code fragment appears to work fine, but when another (unrelated) cursor is added, an exception is raised with the first one.

Here's the SQL outside of the cursor
sql Code:
Original - sql Code
  1.  
  2. SQL> SELECT cd.company_id, lc.dest_id, cd.data_scale, MIN(fy.financial_year) AS FinYear
  3.   2  FROM company_details cd, merged_company mc, linked_company lc, financial_year fy, company_details cd2
  4.   3  WHERE cd.group_id = 303
  5.   4  AND cd.company_id = 133787
  6.   5  AND fy.company_id = cd.company_id
  7.   6  AND fy.latest_flag = 1
  8.   7  AND mc.a_id = cd.company_id
  9.   8  AND lc.dest_id = mc.b_id
  10.   9  AND cd2.company_id = lc.dest_id
  11.  10  GROUP BY cd.company_id, lc.dest_id, cd.data_scale;
  12.  
  13. COMPANY_ID    DEST_ID DATA_SCALE                                                               FINYEAR
  14. ---------- ---------- -------------------------------------------------------------------------------------------------------------------------------- ---------
  15.     133787     154326 m                                                                    01-JAN-00
  16.  
  17. Elapsed: 00:00:00.04


Here's the cursor running correctly:
sql Code:
Original - sql Code
  1. SQL>
  2. SQL> DECLARE
  3.   2          CURSOR cur IS
  4.   3             SELECT cd.company_id, lc.dest_id, cd.data_scale, MIN(fy.financial_year) AS FinYear
  5.   4             FROM company_details cd, merged_company mc, linked_company lc, financial_year fy, company_details cd2
  6.   5             WHERE cd.group_id = 303
  7.   6             AND cd.company_id = 133787
  8.   7             AND fy.company_id = cd.company_id
  9.   8             AND fy.latest_flag = 1
  10.   9             AND mc.a_id = cd.company_id
  11.  10             AND lc.dest_id = mc.b_id
  12.  11             AND cd2.company_id = lc.dest_id
  13.  12             GROUP BY cd.company_id, lc.dest_id, cd.data_scale;
  14.  13 
  15.  14 
  16.  15          ScaleFactor NUMBER;
  17.  16 
  18.  17  BEGIN
  19.  18          FOR rec IN cur loop
  20.  19             NULL;
  21.  20          END loop;
  22.  21  END;
  23.  22  /
  24.  
  25. PL/SQL PROCEDURE successfully completed.
  26.  
  27. Elapsed: 00:00:00.00

And here's the exception when a redundant additional cursor has been added.

sql Code:
Original - sql Code
  1. SQL>
  2. SQL> DECLARE
  3.   2          CURSOR cur IS
  4.   3             SELECT cd.company_id, lc.dest_id, cd.data_scale, MIN(fy.financial_year) AS FinYear
  5.   4             FROM company_details cd, merged_company mc, linked_company lc, financial_year fy, company_details cd2
  6.   5             WHERE cd.group_id = 303
  7.   6             AND cd.company_id = 133787
  8.   7             AND fy.company_id = cd.company_id
  9.   8             AND fy.latest_flag = 1
  10.   9             AND mc.a_id = cd.company_id
  11.  10             AND lc.dest_id = mc.b_id
  12.  11             AND cd2.company_id = lc.dest_id
  13.  12             GROUP BY cd.company_id, lc.dest_id, cd.data_scale;
  14.  13 
  15.  14          CURSOR fy_cur(CID NUMBER, FYEAR DATE) IS
  16.  15             SELECT
  17.  16             FROM financial_year fy
  18.  17             WHERE company_id = CID
  19.  18             AND latest_flag = 1
  20.  19             AND FINANCIAL_YEAR < FYEAR
  21.  20             ORDER BY financial_year ASC;
  22.  21 
  23.  22          ScaleFactor NUMBER;
  24.  23 
  25.  24  BEGIN
  26.  25          FOR rec IN cur loop
  27.  26             NULL;
  28.  27          END loop;
  29.  28  END;
  30.  29  /
  31.         FROM company_details cd, merged_company mc, linked_company lc, financial_year fy, company_details cd2
  32.                                      *
  33. ERROR at line 4:
  34. ORA-06550: line 17, COLUMN 3:
  35. PL/SQL: ORA-00936: missing expression
  36. ORA-06550: line 16, COLUMN 65530:
  37. PL/SQL: SQL Statement ignored


Here's the db info.
sql Code:
Original - sql Code
  1.  
  2. SQL> SELECT *
  3.   2  FROM v$version;
  4.  
  5. BANNER
  6. ----------------------------------------------------------------
  7. Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
  8. PL/SQL Release 9.2.0.1.0 - Production
  9. CORE    9.2.0.1.0   Production
  10. TNS FOR 32-bit Windows: Version 9.2.0.1.0 - Production
  11. NLSRTL Version 9.2.0.1.0 - Production


Thanks in advance.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Error in cursor when adding another cursor


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT