mayan anger
mayan anger

Reputation: 2702

Sql Syntax Error, on CREATE PROCEDURE

Work with mysql on phpMyAdmin

SQL :

drop PROCEDURE if EXISTS mi;

CREATE PROCEDURE mi()  //<-- line 3
BEGIN
  INSERT INTO User ( `name` , `password` ) VALUES ('value1', 'value2');
  SET out_param = LAST_INSERT_ID();
END

CALL mi();

the 'drop' is for multi testing

we have table User there are id primary key , name varchar, password varchar

Error :

1064 - 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 '' at line 3

thanks for any help !

Upvotes: 0

Views: 215

Answers (2)

Fahad Anjum
Fahad Anjum

Reputation: 1256

By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server. To redefine the mysql delimiter, use the delimiter command.

You can read about this in more detail create procedure.

Add "delimiter //"before create statement and "//" after end statement in order to execute your procedure. You can use any other delimiter as well.

Upvotes: 1

Nigel Ren
Nigel Ren

Reputation: 57121

In phpMyAdmin, you can set the delimiter on the SQL page, near the bottom, there is a line on the same area of the page as the Go button. Change the separator to anything ($$ is a common one) and then add this to the end of your script.

Upvotes: 0

Related Questions