Help Center/ GaussDB/ Developer Guide(Distributed_V2.0-3.x)/ Application Development Guide/ ECPG-based Development/ Running SQL Commands/ Running SQL Statements
Updated on 2025-08-19 GMT+08:00
Running SQL Statements
- Create a table.
EXEC SQL CREATE TABLE foo (a int, b varchar);
- Insert a row.
EXEC SQL INSERT INTO foo VALUES (5, 'abc');
- Delete a row.
EXEC SQL DELETE FROM foo WHERE a = 5;
- Update table data.
EXEC SQL UPDATE foo SET b = 'gdp' WHERE a = 7;
- Query data in a single row.
EXEC SQL SELECT a INTO :var_a FROM foo WHERE b = 'def';
A complete example is as follows:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main ()
{
ECPGdebug (1, stderr);
EXEC SQL BEGIN DECLARE SECTION;
int var_a;
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT TO postgres;
// Create a table.
EXEC SQL CREATE TABLE foo (a int, b varchar);
// Insert data.
EXEC SQL INSERT INTO foo VALUES (5, 'abc');
EXEC SQL INSERT INTO foo VALUES (6, 'def');
EXEC SQL INSERT INTO foo VALUES (7, 'ghi');
// Delete a row.
EXEC SQL DELETE FROM foo WHERE a = 5;
// Update table data.
EXEC SQL UPDATE foo SET b = 'gdp' WHERE a = 7;
// Query table data in a single row.
EXEC SQL SELECT a INTO :var_a FROM foo WHERE b = 'def';
// Print the query results.
printf("select res is %d\n", var_a);
EXEC SQL DISCONNECT;
return 0;
} Parent topic: Running SQL Commands
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.