0

我有以下场景:

CREATE DEFINER=`test`@`%` PROCEDURE `prTest`()
BEGIN
     SET @prepared_sql = 'select field1, field2 from table_data1');

     PREPARE stmt FROM @prepared_sql;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt;
END

我必须循环打开“stmt”。如何读取这个循环和每一行,获取“field1”和“field2”的值并将值插入另一个表中?

4

1 回答 1

-1

解决:

CREATE DEFINER=`test`@`%` PROCEDURE `prTest`()
BEGIN
     SET @prepared_sql = 'insert into table_data2
                          select field1, field2 from table_data1');

     PREPARE stmt FROM @prepared_sql;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt;
END
于 2012-11-20T22:34:13.660 回答