CREATE PROCEDURE Statement (External Procedures)

Creates an interface to a native or external procedure.

For CREATE PROCEDURE reference information for Java UDFs, see CREATE PROCEDURE Statement (Java UDF). For CREATE PROCEDURE reference information for table UDFs, see CREATE PROCEDURE Statement (Table UDF)

Quick Links:

Go to Parameters

Go to Usage

Go to Standards

Go to Permissions

Syntax

CREATEOR REPLACE ] PROCEDUREowner.]procedure-name ( [ parameter, …] ) 
   [ SQL SECURITY { INVOKER | DEFINER } ] 
   [ RESULTresult-column, …) | NO RESULT SET ]  
   [ DYNAMIC RESULT SETS integer-expression ]
   [ EXTERNAL NAMEnative-call’
      | EXTERNAL NAME 'c-call' LANGUAGE { C_ESQL32 | C_ESQL64 | C_ODBC32 | C_ODBC64 }
      | EXTERNAL NAME 'perl-call' LANGUAGE PERL
      | EXTERNAL NAME 'php-call' LANGUAGE PHP 
      | EXTERNAL NAME 'java-call' LANGUAGE JAVA }

parameter - (back to Syntax)
   parameter_mode parameter-name data-typeDEFAULT expression ] | SQLCODE | SQLSTATE

parameter_mode - (back to parameter)
   IN | OUT | INOUT

result-column - (back to Syntax)
   column-name data-type

native-call - (back to Syntax)
   [operating-system:]function-name@library

c-call - (back to Syntax)
   [operating-system:]function-name@library; ...

perl-call - (back to Syntax)
   <file=perl-file> $sa_perl_return = perl-subroutine( $sa_perl_arg0[, ... ] ) 

php-call - (back to Syntax)
   <file=php-file> print php-func( $argv[1][, ... ] ) 

java-call - (back to Syntax)
   [package-name.]class-name.method-name method-signature

operating-system - (back to native-call) or (back to c-call)
   Unix

method-signature - (back to java-call) 
   ( [ field-descriptor, ... ] ) return-descriptor

field-descriptor and return-descriptor - (back to method-signature)
   { Z 
     | B
     | S 
     | I 
     | J
     | F
     | D
     | C
     | V 
     | [descriptor 
     | Lclass-name;
   }

Parameters

(back to top)

Usage

(back to top)

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].

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

You cannot create TEMPORARY external call procedures.

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

(back to top)

  • SQL—ISO/ANSI SQL compliant.
  • SAP Sybase Database product—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

(back to top)

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