mysql 计算COUNT得到记录总数并将其赋值给变量
DECLAREcntINTDEFAULT0;SELECTcount(*)INTOcntFROMtx.net_adminroleconfigWHERERoleId=Role...
DECLARE cnt INT DEFAULT 0;
SELECT count(*) INTO cnt FROM tx.net_adminroleconfig WHERE RoleId=RoleId;
IF cnt>0 THEN
IF EXISTS(SELECT * FROM tx.net_adminroleconfig WHERE RoleId<>RoleId AND RoleName=RoleName) THEN
SELECT strErrorDescribe=N'角色名已存在!';
ELSE
UPDATE tx.net_adminroleconfig SET RoleName=RoleName,FkRoleRight=FkList,AgentRoleRight=AgentList,Remark=remark WHERE RoleId=RoleId;
END IF;
ELSEIF cnt<1 THEN
SELECT strErrorDescribe=N'角色名不存在!';
END IF;
END;
提示错误:
DECLARE cnt INT DEFAULT 0;
[Err] 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 'DECLARE cnt INT DEFAULT 0' at line 1 展开
SELECT count(*) INTO cnt FROM tx.net_adminroleconfig WHERE RoleId=RoleId;
IF cnt>0 THEN
IF EXISTS(SELECT * FROM tx.net_adminroleconfig WHERE RoleId<>RoleId AND RoleName=RoleName) THEN
SELECT strErrorDescribe=N'角色名已存在!';
ELSE
UPDATE tx.net_adminroleconfig SET RoleName=RoleName,FkRoleRight=FkList,AgentRoleRight=AgentList,Remark=remark WHERE RoleId=RoleId;
END IF;
ELSEIF cnt<1 THEN
SELECT strErrorDescribe=N'角色名不存在!';
END IF;
END;
提示错误:
DECLARE cnt INT DEFAULT 0;
[Err] 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 'DECLARE cnt INT DEFAULT 0' at line 1 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |