<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>MySQL Forums - Cursors</title>
        <description>Forum for MySQL Cursors</description>
        <link>http://forums.mysql.com/list.php?102</link>
        <lastBuildDate>Fri, 24 May 2013 12:25:21 +0000</lastBuildDate>
        <generator>Phorum 5.2.19</generator>
        <item>
            <guid>http://forums.mysql.com/read.php?102,584862,584862#msg-584862</guid>
            <title>Deleting Rows in a table. (2 replies)</title>
            <link>http://forums.mysql.com/read.php?102,584862,584862#msg-584862</link>
            <description><![CDATA[ I have a table like that <br />
MemberId(F.K) ! Event ! Event Date<br />
1 'Test Event1' &quot;2012-03-20 05:39:51&quot;<br />
1 'Test Event1' &quot;2012-03-21 05:39:51&quot;<br />
1 'Test Event1' &quot;2012-03-22 05:39:51&quot;<br />
3 'Test Event3' &quot;2012-03-23 05:39:51&quot;<br />
2 'Test Event2' &quot;2012-03-24 05:39:51&quot;<br />
2 'Test Event2' &quot;2012-03-19 05:39:51&quot;<br />
1 'Test Event1' &quot;2012-03-23 05:49:51&quot;<br />
3 'Test Event3' &quot;2012-03-23 05:49:51&quot;<br />
4 'Test Event4' &quot;2012-03-27 05:39:51&quot;<br />
3 'Test Event3' &quot;2012-03-21 05:39:51&quot;<br />
. . . <br />
. .<br />
and what i require is to keep only two latest events for each members and to delete the rest ones.<br />
i.e.<br />
1 'Test Event1' &quot;2012-03-23 05:49:51&quot;<br />
1 'Test Event1' &quot;2012-03-22 05:39:51&quot;<br />
2 'Test Event2' &quot;2012-03-24 05:39:51&quot;<br />
2 'Test Event2' &quot;2012-03-19 05:39:51&quot;<br />
3 'Test Event3' &quot;2012-03-23 05:39:51&quot;<br />
3 'Test Event3' &quot;2012-03-23 05:49:51&quot;<br />
4 'Test Event4' &quot;2012-03-27 05:39:51&quot;<br />
<br />
I am able to do that by using Cursor but i want to avoid using it and to write a pure SQL Query for that , <br />
any help will be appreciated.]]></description>
            <dc:creator>Faheem Ahmad</dc:creator>
            <category>Cursors</category>
            <pubDate>Fri, 26 Apr 2013 17:08:28 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,579926,579926#msg-579926</guid>
            <title>ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,579926,579926#msg-579926</link>
            <description><![CDATA[ create table department<br />
(<br />
departmentID int not null auto_increment primary key ,<br />
name varchar(30)<br />
)<br />
type=InnoDB;]]></description>
            <dc:creator>ayman hodesh</dc:creator>
            <category>Cursors</category>
            <pubDate>Mon, 25 Feb 2013 08:23:00 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,576319,576319#msg-576319</guid>
            <title>Getting warning code 1329 Warning Code : 1329 No data - zero rows fetched, selected, or processed (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,576319,576319#msg-576319</link>
            <description><![CDATA[ when i try to execute below code in mysql 5.0 iam getting  warning code 1329 <br />
No data - zero rows fetched, selected, or processed. please suggest be how to handle such type of warnings..<br />
/*<br />
Highlight and execute the following statement to drop the procedure<br />
before executing the create statement.<br />
<br />
DROP PROCEDURE ProcedureTest.test;<br />
<br />
*/<br />
<br />
CREATE DEFINER=`AppAdmin`@`%` PROCEDURE `test`(IN newloginId VARCHAR(40),OUT msg VARCHAR(75), out total int(3))<br />
BEGIN<br />
	<br />
    DECLARE d INT DEFAULT 0;<br />
      DECLARE isExistedAccId INT DEFAULT 0;<br />
         DECLARE a INT;<br />
  <br />
   DECLARE p_AccId INT DEFAULT 0;<br />
   DECLARE i INT DEFAULT 0;<br />
   DECLARE accCount int(10);<br />
     DECLARE cur CURSOR FOR SELECT AccId FROM Table2 order by AccId;<br />
 <br />
SELECT count(AccId) into accCount FROM Table2 ORDER BY AccId;<br />
 -- DECLARE CONTINUE HANDLER FOR NOT FOUND SET isExistedAccId = 0;<br />
 <br />
  OPEN cur;<br />
 <br />
  WHILE(accCount &gt; 0)    <br />
    DO<br />
    <br />
     FETCH cur INTO p_AccId;<br />
    <br />
       SET isExistedAccId = 0;<br />
     <br />
 -- DECLARE CONTINUE HANDLER FOR SQLWARNING BEGIN END;<br />
  -- DECLARE CONTINUE HANDLER FOR NOT FOUND SET isExistedAccId = 0;<br />
       <br />
      SELECT AccountId into isExistedAccId FROM Table1 where AccountId = p_AccId and TeamMemberId = newloginId limit 1;<br />
     <br />
      IF isExistedAccId = 0 THEN<br />
     INSERT INTO Table1(AccountId, TeamMemberId, SalesFlag, PrimaryFlag) VALUES(p_AccId,newloginId,1,0);<br />
      SET isExistedAccId = 0;<br />
      SET i = i + 1;<br />
      END IF;<br />
     SET accCount = accCount - 1;<br />
    END WHILE;<br />
     CLOSE cur;<br />
     <br />
     SET msg = 'rows Inserted';<br />
     set total  = i;<br />
     END]]></description>
            <dc:creator>santosh kola</dc:creator>
            <category>Cursors</category>
            <pubDate>Wed, 19 Dec 2012 17:01:53 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,574257,574257#msg-574257</guid>
            <title>Cursor created for view still returns the same data (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,574257,574257#msg-574257</link>
            <description><![CDATA[ I have data in several tables, that is created every month. I need check all records for inputed user_id.<br />
Here is example:<br />
<br />
DROP TABLE IF EXISTS `month`;<br />
CREATE TABLE IF NOT EXISTS `month` (<br />
  `id` int(11) NOT NULL AUTO_INCREMENT,<br />
  `user_id` int(11) NOT NULL,<br />
  `value` int(11) NOT NULL,<br />
  PRIMARY KEY (`id`)<br />
) ENGINE=InnoDB  DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;<br />
<br />
DROP TABLE IF EXISTS `month_01`;<br />
CREATE TABLE IF NOT EXISTS `month_01` (<br />
  `id` int(11) NOT NULL AUTO_INCREMENT,<br />
  `user_id` int(11) NOT NULL,<br />
  `value` int(11) NOT NULL,<br />
  PRIMARY KEY (`id`)<br />
) ENGINE=InnoDB  DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;<br />
<br />
DROP TABLE IF EXISTS `month_02`;<br />
CREATE TABLE IF NOT EXISTS `month_02` (<br />
  `id` int(11) NOT NULL AUTO_INCREMENT,<br />
  `user_id` int(11) NOT NULL,<br />
  `value` int(11) NOT NULL,<br />
  PRIMARY KEY (`id`)<br />
) ENGINE=InnoDB  DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;<br />
<br />
INSERT INTO `month_01` (`user_id`, `value`) VALUES(1,1);<br />
INSERT INTO `month_01` (`user_id`, `value`) VALUES(2,8);<br />
<br />
INSERT INTO `month_02` (`user_id`, `value`) VALUES(1,21);<br />
INSERT INTO `month_02` (`user_id`, `value`) VALUES(2,28);<br />
<br />
INSERT INTO `month` (`user_id`, `value`) VALUES(1,31);<br />
INSERT INTO `month` (`user_id`, `value`) VALUES(2,38);<br />
<br />
DELIMITER $$<br />
DROP PROCEDURE IF EXISTS `create_view`$$<br />
CREATE DEFINER='root'@'localhost'<br />
PROCEDURE `create_view`(<br />
		p_user_id INT<br />
)<br />
    COMMENT 'create view'<br />
BEGIN<br />
	DECLARE l_sql_command VARCHAR(50000);<br />
	DECLARE l_table_name VARCHAR(64);<br />
<br />
	DECLARE done INT DEFAULT FALSE;	<br />
	DECLARE cur_cv CURSOR FOR<br />
	SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=SCHEMA() AND (`TABLE_NAME` LIKE 'month_%') ORDER BY 1;<br />
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;<br />
<br />
	SET l_sql_command = 'CREATE VIEW `v_temp_data` AS ';<br />
<br />
	OPEN cur_cv;<br />
	read_loop: LOOP<br />
		FETCH cur_cv INTO l_table_name;		<br />
		IF done THEN<br />
			LEAVE read_loop;<br />
		END IF;<br />
<br />
		IF l_table_name LIKE 'month_%' THEN<br />
			SET l_sql_command = CONCAT(l_sql_command<br />
				, &quot; SELECT `id`, `user_id`, `value` FROM &quot;,l_table_name ,&quot; WHERE `user_id` = &quot;,p_user_id<br />
				, &quot; UNION&quot;);<br />
		END IF;<br />
<br />
	END LOOP;<br />
	CLOSE cur_cv;<br />
<br />
	SET l_sql_command = CONCAT(l_sql_command<br />
		, &quot; SELECT `id`, `user_id`, `value` FROM `month`&quot;,&quot; WHERE `user_id` = &quot;,p_user_id<br />
		);<br />
	SET done = FALSE;<br />
<br />
	SET @query = l_sql_command;<br />
	PREPARE stmt from @query; <br />
	EXECUTE stmt; <br />
	DEALLOCATE PREPARE stmt; <br />
END$$<br />
<br />
DELIMITER $$<br />
DROP PROCEDURE IF EXISTS `process_data`$$<br />
CREATE DEFINER='root'@'localhost'<br />
PROCEDURE `process_data`(<br />
		p_user_id INT<br />
)<br />
    COMMENT 'process data'<br />
BEGIN<br />
	DECLARE l_id INT DEFAULT 0;<br />
	DECLARE l_user_id INT DEFAULT 0;<br />
	DECLARE l_value INT DEFAULT 0;<br />
<br />
	DECLARE l_sql_command VARCHAR(50000);<br />
<br />
	DECLARE done INT DEFAULT FALSE;	<br />
	DECLARE cur_pd CURSOR FOR SELECT `id`, `user_id`, `value` FROM `v_temp_data`;<br />
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;<br />
<br />
	OPEN cur_pd;<br />
	read_loop: LOOP<br />
		FETCH cur_pd INTO l_id, l_user_id, l_value;<br />
		IF done THEN<br />
			LEAVE read_loop;<br />
		END IF;<br />
		SELECT IF(p_user_id=l_user_id,'OK','BAD') AS Result, p_user_id, l_user_id, l_value;<br />
	END LOOP;<br />
	CLOSE cur_pd;<br />
	DROP VIEW IF EXISTS `v_temp_data`; <br />
END $$<br />
<br />
DROP PROCEDURE IF EXISTS `data_check_user`$$<br />
CREATE DEFINER='root'@'localhost'<br />
PROCEDURE `data_check_user`(<br />
		p_user_id INT<br />
)<br />
    COMMENT 'Check data for user'<br />
BEGIN<br />
	SELECT 'CHECK USER' AS Type, p_user_id AS User;<br />
	CALL `create_view` (p_user_id);<br />
	CALL `process_data` (p_user_id);<br />
END$$<br />
<br />
DROP PROCEDURE IF EXISTS `data_check`$$<br />
CREATE DEFINER='root'@'localhost'<br />
PROCEDURE `data_check`(<br />
)<br />
    COMMENT 'Check data'<br />
BEGIN<br />
	DECLARE done INT DEFAULT FALSE;<br />
	DECLARE l_id INT DEFAULT 0;<br />
	DECLARE cur CURSOR FOR <br />
	SELECT 1 UNION SELECT 2;<br />
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;<br />
<br />
	SELECT 'CHECK ALL' AS Type;<br />
	OPEN cur;<br />
	read_loop: LOOP<br />
		FETCH cur INTO l_id;<br />
		IF done THEN<br />
			LEAVE read_loop;<br />
		END IF;<br />
		CALL `data_check_user`(l_id);<br />
	END LOOP;<br />
	CLOSE cur;<br />
END$$<br />
<br />
DELIMITER ;<br />
CALL `data_check`();<br />
CALL `data_check_user`(1);<br />
CALL `data_check_user`(2);<br />
<br />
On MySQL 5.1.54 is result:<br />
<br />
Type<br />
CHECK ALL<br />
Type	User<br />
CHECK USER	1<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	1<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	21<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	31<br />
Type	User<br />
CHECK USER	2<br />
Result	p_user_id	l_user_id	l_value<br />
BAD	2	1	1<br />
Result	p_user_id	l_user_id	l_value<br />
BAD	2	1	21<br />
Result	p_user_id	l_user_id	l_value<br />
BAD	2	1	31<br />
Type	User<br />
CHECK USER	1<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	1<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	21<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	31<br />
Type	User<br />
CHECK USER	2<br />
Result	p_user_id	l_user_id	l_value<br />
OK	2	2	8<br />
Result	p_user_id	l_user_id	l_value<br />
OK	2	2	28<br />
Result	p_user_id	l_user_id	l_value<br />
OK	2	2	38<br />
<br />
It shows BAD result when `data_check` repeats calling `data_check_user` with another `user_id`.<br />
On MySQL 5.5.28 it's running correctly:<br />
<br />
Type<br />
CHECK ALL<br />
Type	User<br />
CHECK USER	1<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	1<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	21<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	31<br />
Type	User<br />
CHECK USER	2<br />
Result	p_user_id	l_user_id	l_value<br />
OK	2	2	8<br />
Result	p_user_id	l_user_id	l_value<br />
OK	2	2	28<br />
Result	p_user_id	l_user_id	l_value<br />
OK	2	2	38<br />
Type	User<br />
CHECK USER	1<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	1<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	21<br />
Result	p_user_id	l_user_id	l_value<br />
OK	1	1	31<br />
Type	User<br />
CHECK USER	2<br />
Result	p_user_id	l_user_id	l_value<br />
OK	2	2	8<br />
Result	p_user_id	l_user_id	l_value<br />
OK	2	2	28<br />
Result	p_user_id	l_user_id	l_value<br />
OK	2	2	38<br />
<br />
Is a way to do it correctly on MySQL 5.1.54 ?<br />
Thanks for advice<br />
Dan]]></description>
            <dc:creator>x y</dc:creator>
            <category>Cursors</category>
            <pubDate>Wed, 21 Nov 2012 07:57:36 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,573079,573079#msg-573079</guid>
            <title>Cusors in Stored Procedures + Where Clause (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,573079,573079#msg-573079</link>
            <description><![CDATA[ Hi,<br />
<br />
I have a Stored Procedure called sp_import_tax(). It received two input variables from a PHP file.<br />
<br />
The Stored Procedure is used to update tables based on a Staging table that data is uploaded too. <br />
<br />
Multiple Users can upload data to the table called etl_taxpro - the final column in each row contains an area code. When the user executes the Stored Procedure the area code is passed to it and I want to then use the passed Area Code when I am declaring my cusor so only the specific users rows are used.<br />
<br />
See Store Procedure code below<br />
<br />
<br />
<br />
CREATE DEFINER=`root`@`%` PROCEDURE `sp_import_taxpro`(current_user_id VARCHAR(36), areacode VARCHAR(36))<br />
BEGIN<br />
<br />
DECLARE tax_number VARCHAR(255);<br />
DECLARE year_end VARCHAR(255);<br />
DECLARE filing_date_f11 DATE DEFAULT '1970-01-01';<br />
DECLARE completion_date_f11 DATE DEFAULT '1970-01-01';<br />
DECLARE submission_date_f11 DATE DEFAULT '1970-01-01';<br />
DECLARE f11_ack VARCHAR(255);<br />
DECLARE submission_date_46g DATE DEFAULT '1970-01-01';<br />
DECLARE 46g_ack VARCHAR(255);<br />
DECLARE prelim_date_paid DATE DEFAULT '1970-01-01';<br />
DECLARE prelim_date DATE DEFAULT '1970-01-01';<br />
DECLARE user_area_code VARCHAR(255);<br />
DECLARE done INT DEFAULT 0;<br />
DECLARE cursor1 CURSOR FOR<br />
	SELECT <br />
		TaxNumber,<br />
		YearEnd,<br />
		DATE_FORMAT(STR_TO_DATE(FilingDateF11, '%d/%m/%Y %H:%i:%S'), '%Y-%m-%d') AS filing_date_f11,<br />
		DATE_FORMAT(STR_TO_DATE(CompletionDateF11, '%d/%m/%Y %H:%i:%S'), '%Y-%m-%d') AS completion_date_f11,<br />
		DATE_FORMAT(STR_TO_DATE(SubmissionDateF11, '%d/%m/%Y %H:%i:%S'), '%Y-%m-%d') AS submission_date_f11,<br />
		F11Ack,<br />
		DATE_FORMAT(STR_TO_DATE(SubmissionDate46G, '%d/%m/%Y %H:%i:%S'), '%Y-%m-%d') AS submission_date_46g,<br />
		46GAck,<br />
		DATE_FORMAT(STR_TO_DATE(PrelimTaxDatePaid, '%d/%m/%Y %H:%i:%S'), '%Y-%m-%d') AS prelim_date_paid,<br />
		DATE_FORMAT(STR_TO_DATE(PrelimTax, '%d/%m/%Y %H:%i:%S'), '%Y-%m-%d') AS prelim_date,<br />
		AreaCode<br />
	FROM etl_taxpro<br />
		WHERE AreaCode=area_code;<br />
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; <br />
<br />
OPEN cursor1;<br />
REPEAT FETCH cursor1 INTO tax_number,year_end,filing_date_f11,completion_date_f11,submission_date_f11,f11_ack,submission_date_46g,46g_ack,prelim_date_paid,prelim_date,user_are_code;<br />
IF NOT done THEN<br />
<br />
/** The code I execute here will contain all data from the etl_taxpro and not just the date matching area_code<br />
**/<br />
<br />
<br />
END IF;<br />
UNTIL done END REPEAT;<br />
CLOSE cursor1;<br />
<br />
END$$<br />
<br />
DELIMITER ;<br />
<br />
<br />
Is what I want to achieve possible.]]></description>
            <dc:creator>Chris Lynch</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 06 Nov 2012 17:23:55 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,570291,570291#msg-570291</guid>
            <title>Go through two strings with comma in a cursor (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,570291,570291#msg-570291</link>
            <description><![CDATA[ Hello,<br />
<br />
I have a stored procedure to do the follow things<br />
<br />
There is a table with 3 columns<br />
<br />
ID	|Last_Modified 	    |  Flag	<br />
1	|2011-12-11 02:00:00|	0	<br />
2	|2011-12-13 02:00:00|	0	<br />
3	|2011-12-02 02:00:00|	0<br />
4	|2011-12-12 02:00:00|	0<br />
<br />
the stored procedure “getback(String pId, String pLast_Modified).  E.g. pId =”1,2,3” and pLast_Modified = “2011-12-11 02:00:00, 2011-12-13 02:00:00, 2011-12-01 02:00:00”.<br />
<br />
The logic is that, for the same ID, if the last_modified in the table is later than the passed last_modified, then set the flag for that record to “1”.<br />
<br />
I am trying to find out a simple way to construct a cursor to get the records need to be changed to &quot;1&quot;. But it has no luck. Is there anybody who did similar thing like this before??<br />
<br />
Very appreciated your help!<br />
<br />
Tony]]></description>
            <dc:creator>Tony ding</dc:creator>
            <category>Cursors</category>
            <pubDate>Fri, 05 Oct 2012 20:09:31 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,569047,569047#msg-569047</guid>
            <title>Cursor fetch variable holding null (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,569047,569047#msg-569047</link>
            <description><![CDATA[ Please help me, am getting null values from cursor <br />
<br />
DELIMITER $$<br />
<br />
DROP PROCEDURE IF EXISTS `csms_hq_db`.`sp_test`$$<br />
CREATE DEFINER=`csms`@`%` PROCEDURE `sp_test`(IN `tbl_name` VARCHAR(255),IN `rec_id` int,<br />
IN `crud_action` VARCHAR(1),IN `topublish` datetime,IN `updatedat` datetime,IN `is_published` int,IN `table_id` VARCHAR(255))<br />
BEGIN<br />
DECLARE last_fetched_value int;<br />
START TRANSACTION; <br />
<br />
	BEGIN<br />
	DECLARE  shop_id BIGINT(20);<br />
	DECLARE  db_server VARCHAR(255);<br />
	DECLARE  done INT;<br />
	DECLARE  cur_shop CURSOR FOR  SELECT  shop_id,db_server FROM shop_db_settings;<br />
	DECLARE  CONTINUE HANDLER FOR NOT FOUND SET done = 1;<br />
	OPEN  cur_shop;<br />
	  read_loop: LOOP<br />
	    FETCH  cur_shop INTO shop_id,db_server;<br />
		   IF done THEN<br />
 	    		 LEAVE read_loop;<br />
 	   	   END IF;<br />
 	  	 #Insert entity part<br />
 	  	INSERT INTO `sync_queue` (`table_name`, `record_id`, `shop_id`, `crud_action`, `publishing_date`, `last_updated`, `sync_status`, `error_msg`)<br />
			VALUES (db_server, rec_id, shop_id, crud_action, topublish, updatedat, 0,'');<br />
  	END LOOP read_loop;<br />
	CLOSE  cur_shop;	 <br />
  END;	<br />
<br />
COMMIT;	<br />
END$$<br />
<br />
DELIMITER ;]]></description>
            <dc:creator>Anoop G</dc:creator>
            <category>Cursors</category>
            <pubDate>Thu, 20 Sep 2012 05:52:48 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,566108,566108#msg-566108</guid>
            <title>how can I extract my base correctly (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,566108,566108#msg-566108</link>
            <description><![CDATA[ hi,<br />
<br />
I work with MySQL Server 5.5 and I have a problem in extracting my data base,this how I used this command:<br />
<br />
<br />
mysql&gt; mysqldump -uroot -pkail mybase &gt; C:\Program Files\MySQL\MySQL Server 5.5\b<br />
in\base.sql;<br />
<br />
and this is the Error that I get:<br />
<br />
ERROR:<br />
Unknown command '\P'.<br />
ERROR:<br />
Unknown command '\M'.<br />
ERROR:<br />
Unknown command '\M'.<br />
ERROR:<br />
Unknown command '\b'.<br />
Outfile disabled.<br />
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that<br />
corresponds to your MySQL server version for the right syntax to use near 'mysq<br />
dump -uroot -pkail mybase &gt; C:\Program Files\MySQL\MySQL Server 5.5\bin' at<br />
line 1<br />
<br />
how can I resolve the problem and thanks for any help :)]]></description>
            <dc:creator>genwa kair</dc:creator>
            <category>Cursors</category>
            <pubDate>Fri, 24 Aug 2012 18:11:34 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,565881,565881#msg-565881</guid>
            <title>Loop over cursor results ends ahead of schedule (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,565881,565881#msg-565881</link>
            <description><![CDATA[ Hello,<br />
<br />
I'm executing a loop that iterates over a cursor's results. The code is inside a trigger function, and the part that matters looks like that:<br />
<br />
create trigger my_trigger after delete on my_table <br />
for each row<br />
begin<br />
<br />
declare my_value int;<br />
declare num_rows int default 0;<br />
declare done int default false;<br />
declare my_cursor cursor for select value from table where condition;<br />
declare continue handler for sqlstate '02000' set done = 1;<br />
<br />
open my_cursor;<br />
select found_rows() into num_rows;<br />
<br />
-- This is just for debugging<br />
insert into log_table(key, value) values('foo', num_rows);<br />
<br />
if num_rows &gt; 0 then:<br />
  repeat<br />
    fetch my_cursor into my_value;<br />
    -- Do stuff<br />
  until done end repeat;<br />
end if;<br />
<br />
close my_cursor;<br />
<br />
end<br />
<br />
The loop should be executed 11 times, because the query returns 11 values. This is checked by the 'insert' clause. The var 'num_rows' is equal to 11. But the problem is the loop is only executed 3 times.<br />
<br />
These numbers (11, 3) are not important. If I change the query to return a different amount of results, the problem remains: the loop ends before scheduled.<br />
<br />
Does it make any sense? I may do something inside the loop (the 'do stuff' part) that causes the end of the loop. It's the only thing that soundslogic for me.<br />
<br />
Thanks in advance, and best regards,<br />
Jorge]]></description>
            <dc:creator>Jorge Arévalo</dc:creator>
            <category>Cursors</category>
            <pubDate>Wed, 22 Aug 2012 17:59:32 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,559339,559339#msg-559339</guid>
            <title>Create cursor from Varchar or another variable (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,559339,559339#msg-559339</link>
            <description><![CDATA[ I have a stored procedure that builds a query based on the parameters of the procedure. I need to iterate through the results later (for some additional processing), so I was thinking on doing so with a cursor. I've read that you can´t create a cursor from a prepared statement (http://forums.mysql.com/read.php?61,116597,116597#msg-116597) and I wanted to avoid the creation of a temporary table for performance issues, is there any way to create a cursor from a variable containing the query?<br />
<br />
Greetings and thanks for any help!]]></description>
            <dc:creator>Santiago Del Valle</dc:creator>
            <category>Cursors</category>
            <pubDate>Fri, 29 Jun 2012 20:48:28 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,558651,558651#msg-558651</guid>
            <title>Backup Database Error (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,558651,558651#msg-558651</link>
            <description><![CDATA[ mysql&gt; mysqldump -u root -p foobar<br />
<br />
mysqldump -u [user] -p [database_name] <br />
<br />
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that<br />
corresponds to your MySQL server version for the right syntax to use near 'mysqldump -u root -p foobar' at line 1<br />
<br />
please help how can i backup a database]]></description>
            <dc:creator>noah spiegel</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 26 Jun 2012 15:00:16 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,558447,558447#msg-558447</guid>
            <title>store procedure problems (2 replies)</title>
            <link>http://forums.mysql.com/read.php?102,558447,558447#msg-558447</link>
            <description><![CDATA[ Hi<br />
I had some flouring in sql2000 of MS, but now using MySql I've some problem, particularly on the StoreProcedures.<br />
this code:<br />
<br />
DELIMITER // <br />
CREATE PROCEDURE prova (OUT tot INT,OUT c1 INT) <br />
  BEGIN <br />
  DECLARE cur2 CURSOR FOR SELECT count(*) FROM prove.old WHERE flag &lt;&gt; 0; <br />
  OPEN cur2; <br />
  FETCH cur2 INTO tot; <br />
  CLOSE cur2; <br />
  set c1 = tot; <br />
  END; // <br />
DELIMITER ;<br />
<br />
colling with:    CALL prova(@tot,@c1);<br />
                 select @tot,@c1;<br />
correctly done:<br />
+-------+-------+<br />
| @tot | @c1 |<br />
+-------+-------+<br />
| 33322 | 33322 |<br />
+-------+-------+<br />
1 row in set (0.00 sec)<br />
<br />
if I add a CURSOR, nothing work, also the preceding code:<br />
code:<br />
DELIMITER //<br />
CREATE PROCEDURE prova (OUT tot INT,OUT c1 INT, OUT c2 INT)<br />
BEGIN<br />
	DECLARE done 		INT;<br />
	DECLARE ip_start  	BIGINT;<br />
	DECLARE ip_to  		BIGINT;<br />
	DECLARE city_code  	INT;<br />
	DECLARE flag		TINYINT;<br />
<br />
        DECLARE cur2 CURSOR FOR SELECT count(*) FROM prove.old WHERE flag &lt;&gt; 0;<br />
        DECLARE cur1 CURSOR FOR SELECT * FROM prove.old WHERE flag &lt;&gt; 0;<br />
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;<br />
		<br />
		OPEN cur2;<br />
		FETCH cur2 INTO tot;<br />
		CLOSE cur2;<br />
		<br />
	set c1 = 0;	set c2 = 0;	set done = 0;<br />
		<br />
	OPEN cur1;<br />
	REPEAT<br />
	  FETCH cur1 INTO ip_start,ip_to,city_code,flag;<br />
		  IF NOT done THEN<br />
						IF flag = 1 THEN <br />
							SET c1 = c1 + 1; <br />
							ELSE <br />
							SET c2 = c2 + 1;<br />
						END IF;<br />
		<br />
		  END IF;<br />
	UNTIL done END REPEAT;<br />
	CLOSE cur1;<br />
<br />
END; //<br />
DELIMITER ;<br />
<br />
when I call:       CALL prova(@tot,@c1,@c2);<br />
                   select @tot,@c1,@c2;<br />
the answer is:<br />
<br />
mysql&gt; CALL prova(@tot,@c1,@c2);<br />
Query OK, 0 rows affected, 1 warning (0.00 sec)<br />
mysql&gt; select @tot,@c1,@c2;<br />
+------+------+------+<br />
| @tot | @c1 | @c2 |<br />
+------+------+------+<br />
| 0 | 0 | 0 |<br />
+------+------+------+<br />
1 row in set (0.00 sec)<br />
<br />
why? where am I wrong?<br />
thanks in advance<br />
JeanPaul]]></description>
            <dc:creator>Paolo Rossi</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 26 Jun 2012 14:53:39 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,534699,534699#msg-534699</guid>
            <title>how to handle empty data from select statement inside the procedure (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,534699,534699#msg-534699</link>
            <description><![CDATA[ In the following code how to handle when there are no rows in select statement like in oracle exception NO_DATA_FOUND ????????<br />
HOW TO HANDLE IN MYSQL ??<br />
<br />
<br />
SELECT A.STATUS, A.VISIBLE, NVL(A.STATUS_STRING_CODE, -1), NVL(A.STATUS_STRING, ''), NVL(A.LOCALE_STRING, ''),<br />
              NVL(A.DEVICE_GROUP, 0), NVL(A.CLIENT_IP_ADDR, ''), NVL(A.CLIENT_PORT_NO, 0), NVL(C.DEVICE_GROUP, 0),<br />
 		       NVL(A.MSISDN, '')<br />
 		INTO dbStatus, dbVisible, dbStatusStrCode, dbStatusStr, dbLocalStr, dbDeviceGrp, dbIpAddr, dbPortNo, dbOffDevGrp,<br />
            dbMsisdn<br />
       FROM USERS A, USER_DEVICES B, DEVICES C<br />
       WHERE A.USER_ID = dbPalId<br />
       AND A.USER_ID = B.USER_ID (+)<br />
       AND B.DEVICE_ID = C.DEVICE_ID (+);<br />
 <br />
 	EXCEPTION<br />
       WHEN NO_DATA_FOUND THEN<br />
          dbReturn := PAL_DOES_NOT_EXISTS;<br />
 			goto END_FUNC;]]></description>
            <dc:creator>khadar mohiddin</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 15 May 2012 01:56:03 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,511115,511115#msg-511115</guid>
            <title>increment value based on two fields (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,511115,511115#msg-511115</link>
            <description><![CDATA[ Hi,<br />
<br />
I need to create an incremented value that resets back to 1 based on another field, essentillly a line number per page.<br />
<br />
Given data:<br />
page|ID<br />
1|1<br />
1|2<br />
2|3<br />
2|4<br />
3|5<br />
I'd like output of<br />
page|ID|line_number<br />
1|1|1<br />
1|2|2<br />
2|3|1<br />
2|4|2<br />
3|5|1<br />
<br />
How would I go about this using purely MySQL?<br />
<br />
Any help appreciated!<br />
Thanks]]></description>
            <dc:creator>Long Dog</dc:creator>
            <category>Cursors</category>
            <pubDate>Sat, 21 Jan 2012 16:07:01 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,504588,504588#msg-504588</guid>
            <title>How to use cursor within the trigger? (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,504588,504588#msg-504588</link>
            <description><![CDATA[ the question is: For each student with GPA &gt; 3.5 whose resume contains the keywords “database systems”, create a <br />
notification telling the student about a particular new job announcement that a company has posted. <br />
<br />
there's a student table and a job_announcement table. how to write this query?<br />
<br />
I try to use cursor, but mysql says it's incorrect.<br />
<br />
the sql statement:<br />
<br />
CREATE TRIGGER pushdb after INSERT ON job <br />
FOR EACH ROW BEGIN <br />
<br />
DECLARE done INT DEFAULT FALSE; <br />
DECLARE temp1 VARCHAR(20); <br />
<br />
<br />
DECLARE cursor1 CURSOR FOR select sid from student where gpa&gt;3.5 and match(resume) against('database systems'); <br />
<br />
<br />
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; <br />
<br />
OPEN cursor1; <br />
<br />
read_loop: LOOP <br />
<br />
FETCH cursor1 into temp1; <br />
<br />
if doen THEN <br />
<br />
LEAVE read_loop; <br />
end if; <br />
<br />
insert into push values(temp1, new.cid, new.bname, new.jid, timestamp); <br />
<br />
end loop; <br />
<br />
close cursor1; <br />
end<br />
<br />
<br />
somebody helps me?]]></description>
            <dc:creator>James ZHAN</dc:creator>
            <category>Cursors</category>
            <pubDate>Thu, 08 Dec 2011 12:25:32 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,491708,491708#msg-491708</guid>
            <title>ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL  server version for the right syntax to use near '(id), (2 replies)</title>
            <link>http://forums.mysql.com/read.php?102,491708,491708#msg-491708</link>
            <description><![CDATA[ this is that table i want to create:<br />
<br />
create table UserDB (<br />
UID varchar(25) NOT NULL primary key (id),<br />
FName varchar(25),<br />
LName varchar(25),<br />
Password varchar(16),<br />
Country varchar(50),<br />
Email varchar(50),<br />
SQues varchar(50),<br />
Ans varchar(50),<br />
CellNos int,<br />
ts timestamp)  ENGINE=INNODB;<br />
<br />
<br />
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br />
but when ever i run this query it displays:<br />
<br />
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL  server version for the right syntax to use near '(id),<br />
FName varchar(25),<br />
LName varchar(25),<br />
Password varchar(16),<br />
Country varcha' at line 2]]></description>
            <dc:creator>PULKIT PATEL</dc:creator>
            <category>Cursors</category>
            <pubDate>Thu, 12 Jan 2012 07:11:12 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,490610,490610#msg-490610</guid>
            <title>1328 Incorrect number of FETCH variables (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,490610,490610#msg-490610</link>
            <description><![CDATA[ Getting error<br />
&quot;1328 Incorrect number of FETCH variables&quot;]]></description>
            <dc:creator>Wahab Hussain</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 25 Oct 2011 07:44:30 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,490569,490569#msg-490569</guid>
            <title>Should I use a Cursor in my Procedure (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,490569,490569#msg-490569</link>
            <description><![CDATA[ Hi there, <br />
<br />
I am wanting to use a procedure to perform a particular calculation based on the Eid number in the example below. When the Eid number is 1 add (Salary + Perks). When Eid is 2 add (Salary + Perks) * 2. So for the sample data below I may want to have 2 different calculations that will return two rows... Thats the basic concept.<br />
 <br />
Firstly, I'm not sure whether I should be using the curson construct? And secondly, when I run this code below (with the two selects) it only returns 1 row and I am wanting to return two rows (a row for each select statement).<br />
 <br />
I'm not sure whether I'm on the right track or if I should be using a different control structure? Do I need to use two cursors (as below) or can I use 1 cursor with two Fetch statements? Help!<br />
 <br />
Thanks, Mark <br />
<br />
<br />
DELIMITER $$; <br />
<br />
DROP PROCEDURE IF EXISTS `test`.`DemoCurs6`$$ <br />
<br />
CREATE PROCEDURE `test`.`DemoCurs6` () <br />
BEGIN <br />
DECLARE d INT DEFAULT 0; <br />
DECLARE id,sal,perk, Total INT; <br />
DECLARE name,city,desig VARCHAR(20); <br />
DECLARE cur CURSOR FOR SELECT * FROM Emp; <br />
DECLARE cur1 CURSOR FOR SELECT * FROM Emp; <br />
<br />
OPEN cur; <br />
<br />
FETCH cur INTO id,name,city,desig,sal,perk; <br />
SELECT Eid, Ename, City, Designation, Salary, Perk, (Salary + Perks) AS Total FROM Emp WHERE Eid = '1';<br />
 <br />
OPEN cur1; <br />
<br />
FETCH cur INTO id,name,city,desig,sal,perk; <br />
SELECT Eid, Ename, City, Designation, Salary, Perk, (Salary + Perks) * 2 AS Total FROM Emp WHERE Eid = '2';<br />
 <br />
CLOSE cur; <br />
CLOSE cur1; <br />
END$$ <br />
<br />
DELIMITER ;$$ <br />
<br />
Example Data <br />
<br />
Eid Name City Designation Salary Perks <br />
<br />
1 Rahul Delhi Main Manager 10300 853 <br />
2 Gaurav Mumbai Assistant 11100 853 <br />
3 Chandan Banglore Team Leader 15450 999 <br />
4 Tapan Pune Developer 20600 1111 <br />
5 Amar Chennai Developer 16000 1124]]></description>
            <dc:creator>Mark O'Donnell</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 25 Oct 2011 05:53:43 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,484994,484994#msg-484994</guid>
            <title>Unable to write a cursor inside a Stored Procedure (3 replies)</title>
            <link>http://forums.mysql.com/read.php?102,484994,484994#msg-484994</link>
            <description><![CDATA[ I am trying to write a cursor inside store procedure but it is giving me an error mentioning syntax error<br />
<br />
Create procedure test()<br />
begin<br />
insert into accounttype(accounttype) select distinct AccountType from temptableforbulkimport;<br />
<br />
select * from temptableforbulkimport;<br />
DECLARE done INT DEFAULT 0;<br />
DECLARE a CHAR(16);<br />
DECLARE b,c INT;<br />
<br />
<br />
DECLARE cur1 CURSOR FOR SELECT id,data FROM temptableforbulkimport;<br />
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;<br />
<br />
  OPEN cur1;<br />
  <br />
  read_loop: LOOP<br />
    FETCH cur1 INTO a, b;<br />
    FETCH cur2 INTO c;<br />
    IF done THEN<br />
      LEAVE read_loop;<br />
    END IF;<br />
    IF b &lt; c THEN<br />
      INSERT INTO test.t3 VALUES (a,b);<br />
    ELSE<br />
      INSERT INTO test.t3 VALUES (a,c);<br />
    END IF;<br />
  END LOOP;<br />
<br />
CLOSE cur1;<br />
end]]></description>
            <dc:creator>Wahab Hussain</dc:creator>
            <category>Cursors</category>
            <pubDate>Mon, 24 Oct 2011 13:19:23 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,483427,483427#msg-483427</guid>
            <title>You Have An  Error in you SQL #1064 (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,483427,483427#msg-483427</link>
            <description><![CDATA[ hello im tryin to do this stored procedure but i get this error, i seen it over and over and cannot find where is the error. The code is this:<br />
<br />
<br />
<br />
CREATE PROCEDURE legislacion.resumen (IN parameter_exp VARCHAR(10))<br />
<br />
BEGIN<br />
<br />
DECLARE var_expediente CHAR(10);<br />
DECLARE var_trami longtext;<br />
DECLARE var_trami2 longtext;<br />
<br />
<br />
set var_expediente= '195-PL-11';<br />
<br />
DECLARE origen CURSOR FOR SELECT identificador, descripcion, cabecera, tipo, descripciontipo, otro, orden, visualizar,internet From legislacion.maeid where tipo = 'OR' and visualizar = 'SI' order by descripcion;*/<br />
DECLARE tipo CURSOR FOR Select * From legislacion.maeid where tipo = 'NR' order by descripcion;<br />
DECLARE estado CURSOR FOR Select * From legislacion.maeid where tipo = 'EE' order by descripcion;<br />
DECLARE exped CURSOR FOR Select * From legislacion.expedientes where expediente = var_expediente;<br />
DECLARE ExpeYtramites CURSOR FOR SELECT tramiteexpediente.tramite,expedientes.expediente, expedientes.ley, expedientes.tema, expedientes.resumen, expedientes.idnorma, expedientes.idorigen, expedientes.idestado, expedientes.autores, expedientes.notas, expedientes.fecingreso, expedientes.idexpte, tramiteexpediente.fechatramite, tramiteexpediente.idtramite <br />
FROM expedientes INNER JOIN tramiteexpediente ON expedientes.idexpte = tramiteexpediente.idexpte WHERE expedientes.expediente =  var_exp <br />
ORDER BY expedientes.idnorma, expedientes.idexpte, tramiteexpediente.idtramite;<br />
<br />
CREATE TEMPORARY table extras(expediente varchar(10), tramites longtext);<br />
<br />
open ExpeYtramites;<br />
fetch ExpeYtramites into var_trami; <br />
<br />
while NOT veof do <br />
      begin <br />
      set var_trami2 = concat(var_trami2,concat('\n',var_trami));<br />
end WHILE;<br />
<br />
INSERT INTO extras VALUES (var_exp,var_trami2);<br />
<br />
open exped;<br />
open tipo;<br />
open origen;<br />
<br />
DECLARE Todosxx CURSOR FOR SELECT b.descripcion as Norma, d.descripcion as Origen, a.expediente, a.fecingreso, a.ley, a.tema, a.resumen, a.idnorma, a.IdEstado, a.autores, a.notas, c.Tramites FROM exped a, tipo b, extras c, origen d WHERE  a.idnorma = b.identificador AND a.expediente=c.expediente and a.IdOrigen=d.Identificador ORDER BY a.fecingreso, a.expediente;<br />
<br />
open Todosxxx;<br />
<br />
DECLARE Todos SELECT estado.descripcion as estado, Todosxx.* FROM Todosxx LEFT JOIN estado ON Todosxx.IdEstado = estado.Identificador;<br />
<br />
CLOSE exped;<br />
CLOSE tipo;<br />
CLOSE extras;<br />
CLOSE origen;<br />
CLOSE ExpeYtramites;<br />
CLOSE Todosxxx;<br />
<br />
END <br />
<br />
<br />
<br />
<br />
i hope you can help me. Regards to everyone]]></description>
            <dc:creator>jose luis antonio de figueiredo</dc:creator>
            <category>Cursors</category>
            <pubDate>Thu, 20 Oct 2011 13:53:15 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,483425,483425#msg-483425</guid>
            <title>You Have An  Error in you SQL #1064 (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,483425,483425#msg-483425</link>
            <description><![CDATA[ hello im tryin to do this stored procedure but i get this error, i seen it over and over and cannot find where is the error. The code is this:<br />
<br />
<br />
<br />
CREATE PROCEDURE legislacion.resumen (IN parameter_exp VARCHAR(10))<br />
<br />
BEGIN<br />
<br />
DECLARE var_expediente CHAR(10);<br />
DECLARE var_trami longtext;<br />
DECLARE var_trami2 longtext;<br />
<br />
<br />
set var_expediente= '195-PL-11';<br />
<br />
DECLARE origen CURSOR FOR SELECT identificador, descripcion, cabecera, tipo, descripciontipo, otro, orden, visualizar,internet From legislacion.maeid where tipo = 'OR' and visualizar = 'SI' order by descripcion;*/<br />
DECLARE tipo CURSOR FOR Select * From legislacion.maeid where tipo = 'NR' order by descripcion;<br />
DECLARE estado CURSOR FOR Select * From legislacion.maeid where tipo = 'EE' order by descripcion;<br />
DECLARE exped CURSOR FOR Select * From legislacion.expedientes where expediente = var_expediente;<br />
DECLARE ExpeYtramites CURSOR FOR SELECT tramiteexpediente.tramite,expedientes.expediente, expedientes.ley, expedientes.tema, expedientes.resumen, expedientes.idnorma, expedientes.idorigen, expedientes.idestado, expedientes.autores, expedientes.notas, expedientes.fecingreso, expedientes.idexpte, tramiteexpediente.fechatramite, tramiteexpediente.idtramite <br />
FROM expedientes INNER JOIN tramiteexpediente ON expedientes.idexpte = tramiteexpediente.idexpte WHERE expedientes.expediente =  var_exp <br />
ORDER BY expedientes.idnorma, expedientes.idexpte, tramiteexpediente.idtramite;<br />
<br />
CREATE TEMPORARY table extras(expediente varchar(10), tramites longtext);<br />
<br />
open ExpeYtramites;<br />
fetch ExpeYtramites into var_trami; <br />
<br />
while NOT veof do <br />
      begin <br />
      set var_trami2 = concat(var_trami2,concat('\n',var_trami));<br />
end WHILE;<br />
<br />
INSERT INTO extras VALUES (var_exp,var_trami2);<br />
<br />
open exped;<br />
open tipo;<br />
open origen;<br />
<br />
DECLARE Todosxx CURSOR FOR SELECT b.descripcion as Norma, d.descripcion as Origen, a.expediente, a.fecingreso, a.ley, a.tema, a.resumen, a.idnorma, a.IdEstado, a.autores, a.notas, c.Tramites FROM exped a, tipo b, extras c, origen d WHERE  a.idnorma = b.identificador AND a.expediente=c.expediente and a.IdOrigen=d.Identificador ORDER BY a.fecingreso, a.expediente;<br />
<br />
open Todosxxx;<br />
<br />
DECLARE Todos SELECT estado.descripcion as estado, Todosxx.* FROM Todosxx LEFT JOIN estado ON Todosxx.IdEstado = estado.Identificador;<br />
<br />
CLOSE exped;<br />
CLOSE tipo;<br />
CLOSE extras;<br />
CLOSE origen;<br />
CLOSE ExpeYtramites;<br />
CLOSE Todosxxx;<br />
<br />
END <br />
<br />
<br />
<br />
<br />
i hope you can help me. Regards to everyone]]></description>
            <dc:creator>jose luis antonio de figueiredo</dc:creator>
            <category>Cursors</category>
            <pubDate>Thu, 20 Oct 2011 11:57:13 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,437734,437734#msg-437734</guid>
            <title>Error Number 1415 (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,437734,437734#msg-437734</link>
            <description><![CDATA[ DELIMITER $$<br />
CREATE TRIGGER `AFTER_USER_INSERT` AFTER INSERT ON `USER`<br />
FOR EACH ROW<br />
BEGIN<br />
DECLARE NEW_USER_ID VARCHAR(25);<br />
DECLARE NEW_USER_TYPE ENUM('ADMIN','PM','QA');<br />
DECLARE NEW_SITE_ID VARCHAR(25);<br />
SELECT USER_ID AS NEW_USER_ID, USER_TYPE AS NEW_USER_TYPE,SITE_ID AS NEW_SITE_ID FROM `USER` WHERE USER_ID=NEW.USER_ID;<br />
IF(NEW_USER_TYPE&lt;&gt;&quot;PM&quot;)<br />
THEN<br />
INSERT INTO `SUPPLIERS`(SUPPLIER_ID,SUPPLIER_NAME,CONTACT_NAME,SALES_PHONE,SALES_FAX,SALES_EMAIL,ACTIVE)(SELECT GENERATE_SUPPLIER_ID(),SUPPLIER_NAME,CONTACT_NAME,SALES_PHONE,SALES_FAX,SALES_EMAIL,ACTIVE FROM `SUPPLIERS` WHERE USER_ID=NEW_SITE_ID);<br />
INSERT INTO `USER_PANTRY_LIST`(PRODUCT_ID,USER_ID,SUPPLIER_ID,CATEGORY,CODE,DESCRIPTION,COST,UNIT,STATUS,ACTIVE)(SELECT PRODUCT_ID,NEW.USER_ID,GENERATE_SUPPLIER_ID(),CATEGORY,CODE,DESCRIPTION,COST,UNIT,STATUS,ACTIVE FROM `USER_PANTRY_LIST` WHERE USER_ID=NEW_SITE_ID);<br />
END IF;<br />
END $$<br />
DELIMITER ;<br />
<br />
<br />
<br />
Getting an error as<br />
<br />
Not allowed to return a result set from trigger <br />
<br />
<br />
Can anyone help me to find the solution]]></description>
            <dc:creator>Janarthanan S</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 25 Oct 2011 05:56:22 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,434618,434618#msg-434618</guid>
            <title>PL/SQL or cursors help (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,434618,434618#msg-434618</link>
            <description><![CDATA[ I need to execute code like this:<br />
<br />
select COUNT(*) FROM table_name WHERE table_name.field1 IS NULL;<br />
select COUNT(*) FROM table_name WHERE table_name.field2 IS NULL;<br />
...<br />
select COUNT(*) FROM table_name WHERE table_name.field90 IS NULL;<br />
<br />
How can I automate it with cursors or PL/SQL? I have tried make cursor, but it didn't work.<br />
<br />
Here is how you can get field1-90:<br />
select column_name from information_schema.columns where table_name='tablename';]]></description>
            <dc:creator>NN UU</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 20 Sep 2011 01:35:04 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,433955,433955#msg-433955</guid>
            <title>ERROR 1064 (42000) (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,433955,433955#msg-433955</link>
            <description><![CDATA[ CREATE TABLE cliente(rut VARCHAR(10)  not null ,nombre VARCHAR(100)  not null ,domicilio VARCHAR(100) not null,provincia VARCHAR(50) not null,PRIMARY KEY(rut))ENGINE=INNODB;<br />
<br />
<br />
<br />
<br />
CREATE PROCEDURE insert_cliente(in rutr VARCHAR(10),in nombrer VARCHAR(100),in domicilior VARCHAR(100),in provinciar VARCHAR(50))<br />
BEGIN<br />
 DECLARE bandera BOOLEAN;<br />
 DECLARE validar BOOLEAN DEFAULT FALSE;<br />
 DECLARE rutc VARCHAR(10);<br />
 DECLARE nombrec VARCHAR(100);<br />
 DECLARE domicilioc VARCHAR(100);<br />
 DECLARE provinciac VARCHAR(50);<br />
 DECLARE cur_1 CURSOR FOR SELECT rut,nombre,domicilio,provincia FROM almacen.cliente;<br />
 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET bandera = TRUE;  <br />
 OPEN cur_1;<br />
 cur_1:LOOP<br />
    FETCH cur_1 INTO rutc,nombrec,domicilioc,provinciac;<br />
    IF bandera THEN<br />
      LEAVE cur_1;<br />
    END IF;<br />
    IF rutc=@rutr THEN<br />
       SET @mensaje = 'CLIENTE YA EXISTE ';      <br />
       SELECT @mensaje,rutc,' ',nombrec,' ',domicilioc,' ',provinciac;   <br />
       SET validar = TRUE;           <br />
    END IF;<br />
 END LOOP cur_1;<br />
 CLOSE cur_1;<br />
 IF (validar = FALSE) THEN<br />
        INSERT INT0 almacen.cliente(rut,nombre,domicilio,provincia) VALUES (rutr, nombrer, domicilior, provinciar);<br />
 END IF; <br />
END]]></description>
            <dc:creator>Francisco Hernan</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 13 Sep 2011 08:41:43 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,433893,433893#msg-433893</guid>
            <title>Can I Write Two cursors one inside another (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,433893,433893#msg-433893</link>
            <description><![CDATA[ I want to write two cursors One inside another. Both are used to insert values into to a table. But my requirement, While the outer procedure executes  and fetches one value the inner procedure executes and should get 5 values. This means that the insert statement will execute five times for one value of outer cursor and then the execution goes back to outer procedure.<br />
Do I have to declare two continue handler variable for two procedures. Because any how I am going use loop. <br />
<br />
So is it possible. Any One Please suggest.]]></description>
            <dc:creator>ragen sol</dc:creator>
            <category>Cursors</category>
            <pubDate>Mon, 12 Sep 2011 05:27:23 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,433812,433812#msg-433812</guid>
            <title>getting total count (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,433812,433812#msg-433812</link>
            <description><![CDATA[ I am trying to get a total of each statusType for each agent..<br />
<br />
example of data in accts table (there are more columns, but I'm only concerned with these 2):<br />
<br />
<br />
agent        statusType<br />
Kelly          New<br />
Tom          No Info<br />
Kelly          Active<br />
Kelly          New<br />
Kelly          Exhausted<br />
Mary          Sold<br />
Mary          New<br />
<br />
<br />
Data is all in one table called accts.<br />
<br />
I would like something similar to this as my output:<br />
Kelly:<br />
New  2<br />
Active 1<br />
Exhausted 1<br />
........<br />
<br />
Any help would be greatly appreciated.]]></description>
            <dc:creator>Kelly Brace</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 13 Sep 2011 08:12:54 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,432103,432103#msg-432103</guid>
            <title>Cursor Problems (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,432103,432103#msg-432103</link>
            <description><![CDATA[ I'm working on my first cursor right now and can't get it right. Running the cursor I keep getting a syntax error on line 2.  Any help would be appreciated.<br />
<br />
begin<br />
DECLARE post_id INT;<br />
DECLARE v_not_found BOOL default FALSE;<br />
        DECLARE csr_pst CURSOR FOR <br />
            SELECT ID<br />
            FROM  wp_353qq6_posts<br />
            WHERE post_title LIKE  '%English%'<br />
            AND post_parent =  '0';<br />
        DECLARE continue handler<br />
            for not found<br />
            set v_not_found := TRUE;<br />
        DECLARE exit handler<br />
            for sqlexception<br />
            close csr_pst;<br />
        open csr_pst;<br />
        cursor_loop: loop<br />
            fetch csr_pst into<br />
               post_id<br />
            ;<br />
            if v_not_found then<br />
                leave cursor_loop;<br />
            end if;<br />
            INSERT INTO wp_353qq6_term_relationships VALUES (post_id,666,0);<br />
        end loop;<br />
        close csr_pst;<br />
    end;<br />
<br />
<br />
(I'm totally new to MySQL in regards to anything this complicated.  Thanks to Roland for at least giving me somewhere to start! <a href="http://rpbouman.blogspot.com"  rel="nofollow">http://rpbouman.blogspot.com</a>)]]></description>
            <dc:creator>Emiliano Jordan</dc:creator>
            <category>Cursors</category>
            <pubDate>Sat, 27 Aug 2011 21:40:55 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,431290,431290#msg-431290</guid>
            <title>re-opening a cursor (1 reply)</title>
            <link>http://forums.mysql.com/read.php?102,431290,431290#msg-431290</link>
            <description><![CDATA[ Hi,<br />
Is it possible to reopen a cursor after it has been closed.<br />
My SP has a cursor open-fetch-close inside a loop.<br />
It fetches only in the first pass of the loop.<br />
Please take a look and advice.<br />
<br />
<pre class="bbcode">
BEGIN

declare new_time_id int(10);

declare is_last bool default false;
declare each_day_id, each_time_id int(10);
declare each_start_time, each_end_time, each_duration varchar(5);

DECLARE done BOOLEAN DEFAULT FALSE;
DECLARE c CURSOR FOR SELECT id, start_time, end_time, duration
                     FROM qrt_times
                     WHERE campaign_id = in_campaign_id and day_id = in_day_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=TRUE;


START TRANSACTION;

-- Iterate over a comma delimited string of numbers. Like '1,2'
def_loop: LOOP

  if locate(',',in_day_ids) = 0 then
    set each_day_id = in_day_ids;
    set is_last = true;
  else
    set each_day_id = substring(in_day_ids, 1, locate(',', in_day_ids)-1);
    set in_day_ids = substring(in_day_ids, locate(',', in_day_ids)+1);
  end if;


  -- Iterate over the cursor of time records for the day to copy from
  OPEN c;

  dep_loop: LOOP

    FETCH c INTO each_time_id, each_start_time, each_end_time, each_duration;

    IF done THEN
      LEAVE dep_loop;
    END IF;

    -- Processing done here

  END LOOP dep_loop;

  CLOSE c;


  if is_last then
    leave def_loop;
  end if;

end loop def_loop;

COMMIT;


END $$

</pre>]]></description>
            <dc:creator>Raj Chak</dc:creator>
            <category>Cursors</category>
            <pubDate>Tue, 23 Aug 2011 08:08:36 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,427190,427190#msg-427190</guid>
            <title>1064 Error on Importing SQL Database file (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,427190,427190#msg-427190</link>
            <description><![CDATA[ I have exported my database from a PHP My Admin version 3.4 1 and now i am trying to import that file but it giving me a 1064 error in syntax.<br />
<br />
See here<br />
<br />
***************************************************<br />
Error<br />
<br />
SQL query:<br />
<br />
INSERT INTO `wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (181, 1, '2010-12-13 16:03:00', '2010-12-13 16:03:00', '&lt;strong&gt;Touchscreen Pino Polo Mobile Phone Specifications and Review&lt;/strong&gt;\r\n\r\nToday we are about to tell some of the specifications of the latset mobile phone launced by a Singapore based company.This Pine Polo mobile phone has all the features.You have everything in this mobile phone like internet.It also works with OPera mini browser, now you can browse anything on internet on this mobile just like the Laptop or a Personal Computer.It has great features and applications like Snaptu, Snaptu is one of the most famous applications which helps you t[...]<br />
<br />
MySQL said: Documentation<br />
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''&amp;lt;strong&amp;gt;Touchscreen Pino Polo Mobile Phone Specifications and Review&amp;lt;/strong&amp;gt;\r' at line 2 <br />
*************************************************************<br />
<br />
Can anyone help me in solving this MySQL error so that i can successfully import my database.]]></description>
            <dc:creator>jhon Preston</dc:creator>
            <category>Cursors</category>
            <pubDate>Sun, 17 Jul 2011 16:56:07 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?102,427019,427019#msg-427019</guid>
            <title>Error in MySql script (no replies)</title>
            <link>http://forums.mysql.com/read.php?102,427019,427019#msg-427019</link>
            <description><![CDATA[ Hi,<br />
I am trying to execute a script from my Linux server and it throws below error. When I execute this from mysql workbench, it works fine.<br />
<br />
[mysql@dev03 ~]$ mysql --protocol=tcp -u root -pxxxx &lt; /tmp/provisioning_db_dump_04042011.sql<br />
ERROR 1064 (42000) at line 4274: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '// DELIMITER ;<br />
<br />
<br />
DROP PROCEDURE IF EXISTS `spGetOffersForAccountId`;<br />
<br />
<br />
Can someone please help?<br />
<br />
Thanks.]]></description>
            <dc:creator>Kumar Vikram Dev</dc:creator>
            <category>Cursors</category>
            <pubDate>Fri, 15 Jul 2011 14:51:12 +0000</pubDate>
        </item>
    </channel>
</rss>
