大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 数据库 -> DB2 -> DB2编程序技巧 (二)

DB2编程序技巧 (二)

时间: 2021-08-13 作者:daque

1 db2编制程序 1.1 建保存进程时create 后确定不要用tab键 create procedure 的create后只能用空格,而不行用tab健,要不编写翻译会通然而。 牢记,牢记。 1.2 运用偶尔表   要提防,偶尔表只能建在user tempory tables space 上,即使database惟有system tempory table space是不许建偶尔表的。   其余,db2的偶尔表和sybase及oracle的偶尔表不太一律,db2的偶尔表是在一个session内灵验的。以是,即使步调有多线程,最佳不要用偶尔表,很难遏制。    建偶尔表时最佳加上  with  replace选项,如许就不妨不表露的drop 偶尔表,建偶尔表时即使不加该选项而该偶尔表在该session内已创造且没有drop,这时候会爆发缺点。 1.3 从数据表中取指定前几条记载 select  *  from tb_market_code fetch first 1 rows only 但底下这种办法不承诺 select market_code into v_market_code          from tb_market_code fetch first 1 rows only;           选第一条记载的字段到一个变量以以次办法包办     declare v_market_code char(1);     declare cursor1 cursor for select market_code from tb_market_code  fetch first 1 rows only for update;     open cursor1;     fetch cursor1 into v_market_code;     close cursor1; 1.4 游目标运用 提防commit和rollback 运用游标时要更加提防即使没有加with hold 选项,在commit和rollback时,该游标将被封闭。commit 和rollback有很多货色要提防。更加提防 游目标两种设置办法 一种为 declare continue handler for not found    begin      set v_notfound = 1;    end; declare cursor1 cursor with hold for select market_code from tb_market_code  for update; open cursor1; set v_notfound=0; fetch cursor1 into v_market_code; while v_notfound=0 do --work set v_notfound=0; fetch cursor1 into v_market_code; end while; close cursor1; 这种办法运用起来比拟搀杂,但也比拟精巧。更加是不妨运用with hold 选项。即使轮回内有commit或rollback 而要维持该cursor不被封闭,只能运用这种办法。

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.