You prepare a dynamic statement with PREPARE. You define a name, or statement identifier, that is used to refer to the dynamic statement in subsequent statements and in the EXECUTE statement in particular. All SQL statements that can be prepared are listed in the section "Assignments for PREPARE".
You specify an alphanumeric host variable for the as yet unknown SQL statement represented by the statement identifier. The length of the variable must not exceed 32000 characters. You cannot specify an indicator variable.
In the program, you assign the host variable the desired SQL statement as an alphanumeric string. You can, for example, read in the SQL statement via an interactive program and then use it to construct the string that is transferred to the host variable.
When the PREPARE statement is executed, the dynamic statement must be known with the exception of the values of the placeholders. If the statement is not correct, the PREPARE statement is aborted with errors.