我试图定义在Sybase的功能。我写此脚本:

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

但是当我运行它,我得到这个错误:

>[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] 

我能做些什么? 感谢

有帮助吗?

解决方案

我在搜索网页和其他文件非常多,我发现,Adaptive Server Enterprise中12(ASE)用户定义的函数必须用Java来实现。 我决定使用StordProcedure。它的用法是有点辛苦,但它在所有版本的Sybase的支持。

请参阅: http://www.sypron.nl/udf.html

其他提示

我没有发现任何东西错误的代码。你可以用代码如下─重新尝试

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

尝试这个....它将工作

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

这为我工作。

CREATE FUNCTION GetUserGroup (@userId int)
RETURNS int
AS
BEGIN
 select @userId = 10
    RETURN @userId
END
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top