Was this helpful?
Execute Immediate Statement
The EXECUTE IMMEDIATE statement executes an OpenSQL statement specified as a string literal or using a host variable. The EXECUTE IMMEDIATE is most useful when the program intends to execute a statement only once, or when using a select loop with a dynamic SELECT statement.
The EXECUTE IMMEDIATE statement can be used to execute all OpenSQL statements except for the following statements:
CALL
FETCH
CLOSE
INCLUDE
CONNECT
INQUIRE_SQL
DECLARE
OPEN
DESCRIBE
PREPARE
DISCONNECT
SET_SQL
EXECUTE
WHENEVER
The EXECUTE IMMEDIATE statement has the following syntax:
EXEC SQL EXECUTE IMMEDIATE statement_string
       
[INTO variable {, variable} | USING [DESCRIPTOR]
               descriptor_name
         
[EXEC SQK BEGIN;
               program_code
          
EXEC SQL END;]];
The contents of the statement_string must not include the keywords, EXEC SQL, or a statement terminator. The optional INTO/USING clause and BEGIN/END statement block can only be used when you are executing a dynamic SELECT statement.
Last modified date: 01/30/2023