2009-10-13 96 views
1

我试图在sybase中定义一个函数。我写这个剧本:如何在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] 

我能做些什么? 谢谢

回答

5

我在web和其他文档中搜索得非常多,我发现Adaptive Server Enterprise 12(ASE)中的用户定义函数必须用Java实现。 我决定使用StordProcedure。它的使用有点困难,但在所有版本的Sybase中均受支持。

看到:http://www.sypron.nl/udf.html

1

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

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

不会对ASE 12.x的 – 2015-02-26 12:28:44

-1

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

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

工作在ASE的12.x不起作用 – 2015-02-26 12:29:22

+0

也没有在ASE 15.7的工作。 – 2017-04-24 20:48:51

-1

这为我工作。

CREATE FUNCTION GetUserGroup (@userId int) 
RETURNS int 
AS 
BEGIN 
select @userId = 10 
    RETURN @userId 
END 
相关问题