SP在Control Center中返回结果集,但是从命令行返回结果集 [英] SP returns resultset in Control Center, but empty resultset from command line

查看:69
本文介绍了SP在Control Center中返回结果集,但是从命令行返回结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我已经汇总了几个SP来制作BOM(物料清单)

列表,它们一起使用了几个全局临时表,并从光标返回

结果。这是代码:

- 初始化临时表............

创建程序myschema.init_ebom_tables()

语言sql

特定的init_ebom_tables

- wlm环境< env>

te:begin


声明v_lvl smallint;


- 声明全局临时表以保存结果........

声明全局临时表session.ebom_temp

(zaehler整数不为空

始终作为身份生成

(以1开头

增加1),

nlevel smallint not null,

struktur varchar(16)not null,

item varchar(47)not null,

item_desc varchar(30)not null,

pos smallint not null,

cha varchar(10)not null,

s_item varchar(47)not null,

s_desc varchar(30)not null,

数量小数(16 ,4)not null,

units varchar(10)not null



with replace

on commit保留行;

在session.ebom_temp上创建唯一索引session.ebom_tempX1

(zaehler);

在session.ebom_temp上创建索引session.ebom_tempX2 (item,s_item);


- 声明全局临时表以保存乘数........

声明全局临时表session.ebom_multipliers

(nlevel integer not null

始终作为身份生成

(从1开始$ b / b
增加1),

乘数十进制(20,6)不为空白



在提交保留行时替换

;

创建唯一索引session.ebom_multipliersX1

session.ebom_multipliers(nlevel);


- ...并给它16级别(SP的最大嵌套深度).....

set v_lvl = 0;

while(v_lvl< 16)做

set v_lvl = v_lvl + 1;

插入session.ebom_multipliers

(nlevel,multiplier)

值(默认值,1);

结束时间;


结束te

@

- 启动第一个电话.......................

创建程序myschema.get_bom_struktur(在p_top_item varchar(47) ),

in p_bom_type varchar(1))

语言sql

具体get_bom_struktur

- wlm环境< ; env>

动态结果集1

gbs:开始


声明v_sql varchar(100)默认''select * from session.ebom_temp

由zaehler命令'';

--declare v_sql varchar(100)默认''select * from bb.ttaihz040777

仅获取前10行'';

声明bom_listing游标返回客户端获取stmt;


- 首先调用递归SP以实际生成

BOM ......

if(upper(p_bom _type)='''E'')然后

调用myschema.eng_bom_inner(p_top_item,1);

else

调用myschema.prod_bom_inner( p_top_item,1);

结束if;


- 动态返回最终结果集.....

begin

从v_sql准备stmt;

打开bom_listing;

结束;


- 直接返回最终结果集.....

- 开始

- 声明bom_listing游标返回客户端

- 选择*

- 来自session.ebom_temp

- 由zaehler订购;

- 打开bom_listing;

- 结束;


结束gbs

@


- 递归内部例程........... .....

创建程序myschema.eng_bom_inner(在p_item varchar(47)中,在

p_level smallint中)

语言sql

具体的eng_bom_inner

- wlm环境< env>

动态结果集1

ebi:开始


声明v_eitm varchar(47);

声明v_itmdesc varchar(30);

声明v_pono smallint;

声明v_comp varchar(47);

声明v_cmpdesc varchar(30);

声明v_nqan decimal(12,2);

声明sqlstate char(5)默认''00000'';

声明v_nextlvl smallint;

声明v_dynCall varchar(100)默认''调用

myschema.eng_bom_inner(?,?)'';


- 设置主光标...............

cur:开始

声明e_bom_cur光标并保持


选择bm.t_eitm,item_desc(bm.t_eitm),bm.t_pono ,bm.t_comp,

item_desc(bm.t_comp),bm.t_nqan

来自bb.ttiedm110100作为bm - 工程物料清单....

其中bm.t_eitm = p_item

和bm.t_revi =(从bb.ttiedm110100选择max(t.t_revi)为t

- 获得最高版本这个P / N

其中t.t_eit m = bm.t_eitm

- (t_eitm上的索引1,t_revi,t_pono)...

仅获取前1行)

通过bm.t_pono订购

仅限获取;

- with cr


打开e_bom_cur;

从e_bom_cur获取到v_eitm,v_itmdesc,v_pono,v_comp,

v_cmpdesc,v_nqan;


while(sqlstate =''00000'')do


更新session.ebom_multipliers - 这些值尚未使用
使用....

set multiplier = v_nqan

其中nlevel = p_level;


- 将这些详细信息保存到临时表............

插入session.ebom_temp

(zaehler,nlevel,struktur,item,item_desc,pos,cha,s_item,

s_desc,数量,单位)

值(默认值,p_level,repeat(''*'',p_level),p_item,v_itmdesc,

v_pono,'''',v_comp,v_cmpdesc,v_nqan,'''') ;


- 递归调用此sp - 必须完成此操作使用动态

SQL,

- 因为不支持延迟对象验证

LUW ........

set v_nextlvl = p_level + 1;

从v_dynCall准备v_stmt;

使用v_comp执行v_stmt,v_nextlvl;


- 获取下一行.....

从e_bom_cur获取到v_eitm,v_itmdesc,v_pono,v_comp,

v_cmpdesc,v_nqan;

结束时间;


关闭e_bom_cur;

结束时间;


结束ebi

@


好​​的 - 这就是问题所在:当我在DB2 Control Center中运行这个问题时

(" call myschema.get_bom_struktur (...)),它运行良好,并生成

正确的结果集 - 对于大型BOM,大概需要半分钟才能生成数千美元线。不完全快,但完全足够




但是,当我从命令行(DB2 CLP)运行相同的命令时,

该东西立即返回,显然没有触及''eng_bom_inner''SP中的

''e_bom_cur''光标。用户(我!)对所有这些SP拥有完整的

执行权。从测试运行相同的命令

Windows程序(我当然不是新手!)也立即返回

,再次使用空的结果集。


如果我更改了get_bom_struktur中的最终光标。 SP因此它从某些其他(非临时)表返回数据,结果集是非空的,无论从哪里调用它。这是我的猜测

然后,这个问题与

全球临时表的可见性有关。


我会感激一些帮助,因为我希望使用类似的

方法生成其他列表。


TIA,

Rob

Hi all,

I''ve put together a few SPs to produce a BOM (bill of materials)
listing, which together use a couple of global temp tables, and return
the results from a cursor. Here''s the code:
-- Initialize the temp tables............
create procedure myschema.init_ebom_tables ( )
language sql
specific init_ebom_tables
-- wlm environment <env>
te: begin

declare v_lvl smallint;

-- Declare global temp table to hold results........
declare global temporary table session.ebom_temp
( zaehler integer not null
generated always as identity
( start with 1
increment by 1 ),
nlevel smallint not null,
struktur varchar(16) not null,
item varchar(47) not null,
item_desc varchar(30) not null,
pos smallint not null,
cha varchar(10) not null,
s_item varchar(47) not null,
s_desc varchar(30) not null,
quantity decimal(16, 4) not null,
units varchar(10) not null
)
with replace
on commit preserve rows;
create unique index session.ebom_tempX1 on session.ebom_temp
(zaehler);
create index session.ebom_tempX2 on session.ebom_temp (item, s_item);

-- Declare global temp table to hold multipliers........
declare global temporary table session.ebom_multipliers
( nlevel integer not null
generated always as identity
( start with 1
increment by 1 ),
multiplier decimal(20, 6) not null
)
with replace
on commit preserve rows;
create unique index session.ebom_multipliersX1 on
session.ebom_multipliers (nlevel);

-- ...and give it 16 levels (the maximum nesting depth for SPs) .....
set v_lvl = 0;
while (v_lvl < 16) do
set v_lvl = v_lvl + 1;
insert into session.ebom_multipliers
(nlevel, multiplier)
values (default, 1);
end while;

end te
@
-- Fire up the first call.......................
create procedure myschema.get_bom_struktur (in p_top_item varchar(47),
in p_bom_type varchar(1))
language sql
specific get_bom_struktur
-- wlm environment <env>
dynamic result sets 1
gbs: begin

declare v_sql varchar(100) default ''select * from session.ebom_temp
order by zaehler '';
--declare v_sql varchar(100) default ''select * from bb.ttaihz040777
fetch first 10 rows only '';
declare bom_listing cursor with return to client for stmt;

-- Make first call to recursive SP to actually generate the
BOM......
if (upper(p_bom_type) = ''E'') then
call myschema.eng_bom_inner(p_top_item, 1);
else
call myschema.prod_bom_inner(p_top_item, 1);
end if;

-- Return final resultset dynamically.....
begin
prepare stmt from v_sql;
open bom_listing;
end;

-- Return final resultset directly.....
-- begin
-- declare bom_listing cursor with return to client for
-- select *
-- from session.ebom_temp
-- order by zaehler;
-- open bom_listing;
-- end;

end gbs
@

-- Recursive inner routine................
create procedure myschema.eng_bom_inner (in p_item varchar(47), in
p_level smallint)
language sql
specific eng_bom_inner
-- wlm environment <env>
dynamic result sets 1
ebi: begin

declare v_eitm varchar(47);
declare v_itmdesc varchar(30);
declare v_pono smallint;
declare v_comp varchar(47);
declare v_cmpdesc varchar(30);
declare v_nqan decimal(12, 2);
declare sqlstate char(5) default ''00000'';
declare v_nextlvl smallint;
declare v_dynCall varchar(100) default '' call
myschema.eng_bom_inner(?, ?) '';

-- Set up the main cursor...............
cur: begin
declare e_bom_cur cursor with hold for

select bm.t_eitm, item_desc(bm.t_eitm), bm.t_pono, bm.t_comp,
item_desc(bm.t_comp), bm.t_nqan
from bb.ttiedm110100 as bm -- Engineering BOMs....
where bm.t_eitm = p_item
and bm.t_revi = (select max(t.t_revi) from bb.ttiedm110100 as t
-- get highest revision for this P/N
where t.t_eitm = bm.t_eitm
-- (index 1 on t_eitm, t_revi, t_pono)...
fetch first 1 rows only)
order by bm.t_pono
for fetch only;
--with cr

open e_bom_cur;
fetch from e_bom_cur into v_eitm, v_itmdesc, v_pono, v_comp,
v_cmpdesc, v_nqan;

while (sqlstate = ''00000'') do

update session.ebom_multipliers -- These values not yet being
used....
set multiplier = v_nqan
where nlevel = p_level;

-- Save these details to the temp table............
insert into session.ebom_temp
( zaehler, nlevel, struktur, item, item_desc, pos, cha, s_item,
s_desc, quantity, units )
values (default, p_level, repeat(''*'', p_level), p_item, v_itmdesc,
v_pono, '''', v_comp, v_cmpdesc, v_nqan, '''');

-- Call this sp recursively - this has to be done using dynamic
SQL,
-- because deferred object validation is not supported on
LUW........
set v_nextlvl = p_level + 1;
prepare v_stmt from v_dynCall;
execute v_stmt using v_comp, v_nextlvl;

-- Get the next row.....
fetch from e_bom_cur into v_eitm, v_itmdesc, v_pono, v_comp,
v_cmpdesc, v_nqan;
end while;

close e_bom_cur;
end cur;

end ebi
@

OK - here''s the problem: when I run this in the DB2 Control Center
("call myschema.get_bom_struktur(...)"), it all runs well, and produces
the correct resultset - for large BOMs, it takes maybe half a minute to
produce several thousand lines. Not exactly speedy, but perfectly
adequate.

When I run the same command from the command line (DB2 CLP), however,
the thing returns immediately, apparently without ever touching the
''e_bom_cur'' cursor in the ''eng_bom_inner'' SP. The user (me!) has full
execute rights on all these SPs. Running the same command from a test
Windows program (where I''m certainly no newbie!) also returns
immediately, again with an empty resultset.

If I change the final cursor in the "get_bom_struktur" SP so that it
returns data from some other (non-temporary) table, the resultset is
not empty, regardless of where it has been called from. It''s my guess
then, that the problem has something to do with the visibility of the
global temp tables.

I''d appreciate some help on this, since I''m hoping to use similar
methods to generate other listings.

TIA,
Rob

推荐答案

1。你是绝对的,积极地调用相同的程序吗?

确保你用它的名字来称呼它以避免PATH扮演一个角色。

2.避风港你没有详细分析你的日常工作,但总的来说,你自己修改的表格上打开游标的
会产生非b / b
确定性行为,因为计划依赖于游标的缓冲结果集

3. DB2 for LUW支持使用公共表

表达式和union all的本地递归。这将是一个更快的幅度。在developerWorks上有一些示例,在Graeme Birchall的免费在线书籍和在DB2信息中心的

课程中


哦..我也会在下周的IOD解释递归:-)

干杯

Serge

-

Serge Rielau

DB2解决方案开发

IBM多伦多实验室


IOD会议
http://www.ibm.com/software/data/ond...ness/conf2006 /
1. Are you absolutely,positively sur eyou call teh same procedure?
Make sure you call it with it''s qualified name to avoid PATH playing a role.
2. Haven''t analyzed this in detail for your routine, but in general
having cursors open on tables which you modify yourself yields non
deterministic behavior due plan dependent buffering of the cursor result set
3. DB2 for LUW supports recursion natively using common table
expressions and union all. That will be a magnitudes faster. There are
examples on DeveloperWorks, in Graeme Birchall''s free online book and of
course in the DB2 Information Center

Oh.. and I explain recursion at IOD coming week too :-)
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/


嗨Serge,


- 以前的回复被愚蠢的电脑杀死 -


要点1)是的,我通过

schema_name.proc_name调用完全相同的程序。


第2点)但是我应该得到_some_结果,对吧?


第3点)是的,我已经编写了一些例程来通过原生递归生成BOM

列表;并且使用常用的表格表达式和

union all,正如你所说,它们运行得非常快但不给我

我正在排序。我已经玩了一些例行程序,试图获得一个行数/ rownumber,但还没想到

如何做到这一点。 />

我有Graeme的书(对他的肘部更有力量) - 我也得到了DB2

SQL PL:DB2 UDB基本指南在Linux,UNIX,Windows,i5 / OS和

z / OS(第2版)上作者:Janmohamed等。 - 两者都让我获得了
并且在创纪录的时间内在DB2上运行。好吧,至少对我而言,无论如何; - )......
Hi Serge,

-- Previous reply killed by stupid computer--

Point 1) Yes, I''m calling absolutely the same procedure via
schema_name.proc_name.

Point 2) But I should get _some_ results, right?

Point 3) Yes, I''ve already written some routines to produce BOM
listings via "native recursion" and using common table expressions and
union all and, as you say, they run extremely quickly but don''t give me
the sorting I''m after. I''ve played around with the routines in an
attempt to get a rowcount/rownumber included, but haven''t yet figured
how to do this.

I have Graeme''s book (more power to his elbow) - I''ve also got "DB2
SQL PL: Essential Guide for DB2 UDB on Linux, UNIX, Windows, i5/OS, and
z/OS (2nd edition)" by Janmohamed et al. - both of which have got me up
and running on DB2 in record time. Well, at least for me, anyway ;-)...

哦..我也在下周解释IOD的递归:-) - 啊,什么的惭愧,我不会在那里 - 我肯定我会学到一堆...
Oh.. and I explain recursion at IOD coming week too :-) - Ahhh, what a shame, I won''t be there - I''m sure I ''d learn a bunch...



干杯,

Rob


Serge Rielau写道:

Cheers,
Rob

Serge Rielau wrote:


1.你是否绝对,积极地称之为同样的程序? />
确保用它的限定名称来调用它以避免PATH发挥作用。

2. Haven没有详细分析这个例程,但总的来说

在你自己修改的表上打开游标会产生非b / b
确定性行为,因为游标结果集的计划依赖缓冲

3. DB2 for LUW本地使用公共表

表达式和union all支持递归。这将是一个更快的幅度。在developerWorks上有一些示例,在Graeme Birchall的免费在线书籍和在DB2信息中心的

课程中


哦..我也会在下周的IOD解释递归:-)

干杯

Serge

-

Serge Rielau

DB2解决方案开发

IBM多伦多实验室


IOD会议
http://www.ibm.com/software/data/ond...ness/conf2006 /


你看过这个吗?不同的旋转,但它处理编号。
http://www.ibm.com/developerworks/db...dm-0510rielau/

此外,调试野兽时会发生什么? (打印到临时或使用

开发人员中心或Developer Workbench的SQL PL调试器?


干杯

Serge

-

Serge Rielau

DB2解决方案开发

IBM多伦多实验室


IOD会议
http://www.ibm .com / software / data / ond ... ness / conf2006 /
Have you looked at this one? Different spin, but it handles numbering.
http://www.ibm.com/developerworks/db...dm-0510rielau/
Also, what happens when you debug the beast? (print into a temp or using
the SQL PL Debugger of Developer Center or Developer Workbench?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/


这篇关于SP在Control Center中返回结果集,但是从命令行返回结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