?
Solved

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

Posted on 2016-07-18
1
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
BudDurland earned 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
"Any files you do not have backed up in at least two [other] places are files you do not care about."
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

764 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