最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySql存儲(chǔ)過程異常處理示例代碼分享

 更新時(shí)間:2012年06月09日 00:04:55   作者:  
在網(wǎng)上查了好多資料,發(fā)現(xiàn)關(guān)于mysql的異常處理資料都是一些錯(cuò)誤號(hào)列表,對(duì)于平時(shí)運(yùn)行中,我們可能更多的希望能夠記錄準(zhǔn)確的錯(cuò)誤消息到日志中
下面是示例代碼,在發(fā)生異常的時(shí)候會(huì)將異常信息存入日志表中,并繼續(xù)運(yùn)行后面的語句.

如果您有更好的建議,望不吝賜教.

存儲(chǔ)過程異常處理示例
復(fù)制代碼 代碼如下:

-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`driveradmin`@`%` PROCEDURE `Merge_BrandProductKey`()
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
begin
insert into t_runninglog values(default,default,'exception in MergeBrandProductKey',concat(@@error_count,' errors'));
commit;
end;
DECLARE CONTINUE HANDLER FOR SQLWARNING
begin
insert into t_runninglog values(default,default,'warnings in MergeBrandProductKey',concat(@@warning_count,' warnings'));
commit;
end;
insert into t_runninglog values(default,default,'start in MergeBrandProductKey','');
commit;
-- 任務(wù)執(zhí)行主體 開始
-- /*
-- normal
update brandproductkey as bpk,
(select bp.brandproductid, bp.brandproductenname, bp.brandid
from brandproduct as bp
inner join (select brandid,brandproductid from brandproductdriverrelation group by brandid,brandproductid) as bpr
on bp.brandid=bpr.brandid and bp.brandproductid = bpr.brandproductid
) as bpp
set bpk.brandproductid=bpp.brandproductid
where bpk.brandproductid = 0
-- and bpk.computertype = 2 -- 0
and bpk.brandid = bpp.brandid
and upper(bpk.brandproductkeyname) = upper(replace(bpp.brandproductenname,' ',''));
commit;
insert into t_runninglog values(default,default,'rule normal in MergeBrandProductKey','');
commit;
-- sony rule 1
-- VPCEA37EC --> (VPCEA37EC/B,VPCEA37EC/L,VPCEA37EC/P,VPCEA37EC/W)
update brandproductkey as bpk,
(select bp.brandproductid, bp.brandproductenname, bp.brandid
from brandproduct as bp
inner join (select brandid,brandproductid from brandproductdriverrelation group by brandid,brandproductid) as bpr
on bp.brandid=bpr.brandid and bp.brandproductid = bpr.brandproductid and bp.brandid=60
) as bpp
set bpk.brandproductid=bpp.brandproductid
where bpk.brandproductid = 0
-- and bpk.computertype = 2 -- 0
and bpk.brandid = bpp.brandid
and bpp.brandproductenname like concat(bpk.brandproductkeyname,'/%');
commit;
insert into t_runninglog values(default,default,'rule sony 1 in MergeBrandProductKey','');
commit;
-- sony rule 2
-- VGN-TZ37N_X --> VGN-TZ37N/X
update brandproductkey as bpk,
(select bp.brandproductid, bp.brandproductenname, bp.brandid
from brandproduct as bp
inner join (select brandid,brandproductid from brandproductdriverrelation group by brandid,brandproductid) as bpr
on bp.brandid=bpr.brandid and bp.brandproductid = bpr.brandproductid and bp.brandid=60
) as bpp
set bpk.brandproductid=bpp.brandproductid
where bpk.brandproductid = 0
-- and bpk.computertype = 2 -- 0
and bpk.brandid = bpp.brandid
and upper(bpk.brandproductkeyname) = upper(replace(bpp.brandproductenname,'/','_'));
commit;
insert into t_runninglog values(default,default,'rule sony 2 in MergeBrandProductKey','');
commit;
-- lenovo rule 1
-- ZHAOYANG E45 --> 昭陽E45
update brandproductkey as bpk,
(select bp.brandproductid, bp.brandproductenname, bp.brandid,bpr.driverid
from brandproduct as bp
inner join (select brandid,brandproductid,max(driverinfoid) as driverid from brandproductdriverrelation group by brandid,brandproductid) as bpr
on bp.brandid=bpr.brandid and bp.brandproductid = bpr.brandproductid and bp.brandid=37
) as bpp
set bpk.brandproductid=bpp.brandproductid
where bpk.brandproductid = 0
-- and bpk.computertype = 2 -- 0
and bpk.brandid = bpp.brandid
and bpk.brandproductkeyname <> ''
and instr(bpp.brandproductenname,SUBSTRING_INDEX(bpk.brandproductkeyname,' ',-1))>0
and bpp.brandproductenname regexp concat('^[^\x00-\xff]+', SUBSTRING_INDEX(bpk.brandproductkeyname,' ',-1),'$');
commit;
insert into t_runninglog values(default,default,'rule lenovo 1 in MergeBrandProductKey','');
commit;
-- HP rule 1
-- HP Compaq 6535s --> HP Compaq 6535s 筆記本電腦
update brandproductkey as bpk,
(select bp.brandproductid, bp.brandproductenname, bp.brandid
from brandproduct as bp
inner join (select brandid,brandproductid from brandproductdriverrelation group by brandid,brandproductid) as bpr
on bp.brandid=bpr.brandid and bp.brandproductid = bpr.brandproductid and bp.brandid=36
) as bpp
set bpk.brandproductid = bpp.brandproductid
where bpk.brandproductid = 0
-- and bpk.computertype = 2 -- 0
and bpk.brandid = bpp.brandid
and bpk.brandproductkeyname <> ''
and bpp.brandproductenname = concat(bpk.brandproductkeyname,' 筆記本電腦');
insert into t_runninglog values(default,default,'rule hp 1 in MergeBrandProductKey','');
commit;
-- HP rule 2
-- HP Compaq 6535s --> HP Compaq 6535s Notebook PC
update brandproductkey as bpk,
(select bp.brandproductid, bp.brandproductenname, bp.brandid
from brandproduct as bp
inner join (select brandid,brandproductid from brandproductdriverrelation group by brandid,brandproductid) as bpr
on bp.brandid=bpr.brandid and bp.brandproductid = bpr.brandproductid and bp.brandid=36
) as bpp
set bpk.brandproductid = bpp.brandproductid
where bpk.brandproductid = 0
-- and bpk.computertype = 2 -- 0
and bpk.brandid = bpp.brandid
and bpk.brandproductkeyname <> ''
and upper(bpp.brandproductenname) = upper(concat(bpk.brandproductkeyname,' Notebook PC'));
insert into t_runninglog values(default,default,'rule hp 2 in MergeBrandProductKey','');
commit;
-- */
-- 任務(wù)執(zhí)行主體 結(jié)束
insert into t_runninglog values(default,default,'finish in MergeBrandProductKey','');
commit;
END

