Jump to content

Stored Procedures


djp1988

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 ===

Link to comment
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

Link to comment
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

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

  • 3 months later...

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;

Link to comment
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
Link to comment
Share on other sites

  • 5 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...