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

PREPARE

Syntax

PREPARE statement_name FROM statement

Description

This statement is used to preprocess a statement for later execution. A preprocessing statement is used to save a query in a session with a specified name. A statement can contain parameters to replace the text to be replaced during execution. The parameters are represented by question marks (?).

Example

  • To preprocess a query:
    PREPARE my_select1 FROM SELECT * FROM fruit;
  • The following shows how to preprocess a query that contains parameters. In EXECUTE, the values compared with regionkey and nationkey are replaced.
    PREPARE my_select2 FROM  SELECT name FROM fruit WHERE name= ? AND  price< ?;
  • To preprocess INSERT query:
    PREPARE my_insert FROM INSERT INTO fruit VALUES ('watermelon',18);