select

Description

Retrieves rows from database objects.

Syntax

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

Parameters

select_list

Same as select_list in the Transact-SQL select statement, except that the 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

/* This example retrieves columns from a 
 ** single row of the authors table and 
 ** stores them in host variables. Because the
 ** example’s select statement cannot return more
 ** than one row, no cursor is needed. 
 */
 
 exec sql begin declare section; 
     character        last[40]; 
     character        first[20]; 
     character        phone[12]; 
     character        id[11]; 
 exec sql end declare section;  
 
 printf("Enter author id: ");
gets(id); 
exec sql select au_lname, au_fname, phone       
     into :last, :first, :phone      
     from authors      
     where au_id = :id; 
if (sqlcode != 100)     
 {
         print "Information for Author ", id, ":"; 
         print last, first, phone; 
 }
 else     
 {
         print "Could not locate author ", id; 
 };

Usage

See also

declare cursor