Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a MySQL feature like SQL Server 2005's TRY/CATCH blocks?

Tags:

mysql

I'm thinking about porting a database from Sql Server 2005 to MySQL.

I've become accustomed to using SQL Server's TRY/CATCH block in stored procedures.

Does MySQL have something similar, or am I going to be forced to go back to the old-school "check the error return after every statement, and issue a goto if it failed" style of programming?

like image 912
Eric H. Avatar asked Aug 29 '09 18:08

Eric H.


People also ask

Does SQL have a try catch?

SQL Server TRY CATCH overviewIf the statements between the TRY block complete without an error, the statements between the CATCH block will not execute. However, if any statement inside the TRY block causes an exception, the control transfers to the statements in the CATCH block.

How to use TRY and CATCH in SQL Server?

A TRY... CATCH construct catches all execution errors that have a severity higher than 10 that do not close the database connection. A TRY block must be immediately followed by an associated CATCH block. Including any other statements between the END TRY and BEGIN CATCH statements generates a syntax error.

What is mysql block?

A block consists of various types of declarations (e.g., variables, cursors, handlers) and program code (e.g., assignments, conditional statements, loops). The order in which these can occur is as follows: Variable and condition declarations.

Can we have multiple try catch blocks in SQL Server?

A TRY… CATCH construct cannot span multiple blocks of Transact-SQL statements.


1 Answers

You can declare handlers for specific error results.

like image 63
Zed Avatar answered Nov 10 '22 20:11

Zed