List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:June 13 2001 3:47am
Subject:Re: user variables
View as plain text  
At 3:16 AM +0200 6/13/01, Luis A. Fdez. de Retana Aguirre wrote:
>  My problem is about users variables. I want to do
>a script to create a database so:
>   SET @dbname:="mydbname";
>   CREATE DATABASE @dbname;    #      <------ Don´t
>   CREATE DATABASE (SELECT @dbname);# <------ Don´t

As the manual says, user-defined variables may be used wherever
an expression is legal.  However, expressions aren't legal database
names, so what you're trying to do isn't legal.

If you're trying to write a script, perhaps you can use variable
substitution at the level of your scripting language, rather than
at the SQL level.  For example:

#! /bin/sh


mysql <<EOF

>I have tried to define @dbname=mydbname directly
>but it blocks.

Paul DuBois, paul@stripped
user variablesLuis A. Fdez. de Retana Aguirre13 Jun
  • Re: user variablesPaul DuBois13 Jun