heting
BlogJava
::
首頁
::
新隨筆
::
聯系
::
聚合
::
管理
::
40 隨筆 :: 9 文章 :: 45 評論 :: 0 Trackbacks
<
2009年3月
>
日
一
二
三
四
五
六
22
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(3)
給我留言
查看公開留言
查看私人留言
隨筆分類
c#范例(4)
(rss)
java范例
(rss)
js(3)
(rss)
linux(1)
(rss)
WebSphere(1)
(rss)
數據庫(3)
(rss)
隨筆檔案
2010年10月 (1)
2010年8月 (5)
2010年3月 (2)
2009年11月 (2)
2009年9月 (1)
2009年8月 (1)
2009年7月 (2)
2009年5月 (1)
2009年4月 (3)
2009年3月 (4)
2009年2月 (1)
2009年1月 (3)
2008年12月 (2)
2008年11月 (7)
2008年10月 (4)
2008年9月 (1)
文章檔案
2008年9月 (9)
搜索
最新評論
1.?re: struts2+freemarker中防止表單的重復提交token
@51互聯云-濟南程序猿
你什么都不懂,瞎說
--人
2.?re: struts2+freemarker中防止表單的重復提交token
沒關系,大家好,什么都沒有
--人
3.?re: struts2+freemarker中防止表單的重復提交token
套頭
--人
4.?re: struts2+freemarker中防止表單的重復提交token
評論內容較長,點擊標題查看
--51互聯云-濟南程序猿
5.?re: struts1文件上傳和下載
評論內容較長,點擊標題查看
--zuidaima
閱讀排行榜
1.?struts1文件上傳和下載(21131)
2.?javax.naming.CommunicationException 的一個相關異常(已解決)(11551)
3.?自己寫的一個c#winform打印類(8505)
4.?C# 與 C++ 數據類型比較及結構體轉換 (7217)
5.?WebSphere7.0 上部署struts2 找不到用于處理 JSP 的擴展處理器(2983)
評論排行榜
1.?struts1文件上傳和下載(23)
2.?自己寫的一個c#winform打印類(8)
3.?struts2+freemarker中防止表單的重復提交token(6)
4.?Ireport在瀏覽器中的顯示代碼(2)
5.?EJ3.0將EJB程序和WEb程序發布到weblogic10.3是出現的錯誤weblogic.wsee.async.AsyncResponseBean(2)
MySQL存儲過程例子,包含事務,參數,嵌套調用,游標,循環等
drop
procedure
if
exists
pro_rep_shadow_rs;
delimiter
|
--
--------------------------------
--
rep_shadow_rs
--
用來處理信息的增加,更新和刪除
--
每次只更新上次以來沒有做過的數據
--
根據不同的標志位
--
需要一個輸出的參數,
--
如果返回為0,則調用失敗,事務回滾
--
如果返回為1,調用成功,事務提交
--
--
測試方法
--
call pro_rep_shadow_rs(@rtn);
--
select @rtn;
--
--------------------------------
create
procedure
pro_rep_shadow_rs(out rtn
int
)
begin
--
聲明變量,所有的聲明必須在非聲明的語句前面
declare
iLast_rep_sync_id
int
default
-
1
;
declare
iMax_rep_sync_id
int
default
-
1
;
--
如果出現異常,或自動處理并rollback,但不再通知調用方了
--
如果希望應用獲得異常,需要將下面這一句,以及啟動事務和提交事務的語句全部去掉
declare
exit
handler
for
sqlexception
rollback
;
--
查找上一次的
select
eid
into
iLast_rep_sync_id
from
rep_de_proc_log
where
tbl
=
'
rep_shadow_rs
'
;
--
如果不存在,則增加一行
if
iLast_rep_sync_id
=-
1
then
insert
into
rep_de_proc_log(rid,eid,tbl)
values
(
0
,
0
,
'
rep_shadow_rs
'
);
set
iLast_rep_sync_id
=
0
;
end
if
;
--
下一個數字
set
iLast_rep_sync_id
=
iLast_rep_sync_id
+
1
;
--
設置默認的返回值為0:失敗
set
rtn
=
0
;
--
啟動事務
start
transaction
;
--
查找最大編號
select
max
(rep_sync_id)
into
iMax_rep_sync_id
from
rep_shadow_rs;
--
有新數據
if
iMax_rep_sync_id
>=
iLast_rep_sync_id
then
--
調用
call pro_rep_shadow_rs_do(iLast_rep_sync_id,iMax_rep_sync_id);
--
更新日志
update
rep_de_proc_log
set
rid
=
iLast_rep_sync_id,eid
=
iMax_rep_sync_id
where
tbl
=
'
rep_shadow_rs
'
;
end
if
;
--
運行沒有異常,提交事務
commit
;
--
設置返回值為1
set
rtn
=
1
;
end
;
|
delimiter ;
drop
procedure
if
exists
pro_rep_shadow_rs_do;
delimiter
|
--
-------------------------------
--
處理指定編號范圍內的數據
--
需要輸入2個參數
--
last_rep_sync_id 是編號的最小值
--
max_rep_sync_id 是編號的最大值
--
無返回值
--
-------------------------------
create
procedure
pro_rep_shadow_rs_do(last_rep_sync_id
int
, max_rep_sync_id
int
)
begin
declare
iRep_operationtype
varchar
(
1
);
declare
iRep_status
varchar
(
1
);
declare
iRep_Sync_id
int
;
declare
iId
int
;
--
這個用于處理游標到達最后一行的情況
declare
stop
int
default
0
;
--
聲明游標
declare
cur
cursor
for
select
id,Rep_operationtype,iRep_status,rep_sync_id
from
rep_shadow_rs
where
rep_sync_id
between
last_rep_sync_id
and
max_rep_sync_id;
--
聲明游標的異常處理,設置一個終止標記
declare
CONTINUE
HANDLER
FOR
SQLSTATE
'
02000
'
SET
stop
=
1
;
--
打開游標
open
cur;
--
讀取一行數據到變量
fetch
cur
into
iId,iRep_operationtype,iRep_status,iRep_Sync_id;
--
這個就是判斷是否游標已經到達了最后
while
stop
<>
1
do
--
各種判斷
if
iRep_operationtype
=
'
I
'
then
insert
into
rs0811 (id,fnbm)
select
id,fnbm
from
rep_shadow_rs
where
rep_sync_id
=
iRep_sync_id;
elseif iRep_operationtype
=
'
U
'
then
begin
if
iRep_status
=
'
A
'
then
insert
into
rs0811 (id,fnbm)
select
id,fnbm
from
rep_shadow_rs
where
rep_sync_id
=
iRep_sync_id;
elseif iRep_status
=
'
B
'
then
delete
from
rs0811
where
id
=
iId;
end
if
;
end
;
elseif iRep_operationtype
=
'
D
'
then
delete
from
rs0811
where
id
=
iId;
end
if
;
--
讀取下一行的數據
fetch
cur
into
iId,iRep_operationtype,iRep_status,iRep_Sync_id;
end
while
;
--
循環結束
close
cur;
--
關閉游標
end
;
posted on 2009-03-25 09:55
賀挺
閱讀(534)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright © 賀挺
主站蜘蛛池模板:
九江县
|
万荣县
|
汝州市
|
新兴县
|
卢龙县
|
阳山县
|
德阳市
|
淅川县
|
胶南市
|
五华县
|
盖州市
|
石柱
|
丰都县
|
七台河市
|
闽清县
|
九龙城区
|
夹江县
|
呼和浩特市
|
阿城市
|
苏尼特右旗
|
盐边县
|
扎鲁特旗
|
巫溪县
|
望都县
|
丹江口市
|
阿克
|
宁武县
|
海门市
|
汨罗市
|
汝城县
|
商水县
|
揭阳市
|
长沙县
|
济宁市
|
始兴县
|
淮南市
|
上饶县
|
定兴县
|
盈江县
|
庆安县
|
林芝县
|