Solved

Mysql Stored Procedure Dynamic Paramter For Cursor

Posted on 2009-07-14
1
1,790 Views
Last Modified: 2013-12-13
Hi to all,
I want to pass a db name ChangeCreationDate function to alter all tables of db which passed via parameters.
But i take an error Unknown database 'dbName'.. I can't use database name dynamically. How can i do this?

Thanks
DELIMITER $$
 
DROP PROCEDURE IF EXISTS `ChangeCreationDate`$$
 
CREATE  PROCEDURE `ChangeCreationDate`(dbName VARCHAR(50))
BEGIN
  DECLARE done INT DEFAULT 0;
  DECLARE tableName TINYTEXT;
  DECLARE cur1 CURSOR FOR SHOW TABLES FROM dbName; //i need at here db name passes via parameter.
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
  OPEN cur1;
  REPEAT
    FETCH cur1 INTO tableName;
    SELECT tableName;
    IF NOT done THEN
		IF SUBSTRING(tableName,1,3)='fd_' THEN
			IF v5_versioning.ColumnIsExists(dbName,tableName,'creation_date') THEN
				SET @ssql=CONCAT('ALTER TABLE ',dbName,'.',tableName,' CHANGE creation_date created_date TIMESTAMP');
				SELECT @ssql;
				/*
				PREPARE stmt FROM @ssql;
				EXECUTE stmt;
				*/
			END IF;
		END IF;
    END IF;
  UNTIL done END REPEAT;
  CLOSE cur1;
END$$
 
DELIMITER ;

Open in new window

0
Comment
Question by:erenpasa
1 Comment
 

Accepted Solution

by:
erenpasa earned 0 total points
ID: 24849999
I've change the line with
DECLARE cur1 CURSOR FOR SELECT table_name FROM information_schema.TABLES WHERE table_schema=dbName;

it's okay.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question