结贴了, 最后是研究存储过程搞定了. 通过游标和临时表, 最终实现了功能.
伪代码:
```
DROP PROCEDURE IF EXISTS COMBINE_RESULT_SET;
CREATE PROCEDURE COMBINE_RESULT_SET()
BEGIN
-- 定义要在 DROP TABLE 的前面, 要显示在最前面
DECLARE s INT DEFAULT 0;
DECLARE TASKID INT(11);
-- 定义游标,并将 SQL 结果集赋值到游标中
DECLARE IDLIST CURSOR FOR SELECT ID FROM PL_TASK;
-- 声明当游标遍历完后将标志变量置成某个值
DECLARE CONTINUE HANDLER FOR NOT FOUND SET s=1;
-- SQL Error [1337] [42000]: Variable or condition declaration after cursor or handler declaration
DROP TABLE IF EXISTS USER_TEMPORARY;
-- 创建临时表
CREATE TEMPORARY TABLE IF NOT EXISTS USER_TEMPORARY(NAME VARCHAR(32), DESCRIPTION VARCHAR(225));
-- 打开游标
OPEN IDLIST;
-- 将游标中的值赋值给变量,注意:变量名不要和返回的列名同名,变量顺序要和 SQL 结果列的顺序一致
FETCH IDLIST INTO TASKID;
-- 当 S 不等于 1,也就是未遍历完时,会一直循环
WHILE s<>1 DO
-- 执行业务逻辑
-- INSERT INTO USER_TEMPORARY(NAME, DESCRIPTION) VALUES (SELECT USER_NAME, EMAIL FROM PL_USER WHERE
PL_USER.ID = TASKID) ;
-- INSERT INTO USER_TEMPORARY(NAME, DESCRIPTION) VALUES (SELECT TASK_NO, TASK_TITLE FROM PL_TASK WHERE CREATE_BY = TASKID) ;
INSERT INTO USER_TEMPORARY(SELECT USER_NAME, EMAIL FROM PL_USER WHERE
PL_USER.ID = TASKID) ;
INSERT INTO USER_TEMPORARY(SELECT TASK_NO, TASK_TITLE FROM PL_TASK WHERE CREATE_BY = TASKID) ;
-- 将游标中的值再赋值给变量,供下次循环使用
FETCH IDLIST INTO TASKID;
-- 当 S 等于 1 时表明遍历以完成,退出循环
END WHILE;
-- 关闭游标
CLOSE IDLIST;
SELECT * FROM USER_TEMPORARY;
END
CALL COMBINE_RESULT_SET();
```