Skip to content Skip to sidebar Skip to footer

Error Handling In Sybase

Is there a way to handle errors in SYBASE, such as the TRY-CATCH block you can use in MS SQL Server, Oracle, etc? I've searched the web and the only option I found was the global v

Solution 1:

1st solution.

You can't catch an exception this way on Sybase. Before you update you have to check data:

if notexists
(
  select1from table2
  where id =1
)
beginupdate table2
  set id =1where id =30endelsebegin
  print 'rolled back'rollbackend

2nd solution.

You can also put an update command to procedure, then you can catch an exception. Create procedure:

createprocedure myproc
asbeginupdate table2
  set id =1where id =30end

and run it as below:

begin tran

update table1
set name ='new name'where name ='old name'exec myproc

IF @@error=0begin
    print 'commited'commitendelsebegin
    print 'rolled back'rollbackend

Post a Comment for "Error Handling In Sybase"