You use the CREATE FUNCTION statement to create user-defined functions. You must have RESOURCE authority to execute this statement.
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;
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.