How to call a mysql stored procedure, with arguments, from command line?

不打扰是莪最后的温柔 提交于 2019-12-20 10:30:46

问题


How can I call a stored procedure from command line?

I have a procedure:

CREATE DEFINER=`root`@`localhost` PROCEDURE `insertEvent`(IN `dateTimeIN` DATETIME)
    NO SQL
BEGIN
    SET @eventIDOut = NULL;

    IF  EXISTS(SELECT * FROM `events` WHERE `eventDate` = dateTimeIN) THEN
        SELECT `eID` INTO @eventIDOut FROM `events` WHERE `eventDate` = dateTimeIN LIMIT 1;
        ELSE
        INSERT INTO `events` (`eventDate`) VALUES(dateTimeIN);
        SET @eventIDOut = last_insert_id();
    END IF;

    SELECT CONCAT(@eventIDOut);
END
  1. I tried this: mysql> CALL insertEvent(2012.01.01 12:12:12);

    Result:

    ERROR 1064 (42000): 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 '.01 12:12:12)' at line 1

  2. And this: mysql> CALL insertEvent

    -> 2012.01.01 12:12:12;

    Result:

    ERROR 1064 (42000): 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 '2012.01.01 12:12:12' at line 2


回答1:


With quotes around the date:

mysql> CALL insertEvent('2012.01.01 12:12:12');


来源:https://stackoverflow.com/questions/16157349/how-to-call-a-mysql-stored-procedure-with-arguments-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!