如何在MySQL存储过程中进行转换
尝试在 MySQL Workbench 中创建以下例程会产生“此对象的 DDL 语句包含语法错误。您确定要不更改地应用 DDL 语句吗?”:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE PROCEDURE `dbName`.`testFunc` ()
BEGIN
SET i = CAST(100 AS DOUBLE);
END
有什么想法吗?
这做了同样的事情:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE PROCEDURE `rateGenius`.`testFunc` ()
BEGIN
SET i = CONVERT(100, DOUBLE);
END
Trying to create the following routine in MySQL Workbench yields a "This object's DDL statement contains syntax errors. Are you sure you want to apply the DDL statement unchanged?":
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $
CREATE PROCEDURE `dbName`.`testFunc` ()
BEGIN
SET i = CAST(100 AS DOUBLE);
END
Any ideas?
This does the same thing:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $
CREATE PROCEDURE `rateGenius`.`testFunc` ()
BEGIN
SET i = CONVERT(100, DOUBLE);
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在存储过程中声明 i 。
但不确定您实际上想用这个存储过程做什么。在这种情况下,您的
CAST/CONVERT
是不必要的,但这些函数的语法实际上是正确的。You need to declare i in your stored procedure.
Not sure what you're actually trying to do with this stored proc though. Your
CAST/CONVERT
is unecessary in this case but your syntax for those functions is in fact correct.