HomeMogDBMogDB StackUqbar
v5.0

Documentation:v5.0

Supported Versions:

Other Versions:

EXECUTE

Function

Execute a prepared statement that was prepared earlier. Because a prepared statement exists only for the life of the session, the prepared statement must have been created with a PREPARE statement some time before the current session.

Precautions

  • If the PREPARE statement that creates the prepared statement declares some parameters, then what is passed to the EXECUTE statement must be a compatible set of parameters or an error will be generated.
  • Compared to the original MogDB, dolphin's modification to the PREPARE syntax is that it supports the EXECUTE USING syntax.

Syntax

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

Parameter Description

  • name

    The name of the preparatory statement to be executed.

  • parameter

    The specific value given to one of the parameters of the prepared statement. It must be an expression that generates a value compatible with the data type of the parameter specified when the prepared statement was created.

Examples

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

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

-- Create the table reason_t1.
MogDB=# CREATE TABLE tpcds.reason_t1 AS TABLE tpcds.reason;

-- Create a prepared statement for an INSERT statement and then executes it.
MogDB=# PREPARE insert_reason(integer,character(16),character(100)) AS INSERT INTO tpcds.reason_t1 VALUES($1,$2,$3);

MogDB=# EXECUTE insert_reason(52, 'AAAAAAAADDAAAAAA', 'reason 52'); 

MogDB=# EXECUTE insert_reason USING 52, 'AAAAAAAADDAAAAAA', 'reason 52'; 

-- Delete the tables reason and reason_t1.
MogDB=# DROP TABLE tpcds.reason;
MogDB=# DROP TABLE tpcds.reason_t1;
Copyright © 2011-2024 www.enmotech.com All rights reserved.