存储过程内写了2次select,只想返回第二次select的结果集
select count(1) from information_schema.tables where table_name = 'ViewTb1' into @cnt;
if @cnt = 0 then
select * from ViewTb2 where pos < 7
else
select * from ViewTb1 where pos < 7
end if;
select count(1) from information_schema.tables where table_name = 'ViewTb1' into @cnt;
if @cnt = 0 then
select * from ViewTb2 where pos < 7
else
select * from ViewTb1 where pos < 7
end if;
插入到1个临时表中保存不行?
select count(*) into @cnt from information_schema.tables where table_name = 'ViewTb1' ;
if @cnt = 0 then
select * from ViewTb2 where pos < 7 ;
else
select * from ViewTb1 where pos < 7 ;
end if; 没有分号语法通过吗 ?
if @cnt > 0 then
select * from ViewTb1 where pos < 7 ;
else
select * from ViewTb2 where pos < 7 ;
end if;
目前在客户端会报1312错误,差不多意思是说我返回了多个数据集,这里唯一可能产生多个数据集的就是它把第一句select count也算成一个数据集了
Error 1312: PROCEDURE xxxx can't return a result set in the given context
select count(1) from information_schema.tables where table_name = 'ViewTb1' into @cnt;
就不报错了吗;
if @cnt = 0 then
select * from ViewTb2 where pos < 7 limit 0;
else
select * from ViewTb1 where pos < 7;
end if;
set @cnt = (select count(1) from information_schema.tables where table_name = 'ViewTb1');
if @cnt=0 then
select * from viewtb2 where pos<7 limit 0
else
select * from viewtb1 where pos<7
end if;
受影响的行: 1
时间: 0.000s
我这里就没返回啊,只返回影响行数。