Search code examples
mysqlstored-proceduresmysql-error-1064

Stored Procedure - Error #1064


Getting error during Creating Stored Procedure for Callable Statement: I know some thing very simple going wrong, but i'm just unable to figure out!

My QUERY:

USE demo;

1. CREATE PROCEDURE
2.  INSERT_emp_data (IN ID INT, IN NAME VARCHAR(2), IN AGE INT, IN IMAGE BLOB)
3. BEGIN
4.  INSERT INTO emp_data VALUES(ID, NAME, AGE, IMAGE);
5. END;
/

SQL query:

CREATE PROCEDURE
    INSERT_emp_data (IN ID INT, IN NAME VARCHAR(2), IN AGE INT, IN IMAGE BLOB)
BEGIN
    INSERT INTO emp_data VALUES(ID, NAME, AGE, IMAGE);
MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4 

Appreciate your help! Thank for your time!


Solution

  • When you write a stored procedure in MySQL, you should use the DELIMITER statement. In addition, you should name your columns so they do not conflict with column names. And, when using INSERT always list the columns name. So:

    DELIMITER $$
    CREATE PROCEDURE INSERT_emp_data (
        IN IN_ID INT,
        IN IN_NAME VARCHAR(2),
        IN IN_AGE INT,
        IN IN_IMAGE BLOB
    )
    BEGIN
        INSERT INTO emp_data(id, name, age, image)
            VALUES(IN_ID, IN_NAME, IN_AGE, IN_IMAGE);
    END;
    $$
    DELIMITER ;