Host-language Data Structures
Go Up to Declaring Host Variables
If a host language supports data structures, data fields within a structure can correspond to a collection of database columns. For example, the following C declaration creates a structure, BILLING_ADDRESS, that contains six variables, or data members, each of which corresponds to a similarly named column in a table:
Using host-language data structures to reference table columns
struct
{
char fname[25];
char lname[25];
char street[30];
char city[20];
char state[3];
char zip[11];
} billing_address;
SQL recognizes data members in structures, but information read from or written to a structure must be read from or written to individual data members in SQL statements. For example, the following SQL statement reads data from a table into variables in the C structure, BILLING_ADDRESS:
Using SQL to read table data into a C struct
EXEC SQL SELECT FNAME, LNAME, STREET, CITY, STATE, ZIP INTO :billing_address.fname, :billing_address.lname, :billing_address.street, :billing_address.city, :billing_address.state, :billing_address.zip FROM ADDRESSES WHERE CITY = 'Brighton';