有關(guān)HANDLER的語法結(jié)構(gòu)如下:
復(fù)制代碼 代碼如下:

DECLARE handler_type HANDLER FOR condition_value[,...] sp_statement
handler_type: CONTINUE | EXIT
condition_value: SQLSTATE [VALUE] sqlstate_value | condition_name | SQLWARNING | NOT FOUND | SQLEXCEPTION | mysql_error_code
Handlers類型:
, EXIT: 發(fā)生錯(cuò)誤時(shí)退出當(dāng)前代碼塊(可能是子代碼塊或者main代碼塊)
, CONTINUE: 發(fā)送錯(cuò)誤時(shí)繼續(xù)執(zhí)行后續(xù)代碼
condition_value:
condition_value支持標(biāo)準(zhǔn)的SQLSTATE定義;
SQLWARNING是對(duì)所有以01開頭的SQLSTATE代碼的速記
NOT FOUND是對(duì)所有以02開頭的SQLSTATE代碼的速記
SQLEXCEPTION是對(duì)所有沒有被SQLWARNING或NOT FOUND捕獲的SQLSTATE代碼的速記
除了SQLSTATE值,MySQL錯(cuò)誤代碼也被支持
但是對(duì)于mysql而言,優(yōu)先級(jí)如下:
MySQL Error code > SQLSTATE code > 命名條件

