PREPARE Statement [ESQL]

Prepares a statement to be executed later or used for a cursor.

Quick Links:

Go to Parameters

Go to Examples

Go to Usage

Go to Standards

Go to Permissions

Syntax

PREPARE statement-name 
FROM statementFORREAD ONLY | UPDATEOF column-name-list ] } ] 
... [ DESCRIBE describe-type INTO [ [ SQL ] DESCRIPTOR ] descriptor ]
... [ WITH EXECUTE ]

describe-typeALL 
   | BIND VARIABLES
   | INPUT 
   | OUTPUT 
   | SELECT LIST } ... { LONG NAMES [ [ OWNER.]TABLE.]COLUMN ] 
   | WITH VARIABLE RESULT }

Parameters

(back to top)

Examples

(back to top)

Usage

(back to top)

The PREPARE statement prepares an SQL statement from the statement and associates the prepared statement with statement-name.

If a host variable is used for statement-name, it must have the type short int. There is a typedef for this type in sqlca.h called a_sql_statement_number. This type is recognized by the SQL preprocessor and can be used in a DECLARE section. The host variable is filled in by the database during the PREPARE statement and need not be initialized by the programmer.

These statements can be prepared:
  • ALTER
  • CALL
  • COMMENT ON
  • CREATE
  • DELETE
  • DROP
  • GRANT
  • INSERT
  • REVOKE
  • SELECT
  • SET OPTION

Preparing COMMIT, PREPARE TO COMMIT, and ROLLBACK statements is still supported for compatibility. However, perform all transaction management operations with static Embedded SQL, because certain application environments may require it. Also, other Embedded SQL systems do not support dynamic transaction management operations.

Note: Make sure that you DROP the statement after use. If you do not, then the memory associated with the statement is not reclaimed.
Side Effects
  • Any statement previously prepared with the same name is lost.

Standards

(back to top)

  • SQL—ISO/ANSI SQL compliant.
  • SAP Sybase Database product—Supported by Open Client/Open Server.

Permissions

(back to top)

None

Related reference
DECLARE CURSOR Statement [ESQL] [SP]
DESCRIBE Statement [ESQL]
DROP Statement
EXECUTE Statement [ESQL]
OPEN Statement [ESQL] [SP]