4

I'm trying to create a stored procedure in heidisql (mysql).

CREATE PROCEDURE SP_FORM20_POST(
    P_SESSIONID     VARCHAR(256)
)
BEGIN
    INSERT INTO tbForm20
        ( SESSIONID, RegDT)
    VALUES
        ( P_SESSIONID, NOW()); 
END

This is my query. I'm trying to create this procedure, but occur some error:

Error code is 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 8".

However, I don't know wrong syntax. What is wrong?

I want to success in heidisql tool. I don't want other db tool. Please help me.

Community
  • 1
  • 1
HanTael
  • 97
  • 1
  • 3
  • 8
  • Did you solve this yet? Do you have any feedback on my answer? You are new and have not marked any answers yet with the Green check mark showing the question is answered (if that is the case). – Drew Jun 24 '16 at 12:52
  • I'm sorry too late. It still occur same error. So I'm using toad for mysql instead of heidisql. Thank you for your answer. Good day!! – HanTael Jun 27 '16 at 01:17

3 Answers3

3

The problem in that query is the semicolon, which is the default query delimiter.

In order to change the delimiter in HeidiSQL, add the DELIMITER client command above the CREATE PROCEDURE query:

DELIMITER \\
SELECT 1\\
CREATE PROCEDURE ...\\
DELIMITER ;

HeidiSQL also has a procedure designer, with no need to set the delimiter:

HeidiSQL procedure designer

Anse
  • 1,573
  • 12
  • 27
3

The problem is this. The database reads the ; in your code as an end of the procedure. You probably don't intend it like that :). The DELIMITER command takes care of that by changing ; to something customizable, like $$. Try this:

DELIMITER $$
CREATE PROCEDURE SP_FORM20_POST(
    P_SESSIONID     VARCHAR(256)
)
BEGIN
    INSERT INTO tbForm20
        ( SESSIONID, RegDT)
    VALUES
        ( P_SESSIONID, NOW()); 
END$$
DELIMITER ;
user2728841
  • 1,333
  • 17
  • 32
0

Try this one

DELIMITER //

CREATE PROCEDURE SP_FORM20_POST(
    P_SESSIONID     VARCHAR(256)
)

BEGIN
    INSERT INTO tbForm20
        ( SESSIONID, RegDT)
    VALUES
        ( P_SESSIONID, NOW());

END //

DELIMITER;