Help Center/
GaussDB/
Developer Guide(Distributed_3.x)/
Application Development Guide/
ECPG-based Development/
Preprocessor Directives/
Directives: define and undef
Updated on 2024-05-07 GMT+08:00
Directives: define and undef
Similar to the directive #define that is known from C, embedded SQL has a similar concept.
EXEC SQL DEFINE name; EXEC SQL DEFINE name value; EXEC SQL UNDEF name;
Example:
/* Define a name. */ EXEC SQL DEFINE HAVE_FEATURE; /* Define constants. */ EXEC SQL DEFINE MYNUMBER 12; EXEC SQL DEFINE MYSTRING 'abc'; /* Use undef to remove a previous definition. */ EXEC SQL UNDEF MYNUMBER;
You can also use the C versions #define and #undef in your embedded SQL program. The difference is where your defined values get evaluated. If you use EXEC SQL DEFINE, then ecpg evaluates the definitions and substitutes the values. In the following example, ecpg does the substitution and the compiler will never see any name or identifier MYNUMBER:
EXEC SQL DEFINE MYNUMBER 12; ... EXEC SQL UPDATE Tbl SET col = MYNUMBER;
Note that you cannot use #define for a constant that you are going to use in an embedded SQL query because in this case the embedded SQL precompiler is not able to see this declaration.
Parent topic: Preprocessor Directives
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