Static and dynamic SQL statement execution in embedded SQL applications
Both static and dynamic
SQL statement execution is supported in embedded SQL applications.
The decision to execute SQL statements statically or dynamically
requires an understanding of packages, how SQL statements are issued
at run time, host variables, parameter markers, and how these things
are related to application performance.
Static SQL in embedded SQL programs
An example of a statically issued statement in C is:
/* select values from table into host variables using STATIC SQL and print them*/
EXEC SQL SELECT id, name, dept, salary INTO :id, :name, :dept, :salary
FROM staff WHERE id = 310;
Dynamic SQL in embedded SQL programs
An example of a dynamically issued statement in C is:
/* Update column in table using DYNAMIC SQL*/
strcpy(hostVarStmtDyn, "UPDATE staff SET salary = salary + 1000 WHERE dept = ?");
EXEC SQL PREPARE StmtDyn FROM :hostVarStmtDyn;
EXEC SQL EXECUTE StmtDyn USING :dept;