日期:2014-05-17  浏览次数:20565 次

SQL中存储过程存在多个EXEC返回值出现问题
存储过程存在多个EXEC

EXEC a1
EXEC a2
EXEC a3

但是 JAVA获取返回值渠道的是a1的值 
请问如何解决

------解决方案--------------------
引用:
Quote: 引用:

把前2个exec中的结果集,分别插入到临时表中,就不会再返回数据。示例:
exec('select field into #temp1 from tb1 where id = 1')
exec('select field into #temp2 from tb2 where id = 2')
exec('select field from tb3 where id = 3')


我现在用的就是你这个方法,觉得太麻烦了 才上来求救的.

--#1.呵呵,应该无其它方法。
--#2..NET里可以得到3个结果集,你直接取第三个用就可以。估计JAVA也可以。
--#3.重新定义前2个存储过程,不返回结果集。
------解决方案--------------------
把结果插入到临时表,是个好办法,然后再select出你想要的临时表结果
create table #temp1(...)
create table #temp2(...)
create table #temp3(...)

insert into #temp1
exec a1
insert into #temp2
exec a2
insert into #temp3
exec a3

select * from #temp1 (或temp2或temp3)