CREATE FUNCTION statement

CREAT FUNTION enables users to create a user-defined function with the Sybase CEP Function Language.

Syntax

CREATE FUNCTION fname ( [ pname type [, ...] ] ) RETURNS type { statement [, ...] }END FUNCTION ;
Components

fname

The name of the function.

pname

The name of a parameter.

type

A CCL data type, either for a specific parameter or the return value of the function.

statement

A CFL statement. See statement for syntax.

statement

{ create_variable_statement | assignment_statement | return_statement | break_statement | continue_statement } | { if_statement | case_statement | while_statement }
Components

fname

The name of the function.

pname

The name of a parameter.

type

A CCL data type, either for a specific parameter or the return value of the function.

statement

A CFL statement. See statement for syntax.

Usage

The CCL Create Function statement creates a user-defined function (UDF). The function definition is valid only inside the query module in which it is defined, or in any other query module which imports it by using the CCL Import statement. In all other ways, CCL UDFs can be used according to the same rules, and subject to the same restrictions, as predefined Sybase CEP functions.

Restrictions

See Also

Example

The following example shows an EARTHDISTANCE() function definition that calculates the distance between two geographical points:

CREATE FUNCTION EARTHDISTANCE(
  Latitude1 FLOAT, Longitude1 FLOAT, 
  Latitude2 FLOAT, Longitude2 FLOAT)
  RETURNS FLOAT;
  RETURN (180/pi()) * 60 * 1.1515 * 
    ACOS(
      SIN(Latitude1*pi()/180) * SIN(Latitude2*pi()/180) + 
      COS(Latitude1*pi()/180) * COS(Latitude2*pi()/180) * 
      COS((Longitude1 - Longitude2)*pi()/180)
    );
END FUNCTION;