Help Center/
GaussDB/
Developer Guide(Centralized_3.x)/
Application Development Guide/
ECPG-based Development/
Running SQL Commands/
Executing SQL Statements
Updated on 2024-05-07 GMT+08:00
Executing 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
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot