MySQL Forums
Forum List  »  Stored Procedures

Drop statement in stored procedure
Posted by: tomas bar
Date: January 28, 2010 10:02AM

Hi,

I'm trying to write a stored procedure that deletes all triggers of a database by retrieving the trigger names form the INFORMATION_SCHEMA.triggers table. The database name is the input parameter of the stored procedure. I've pasted the code of the procedure here below:

##### CODE

DELIMITER $$
DROP PROCEDURE IF EXISTS deleteAllTriggers$$
CREATE PROCEDURE deleteAllTriggers (databaseName TEXT)


BEGIN
DECLARE done INT DEFAULT 0;
DECLARE triggerName TEXT;
DECLARE statem TEXT;
DECLARE cur1 CURSOR FOR SELECT trigger_name from INFORMATION_SCHEMA.triggers where trigger_schema=databaseName;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
OPEN cur1;
loop1: LOOP
FETCH cur1 INTO triggerName;
IF done=1 THEN
LEAVE loop1;
END IF;
drop trigger triggerName;
END LOOP loop1;
CLOSE cur1;

END$$

####

However, on execution, I get the message

"ERROR 1360 (HY000): Trigger does not exist"

The problem in my stored procedure is (I think) the command:

drop trigger triggerName;

where triggerName is taken literally and not as a variable.
Do you have any suggestions as to how I can solve this problem?
Many thanks

Options: ReplyQuote


Subject
Views
Written By
Posted
Drop statement in stored procedure
4575
January 28, 2010 10:02AM
1671
January 28, 2010 10:33AM
1571
January 29, 2010 04:35AM


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.