Does mySql have the SQLserver @ error variable, or the try catch syntax in c.
The answer is yes. The instance code is as follows:
Code
Drop procedure if exists sp_call_jobs;
Create procedure sp_call_jobs ()
NOT DETERMINISTIC
SQL SECURITY DEFINER
COMMENT''
BEGIN
Declare _ row, _ err, _ count int default 0;
Declare continue handler for sqlexception, SQLWARNING, not found set _ err = 1;
While _ row <3 DO
Start transaction;
Insert into t1 (cond_val) values (null );
COMMIT;
If _ err = 1 then
Set _ count = _ count + 1;
End if;
Set _ row = _ row + 1;
End while;
Select _ count;
END;
Statement:
Declare continue handler for sqlexception, SQLWARNING, not found set _ err = 1;
When an SQLEXCEPTION, SQLWARNING, and not found error occurs, SET _ err = 1 and execute the CONTINUE operation, that is, CONTINUE to execute the following statement.
This is similar to the try catch syntax in c.
We also use the TRANSACTION statement: start transaction ;...... COMMIT; can ensure integrity.