Retrieves rows from database objects.
exec sql [at connect_name] select select_list into destination from table_name…;
Same as select_list in the Transact-SQL select statement, except that the select_list cannot perform variable assignments in Embedded SQL.
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.
/* 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; };
This reference page mainly describes aspects of the Transact-SQL select statement that differ when the statement is used in Embedded SQL. See the Adaptive Server Enterprise Reference Manual for more information about the select statement.
The compute clause of the Transact-SQL select statement cannot be used in Embedded SQL programs.
Host variables in a select statement are input variables only, except in the statement’s into clause. Host variables in the into clause are output variables.
Previously declared input host variables can be used anywhere in a select statement that a literal value or Transact-SQL variable is allowed. Indicator variables can be associated with input host variables to specify null values.
If a select statement returns more than one row, each host variable in the statement’s into clause must be an array with enough space for all the rows. Otherwise, you must use a cursor to bring the rows back one at a time.
declare cursor