Help Center/ GaussDB/ Developer Guide(Distributed_V2.0-8.x)/ Application Development Guide/ ECPG-based Development/ Executing Dynamic SQL Statements/ Executing a Statement with Input Parameters
Updated on 2025-08-19 GMT+08:00
Executing a Statement with Input Parameters
Prepare a normal statement and execute a specific version of it by replacing its parameters (with question marks). Use the EXECUTE statement to execute the prepared statement by specifying parameters in the USING clause.
Example:
EXEC SQL BEGIN DECLARE SECTION;
const char *stmt = "INSERT INTO test1 VALUES(?, ?);";
EXEC SQL END DECLARE SECTION;
/* PREPARE Prepare a statement for execution. */
EXEC SQL PREPARE mystmt FROM :stmt;
...
/* Single quotation marks are valid characters. If a character string is used, use double quotation marks. */
EXEC SQL EXECUTE mystmt USING 42, 'foobar';
/* When you no longer need a prepared statement, you should deallocate it. */
EXEC SQL DEALLOCATE PREPARE name; Parent topic: Executing Dynamic SQL Statements
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.