Creating a SQL Anywhere or Sybase IQ User-Defined Function

Use Database Development tools to create your own functions for SQL Anywhere or Sybase IQ.

Prerequisites 

Before you can create a user-defined function, be sure the data server that contains the user-defined function is running, and you created and established a connection to the data server.

  1. Right-click the User Defined Functions folder, and choose New > User Defined Function.

    The Create Function Skeleton page appears.

  2. In the Name field, enter the new function name.
  3. Specify the SQL type you are using.
    SQL Type Description
    Watcom-SQL You can then choose either Deterministic function or On exception resume. A deterministic function only works with Watcom-SQL. A function specified as not deterministic is re-evaluated each time it is called in a query.
    Transact-SQL You can only select On exception resume. The On Exception Resume clause enables Transact SQL-like error handling to be used within a Watcom SQL syntax procedure.
  4. Enter a name in the Return Data field, and select the appropriate datatype from the drop-down.
  5. (Optional) Enter a description of the function in the Comments field and click Next.

    The Provide Optional Parameters and Variables Declaration page appears.

  6. Enter a parameter name in the Name column.
  7. Click the Datatype column to select a datatype from the drop-down.
  8. Specify any optional default value for the parameter you are defining.
  9. Declare variables, or click Finish if you have no variables to declare.
  10. In the Name column, enter any local variable names that you want to declare.
  11. Click the Datatype column to select a datatype from the drop-down list.
  12. Click Next, and specify save and execution properties for the user-defined function.
    Field Description
    Generate script Select this option to generate the script for the user-defined function.
    Enter or select the parent folder Specify an existing project or create a new project in which to save the SQL.
    File name Enter the name of the file in which to store the SQL.
    Execute immediately Execute the SQL immediately. If you do not select this option, you must complete execution of the SQL later to create the user-defined function.
    Open in editor after creation Create the user-defined function, and then open it in the User Defined Function Editor.
  13. Click Finish to create the user-defined function.

    The newly created user-defined function is opened automatically in the User-Defined Function Editor.

Related concepts
User-Defined Functions
Related tasks
Editing a User-Defined Function
Dropping a User-Defined Function
Renaming a User-Defined Function

Send your feedback on this help topic to Sybase Technical Publications: pubs@sybase.com

Your comments will be sent to the technical publications staff at Sybase, Inc. For product-related issues or technical support, contact Sybase Technical Support at 1-800-8SYBASE.