简体   繁体   中英

mysql stored procedure, use column name as an argument

i have here a table of tapes with 3 fields:

Tapes

  TapesID      Title       Qty

     T1     BatDog         3

     T2    UnderCat        2

     T3    IronMouse       1

     T4    Boys Zone       1

     T5    RoboCat         1

i want to create a stored procedure that extract and displays specific id's of tape by entering tape title as argument to the procedure. The procedure should be called list_tspec_id.

can u help me out?im having a hard time with this...

here's my code but it's not right:

create procedure tapesid
@columnname varchar
AS
begin
select @columnname from tapes
end 
exec tapesid 'title'

You've tagged this as MySQL , so... here's a stored procedure, though it's unclear from your example what you're really wanting it to do or why.

The variables passed into a stored procedure as arguments don't use '@' in front of them.

DELIMITER $$

CREATE PROCEDURE list_tspec_id (IN my_title VARCHAR(254))
BEGIN

  SELECT TapesID, Title, Qty FROM Tapes WHERE Title = my_title;

END $$
DELIMITER ;

then...

mysql> CALL list_tspec_id('BatDog');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM