4 EXECUTE IMMEDIATE — dynamically prepare and execute a statement
8 EXECUTE IMMEDIATE string
12 EXECUTE IMMEDIATE immediately prepares and executes a dynamically
13 specified SQL statement, without retrieving result rows.
18 A literal string or a host variable containing the SQL statement
23 In typical usage, the string is a host variable reference to a string
24 containing a dynamically-constructed SQL statement. The case of a
25 literal string is not very useful; you might as well just write the SQL
26 statement directly, without the extra typing of EXECUTE IMMEDIATE.
28 If you do use a literal string, keep in mind that any double quotes you
29 might wish to include in the SQL statement must be written as octal
30 escapes (\042) not the usual C idiom \". This is because the string is
31 inside an EXEC SQL section, so the ECPG lexer parses it according to
32 SQL rules not C rules. Any embedded backslashes will later be handled
33 according to C rules; but \" causes an immediate syntax error because
34 it is seen as ending the literal.
38 Here is an example that executes an INSERT statement using EXECUTE
39 IMMEDIATE and a host variable named command:
40 sprintf(command, "INSERT INTO test (name, amount, letter) VALUES ('db: ''r1''',
42 EXEC SQL EXECUTE IMMEDIATE :command;
46 EXECUTE IMMEDIATE is specified in the SQL standard.