0

I'm trying to write a stored procedure to insert data into a table.

The procedure which I wrote is:

CREATE PROCEDURE insrtem (IN x int(3),IN y varchar(3))

BEGIN

    insert into emp (empid,empname) values (x,y);
END;

but it doesn't work.

What's the correct syntax?

1
  • You should specify what the error is. Commented Mar 7, 2015 at 2:53

1 Answer 1

2

In MySQL, you often need a delimiter statement, so that is my first guess:

DELIMITER $$
CREATE PROCEDURE insrtem (IN in_x signed, IN in_y varchar(3))
BEGIN
    insert into emp (empid, empname)
        values (in_x, in_y);
END;
DELIMITER ;

Notice I changed the names of the parameters to have an in prefix. This helps distinguish the parameters from columns in the table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.