Solved

How to use a TRY CATCH in Sybase SQL syntax. Or something similar?

Posted on 2016-07-18
1
75 Views
Last Modified: 2016-07-19
Hello Sybase Experts. I am porting some SQL Server sql to Sybase sql. The SQL Server sql uses several TRY CATCH blocks in sql server.
Is there any similar type of structure in Sybase to handle exceptions? If so, can someone show me how to do it?
BEGIN TRY
   EXEC (@spName)
END TRY
BEGIN CATCH
     -- Recovery code goes here

END CATCH
0
Comment
Question by:brgdotnet
1 Comment
 
LVL 17

Accepted Solution

by:
BudDurland earned 500 total points
ID: 41719979
You didn't mention which version of Sybase, but it should pretty much be the same.  Here's a sample from the SQLAnywhere docs.  It puts the value 6 in the table 't'

BEGIN TRY
    DECLARE val INT;

    SET val = 0;

    INSERT INTO t VALUES( 1 / val );
    -- This statement will not be executed
    INSERT INTO t VALUES( val );
END TRY
BEGIN CATCH
    SET val = 6;
    INSERT INTO t VALUES( val );
END CATCH;

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reading ASE Optimizer trace flag / switch output 4 574
SQL Query Syntax 11 160
Sybase 2 MS SQL migration/conversion 4 144
How to get the table names associated with a server 3 54
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Note: This is the second blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   Every month t…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now