Contents Index Introduction to user-defined functions Calling user-defined functions

ASA SQL User's Guide
  Using Procedures, Triggers, and Batches
    Introduction to user-defined functions

Creating 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

  1. 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.

  2. In the SQL Statements pane, type the above function code.

Note 
If 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:


Contents Index Introduction to user-defined functions Calling user-defined functions