Domanda

I cercando di definire una funzione in Sybase. Scrivo questo script:

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

, ma quando ho eseguito questo, ottengo questo errore:

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

Che cosa posso fare? Grazie

È stato utile?

Soluzione

Ho cercato molto in web e altri documenti, trovo che le funzioni definite dall'utente in Adaptive Server Enterprise 12 (ASE) devono essere implementate in Java. Ho deciso di usare uno StordProcedure. utilizzo E 'un po' difficile ma è supportata in tutte le versioni di Sybase.

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

Altri suggerimenti

I non trovo nulla di sbagliato con il codice. è possibile ri-provare con il codice sotto-

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

Try This .... che funzionerà

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

questo ha funzionato per me.

CREATE FUNCTION GetUserGroup (@userId int)
RETURNS int
AS
BEGIN
 select @userId = 10
    RETURN @userId
END
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top