Executes an SQL statement.
Syntax 1 – Executes the named dynamic statement that was previously prepared
EXECUTE statement-name ... [ { USING DESCRIPTOR sqlda-name | USING host-variable-list } ] ... [ { INTO DESCRIPTOR into-sqlda-name | INTO into-host-variable-list ] ... [ ARRAY :nnn } ]
Syntax 2 – A short form to PREPARE and EXECUTE a statement that does not contain bind variables or output
EXECUTE IMMEDIATE statement
EXEC SQL EXECUTE IMMEDIATE 'DELETE FROM Employees WHERE EmployeeID = 105';
EXEC SQL PREPARE del_stmt FROM 'DELETE FROM Employees WHERE EmployeeID = :a'; EXEC SQL EXECUTE del_stmt USING :employee_number;
EXEC SQL PREPARE sel1 FROM 'SELECT Surname FROM Employees WHERE EmployeeID = :a'; EXEC SQL EXECUTE sel1 USING :employee_number INTO :emp_lname;
Syntax 1 — If the dynamic statement contains host variable placeholders which supply information for the request (bind variables), then either the sqlda-name must specify a C variable which is a pointer to an SQLDA containing enough descriptors for all bind variables occurring in the statement, or the bind variables must be supplied in the host-variable-list.
Syntax 2 — The SQL statement contained in the string or host variable is immediately executed and is dropped on completion.
EXECUTE can be used for any SQL statement that can be prepared. Cursors are used for SELECT statements or CALL statements that return many rows from the database.
After successful execution of an INSERT, UPDATE, or DELETE statement, the sqlerrd[2] field of the SQLCA (SQLCOUNT) is filled in with the number of rows affected by the operation.