2009-10-13 99 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 
相關問題