Question

I trying to define a function in sybase. I write this script:

CREATE FUNCTION GetUserGroup (userId int)
RETURNS int
BEGIN
    RETURN (10)
END

but when I run this, I get this error:

>[Error] Script lines: 1-6 --------------------------
 Incorrect syntax near the keyword 'BEGIN'.
 Msg: 156, Level: 15, State: 2
 Server: NEWSERVER, Procedure: GetUserGroup, Line: 3 

>[Error] Script lines: 1-6 --------------------------
 A RETURN statement with a return status may only be used in a SQL stored procedure.
 Msg: 178, Level: 15, State: 1
 Server: NEWSERVER, Procedure: GetUserGroup, Line: 4 

 [Executed: 10/13/09 11:01:29 AM IRST ] [Execution: 0/ms] 

What can I do? Thanks

Was it helpful?

Solution

I searched very much in web and other documents, I find that user-defined functions in Adaptive Server Enterprise 12 (ASE) must be implemented in Java. I decided to use a StordProcedure. It usage is a little hard but it supported in all version of Sybase.

see: http://www.sypron.nl/udf.html

OTHER TIPS

I doesn't find any thing wrong with the code. you can re-try with the code below-

CREATE FUNCTION GetUserGroup (userId int)
RETURNS int
As
BEGIN
    RETURN (10)
END

Try This ....it will work

CREATE FUNCTION GetUserGroup (@userId int)
RETURNS int
As
BEGIN
declare @Result int
select @Result=10
RETURN @Result
END

this worked for me.

CREATE FUNCTION GetUserGroup (@userId int)
RETURNS int
AS
BEGIN
 select @userId = 10
    RETURN @userId
END
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top