1. Condition definition
DECLARE condition_name CONDITION FOR condition_vale
condition_value:
sqlstate[value] sqldata_value |mysql tutorial_error_code
2. Condition processing
DECLARE htype HANDLER FOR cond_ value[...] sp_statement
handtype_value :
sqlstate [value] saltate_value
|contentname
|sqlwarning
|not found
|sqlexeeption
|mysql_erroe_code
The above is the syntax, let’s talk about it through examples
mysq l>select max(id) from ac
maxid =200;
1row in set (0.00 sec)
mysql->delimiter $$
mysql>
mysql>create procedure actor_insret()
->begin
-> set @x=1;
->nsert into actor(id)values(201)
->sex @x=2;
insert into actor(id)values(202)
->set @ x=3;
->end
->$$
query ok, 0 rows affected (0.00 sec)
mysql->delimiter;
mysql>call actor_insert();
error 1062 (23000):duplicate entyr 202 from key primary
mysql->select @x;
@x
201
1row in set (0.00 sec)
As can be seen from the above, when the primary key is duplicated, it will not Do other operations
The above is the content of mysql sql stored procedure condition definition and processing. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!