如何在MySQL存储过程中进行转换

发布于 2025-01-05 10:49:43 字数 891 浏览 1 评论 0原文

尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

送君千里 2025-01-12 10:49:43

您需要在存储过程中声明 i 。

DELIMITER $

CREATE PROCEDURE `rateGenius`.`testFunc` ()
BEGIN

DECLARE i DOUBLE
SET i = 100.0;

END

但不确定您实际上想用这个存储过程做什么。在这种情况下,您的 CAST/CONVERT 是不必要的,但这些函数的语法实际上是正确的。

You need to declare i in your stored procedure.

DELIMITER $

CREATE PROCEDURE `rateGenius`.`testFunc` ()
BEGIN

DECLARE i DOUBLE
SET i = 100.0;

END

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文