From: Peter Brawley Date: April 27 2009 3:22am Subject: Re: dynamic table name List-Archive: http://lists.mysql.com/mysql/217281 Message-Id: <49F52506.6040507@earthlink.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------050509070908020008060908" --------------050509070908020008060908 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit > DECLARE my_table CHAR(32); > SET my_table = UNIX_TIMESTAMP(); > > CREATE TABLE my_table See the manual page for PREPARE. PB ----- Mauricio Tellez wrote: > Hi, I'm creating a stored procedure and inside this procedure I have a > CREATE TABLE statement, but I want to make a dynamic table for this table. > Also, this table name is passed as a parameter for another SP, but instead > of get the value of the parameter, I got the name of the parameter. For > example: > > CREATE PROEDURE my_test_sp() > BEGIN > DECLARE my_table CHAR(32); > SET my_table = UNIX_TIMESTAMP(); > > CREATE TABLE my_table ( > id int, > name char(64)); > > call nested_sp(my_table); > END > > CREATE PROCEDURE nested_sp(my_table CHAR(32)) > BEGIN > INSERT INTO my_table 1, 'John Doe'; > END > > of course nested_sp is very silly, but the idea is the same. When I run > this, I found that there is no table name like '20080426...' but I get a > table 'my_table', how can I fix this? > > > ------------------------------------------------------------------------ > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 8.0.238 / Virus Database: 270.12.4/2081 - Release Date: 04/26/09 09:44:00 > > --------------050509070908020008060908--