Help Center > > Developer Guide> SQL Reference> SQL Syntax> EXECUTE

EXECUTE

Updated at: Mar 13, 2020 GMT+08:00

Function

EXECUTE executes a prepared statement. A prepared statement only exists in the lifecycle of a session. Therefore, only prepared statements created using PREPARE earlier in the session can be executed.

Precautions

If the PREPARE statement creating the prepared statement declares certain parameters, the parameter set transferred to the EXECUTE statement must be compatible. Otherwise, an error occurs.

Syntax

EXECUTE name [ ( parameter [, ...] ) ];

Parameter Description

  • name

    Specifies the name of the statement to be executed.

  • parameter

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
-- Create the reason table:
CREATE TABLE tpcds.reason ( 
    CD_DEMO_SK          INTEGER          NOT NULL,
    CD_GENDER           character(16)            ,
    CD_MARITAL_STATUS   character(100)
)
;

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

-- Create the reason_t1 table:
CREATE TABLE tpcds.reason_t1 AS TABLE reason;

-- Create and execute a prepared statement for the INSERT statement:
PREPARE insert_reason(integer,character(16),character(100)) AS INSERT INTO tpcds.reason_t1 VALUES($1,$2,$3);

EXECUTE insert_reason(52, 'AAAAAAAADDAAAAAA', 'reason 52'); 

-- Delete tables reason and reason_t1:
DROP TABLE tpcds.reason;
DROP TABLE tpcds.reason_t1;

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel