MySQL Forums
Forum List  »  Stored Procedures

IF EXISTS for SELECT statements
Posted by: Tom Dean
Date: July 07, 2005 01:37PM

I've searched around but can't find an answer for this one. I'm trying to duplicate this T-SQL code from MSSQL:

if exists(SELECT 1 FROM table WHERE id=@id)
begin
// do something here....
end

Any help would be greatly appreciated!

On another note, I read that there are plans, or at least a feature request, to support something along the lines of T-SQL's @@ERROR, where in you can check if an error occurred exactly after a statement. Example:

INSERT INTO table (col1, col2, col3) VALUES (val1, val2, val3)
if (@@ERROR <> 0)
begin
// An error occurred and we'll handle it here
end

Basically I need the means to respond to a an error for a specific query, and not just an error code.

Additionally, is it possible to setup a general catch-all error block? Will the SQLEXCEPTION catch all errors?

Thanks in advance!

Options: ReplyQuote


Subject
Views
Written By
Posted
IF EXISTS for SELECT statements
98140
July 07, 2005 01:37PM
28022
July 08, 2005 05:54AM
10397
July 11, 2005 02:59AM
8673
November 08, 2006 02:52PM
8206
November 08, 2006 03:30PM
7413
November 21, 2006 12:04PM
7221
January 18, 2007 01:10AM
6586
November 16, 2007 01:59AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.