Executing static SQL statements in embedded SQL applications
You cannot modify static
SQL statements at run time. You can use static SQL statements for
tasks such as initialization and cleanup.
SQL statements can be executed statically in a host language using the following approach:
- C or C++ (tbmod.sqc/tbmod.sqC)
The following three examples are from the tbmod sample. See this sample for a complete program that shows how to modify table data in C or C++.
The following example shows how to insert table data:EXEC SQL INSERT INTO staff(id, name, dept, job, salary) VALUES(380, 'Pearce', 38, 'Clerk', 13217.50), (390, 'Hachey', 38, 'Mgr', 21270.00), (400, 'Wagland', 38, 'Clerk', 14575.00);The following example shows how to update table data:EXEC SQL UPDATE staff SET salary = salary + 10000 WHERE id >= 310 AND dept = 84;The following example shows how to delete from a table:EXEC SQL DELETE FROM staff WHERE id >= 310 AND salary > 20000 AND job != 'Sales'; - COBOL (updat.sqb)
The following three examples are from the updat sample. See this sample for a complete program that shows how to modify table data in COBOL.
The following example shows how to insert table data:EXEC SQL INSERT INTO staff VALUES (999, 'Testing', 99, :job-update, 0, 0, 0) END-EXEC.The following example shows how to update table data wherejob-updateis a reference to a host variable declared in the declaration section of the source code:EXEC SQL UPDATE staff SET job=:job-update WHERE job='Mgr' END-EXEC.The following example shows how to delete from a table:EXEC SQL DELETE FROM staff WHERE job=:job-update END-EXEC.