我正在尝试创建一个具有INT参数并返回管理员名称的VARCHAR的函数。
这是我最近尝试过的代码:
DELIMITER //
CREATE FUNCTION `SHOW_ADMIN`(`PID` INT(11)) RETURNS VARCHAR(50)
NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER
BEGIN
DECLARE @retval VARCHAR;
SELECT NAME INTO @retval
FROM ADMINS WHERE ID = `PID`;
RETURN @retval;
END//
DELIMITER ;
注意:上面的代码基本上是从“添加例程” GUI复制粘贴。
我尝试过的其他代码:
DELIMITER //
CREATE FUNCTION SHOW_ADMIN(PID INT) RETURNS VARCHAR
BEGIN
DECLARE @retval VARCHAR;
SELECT NAME INTO @retval
FROM ADMINS WHERE ID = PID;
RETURN @retval;
END//
DELIMITER ;
当前代码显示的错误显示:
1064 - You have an error in your SQL syntax;
check the manual that corresponds to your MariaDB
server version for the right syntax to use near
'@retval VARCHAR;
SELECT NAME INTO @retval
FROM ADMINS WHERE ID = `PID`' at line 4
代码最初来自:MySQL, create a simple function
编辑:
How to declare a variable in MySQL? 不介绍在函数上下文中如何使用它,而是:MySQL select in function。
答案 0 :(得分:1)
设法找到一个解决方案,它与MySQL select in function
重复无论如何,这解决了我的问题。
- Installing doctrine/dbal (v2.7.1): Downloading (failed)
Downloading (failed)
Downloading (failed) Failed to download doctrine/dbal from dist: The "https://files.phpcomposer.com/files/doctrine/dbal/11037b4352c008373561dc6fc836834eed80c3b5.zip" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
Failed to enable crypto
failed to open stream: operation failed