Mysql Stored Procedures - Returning Message
It's a bit silly asking homework questions here, however I'm genuinely stumped as to what this question is asking.
Create a stored procedure to add results. The procedure should take four (4) parameters. These are; The student's name (first and last), the name of the apparatus and the score. When the data has been inserted, return a message to the user advising that the data has been inserted. Name the procedure, addresults_xxx(), where xxx is to be replaced by your initials. Include the date.
I've highlighted the part in bold that I don't understand.
This is what I have so far.
DELIMITER //
CREATE PROCEDURE addresults_JB( IN student_first_name VARCHAR(20),
IN student_last_name VARCHAR(20),
IN apparatus_name VARCHAR(20),
IN test_result INT)
BEGIN
DECLARE student_id INT;
DECLARE apparatus_id开发者_运维百科 INT;
SELECT studentid INTO student_id
FROM tblstudents
WHERE studentfirstname = student_first_name
AND studentlastname = student_last_name;
SELECT apparatusid INTO apparatus_id
FROM tblapparatus
WHERE apparatusname = apparatus_name;
INSERT INTO tblresults (studentid, apparatusid, result, date_added)
VALUES (student_id, apparatus_id, test_result, NOW());
END //
DELIMITER ;
How can I return a message from a stored procedure?
This will work, unfortuately I don't think there is a Print command like in MS SQL.
select "Procedure Completed" as "Result";
You could do: SELECT "The data has been inserted"
精彩评论