Jump to content
djp1988

Stored Procedures

Recommended Posts

Hi all the following is taken from mysql.com

CREATE PROCEDURE simpleproc (OUT param1 INT)   BEGIN   SELECT COUNT(*) INTO param1 FROM t;   END;

What i wanted to know is the syntax to select a database for this query, as the mysql error message for this is:===#1046 - No database selected ===

Share this post


Link to post
Share on other sites

What is your complete code?

Share this post


Link to post
Share on other sites

I don't have one, I am just try to manually make a stored procedure, and I can't because i can't find out how to select a database to use in the sql

Share this post


Link to post
Share on other sites

I mean what is the query you are trying to use at the moment to select the DB? It should be something like

USE database

Share this post


Link to post
Share on other sites

I'm not, I have this query:

CREATE PROCEDURE simpleproc (OUT param1 INT)   BEGIN   SELECT COUNT(*) INTO param1 FROM t;   END;

And the mysql error says I need to add into the SQL the syntax to select a database to use, so i don't understand

Share this post


Link to post
Share on other sites

Did you try USE?

USE database;CREATE PROCEDURE simpleproc (OUT param1 INT)   BEGIN   SELECT COUNT(*) INTO param1 FROM t;   END;

Where database is your db name.

Share this post


Link to post
Share on other sites

USE database;CREATE PROCEDURE simpleproc (OUT param1 INT) BEGIN SELECT COUNT(*) INTO param1 FROM t; END;if your table contain two field id and nameu should writeCREATE PROCEDURE simpleproc (OUT param1 INT) BEGIN SELECT COUNT(id) INTO param1 FROM t; END;you can write name instand of id;

Edited by fasttrack

Share this post


Link to post
Share on other sites
Hi all the following is taken from mysql.com
CREATE PROCEDURE simpleproc (OUT param1 INT)   BEGIN   SELECT COUNT(*) INTO param1 FROM t;   END;

What i wanted to know is the syntax to select a database for this query, as the mysql error message for this is:===#1046 - No database selected ===

try something like this SELECT COUNT(*) = @var FROM t@var should be your param1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...