CREATE PROCEDURE Statement (External Procedures)

Creates an interface to a native or external procedure.

Syntax

CREATEOR REPLACE ] PROCEDUREowner.]procedure-name ( [ parameter, …] ) 
[ RESULTresult-column, …) | NO RESULT SET ]  
[  DYNAMIC RESULT SETS integer-expression ]
 [ SQL SECURITY { INVOKER | DEFINER } ] 
[ EXTERNAL NAME external-call’ [ LANGUAGE environment-name ]

Parameters

Usage

The body of a procedure consists of a compound statement. For information on compound statements, see BEGIN … END Statement.

Note: There are two ways to create stored procedures: ISO/ANSI SQL and T-SQL. BEGIN TRANSACTION, for example, is T-SQL specific when using CREATE PROCEDURE syntax. Do not mix syntax when creating stored procedures. See CREATE PROCEDURE Statement [T-SQL].

CREATE PROCEDURE creates a procedure in the database. Users with the CREATE ANY OBJECT system privilege can create procedures for other users by specifying an owner. A procedure is invoked with a CALL statement.

If a stored procedure returns a result set, it cannot also set output parameters or return a return value.

When referencing a temporary table from multiple procedures, a potential issue can arise if the temporary table definitions are inconsistent and statements referencing the table are cached.

You can create permanent stored procedures that call external or native procedures written in a variety of programming languages. You can use PROC as a synonym for PROCEDURE.

Side Effects
  • Automatic commit

Standards

  • SQL—ISO/ANSI SQL compliant.

  • Sybase—The Transact-SQL CREATE PROCEDURE statement is different.

  • SQLJ—The syntax extensions for Java result sets are as specified in the proposed SQLJ1 standard.

Permissions

External procedure to be owned by self – Requires: External procedure to be owned by any user – Requires CREATE EXTERNAL REFERENCE system privilege. Also requires one of:
Related reference
ALTER PROCEDURE Statement
BEGIN … END Statement
CALL Statement
CREATE PROCEDURE Statement
CREATE PROCEDURE Statement [T-SQL]
DROP Statement
EXECUTE IMMEDIATE Statement [ESQL] [SP]
GRANT EXECUTE Statement