0

This is what i tried. I have table called crop, and want to create stored procedure of selecting all in that table.

Here is the error i got:

MariaDB [sample]> CREATE PROCEDURE AllFarmers
    -> AS
    -> SELECT * FROM crop
    -> GO;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AS SELECT * FROM crop GO' at line 2

Thank you for your help in advance

3
  • Looks to me like you're coming from the SQL Server world. The MySQL stored procedure syntax is different. Read this to see an example. dev.mysql.com/doc/connector-net/en/… Maddening, isn't it? Commented Sep 17, 2019 at 11:54
  • Check this: stackoverflow.com/a/15786615/2469308 Commented Sep 17, 2019 at 11:56
  • Perfectly works. Thanks Madhur Commented Sep 17, 2019 at 12:52

2 Answers 2

3

I saw that the syntax is not correct on your procedure. You should replace AS by BEGIN and GO by END.

I put an example here

delimiter //
CREATE PROCEDURE AllFarmers ()
BEGIN
SELECT * FROM Test;
END;
//
call allfarmers()

Try it and tell me if there is any problem

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

1 Comment

CREATE PROCEDURE AllFarmers () SELECT * FROM Test; is the shortest you can write in MySQL and MariaDB.. As single statements does not need to use BEGIN / END blocks and also there for not need to use a DELIMITER
0

Might also be worth mentioning you can a drop to the start in case the stored procedure already exists:

DROP PROCEDURE IF EXISTS `AllFarmers`

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.