我遇到了一个问题,我试图创建一个存储函数来搜索用户的用户名和密码。该函数的参数应该是用户名和密码,如果存在用户名和密码组合,它必须返回true,如果不存在则必须返回false。这是我迄今为止创造的并没有成功:
DELIMITER ;
use db_name;
DROP procedure IF EXISTS `proc_name`;
DELIMITER $$
CREATE PROCEDURE `proc_name`(IN _insertId INT)
BEGIN
-- DISPLAYED CORRECTLY HERE
SELECT _insertId INTO @insertbuff;
SELECT
`TABLE1_ALIAS1`.`PARAM1_ALIAS`,
`TABLE2_ALIAS2`.`PARAM2_ALIAS`,
`TABLE3_ALIAS3`.`PARAM3_ALIAS`
INTO @VAR1, @VAR2, @VAR3,
FROM `TABLE1` AS `TABLE1_ALIAS1`
INNER JOIN `TABLE2` AS `TABLE2_ALIAS2` ON ...
JOIN `TABLE3` AS `TABLE3_ALIAS3` ON ...
-- SEEMS TO BE IGNORE IN THIS WHERE CLAUSE
WHERE `MAIN_TXN`.`id` = _insertId -- OPTION 1: NOT WORKING
-- WHERE `TABLE1`.`id` = CONCAT('', @insertbuff); -- OPTION 2: ALSO NOT WORKING
END$$
DELIMITER ;
答案 0 :(得分:0)
您需要在函数中使用return语句来返回值。此外,对您与客户匹配的实际查询进行了小修复:
create function cred(in_username varchar(15), in_password varchar(6))
returns char(5)
begin
declare v_cnt int;
select count(*) into v_cnt
from customers
where username = in_username and pwd = in_password;
if (v_cnt>0) then
return 'true';
else
return 'false';
end if;
end
$$