Was this helpful?
SELECT (embedded)
Valid in: ESQL
The embedded SELECT statement retrieves values from the database.
Values are returned from tables to host language variables in an embedded OpenSQL 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 [ALLl | DISTINCT]
              * | result_expression{, result_expression}
              INTO variable[:indicator_var] {, variable[:indicator_var]}
              [FROM from_source {, from_source}
              [WHERE search_condition]
              [GROUP BY column {, column}]
              [HAVING search_condition]]
              [UNION [ALL] full_select]
              [ORDER BY result_column [ASC | DESC]
                            {, result_column [ASC | DESC]}]
[EXEC SQL BEGIN;
              program code;
EXEC SQL END;]
Cursor version (embedded in a DECLARE CURSOR statement):
SELECT [ALL|DISTINCT]
       * | result_expression {, result_expression}
       [FROM from_source {, from_source}
       [WHERE search_condition]
       [GROUP BY column {, column}]
       [HAVING search_condition]
       [UNION [ALL] full_select]
       [ORDER BY result_column [ASC|DESC]
              {, result_column [ASC|DESC]}]
where result_expression is one of the following:
[schema.]table_name.*
Selects all columns
[[schema.]table_name.]column_name AS result_column
Selects one column
expression AS result_column
Last modified date: 11/28/2023