]> begriffs open source - ai-pg/blob - full-docs/txt/ecpg-sql-execute-immediate.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / ecpg-sql-execute-immediate.txt
1
2 EXECUTE IMMEDIATE
3
4    EXECUTE IMMEDIATE — dynamically prepare and execute a statement
5
6 Synopsis
7
8 EXECUTE IMMEDIATE string
9
10 Description
11
12    EXECUTE IMMEDIATE immediately prepares and executes a dynamically
13    specified SQL statement, without retrieving result rows.
14
15 Parameters
16
17    string #
18           A literal string or a host variable containing the SQL statement
19           to be executed.
20
21 Notes
22
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.
27
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.
35
36 Examples
37
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''',
41 1, 'f')");
42 EXEC SQL EXECUTE IMMEDIATE :command;
43
44 Compatibility
45
46    EXECUTE IMMEDIATE is specified in the SQL standard.