0

I am trying to write a script that creates and calls a stored procedure named spInsertNewCategory and getting this error on the following code:

CREATE PROCEDURE spInsertCategory(category_name VARCHAR(50))
BEGIN
INSERT INTO Categories
VALUES (@CategoryName);
END

enter image description here

Any help would be appreciated.

Also getting an error on the 50 that says it is expecting '(' or SELECT. This is the first time I have been completely lost on something. What am I doing wrong?

The code is supposed to be a single input parameter with no return value and I just don't know what to write.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Ben
  • 9
  • 1
  • My apologies, the formatting of this post looks off. I don't think it's supposed to look like that. This is my first post here. I hope it is at least understandable. – Ben Nov 16 '22 at 03:17
  • 1
    Add the DELIMITER // before the statement and at the end – Punit Gajjar Nov 16 '22 at 03:35
  • 1
    You are using category_name as the parameter name then your query is referencing a global variable called CategoryName (via the @ symbol). Check out https://stackoverflow.com/questions/5039324/creating-a-procedure-in-mysql-with-parameters for an example of a simple stored procedure such as you are trying to create. – Sam M Nov 16 '22 at 03:35

2 Answers2

1

You are using the syntax of MySQL, in SQL Server its:

CREATE PROCEDURE spInsertCategory @CategoryName VARCHAR(50)
AS
BEGIN
INSERT INTO Categories
VALUES (@CategoryName);
END 
Dale K
  • 25,246
  • 15
  • 42
  • 71
D T
  • 3,522
  • 7
  • 45
  • 89
0

Add the DELIMITER // before the statements incase you are executing the statement

DELIMITER //
CREATE PROCEDURE spInsertCategory(IN category_name VARCHAR(50))
BEGIN
INSERT INTO Categories
VALUES (@CategoryName);
END//
DELIMITER ;

If the above doesn't work Try with the below steps!

Go To your Routine tab in MySQL, Click on Add Routin and follow these steps

enter image description here

Punit Gajjar
  • 4,937
  • 7
  • 35
  • 70