Solved

Mysql Stored Procedure Dynamic Paramter For Cursor

Posted on 2009-07-14
1
1,793 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
selector:validator cookies 4 30
Accessing specific element - DOM PHP HTML 8 36
php error 27 31
SQL 2008 R2 2 6
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

821 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