|
|
SELECT INTO
Selects a single-row result table and assigns the values directly to host variables. Also known as a singleton
SELECT.Usage
Description
Values defined by the
SELECT,FROMandWHEREclauses are assigned to target variables as specified in theINTOclause. The value of the first element in theSELECTclause is assigned to the first variable, the value of the second element to the second variable, and so on. The data types of the variables must be assignment-compatible with those of the corresponding values.The number of elements in the select-list must be the same as the number of elements in the
target-variablelist.The result table defined by the
SELECT INTOstatement may not contain more than one row.If a table reference or correlation name is used together with an asterisk in the
SELECTclause, all columns are selected from the referred table. Columns listed explicitly in theSELECTclause need not be prefixed with the table or view name unless the same column name is used in more than one source table or view.The whole list of values in the
SELECTclause may be replaced by a single asterisk, in which case all columns from the table(s) or view(s) named in theFROMclause are selected, in the order in which they are defined in the source table(s) or view(s).Note: Use of SELECT * is discouraged in ESQL programs (except in EXISTS predicates) since the asterisk is expanded to a column list when the statement is compiled, and any subsequent alterations in the table or view definitions may cause the program to function incorrectly.
When set functions are used in the list of values in the
SELECTclause, their evaluation is influenced by the keywordsALLandDISTINCT. IfALLis specified, all rows in the result table are used in calculating the result of the set function. IfDISTINCTis specified, duplicate rows are eliminated from the result table before the set function is evaluated. If no keyword is specified,ALLis assumed.Language Elements
expression, see Expressions.
search-condition, see Search Conditions.
target-variable, see Target Variables.Restrictions
SELECTaccess is required on all tables and views specified in the statement.In a
proceduralusage context, theSELECT INTOstatement is only permitted if the routineaccess-clauseisREADS SQL DATAorMODIFIES SQL DATA, see CREATE FUNCTION and CREATE PROCEDURE.Notes
Correlation names used in the
SELECTorWHEREclause must be defined in theFROMclause of the sameSELECT INTOstatement. The same correlation name may not be defined more than once in oneFROMclause.A
SELECT INTOstatement may include aGROUP BYorHAVINGclause. However, care must be exercised to ensure that theHAVINGclause selects one and only one group, and that the selected group either contains only one member or is reduced to a single row by a set function.Example
SELECT SUM(quantity * "VALUE") INTO :hv FROM mimer_store.items NATURAL JOIN mimer_store.order_items WHERE order_id = data.order_id;Standard Compliance
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|