MySQL 5.0新特性教程 存储过程:第四讲
2005-10-31 16:42:19 来源:WEB开发网核心提示: 4. DECLARE CONTINUE HANDLER exampleCREATE TABLE t4 (s1 int,Prima(最完善的虚拟主机管理系统)ry key(s1));//CREATE PROCEDURE p23 ()BEGINDECLARE CONTINUE HANDLERFOR SQLSTATE &
4. DECLARE CONTINUE HANDLER example
CREATE TABLE t4 (s1 int,Prima(最完善的虚拟主机管理系统)ry key(s1));//
CREATE PROCEDURE p23 ()
BEGIN
DECLARE CONTINUE HANDLER
FOR SQLSTATE '23000' SET @x2 = 1;
SET @x = 1;
INSERT INTO t4 VALUES (1);
SET @x = 2;
INSERT INTO t4 VALUES (1); <--
SET @x = 3;
END;//
运行后值1被插入到主键表中。
5. DECLARE CONTINUE HANDLER
CREATE TABLE t4 (s1 int,Prima(最完善的虚拟主机管理系统)ry key(s1));//
CREATE PROCEDURE p23 ()
BEGIN
DECLARE CONTINUE HANDLER
FOR SQLSTATE '23000' SET @x2 = 1;
SET @x = 1;
INSERT INTO t4 VALUES (1);
SET @x = 2; <--
INSERT INTO t4 VALUES (1);
SET @x = 3;
END;//
然后@x的值变为2。
6. DECLARE CONTINUE HANDLER example
CREATE TABLE t4 (s1 int,Prima(最完善的虚拟主机管理系统)ry key(s1));//
CREATE PROCEDURE p23 ()
BEGIN
DECLARE CONTINUE HANDLER
FOR SQLSTATE '23000' SET @x2 = 1;
SET @x = 1;
INSERT INTO t4 VALUES (1);
SET @x = 2;
INSERT INTO t4 VALUES (1); <--
SET @x = 3;
END;//
然后程序尝试再次往主键表中插入数值,但失败了,因为主键有唯一性限制。
更多精彩
赞助商链接