Functions

From DBArtisan
Jump to: navigation, search

Go Up to Supported Objects

Functions are subroutines that you define. Functions are useful for reusable application logic. You can use functions to determine the best methods for controlling access and manipulation of the underlying data contained in an object.

The table below describes the types of user-defined functions you can create:

Function Description

Column or External Table Function

You can write in a host programming language, such as C. This function can act on a table and returns a table value rather than a scalar value.

External Scalar Function

You can write in a language other than SQL, such as C++ or Java and returns a scalar value to the program. This type of function is referenced by the CREATE FUNCTION statement and can be used to perform computations on data contained in the database but cannot directly reference the data.

OLEDB Function

Accesses OLE DB data in user-defined OLE DB external tables.

Sourced Function

Inherits the semantics of another function and can be an operator.

Template Function

Partial functions that do not contain any executable code. Mainly used in a federated database to map the template function to a data source function -Oracle, SQL Server, Sybase ASE, etc. A function mapping needs to be created in conjunction with the template function.

Creating and editing

Note: Creation and editing of objects of this type is not supported against Sybase IQ datasources.

DBMS platform availability and object actions/operations supported

The following table lists object actions available for this object type. For an introduction to object actions and details on usage of specific actions, see Object actions.

DB2 LUW DB2 z/OS MySQL ORCL PSTGRS * SQL SVR SYB ASE SYB IQ

Change Owner

Change Owner

Compile

Create Synonym

Describe

Drop

Execute

Extract

Hide Text

Migrate

Object Properties

Rename

Report

Transfer Ownership

Important Notes

With respect to functions and stored procedures, it can be necessary to have statements executed before and after creation of the procedure or function. This can be useful for example, if you need to create or drop temporary tables used by the function or procedure. Two tag pairs, ETStart and ETEnd, let you embed statements in the first comment block of a stored procedure or function. The following shows the expected syntax:

create procedure dbo.procname(@a numeric) as

/*

<ETStart>SQL Statement</ETStart>

<ETEnd>SQL Statement</ETEnd>

*/

begin

...