Sybase 12.4.2 Server User Manual


 
Introduction to user-defined functions
236
If you are using a tool other than DBISQL or Sybase Central, you may need to
change the command delimiter away from the semicolon before entering the
CREATE FUNCTION statement.
CREATE FUNCTION fullname (firstname CHAR(30),
lastname CHAR(30))
RETURNS CHAR(61)
BEGIN
DECLARE name CHAR(61);
SET name = firstname || ’ ’ || lastname;
RETURN ( name );
END
For a complete description of the CREATE FUNCTION syntax, see Adaptive
Server IQ Reference Manual.
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.
Calling user-defined functions
A user-defined function can be used, subject to permissions, in any place that
a built-in non-aggregate function is used.
The following statement in DBISQL returns a full name from two columns
containing a first and last name:
SELECT fullname (emp_fname, emp_lname)
FROM employee;
The following statement in DBISQL returns a full name from a supplied first
and last name:
fullname (emp_fname, emp_lname)
Fran Whitney
Matthew Cobb
Philip Chin
...