gpt4 book ai didi

MySQL 创建函数语法

转载 作者:IT老高 更新时间:2023-10-28 12:58:22 25 4
gpt4 key购买 nike

我正在尝试在 MySQL 中创建一个函数:

下面是 SQL 代码:

CREATE FUNCTION F_Dist3D (x1 decimal, y1 decimal) 
RETURNS decimal
DETERMINISTIC
BEGIN
DECLARE dist decimal;
SET dist = SQRT(x1 - y1);
RETURN dist;
END;

我收到以下错误:

#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 10

我在 phpMyAdmin 中运行这个创建语句。这个函数有什么问题?

最佳答案

你必须用类似 $$ 的东西覆盖你的 ; 分隔符以避免这种错误。

函数定义后,您可以将分隔符设置回;

这应该可行:

DELIMITER $$
CREATE FUNCTION F_Dist3D (x1 decimal, y1 decimal)
RETURNS decimal
DETERMINISTIC
BEGIN
DECLARE dist decimal;
SET dist = SQRT(x1 - y1);
RETURN dist;
END$$
DELIMITER ;

关于MySQL 创建函数语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6740932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com