select

Description

Retrieves rows from database objects.

Syntax

exec sql [at connect_name] 
 select select_list 
 into destination
from table_name… end-exec

Parameters

select_list

Same as select_list in the Transact-SQL select statement, except that select_list cannot perform variable assignments in Embedded SQL.

destination

A table or a series of one or more Embedded SQL host variables. Each host variable must first be defined in a previous declare section. Indicator variables can be associated with the host variables.

Examples

Example 1

 EXEC SQL BEGIN DECLARE SECTION END-EXEC.
           01     LNAME      PIC X(25).
           01     FNAME      PIC X(25).
           01     PHONE      PIC X(15).
           01     AU-ID      PIC X(12).
      EXEC SQL END DECLARE SECTION END-EXEC.
 
           ...
 
 
      DISPLAY "AUTHOR ID ? ".
      ACCEPT AU-ID.
 
      EXEC SQL SELECT au_lname, au_fname, phone
                INTO :LNAME, :FNAME, :PHONE
            FROM authors
            WHERE au_id = :AU-ID END-EXEC.
 
      IF SQLCODE = 100
 DISPLAY "COULD NOT LOCATE AUTHOR ",AU-ID
      ELSE
           DISPLAY "DETAIL RECORD FOR AUTHOR: ", AU-ID
                DISPLAY "NAME  :",LNAME, " ", FNAME
                DISPLAY "PHONE :",PHONE
      END-IF.

Usage

See also

declare cursor