ASA SQL User's Guide
Using Procedures, Triggers, and Batches
Introduction to user-defined functions
You use the CREATE FUNCTION statement to create user-defined functions. However, you must have RESOURCE authority.
The following simple example creates a function that concatenates two strings, together with a space, to form a full name from a first name and a last name.
CREATE FUNCTION fullname (firstname CHAR(30), lastname CHAR(30)) RETURNS CHAR(61) BEGIN DECLARE name CHAR(61); SET name = firstname || ' ' || lastname; RETURN ( name ); END
To create this example using Interactive SQL
Connect to the sample database from Interactive SQL with a user ID of DBA and a password of SQL. For more information about connecting, see Connecting to a Database.
In the SQL Statements pane, type the above function code.
NoteIf you are using a tool other than Interactive SQL or Sybase Central, you may need to change the command delimiter to something other than the semicolon. |
For more information, see CREATE FUNCTION statement.
The CREATE FUNCTION syntax differs slightly from that of the CREATE PROCEDURE statement. The following are distinctive differences:
No IN, OUT, or INOUT keywords are required, as all parameters are IN parameters.
The RETURNS clause is required to specify the data type being returned.
The RETURN statement is required to specify the value being returned.