DELIMITER;;
CREATE PROCEDURE ROWPERROW()
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
DECLARE j INT DEFAULT 0;
SELECT COUNT(*) FROM jos_downloads_files INTO n;
SET j=0;
SET i=0;
WHILE i<n DO
INSERT INTO jos_downloads_files_temp(id,filetitle,filetype)
SELECT DISTINCT T.id, T.filetitle, T.filetype
FROM jos_downloads_files T
LEFT JOIN jos_downloads_files T2 ON T.filetitle != T2.filetitle
WHERE T.filetitle LIKE CONCAT('%', T2.filetitle, '%') AND T.filetype like 'pdf'
UNION
SELECT DISTINCT T2.id, T2.filetitle, T2.filetype
FROM jos_downloads_files T
LEFT JOIN jos_downloads_files T2 ON T.filetitle != T2.filetitle
WHERE T.filetitle LIKE CONCAT('%', T2.filetitle, '%') AND T.filetype like 'pdf'
ORDER BY filetitle, filetype
LIMIT j,2;
set @myVar := (select filetitle from jos_downloads_files_temp where filetype like 'pdf');
set @dwg := (select id from jos_downloads_files_temp where filetype like 'dwg');
update jos_downloads_files set filetitle = @myVar where filetype like 'dwg' AND id=@dwg AND filetitle!=@myVar;
TRUNCATE TABLE jos_downloads_files_temp;
SET i = i + 1;
SET j = j + 2;
END WHILE;
END;
;;
结果如下:
错误
SQL查询:
CREATE PROCEDURE ROWPERROW()
BEGIN
DECLARE n INT DEFAULT 0;
MySQL说:文档
1064 - 您的SQL语法出错;检查手册 对应于您的MariaDB服务器版本,以获得正确的语法 靠近&#39;&#39;在第3行