drop PROCEDURE if exists find_options;
create procedure find_options()
BEGIN
DECLARE done int DEFAULT 0;
declare blogid int;
declare cur cursor for select blog_id from sitebuilt_blog.wp_blogs b;
declare CONTINUE HANDLER for SQLSTATE '02000' set done = 1;
open cur;
REPEAT
fetch cur into blogid;
if not done THEN
set @blogid=blogid;
if not EXISTS (select table_name from information_schema.tables where table_schema = 'sitebuilt_blog' and table_name = CONCAT('wp_',@blogid,'_options') limit 1)
THEN
select @blogid;
end if;
end if;
UNTIL done END REPEAT;
close cur;
end;
call find_options();