Embedded SQL is a method of combining the computing power of a programming language and the database manipulation capabilities of SQL. Embedded SQL statements are SQL statements written inline with the program source code of the host language. The embedded SQL statements are parsed by an embedded SQL preprocessor and replaced by host-language calls to a code library. The output from the preprocessor is then compiled by the host compiler. This allows programmers to embed SQL statements in programs written in any number of languages such as: C/C++, COBOL and Fortran.
The SQL standards committee defined the embedded SQL standard in two steps: a formalism called Module Language was defined, then the embedded SQL standard was derived from Module Language.
Embedded SQL is a robust and convenient method of combining the computing power of a programming language with SQL's specialized data management and manipulation capabilities.
Static Vs Dynamic SQL:
The source form of a static SQL statement is embedded within an application program written in a host language such as COBOL.
The statement is prepared before the program is executed and the operational form of the statement persists beyond the execution of the program.
Static SQL statements in a source program must be processed before the program is compiled. This processing can be accomplished through the DB2 precompiler or the SQL statement coprocessor.
The DB2 precompiler or the coprocessor checks the syntax of the SQL statements, turns them into host language comments, and generates host language statements to invoke DB2.
The preparation of an SQL application program includes precompilation, the preparation of its
static SQL statements, and compilation of the modified source program.
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 statement PREPARE or EXECUTE IMMEDIATE.