如何从命令行调用带有参数的 mysql 存储过程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16157349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call a mysql stored procedure, with arguments, from command line?
提问by Gábor Dani
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
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
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
我试过这个:
mysql> CALL insertEvent(2012.01.01 12:12:12);
结果:
ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行的“.01 12:12:12)”附近使用的正确语法
和这个:
mysql> CALL insertEvent
-> 2012.01.01 12:12:12;
结果:
ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 2 行的“2012.01.01 12:12:12”附近使用的正确语法
回答by koriander
With quotes around the date:
在日期周围引用:
mysql> CALL insertEvent('2012.01.01 12:12:12');