gpt4 book ai didi

mysql - 错误代码: 1064 You have an error in your SQL syntax (the new One)

转载 作者:行者123 更新时间:2023-11-30 00:04:17 26 4
gpt4 key购买 nike

我从 MySQL 代码中收到此错误消息。但我不知道我的错在哪里..这是我的代码:

DELIMITER $$

USE `kp`$$

DROP PROCEDURE IF EXISTS `getAllUmurPegawai`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `getAllUmurPegawai`()

BEGIN

DECLARE currdate INT;
DECLARE birthdate INT;
DECLARE numRows INT;
DECLARE numIteration INT;
DECLARE tempMonth INT;

SET numRows = SELECT COUNT(*) FROM pegawai;
SET numIteration = 1;
WHILE numIteration <= numRows DO
SET currdate = (SELECT EXTRACT(YEAR FROM CURRENT_DATE));
SET birthdate = (SELECT EXTRACT(YEAR FROM (SELECT TGL_LAHIR FROM pegawai WHERE INDEXING = numIteration)));
SET umur = currdate - birthdate;
SET tempMonth = SELECT EXTRACT(MONTH FROM (SELECT TGL_LAHIR FROM pegawai WHERE INDEXING = numIteration));
IF umur < 56 THEN
INSERT INTO pegawai(STATUS_PEGAWAI,BULAN_PENSIUN(JIKA_SUDAH)) VALUES('Belum Pensiun',0);
ELSE
INSERT INTO pegawai(STATUS_PEGAWAI,BULAN_PENSIUN(JIKA_SUDAH)) VALUES('Pensiun',tempMonth);
END IF;
SET numIteration = numIteration + 1;
END WHILE;
END$$
DELIMITER ;

我收到此错误消息:

Query : CREATE DEFINER=`root`@`localhost` PROCEDURE `getAllUmurPegawai`() BEGIN DECLARE currdate INT; DECLARE birthdate INT; DECLARE num...

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT COUNT(*) FROM pegawai;
SET numIteration = 1;

WHILE numIteration <= numR' at line 8

我该如何解决这个问题?最佳答案将不胜感激:))

最佳答案

要使用 SELECT 查询作为表达式,您必须将其放在括号中:

SET numRows = (SELECT COUNT(*) FROM pegawai);

您在设置 currDatebirthdate 时做得正确,但您忘记了这一行中的括号。

关于mysql - 错误代码: 1064 You have an error in your SQL syntax (the new One),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24726055/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com