Was this helpful?
SELECT (embedded)
Valid in: ESQL
The SELECT statement returns values from tables to host language variables in an embedded SQL program.
For details about the various clauses of the SELECT statement, see SELECT (interactive).
The SELECT (embedded) statement has the following format:
Non-cursor version:
EXEC SQL [REPEATED] SELECT [FIRST rowCount] [ALL | DISTINCT]
              SELECT [FIRST rowCount] [ALL | DISTINCT]
              INTO variable[:indicator_var] {, variable[:indicator_var]}
              [FROM from_source {, from_source}
              [WHERE search_condition]
              [GROUP BY [ALL | DISTINCT] grouping element {,grouping element}]
              [HAVING search_condition]]
              [UNION [ALL] full_select]
              [ORDER BY ordering-expression [ASC | DESC]
                            {, ordering-expression [ASC | DESC]}]
              [LIMIT n][OFFSET n]
              [FETCH FIRST|NEXT n ROWS|ROW ONLY]
              [WITH options]
[EXEC SQL BEGIN;
              program code;
EXEC SQL END;]
To retrieve long varchar or long byte columns, specify a data handler routine in the INTO clause. For details, see INTO Clause--Retrieve Values into Host Language Variables.
Cursor version (embedded in a DECLARE CURSOR statement):
SELECT [ALL|DISTINCT]
       SELECT [FIRST rowCount] [ALL | DISTINCT]
       [FROM from_source {, from_source}
       [WHERE search_condition]
       [GROUP BY [ALL | DISTINCT] grouping element {,grouping element}]
       [HAVING search_condition]
       [UNION [ALL] full_select]
       [ORDER BY result_column [ASC|DESC]
              {, result_column [ASC|DESC]}]
       [FOR [DEFERRED | DIRECT] UPDATE OF column {, column}];
       [WITH options]
where result_expression is:
expression | result_name = expression | expression AS result_name
Last modified date: 08/29/2024