我正在尝试创建一个存储过程来检查数据库中是否存在用户名。但是,呃
CREATE PROCEDURE `USER_EXISTS`
(IN `GIVEN_USERNAME` VARCHAR(32))
BEGIN
SET @User_exists = 0;
SELECT COUNT(1) INTO @found
FROM `users`
WHERE `username` = `GIVEN_USERNAME`
IF @found > 0 THEN
SET @User_exists = 1
END IF
SELECT @User_exists
END
答案 0 :(得分:3)
试试这个
CREATE PROCEDURE USER_EXISTS(IN GIVEN_USERNAME VARCHAR(32))
BEGIN
SET @User_exists = 0;
SELECT 1 INTO @User_exists
FROM users
WHERE username = GIVEN_USERNAME;
SELECT @User_exists
END