程序中的错误INSERT。此插件添加所有列而不包含 UserId
----------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
DROP PROCEDURE IF EXISTS CreateTable $$
CREATE PROCEDURE `CreateTable`
(
md5 VARCHAR(255),table_name VARCHAR(255),CommentsId INT(11),
Parent VARCHAR(100), Content TEXT,UserId INT(11), Title VARCHAR(255),
Nick VARCHAR(20), IdLength INT(11), suffix INT(11)
)
BEGIN
DECLARE full_table_name varchar(255);
SET @SQL=CONCAT('SELECT COUNT(\'X\') INTO @COUNTER FROM INFORMATION_SCHEMA.COLUMNS ',
'WHERE TABLE_NAME like \'', table_name, '%\'');
PREPARE stmt FROM @SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET full_table_name= table_name;
SET @SQL=CONCAT('CREATE TABLE IF NOT EXISTS ', full_table_name, ' LIKE CommentsPattern');
PREPARE stmt FROM @SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @SQL=CONCAT('INSERT INTO ', full_table_name,'(md5,UserId, Parent, Content, CommentsId, Title, Nick,IdLength,suffix)',
'values(',UserId,',"',md5, '",', Parent, ',"', Content, '",',CommentsId,',"',Title,'","',Nick,'",', IdLength, ',',suffix, ')');
prepare stmt from @sql;
execute stmt;
deallocate prepare stmt;
END
我想添加这些值:
call CreateTable('dcf57shasdsd5723m','dcf',2,60201,'My article is',444,'New Title','Ethan',1,2);
其中:
答案 0 :(得分:1)
在INSERT INTO中,您按顺序声明列:md5,UserId,Parent,... 但是,在值中,md5和UserId值被切换:',UserId,','',md5,'“,',Parent