Skip to main content

PREPARE SQL STMT

The PREPARE statement compiles a SQL statement into its execution plan. The plan is given a name and stored in the query cache. A subsequent EXECUTE command retrieves it from the cach eand executes it.

PREPARE statements executions can be given positional  arguments to replace any literal constant in the query.  Each argument is denoted with a '?'.

sql>prepare select * from tables;
execute prepared statement using: EXEC 2(...)
+----------+--------+-------+--------+--------+---------------+
| type     | digits | scale | schema | table  | column        |
+==========+========+=======+========+========+===============+
| int      |     32 |     0 |        | tables | id            |
| varchar  |   1024 |     0 |        | tables | name          |
| int      |     32 |     0 |        | tables | schema_id     |
| varchar  |   2048 |     0 |        | tables | query         |
| smallint |     16 |     0 |        | tables | type          |
| boolean  |      1 |     0 |        | tables | system        |
| smallint |     16 |     0 |        | tables | commit_action |
| boolean  |      1 |     0 |        | tables | readonly      |
| tinyint  |      8 |     0 |        | tables | temporary     |
+----------+--------+-------+--------+--------+---------------+
9 tuples (3.340ms)
sql>exec 2();