MySQL Forums
Forum List  »  Stored Procedures

SP syntax error??
Posted by: Grace Cortright
Date: March 27, 2014 04:08PM

So I'm pretty new to stored procedures in MySQL. I've read the docs, and read tutorials to make this, my first stored procedure. Trouble is I get a syntax error when I run it, and I cannot for the life of me figure out why. Code and error below. Can any gurus on here point out my (probably obvious) error?? The rest of the code may be junk, but I wouldn't know because it is hanging at the cursor declaration.

DROP PROCEDURE IF EXISTS getCheaters;
DELIMITER $$;
CREATE PROCEDURE getCheaters()
BEGIN

DECLARE id_val INT (11);
DECLARE first_name_val VARCHAR (255);
DECLARE last_name_val VARCHAR(255);
DECLARE file_name VARCHAR(255);

DECLARE no_more_rows BOOLEAN;
DECLARE loop_cntr INT DEFAULT 0;
DECLARE num_rows INT DEFAULT 0;

DECLARE userCursor FOR
SELECT last_name, first_name, users.id
FROM users JOIN documents ON (users.id = documents.user_id)
JOIN licenses ON (licenses.user_id = users.id)
WHERE multi_user_license_id IS NULL
GROUP BY last_name, first_name
HAVING count(documents.title) > 60;


DECLARE CONTINUE HANDLER FOR NOT FOUND
SET no_more_rows = TRUE;


OPEN userCursor;
SELECT FOUND_ROWS() INTO num_rows;


read_loop: LOOP
FETCH userCursor INTO id_val, first_name_val, last_name_val;

/*file_name = first_name_val + " " + last_name_val + ".csv";

SELECT last_name, first_name, documents.title, created_at, status
from users
join documents on (users.id = documents.user_id)
where users.id = id_val
order by created_at desc
into OUTFILE file_name
FIELDS TERMINATED BY ',';*/

IF no_more_rows THEN
CLOSE userCursor;
LEAVE read_loop;
END IF;
SET loop_cntr = loop_cntr + 1;
END LOOP;

END$$
DELIMITER;


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 'DELIMITER' at line 1
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 'FOR
SELECT last_name, first_name, users.id
FROM users JOIN docum' at line 13

THANK YOU!

Options: ReplyQuote


Subject
Views
Written By
Posted
SP syntax error??
2497
March 27, 2014 04:08PM
1210
March 27, 2014 08:26PM
1159
March 28, 2014 10:47AM
1150
March 28, 2014 12:04PM
1208
April 04, 2014 01:49PM
1164
March 28, 2014 01:09AM
1272
March 28, 2014 10:41AM
1140
March 28, 2014 12:11PM
1144
March 30, 2014 11:04PM
1070
April 04, 2014 01:02PM
1085
April 04, 2014 01:36PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.