MySQL CREATE FUNCTION Syntax(MySQL CREATE FUNCTION 语法)
问题描述
我正在尝试在 MySQL 中创建一个函数:
I am trying to create a function in 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 中运行这个 create 语句.这个功能有什么问题?
I am running this create statement in phpMyAdmin. What is wrong with this function?
推荐答案
你必须用 $$
之类的东西覆盖你的 ;
分隔符,以避免这种错误.
You have to override your ;
delimiter with something like $$
to avoid this kind of error.
在函数定义之后,您可以将分隔符重新设置为 ;
.
After your function definition, you can set the delimiter back to ;
.
这应该有效:
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 CREATE FUNCTION 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL CREATE FUNCTION 语法


- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01