我想在 MySQL 中编写一个带有事件的 While 循环。不幸的是,在互联网上搜索后,我没有找到这样的东西。但是,我不想用程序来写它。
CREATE DEFINER=`root`@`localhost` EVENT `try`
ON SCHEDULE EVERY 1 DAY STARTS '2023-03-10 09:00:00.000000'
ON COMPLETION NOT PRESERVE ENABLE DO
BEGIN
DECLARE counter int DEFAULT 1;
WHILE counter <= 10 DO
INSERT INTO admin(admin.admin_username, admin.admin_password, admin.admintype_id) VALUES('aaaa','bbbb',1)
SET counter = counter + 1;
END WHILE
END;
除非这是在事件中使用 while 循环的练习,否则我认为可以使用 and insert..select 实现同样的效果
INSERT INTO admintouser_cocuk(admintouser_cocuk.kullanici_cocuk_id,
admintouser_cocuk.admintouser_cocuk_mesaj)
SELECT kullanici_cocuk.kullanici_cocuk_id ,
'Sevgili evladınızın yeni yaşını kutlar, tüm ailenizle birlikte mutlu bir yaşam dileriz.'
FROM kullanici_cocuk
wHERE SUBSTRING(kullanici_cocuk.cocuk_dogum_tarihi, 6, 5) = SUBSTRING(CURDATE(), 6, 5)
;
而且我怀疑使用日期函数而不是子字符串也会更整洁。