MySQL Forums
Forum List  »  Stored Procedures

create database name with variables
Posted by: Th. Schütt
Date: October 29, 2005 06:06AM

hello,

I must create different databases with a "stored procedure" and variables don´t know the names of it.

I test the following options :
CREATE PROCEDURE newdb (in myno VARCHAR(4), in myyear VARCHAR(4))
BEGIN
DECLARE myname CHAR(4);
SET myname = concat(myno, myyear);
CREATE DATABASE myname;
END;
--> MySQL created a database named "myname"

Change the follwing line in the above example :
SET @myname = concat(myno, myyear);
CREATE DATABASE @myname;
--> I get an "Syntax"-Error in Mysql-Querry.

Last option :
CREATE PROCEDURE newdb (in myno VARCHAR(4), in myyear VARCHAR(4))
BEGIN
SET @myno = myno;
SET @myyear = myyear;
SET @insert_query = concat('create database ', @myno, @ myyear);
PREPARE stmt1 FROM @insert_query;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
END;
--> ..."CREATE DATABASE not allowed.." (in the Prepare-Statement)

So, what I have to do, do create different databases with different variables names,like

- 0012005
- 0012006
- 0032007
- M012005 ?

Options: ReplyQuote


Subject
Views
Written By
Posted
create database name with variables
4109
October 29, 2005 06:06AM
3544
November 01, 2005 01:21AM


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.