5. Working with Embedded SQL : Dynamic Programming : Dynamic SQL Statements : Execute Immediate Statement
 
Share this page                  
Execute Immediate Statement
The EXECUTE IMMEDIATE statement executes an SQL statement specified as a string literal or using a host language variable. This statement is most useful when the program intends to execute a statement only once, or when using a select loop with a dynamic SELECT statement.
Use the EXECUTE IMMEDIATE statement to execute all SQL statements except for the following statements:
CALL
CLOSE
CONNECT
DECLARE
DESCRIBE
DISCONNECT
ENDDATA
EXECUTE PROCEDURE
EXECUTE
FETCH
GET DATA
GET DBEVENT
INCLUDE
INQUIRE_SQL
OPEN
PREPARE TO COMMIT
PREPARE
PUT DATA
SET_SQL
WHENEVER
The syntax of EXECUTE IMMEDIATE is:
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 executing a dynamic SELECT statement.