2

我试图在 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] 

我能做些什么?谢谢

4

4 回答 4

5

我在网络和其他文档中搜索了很多,我发现 Adaptive Server Enterprise 12 (ASE) 中的用户定义函数必须用 Java 实现。我决定使用一个StordProcedure。它的使用有点困难,但它在所有版本的 Sybase 中都支持。

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

于 2009-10-13T08:18:23.603 回答
1

我没有发现代码有任何问题。您可以使用下面的代码重试 -

CREATE FUNCTION GetUserGroup (userId int)
RETURNS int
As
BEGIN
    RETURN (10)
END
于 2012-05-10T09:46:22.307 回答
-1

试试这个....它会工作

CREATE FUNCTION GetUserGroup (@userId int)
RETURNS int
As
BEGIN
declare @Result int
select @Result=10
RETURN @Result
END
于 2014-06-18T08:50:47.197 回答
-1

这对我有用。

CREATE FUNCTION GetUserGroup (@userId int)
RETURNS int
AS
BEGIN
 select @userId = 10
    RETURN @userId
END
于 2016-01-21T16:16:05.393 回答