MySQL IF...THEN 后跟查询语句
这样的东西在 MySQL 中有效吗:
DELIMITER //
CREATE FUNCTION LOGIN_VALIDATE(IN uName VARCHAR(32),IN uPass VARCHAR(32))
RETURNS BOOLEAN
BEGIN
DECLARE row_count BOOLEAN DEFAULT 0;
DECLARE stored_pass VARCHAR(32) DEFAULT NULL;
DECLARE valid_return BOOLEAN DEFAULT 0;
SELECT count(*) INTO row_count FROM Login WHERE userId='uName';
IF row_count = 1 THEN
SELECT pWord INTO stored_pass FROM Login WHERE userId='uName';
END IF;
IF stored_pass = 'uPass' THEN
SET valid_return = 1;
END IF;
RETURN valid_return;
END //
DELIMITER ;
Is something like this valid in MySQL:
DELIMITER //
CREATE FUNCTION LOGIN_VALIDATE(IN uName VARCHAR(32),IN uPass VARCHAR(32))
RETURNS BOOLEAN
BEGIN
DECLARE row_count BOOLEAN DEFAULT 0;
DECLARE stored_pass VARCHAR(32) DEFAULT NULL;
DECLARE valid_return BOOLEAN DEFAULT 0;
SELECT count(*) INTO row_count FROM Login WHERE userId='uName';
IF row_count = 1 THEN
SELECT pWord INTO stored_pass FROM Login WHERE userId='uName';
END IF;
IF stored_pass = 'uPass' THEN
SET valid_return = 1;
END IF;
RETURN valid_return;
END //
DELIMITER ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用:
始终尝试尽量减少通过桌子的次数以获得所需的结果。 SQL 是基于 SET 的,而不是过程式的 - 当正确使用 SQL 时,它会更好地为您工作。
Use:
Always try to minimize the number of passes over a table to get your desired result. SQL is SET based, not procedural - SQL will work better for you when it is approached correctly.