MySQL CREATE FUNCTION语法

编程入门 行业动态 更新时间:2024-10-26 19:31:45
本文介绍了MySQL CREATE FUNCTION语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

以下是SQL代码: <$ p $创建函数F_Dist3D(x1十进制,y1小数) RETURNS十进制 DETERMINISTIC BEGIN DECLARE dist decimal; SET dist = SQRT(x1 - y1); RETURN dist; END;

我收到以下错误:

#1064 - 你的SQL语法有错误; 检查与您的MySQL 服务器版本相对应的手册,在第10行附近使用正确的语法

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

解决方案

您必须覆盖您的; 分隔符类似于 $$ 来避免这种错误。

在函数定义之后,您可以设置分隔符回到; 。

这应该起作用:

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

I am trying to create a function in MySQL:

Here is the SQL code:

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

I am getting the following error:

#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

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 ;.

This should work:

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语法

本文发布于:2023-07-22 04:07:38,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法   MySQL   CREATE   FUNCTION

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!