SQL$HELP_OLD72.HLB  —  SELECT  Singleton Select
    Specifies a result table. A result table is an intermediate table
    of values derived from columns and rows of one or more tables or
    views that meet conditions specified by a select expression.
    The tables or views that the columns and rows come from are
    identified in the FROM clause of the statement.

    The basic element of a SELECT statement is called a select
    expression. The Select_Expressions HELP topic describes select
    expressions in detail.

    To retrieve rows of a result table in host language programs,
    you must use the DECLARE CURSOR statement or a special form of
    SELECT statement called a singleton select. A singleton select
    statement specifies a one-row result table, and is allowed in
    either precompiled programs or as part of a procedure in an SQL
    module. A singleton select includes an additional clause, INTO,
    to assign the values in the row to host language variables in a
    program.

    For information on the general form of the SELECT statement, see
    the SELECT General_Form statement.

1  –  Environment

    You can use a singleton select statement:

    o  In interactive SQL

    o  Embedded in host language programs to be precompiled

    o  As part of a procedure in an SQL module

    o  In dynamic SQL as a statement to be dynamically executed

2  –  Format

  singleton-select =

  SELECT -+-------------+-> select-list --+
          +-> ALL ------+                 |
          +-> DISTINCT -+                 |
    +-------------------------------------+
    +-> into-target -----------------+
    +--------------------------------+
    +> FROM -+--> table-ref -----+-+
             +---------- , <-----+ |
    +------------------------------+
    +> WHERE predicate -+------------->-----------------++
                        +-> GROUP BY -+> <column-name> ++|
                                      +------- , <-----+ |
    +--------------------------<-------------------------+
    ++--------------------+-+-----------------------+----+
     +> HAVING predicate -+ +-> limit-to-clause ----+    |
    +----------------------------------------------------+
    +-+---------------------+-+---------------------+------>
      +> for-update-clause -+ +-> optimize-clause --+

  into-target =
  ----> INTO --+-+-> <parameter> -----------++->
               | +-> <qualified-parameter> -+|
               | +-> <variable> ------------+|
               +------------- , <------------+

  for-update-clause =

  --> FOR UPDATE -+-------------------------+->
                  +-+-> OF <column-name> -+-+
                    +-------- , <---------+

  optimize-clause =

  --+---------------------------------------------------------------+--->
    +-> OPTIMIZE --+-+-> FOR -+-> FAST FIRST --------+----------+-+-+
                   | |        +-> TOTAL TIME --------+          | |
                   | |        +-> SEQUENTIAL ACCESS -+          | |
                   | +-> USING <outline-name> ------------------+ |
                   | +-> WITH -+-> DEFAULT  --+-> SELECTIVITY  -+ |
                   | |         +-> SAMPLED  --+                 | |
                   | |         +-> AGGRESSIVE +                 | |
                   | +-> AS <query-name> -----------------------+ |
                   +---------------- <----------------------------+

3  –  Arguments

3.1  –  INTO

    Syntax options:

       INTO parameter
       INTO qualified-parameter
       INTO variable

    Specifies a list of parameters, qualified parameters
    (structures), or variables to receive values from the columns
    of the one-row result table. The variables named must have been
    declared in the host program. If a variable named in the list
    is a host structure, SQL considers the reference the same as a
    reference to each of the elements of the host structure.

    If the number of variables specified, either explicitly or by
    reference to a host structure, does not match the number of
    values in the row of the result table, SQL generates an error
    when it precompiles the program or compiles the SQL module file.

    If columns in the result table from a singleton select include
    null values, the corresponding parameters must include indicator
    parameters.

3.2  –  select-list

    For a description of select lists, see the Select_Expressions
    HELP topic.
Close Help