我在使用游标在MySQL上创建过程中的用户时遇到问题。我无法创建该用户,我认为我的光标有一些东西,但我不知道问题可能是什么。
以下是创建光标的位置代码以及我尝试创建用户的位置:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
我用这个解决了这个问题:
DELIMITER $$
DROP procedure IF EXISTS test $$
CREATE PROCEDURE test (in x int)
begin
DECLARE StudentID INT;
DECLARE Password varchar(32);
DECLARE otherID INT;
declare done boolean default false;
DECLARE c1
CURSOR FOR
select SID, pw,OID from testing_table where date is null;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
set StudentID = (select SID from testing_table limit 1);
set Password = (Select pw from testing_table limit 1);
set otherID = (Select OID from testing_table limit 1);
OPEN c1;
Loop1:LOOP
FETCH c1 INTO StudentID , Password, otherID;
if done then leave Loop1;
else
set @sql1 = concat('CREATE USER U_',otherID ,'_',StudentID ,' IDENTIFIED BY', Password);
prepare stmt from @sql1;
execute stmt;
DEALLOCATE PREPARE stmt;
end if;
end loop Loop1;
close c1;
END $$
DELIMITER ;