'mysql procedure error occurrence 'Subquery returns more than 1 row'
select query
select concat('call db_name.tmp_proc(', '\'' , TABLE_SCHEMA, '\'' ',' , '\'' , TABLE_NAME , '\'' ',30,1' ');' )
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='logdb';
result
call db_name.tmp_proc('logdb','monthly_test',30,1);
call db_name.tmp_proc('logdb','monthly_test1',30,1);
call db_name.tmp_proc('logdb','monthly_test2',30,1);
call db_name.tmp_proc('logdb','monthly_test3',30,1);
call db_name.tmp_proc('logdb','monthly_test4',30,1);
5 rows in set (0.00 sec)
Create this query as a procedure
DROP PROCEDURE test$$
CREATE PROCEDURE test() BEGIN
DECLARE result INT default 0;
SET @result = (select concat('call db_name.tmp_proc(', '\'' , TABLE_SCHEMA, '\'' ',' , '\'' , TABLE_NAME , '\'' ',30,1' ');' )
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='logdb');
PREPARE stmt1 FROM @result;
EXECUTE stmt1;
END$$
call test$$
ERROR 1242 (21000): Subquery returns more than 1 row
ERROR 1242 (21000): Subquery returns more than 1 row
This error has occurred and cannot be executed.
Is there a way to eliminate errors and execute all queries of results?
============ ============ It was revised as follows with reference to the advice and performed well without errors. Thank you.
delimiter $$
DROP PROCEDURE test$$
CREATE PROCEDURE test() BEGIN
-- DECLARE result text(65535) ;
-- DECLARE cnt int default 0;
DECLARE i int default 0;
SET @cnt = (select count(*) -1 as cnt FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='logdb' AND CREATE_OPTIONS ='partitioned' ) ;
WHILE i <= @cnt DO
SET @result = (select concat('call db_name.tmp_proc(', '\'' , TABLE_SCHEMA, '\'' ',' , '\'' , TABLE_NAME , '\'' ',30,1' ')' )
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='logdb' limit i, 1) ;
PREPARE stmt1 FROM @result;
EXECUTE stmt1;
SET i = i + 1;
END WHILE;
END$$
call test$$
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
