MySQL 使用 phpMyAdmin 创建一个函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14176583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:03:39  来源:igfitidea点击:

Create a function with phpMyAdmin

mysqlfunctionphpmyadmin

提问by Wassim Sboui

I have trouble creating a function using phpMyAdminlike an interface for MySQL. So I write:

我在使用phpMyAdmin创建函数(如MySQL接口)时遇到问题。所以我写:

DELIMITER //
Create or Replace Function  affecter (id_patient IN integer , id_maladie IN VARCHAR2 ) 
Return VARCHAR2(30) IS  msg Varchar2(30);
Begin
    Insert into souffrir values (id_patient,id_maladie);
    msg:= 'Insertion effectuée';
    Return msg;
END//

I get this 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 'Function affecter (id_patient IN integer , id_maladie IN VARCHAR2 ) Returns V' at line 1

#1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行的“函数影响器 (id_patient IN integer , id_maladie IN VARCHAR2) Returns V”附近使用的正确语法

How do I fix this error?

我该如何解决这个错误?

回答by Vijay Satluri

Try this:

尝试这个:

DELIMITER $$
CREATE FUNCTION calcProfit(cost FLOAT, price FLOAT) RETURNS DECIMAL(9,2)
BEGIN
  DECLARE profit DECIMAL(9,2);
  SET profit = price-cost;
  RETURN profit;
END$$
DELIMITER ;

Got it from https://www.a2hosting.com/kb/developer-corner/mysql/mysql-stored-functions-and-procedures

https://www.a2hosting.com/kb/developer-corner/mysql/mysql-stored-functions-and-procedures得到它

回答by WhyteWolf

Currently, MySQLdoes not have an 'or replace' part of the create function. You should instead, after defining the delimiter, add a DROP FUNCTION IF EXISTSwith the function name.

目前,MySQL没有创建函数的“或替换”部分。相反,您应该在定义分隔符后,添加DROP FUNCTION IF EXISTS带有函数名称的 a。

See 13.1.12. CREATE PROCEDURE and CREATE FUNCTION Syntax.

13.1.12。CREATE PROCEDURE 和 CREATE FUNCTION 语法

回答by symcbean

If you go to the SQL tab in PMA, just below the big box for entering your SQL, there's a small input field for the delimiter. Remove DELIMITER //from your SQL, change the delimiter input field from ';' to '//' paste your code and submit it.

如果您转到 PMA 中的 SQL 选项卡,就在用于输入 SQL 的大框下方,有一个用于分隔符的小输入字段。DELIMITER //从您的 SQL 中删除,将分隔符输入字段从 ';' 更改为 '//' 粘贴您的代码并提交。