相關(guān)文章

  • MySQL優(yōu)化之緩存優(yōu)化

    MySQL優(yōu)化之緩存優(yōu)化

    在平時(shí)被問及最多的問題就是關(guān)于 MySQL 數(shù)據(jù)庫性能優(yōu)化方面的問題,所以最近打算寫一個(gè)MySQL數(shù)據(jù)庫性能優(yōu)化方面的系列文章,希望對(duì)初中級(jí) MySQL DBA 以及其他對(duì) MySQL 性能優(yōu)化感興趣的朋友們有所幫助。
    2017-03-03
  • ubuntu 16.04配置MySQL主從同步的配置方法

    ubuntu 16.04配置MySQL主從同步的配置方法

    這篇文章主要介紹了ubuntu 16.04配置MySQL主從同步的配置方法,需要的朋友可以參考下
    2018-03-03
  • MySQL 5.5 range分區(qū)增加刪除處理的方法示例

    MySQL 5.5 range分區(qū)增加刪除處理的方法示例

    這篇文章主要給大家介紹了關(guān)于MySQL 5.5 range分區(qū)增加刪除處理的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。
    2017-06-06
  • 基于mysql實(shí)現(xiàn)group by取各分組最新一條數(shù)據(jù)

    基于mysql實(shí)現(xiàn)group by取各分組最新一條數(shù)據(jù)

    這篇文章主要介紹了基于mysql實(shí)現(xiàn)group by取各分組最新一條數(shù)據(jù),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • 構(gòu)建雙vip的高可用MySQL集群

    構(gòu)建雙vip的高可用MySQL集群

    大家好,本篇文章主要講的是構(gòu)建雙vip的高可用MySQL集群,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • 深入理解MySQL主從復(fù)制線程狀態(tài)轉(zhuǎn)變

    深入理解MySQL主從復(fù)制線程狀態(tài)轉(zhuǎn)變

    這篇文章主要給大家介紹了關(guān)于MySQL主從復(fù)制線程狀態(tài)轉(zhuǎn)變的相關(guān)資料,文中介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • MySQL鎖阻塞的深入分析

    MySQL鎖阻塞的深入分析

    這篇文章主要給大家介紹了關(guān)于MySQL鎖阻塞的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • MySQL高級(jí)查詢之JOIN、子查詢、窗口函數(shù)實(shí)際案例

    MySQL高級(jí)查詢之JOIN、子查詢、窗口函數(shù)實(shí)際案例

    這篇文章主要介紹了MySQL高級(jí)查詢之JOIN、子查詢、窗口函數(shù)實(shí)際案例的相關(guān)資料,JOIN用于多表關(guān)聯(lián)查詢,子查詢用于數(shù)據(jù)篩選和過濾,窗口函數(shù)則提供靈活的數(shù)據(jù)統(tǒng)計(jì)和排名功能,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-04-04
  • mysql8如何設(shè)置不區(qū)分大小寫ubuntu20

    mysql8如何設(shè)置不區(qū)分大小寫ubuntu20

    這篇文章主要介紹了mysql8如何設(shè)置不區(qū)分大小寫ubuntu20問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Mysql關(guān)聯(lián)查詢的幾種實(shí)現(xiàn)方式

    Mysql關(guān)聯(lián)查詢的幾種實(shí)現(xiàn)方式

    這篇文章主要介紹了Mysql關(guān)聯(lián)查詢的幾種實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04

最新評(píng)論

龙川县| 临江市| 新蔡县| 鹿泉市| 荥阳市| 云林县| 舞阳县| 乌鲁木齐市| 宝兴县| 汪清县| 商河县| 抚顺市| 双城市| 微山县| 民权县| 安福县| 长岛县| 湖州市| 正阳县| 莱州市| 原阳县| 渝北区| 泸定县| 纳雍县| 山阳县| 商洛市| 旺苍县| 左贡县| 合作市| 会宁县| 维西| 新源县| 尚义县| 城步| 买车| 平利县| 化州市| 桂阳县| 石棉县| 沂源县| 青河县|