Reputation: 2325
I'm trying for the first time to create a simple Stored Procedure. I have scouted the net and found several of tutorials, but keep getting some errors when I try to create an INSERT procedure?
I'm trying this:
DELIMITER //
CREATE PROCEDURE my_insert(IN fname VARCHAR(50),IN lname VARCHAR(50))
BEGIN
SET @fname=fname;
SET @lname=lname;
PREPARE STMT FROM
"INSERT INTO users(fname,lname) VALUES (?,?)";
EXECUTE STMT USING @fname,@lname;
END
I get this error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'my_insert(IN fname VARCHAR(50),IN lname VARCHAR(50)) BEGIN SET @fname=fn' at line 1
Hoping for help and thanks in advance :-)
Upvotes: 0
Views: 210
Reputation: 8741
you used " instead of ' . Thats the error in your query. Correct query is given below
DELIMITER //
CREATE PROCEDURE my_insert(IN fname VARCHAR(50),IN lname VARCHAR(50))
BEGIN
SET @fname=fname;
SET @lname=lname;
PREPARE STMT FROM
'INSERT INTO users(fname,lname) VALUES (?,?)';
EXECUTE STMT USING @fname,@lname;
END //
Or you can simply use
DELIMITER //
CREATE PROCEDURE my_insert(IN fname VARCHAR(50),IN lname VARCHAR(50))
BEGIN
INSERT INTO users(`fname`,`lname`) VALUES (fname,lname);
END //
Upvotes: 1