prepare

Description

Declares a name for a dynamic SQL statement buffer.

Syntax

exec sql [at connection_name] prepare statement_name from {:host_variable | "string"};

Parameters

statement_name

An identifier used to reference the statement. statement_name must uniquely identify the statement buffer and must conform to the SQL identifier rules for naming variables. The statement_name can also be a host_variable string containing a valid SQL identifier. statement_name can be up to 255 characters.

host_variable

A character-string host variable that contains an executable SQL statement. Place dynamic parameter markers (“?”) anywhere in the select statement where a host variable value will be substituted.

string

A literal string that can be used in place of host_variable.

Examples

Example 1

exec sql begin declare section; 
     CS_CHAR        dyn_buffer[128]; 
     CS_CHAR        state[2]; 
 exec sql end declare section; 
  
 -- The select into table_name statement returns no
 -- results to the program, so it does not 
 -- need a cursor. 
  
 dyn_buffer = "select * into #work from authors" 
         + "where state = ?”; 
  
 printf("State? ");
 gets(state); 
exec sql prepare make_work from :dyn_buffer;
exec sql execute make_work using :state; 

Usage

See also

declare cursor, execute, execute immediate, deallocate prepare