PS,1880后程序員

          看不完的牙,寫不完的程序,跑不完的步。
          隨筆 - 97, 文章 - 34, 評論 - 10, 引用 - 0
          數(shù)據(jù)加載中……

          MySQL 定義異常


          MySQL5.6,使用SIGNAL可以根據(jù)變量的值,拋出Exception

          測試數(shù)據(jù)

          create table t1(f1 int);

          insert into t1(f1) values(2);

          insert into t1(f1) values(12);

          insert into t1(f1) values(4);

          insert into t1(f1) values(6);

          insert into t1(f1) values(7);

           

          存儲過程定義

          -- --------------------------------------------------------------------------------

          -- Routine DDL

          -- Note: comments before and after the routine body will not be stored by the server

          -- --------------------------------------------------------------------------------

          DELIMITER $$

           

          CREATE PROCEDURE `my_test`

           (

              in_c_t int

           )

          BEGIN

           DECLARE my_n_t int;

           DECLARE specialty CONDITION FOR SQLSTATE '45000';

           

          SELECT count(1) into my_n_t

              FROM t1

              WHERE f1 = in_c_t;

           

          IF my_n_t = 0 THEN

              SIGNAL SQLSTATE '45000'

                SET MESSAGE_TEXT = 'Can not delete';

          end IF;

           

           delete from t1 WHERE f1 = in_c_t;

           COMMIT ;

           

          END

           

          執(zhí)行

          call my_test(2);

          輸出:





          posted on 2013-10-24 10:24 amenglai 閱讀(198) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 肃南| 观塘区| 班玛县| 台安县| 阳信县| 三都| 万年县| 北辰区| 扎鲁特旗| 永福县| 威远县| 临洮县| 阿勒泰市| 肥城市| 西峡县| 菏泽市| 龙海市| 翼城县| 格尔木市| 兴安盟| 合阳县| 嘉禾县| 山西省| 甘肃省| 古田县| 巴塘县| 濉溪县| 连平县| 东乌珠穆沁旗| 台东市| 松阳县| 巴塘县| 昌吉市| 泰来县| 新野县| 定远县| 集贤县| 连山| 琼结县| 萨嘎县| 淮滨县|