Question

I created a procedure but when i tried to execute its giving an error that no database is selected.Here is my procedure.

  DELIMITER $$  
   create procedure myproced  
   as  
   declare arpt varchar(10);  
   declare num int;  
   BEGIN  
   use lookup;  
   create temporary table lookup.airportname as (select distinct name from lookup.airpot);  
   select count(*) into num from (select * from airportname);  
   END;  
   $$  

I have also seen some posts in stack overflow regarding the same problem.They had mentioned to select the database from drop down if u are working with mysql workbench.I am using mysql query browser.Even i had mentioned use database.But still it is prompting error.

Was it helpful?

Solution 2

Use USE statement outside the procedure. Not required inside.

DELIMITER $$  
USE [DAtabase Name]$$
DELIMITER $$  
   create procedure myproced  
   as  
   declare arpt varchar(10);  
   declare num int;  
   BEGIN  
   create temporary table lookup.airportname as (select distinct name from lookup.airpot);  
   select count(*) into num from (select * from airportname);  
   END;  
   $$  

OTHER TIPS

Try adding this line to your procedure declaration :

create procedure `lookup`.myproced

This might solve your problem, I use this kind of declaration with my own procedures and never got any such problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top