Embedded SQL programming

Application programs written in host languages such as COBOL can contain SQL statements. The source form of a static SQL statement is embedded within application program, and the statement is prepared before the program is executed and the operational form of the statement persists beyond the execution of the program.

An application program can also contain dynamic SQL statements referred to as embedded dynamic SQL. Programs that contain embedded dynamic SQL statements must be precompiled like those that contain static SQL, but unlike static SQL, the dynamic statements are constructed and prepared at run time. The source form of a dynamic statement is a character string that is passed to Db2 by the program using the static SQL PREPARE or EXECUTE IMMEDIATE statement. A statement that is prepared using the PREPARE statement can be referenced in a DECLARE CURSOR, DESCRIBE, or EXECUTE statement. Whether the operational form of the statement is persistent depends on whether dynamic statement caching is enabled.