List:General Discussion« Previous MessageNext Message »
From:SGreen Date:February 9 2006 2:24pm
Subject:Re: Passing db names to a stored proc in MySQL 5
View as plain text  
Rory McKinley <rorym@stripped> wrote on 02/09/2006 07:37:17 AM:

> Hello List
> 
> I have tried dynamically assigning a database name to a stored proc via 
> its parameter list:
> 
> CREATE STORED PROCEDURE testStoredProc (IN test_db_name CHAR)
>    BEGIN
>    SELECT * FROM test_db_name.test_table;
>    END;
> 
> MySQL does not resolve test_db_name to the value passed in the 
> parameter, and the query fails because there is no database with that 
name.
> 
> Is there any way around this?
> 
> Regards
> 
> Rory
> 

Use a "prepared statement". Build your SQL statement as a string, prepare 
it, and execute it. It's all right there in the manual.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine


Thread
Passing db names to a stored proc in MySQL 5Rory McKinley9 Feb
  • Re: Passing db names to a stored proc in MySQL 5Martijn Tonies9 Feb
    • Re: Passing db names to a stored proc in MySQL 5Peter Brawley12 Feb
  • Re: Passing db names to a stored proc in MySQL 5SGreen9 Feb
    • Re: Passing db names to a stored proc in MySQL 5Martijn Tonies9 Feb
    • Re: Passing db names to a stored proc in MySQL 5Rory McKinley9 Feb
      • Re: Passing db names to a stored proc in MySQL 5SGreen9 Feb
        • Re: Passing db names to a stored proc in MySQL 5Rory McKinley10 Feb
        • Re: [SOLVED]Passing db names to a stored proc in MySQL 5Rory McKinley10 Feb
      • Re: Passing db names to a stored proc in MySQL 5Peter Brawley11 Feb