0
오류 : 두 개 이상의 행으로 구성된 결과 문제는 단어 LIMIT로 생각됩니다. sb가이 문제를 해결할 수 있습니까?절차 두 개 이상의 행
DELIMITER $$
CREATE PROCEDURE `InsertComment`(crc int(11) unsigned, userId int, title varchar(255),
nick varchar(20), parentId int, content text)
BEGIN
DECLARE tableName VARCHAR(4);
DECLARE tbName VARCHAR(15);
DECLARE results INTEGER;
DECLARE depth integer;
DECLARE results2 INTEGER;
DECLARE resultsM INTEGER;
DECLARE commentsId INTEGER;
DECLARE CommentX INTEGER ;
DECLARE COUNTER INTEGER;
set tbName = CAST(crc AS CHAR);
set tableName = SUBSTRING(tbName, 1, 5);
CALL CreateCommentsTable(tableName);
if parentId = 0 then
SET @results2 = 0;
SET @q2 = CONCAT("SELECT commentsId INTO @results2 FROM `",tableName,"` WHERE CRC32 = ",crc," ORDER BY commentsId DESC LIMIT 1");
PREPARE stmq2 FROM @q2;
EXECUTE stmq2;
DEALLOCATE PREPARE stmq2;
SET commentsId = @results2 + 1;
SET depth = 0;
SET @results = 0;
else
SET @q2 = CONCAT("SELECT Depth INTO @results FROM `",tableName,"` WHERE CRC32 = ",crc," AND commentsId = ",parentId);
PREPARE stmq2 FROM @q2;
EXECUTE stmq2;
DEALLOCATE PREPARE stmq2;
set depth = @results;
set depth = depth + 1;
set @CommentX = 0;
SET @COUNTER = 0;
WHILE @COUNTER = 0 AND @results > -1 DO
SET @q4= CONCAT("SELECT COUNT(*) INTO @COUNTER FROM `",tableName,"` WHERE CRC32 = ",crc," AND Depth = ",@results," AND commentsId > ",parentId);
PREPARE stmq2 FROM @q4;
EXECUTE stmq2;
DEALLOCATE PREPARE stmq2;
IF @COUNTER > 0 THEN
SET @q3= CONCAT("SELECT commentsId INTO @CommentX FROM `",tableName,"` WHERE CRC32 = ",crc," AND Depth = ",@results," AND commentsId > ",parentId," ORDER BY commentsId ASC Limit 1");
PREPARE stmq2 FROM @q3;
EXECUTE stmq2;
DEALLOCATE PREPARE stmq2;
END IF;
SET @results = @results - 1;
END WHILE;
SET @resultsM = 0;
IF @CommentX = 0 THEN
SET @q2 = CONCAT("SELECT commentsId INTO @resultsM FROM `",tableName,"` WHERE CRC32 = ",crc," ORDER BY commentsId DESC LIMIT 1");
PREPARE stmq2 FROM @q2;
EXECUTE stmq2;
DEALLOCATE PREPARE stmq2;
SET commentsId = @resultsM +1;
else
SET commentsId = @CommentX + 1;
END IF;
SET @u = CONCAT("UPDATE `",tableName,"` SET commentsId = commentsId + 1 WHERE CRC32 = ",crc," AND commentsId > ",commentsId + 1);
PREPARE stmq FROM @u;
EXECUTE stmq;
DEALLOCATE PREPARE stmq;
end if;
SET @a = CONCAT("INSERT INTO `", tableName ,"` (`Crc32`, `UserId`, `Title`, `Nick`, `CommentsId`, `Depth`, `Content`, `CommentStatus`, `ViewStatus`)
VALUES (",crc,", ",userId,", '",title,"', '",nick,"',",commentsId,", ",depth,", '",content,"', 1, 1);");
PREPARE stmi FROM @a;
EXECUTE stmi;
DEALLOCATE PREPARE stmi;
set @results = null;
set @results2 = null;
set @tableName = null;
set @tbName = null;
END
정확히 DELIMITER $$ 및 END $$ ?? – Przemek
예. 정확하게. 'DELIMITER $$'와'END $$' – sel
아래의 코드와 동일한 문제가 – Przemek