473,695 Members | 2,587 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cursor Problem

19 New Member
I have mysql server version: 5.0.15
I am facing this problem last a week about cursor.
well ! i have created cursor program as follows...
I written this program as external file, named as c:\sqldata\cur_ test.sql
and compiled it using command
mysql> \. c:\sqldata\cur_ test.sql

drop procedure if exists cur_test;
delimiter $$
create procedure cur_test()#out p1 text
declare tid int(11) default 0;
declare tname varchar(20) default '';
declare op text default '';
declare done int default 0;
declare done1 int default 0;
declare cur1 cursor for select id,tab_name from tab;
declare continue handler for sqlexception set done=1;
open cur1;
fetch cur1 into tid,tname;
if done=1 then
leave loop1;
end if;
set op=concat(op,'\ n',tid,' ',tname);
end loop loop1;
close cur1;
select op as output;
delimiter ;

when i go to run this program, i always get an error message....

mysql> \. c:\sqldata\cur_ test.sql
Query OK, 0 rows affected (0.05 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> call cur_test();
ERROR 1329 (02000): No data to FETCH

while 'tab' table is not empty

mysql> select * from tab;
| id | tab_name |
| 1 | xyz |
| 2 | pqr |
| 3 | lmn |
| 4 | abc |
| 5 | asd |
| 6 | zxc |
| 7 | qwe |
| 8 | rty |
| 9 | uio |
| 10 | cvb |
| 11 | poi |
11 rows in set (0.11 sec)

plz help me:
plz solve this problem immediatly plz plz plz
point out any error if there in my program...
suggest any idea or give me any clue...

plz plz plz
Mar 28 '07 #1
3 2388
39 New Member
DECLARE tid int(11) DEFAULT 0;
DECLARE tname varchar(20)DEFA ULT '';
DECLARE cur1 CURSOR FOR SELECT id,tab_name FROM tab;
DECLARE CONTINUE handler for NOT FOUND set done=1;
open cur1;
FETCH cur1 INTO tid,tname;
IF done=1 THEN
close cur1;
LEAVE loop1;
SET op=CONCAT(op,'\ n',tid,' ',tname);
END LOOP loop1;
SELECT op AS output;

CALL cur_test();
Mar 30 '07 #2
4,258 Recognized Expert Specialist
Both posters: read the Posting Guidelines about enclosing code within php or code tags!!

It would be a pity to remove posts because some members constantly refuse to adhere to the posting guidelines.

Mar 31 '07 #3
19 New Member
Expand|Select|Wrap|Line Numbers
  2. CREATE PROCEDURE cur_test()
  3. BEGIN
  4. DECLARE tid int(11) DEFAULT 0;
  5. DECLARE tname varchar(20)DEFAULT '';
  6. DECLARE op text DEFAULT '';
  7. DECLARE done int DEFAULT 0;
  8. DECLARE cur1 CURSOR FOR SELECT id,tab_name FROM tab;
  9. DECLARE CONTINUE handler for NOT FOUND set done=1;
  10. open cur1;
  11. loop1:
  12. LOOP
  13. FETCH cur1 INTO tid,tname;
  14. IF done=1 THEN
  15. close cur1;
  16. LEAVE loop1;
  17. END IF;
  18. SET op=CONCAT(op,'\n',tid,' ',tname);
  19. END LOOP loop1;
  20. SELECT op AS output;
  21. END;
  23. CALL cur_test();
  26. What is the different between your code and my code?
Apr 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection Timed out) I am using the Data Access Application Blocks as ASP.NET (using VB.NET) and SQL 2000. In there first question there can be up to 27 answers. So I figured instead of making 27 different trips to the database I woulc just concatenate my...
by: Oliver Stratmann | last post by:
Hello All! We have a cursor in an application which fetches some data out of a DB2-DB. Normally it all works kind of well. We inserted a routine at certain places in order to do some perfomance-monitoring . Now we got the problem, that the cursor closes at some point although not all the data has been fetched and then next fetch of the application causes an error. Is there a way to force the cursor to stay open?
by: Prashanth | last post by:
I am getting this error from BEA DB2 Driver in weblogic console. java.sql.SQLException: CURSOR C02 NOT IN A PREPARED STATE java.sql.SQLException: CURSOR C02 NOT IN A PREPARED STATE We keep running into this problem, frequently almost everyday. We figured what exactly to do when the problem happens but not the reason or the solution to this.
by: ilPostino | last post by:
I'm using this function to load a custom cursor from a .cur file; public static extern IntPtr LoadCursorFromFile(String str); It works great but if I popup a ContextMenu or Control like a ListView, the cursor resets to the system arrow. Even if I set the cursor property of each control to the one loaded it just ignores it. The ContextMenu doesn't support a cursor property either.
by: Vlad Simionescu | last post by:
Hello I'm trying to let my Windows Form application perform a lengthy operation while displaying a progress bar in a modal dialog window; the dialog has a cancel button. The dialog is displayed in the main thread while the work is done in a background thread. I managed to do it except for one minor problem: I want the cursor to be hourglass when it is over the main window and be normal (arrow) when it is over the dialog box. I cannot do...
by: Craig | last post by:
I'm trying to do this within a control I've created: Cursor.Current = Cursors.WaitCursor; During the initialization of the parent form, my control gets added to the form, and while the control is being intialized, I call a method within the control that sets the cursor to Cursors.WaitCursor, then processing continues. I want the Cursor to remain that way until I set it back at any given time, and if I don't set it back, I want to...
by: Just Me | last post by:
Does Me.Cursor.Current=Cursors.WaitCursor set the current property of Me.Cursor to Cursors.WaitCursor And Me.Cursor.Current=Cursors.Default set the Me.Current property to something (default) stored in Me.Cursor. Or is Cursors.Default some process wide cursor shape? What is a correct statement?
by: Lucky | last post by:
Hi guys! i want to create one cursor in the t-sql. the problem is i want to use stored procedure instead of select command in cursor. can anyone tell me how can i use stored procedure's o/p to create cursor? i'm using sql 2000 and .net 2.0 thanks,
by: Tomek | last post by:
In my page I reload JavaScript. When it is reloading the cursor change to "wait" (hourglass). After javascript loaded it does not change back to the "hand" if cursor stay on hyperlinks. How can I turn off changing cursor to "wait" (hourglass) is javascript is reloading.
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be programmed. Stop snickering!!! I didn't do it...I just gotta fix it. I need to make some calculations on the measurements and VB6 is my language. Yes, the system mouse will corrupt the measurement, but it's an auditing function and that's acceptable.
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.