Updated on 2025-10-23 GMT+08:00

EXECUTE

Description

Executes a prepared statement. Because a prepared statement exists only in the lifetime of the session, the prepared statement must be created earlier in the current session by using the PREPARE statement.

Precautions

If the PREPARE statement declares some parameters when the prepared statement is created, the parameter set passed to the EXECUTE statement must be compatible. Otherwise, an error occurs.

Syntax

EXECUTE name;

Parameters

  • name

    Specifies the name of the prepared statement to be executed.

  • parameter

    Specifies a parameter variable of the prepared statement. It must be a variable that generates a value compatible with the data type of the parameter specified when the prepared statement was created.

Examples

-- Create a schema.
m_db=# CREATE SCHEMA tpcds;

-- Create the reason table.
m_db=# CREATE TABLE tpcds.reason ( 
    CD_DEMO_SK          INTEGER          NOT NULL,
    CD_GENDER           character(16)            ,
    CD_MARITAL_STATUS   character(100)
);

-- Insert data.
m_db=# INSERT INTO tpcds.reason VALUES(51, 'AAAAAAAADDAAAAAA', 'reason 51');

-- Create the reason_t1 table.
m_db=# CREATE TABLE tpcds.reason_t1 LIKE tpcds.reason;

-- Create a prepared statement for an INSERT statement and execute the prepared statement.
m_db=# PREPARE insert_reason FROM 'INSERT INTO tpcds.reason_t1 VALUES(52,''AAAAAAAADDAAAAAA'',''reason 52'')';

m_db=# EXECUTE insert_reason;

-- Delete the reason and reason_t1 tables.
m_db=# DROP TABLE tpcds.reason;
m_db=# DROP TABLE tpcds.reason_t1;

-- Delete the schema.
m_db=# DROP SCHEMA tpcds;