Updated on 2022-11-18 GMT+08:00

EXECUTE

Syntax

EXECUTE statement_name [ USING parameter1 [ , parameter2, ... ] ]

Description

This statement is used to run the prepared SQL statement and use USING to specify input parameters.

Example

  • To run a precompiled statement without input parameters.
    PREPARE my_select1 FROM SELECT name FROM fruit;
    EXECUTE my_select1;
  • To run the SQL statement with two input parameters:
    PREPARE my_select2 FROM SELECT name FROM  fruit WHERE name= ? and price< ?;
    EXECUTE my_select2 USING  'peach',10;
    This is equivalent to:
    SELECT name FROM fruit WHERE name = 'peach' AND price<10;