Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stored procedure first look

Status
Not open for further replies.

gcaramia

Programmer
Oct 30, 2003
185
IT
I installed MySQL 5.0 alpha and tried for my first time stored procedures.
I begin with this:

CREATE PROCEDURE `myfirstproc`(in codx char(16),OUT descr char(50))
BEGIN
select description into descr from artics where cod = codx;
END

then

call myfirstproc("mycod",@retreivedDescription)
select @retreivedDescription

it works!!

Now a little step behind.

I should like to parametrize the table name. How can i do?

I tried somthing like:

CREATE PROCEDURE `myfirstproc`(IN codx char(16), IN TableName char(20), OUT descr char(50))
BEGIN
select description into descr from (MyTableName) where cod = codx;
END

I tried a lot of forms but the 'call myfirstproc' always fall in error.

Can SomeBody help me?
Thanks

Giovanni Caramia
 
May be that it is not possible parametrize table's name because DBMS precompile stored procedure?
 
Drop procedure if exists myfirstproc //

CREATE PROCEDURE myfirstproc (IN codx char(16), IN TableName char(20), OUT descr char(50))
BEGIN
select description into descr from TableName where cod = codx;
END;
//

IF you still see error, you may probably add a databasename,
which you use, before the tablename like:

call myfirstproc('mycod','test.artics',@result);

Hope it'll work.
 
Thanks for your replay.
But ...
Sorry it doesnt work!

Giovanni Caramia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top