CREATE PROCEDURE

Advantage SQL Engine

Adds an Advantage Extended Procedure (stored procedure) definition in the Advantage Data Dictionary

Syntax

CREATE PROCEDURE <procedure-name>

( [<parameter-identifier> <data-type> [OUTPUT]]

 [,<parameter-identifier> <data-type> [OUTPUT]] …)

procedure_definition

 

procedure_definition ::= script_procedure_definition | external_procedure_definition

 

script_procedure_definition ::= BEGIN script END

 

external_procedure_definition ::= FUNCTION <container-function-name> IN (LIBRARY | COMLIBRARY) < AEP-library >

 

Remarks

The CREATE PROCEDURE statement can be used to create a stored procedure that is written in SQL script language and stored entirely in the Advantage Data Dictionary, or it can be used to create a stored procedure (Advantage Extended Procedure) that references a function in an external library.

To create a stored procedure written in SQL script language and stored the procedure in the Advantage Data dictionary, use the syntax with the script_procedure_defintion. The SQL script enclosed between the BEGIN and END token will be stored in the data dictionary. The SQL script will be executed when an EXECUTE PROCEDURE <procedure-name> statement is executed.

To create a stored procedure that references a function in an external library, use the external_procedure_definition syntax. The reference to the external function will be stored in the data dictionary. Advantage SQL engine will load the external library and call the function when the EXECUTE PROCEDURE <procedure-name> statement is executed.

<container-function-name> is the name of the function in the Advantage Extended Procedures file that should be invoked when the procedure named <procedure-name> is executed.

COM and .NET Users

<AEP-library> is the ProgID of your AEP library. This value consists of the project name combined with the class name, and must be surrounded by quotation marks or [] (brackets). For example:

 

CREATE PROCEDURE MyComAEP

( Lastname CHAR(20) )

FUNCTION MyProcedure IN COMLIBRARY "ClassLibrary1.ComClass1"

 

Note Your COM or .NET DLL must be registered on the server that will be executing the extended procedure.

WIN32 and Linux Shared Object Users

<AEP-library> is the file name of the Advantage Extended Procedures file. This file is a Win32 Dynamic Link Library (DLL) or a Linux shared object (so). The default extension is .AEP. If the .AEP file has a different extension or if the file exists in a different directory than the Advantage Data Dictionary, then two things must be done. First, the entire name and path must be surrounded with double quotes (") or [] (brackets). Secondly, the path must not contain drive letters. The SQL statement and the stored procedure are run from the Advantage Database Server. The file server where the Advantage server is running will not have the same drive mappings. Always use a relative path or a UNC path. An example relative path would be:

Assume the data dictionary file is located at \\server1\datashare\database\sample.add

Assume the stored procedure file named SP.AEP is located at \\server1\datashare\database\stored_procs\sp.aep

The relative path is stored_procs\sp.aep or \stored_procs\sp.aep

The keyword OUTPUT indicates that the parameter is an output parameter. Other parameters are input parameters. Input parameters must be supplied in the EXECUTE PROCEDURE call and are passed to the stored procedure. If the stored procedure definition has output parameters, the EXECUTE PROCEDURE call will result in an opened cursor that contains the output parameter values in columns. The cursor may consist of multiple rows.

The CREATE PROCEDURE statement can only be executed by a user with CREATE PROCEDURE permissions.

Examples

CREATE PROCEDURE BeginTransaction()

FUNCTION BeginTransaction IN LIBRARY "Example4StoredProc.aep"

 

CREATE PROCEDURE CommitTransaction()

FUNCTION CommitTransaction IN LIBRARY "Example4StoredProc.aep"

 

CREATE PROCEDURE RollBackTransaction()

FUNCTION RollBackTransaction IN LIBRARY "Example4StoredProc.aep"

 

CREATE PROCEDURE GetInfoForTable

( RecordCount INTEGER OUTPUT,

MaxEmployeeID INTEGER OUTPUT,

NewestEmployee CHAR(41) OUTPUT,

UniqueLastNameCount INTEGER OUTPUT )

FUNCTION GetInfoForTable IN LIBRARY "Example4StoredProc.aep"

 

CREATE PROCEDURE AddRecordToData

( LastName CHAR(20),

FirstName CHAR(20),

EmpID SHORT,

Married LOGICAL )

FUNCTION AddRecordToData IN LIBRARY "Example4StoredProc.aep"

 

CREATE PROCEDURE MyComAEP

( Lastname CHAR(20) )

FUNCTION MyProcedure IN COMLIBRARY "ClassLibrary1.ComClass1"

 

// A simple stored procedure implemented using SQL script

CREATE PROCEDURE AddRecordToData

( LastName CHAR(20),

FirstName CHAR(20),

EmpID SHORT,

Married LOGICAL )

BEGIN

INSERT INTO Data( lastname, firstname, empid, married ) SELECT * FROM __input;

END;

 

See Also

sp_ModifyProcedureProperty