8. SQL Statements : SELECT (embedded) : Select (embedded) Syntax
 
Share this page                  
Select (embedded) Syntax
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]}]
              [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 (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