Icon UNPREPARE

Un-prepares an SQL statement, releasing all associated resources.

Syntax
UNPREPARE <StatementName>

Usage
Use this statement to un-prepare a DDL, DML, or administrative SQL statement and release all resources associated with the statement, including any compiled symbols, opened tables, or result set cursors. The statement variable must have been previously declared in a DECLARE statement.

For a SELECT statement, the UNPREPARE statement will cause any cursor created using the OPEN to be released, making it inaccessible until the OPEN statement is used again to create a new cursor.

Examples
-- This function looks up the sales tax
-- rate for a given state and county

CREATE FUNCTION LookupSalesTaxRate(IN State CHAR(2), IN County VARCHAR)
RETURNS DECIMAL(19,2)
BEGIN
   DECLARE TempCursor CURSOR FOR stmt;
   DECLARE Result DECIMAL(19,2) DEFAULT 0;

   PREPARE stmt FROM 'SELECT * FROM SalesTaxes WHERE State = ? AND County = ?';

   OPEN TempCursor USING State, County;

   IF (ROWCOUNT(TempCursor) > 0) THEN
      FETCH FIRST FROM TempCursor ('TaxRate') INTO Result;
   END IF;

   CLOSE TempCursor;
   UNPREPARE stmt;

   RETURN Result;
END

SQL 2003 Standard Deviations
This statement deviates from the SQL 2003 standard in the following ways:

DeviationDetails
Dynamic SQLThe use of dynamic SQL for DDL, DML, and administrative statement execution instead of static SQL in procedures and functions is both an ElevateDB extension and a deviation from the standard.
Image