How to retrieve single row queries by using data structures in embedded SQL?

Many host programming languages use data structures in embedded SQL. While using data structures you have to make sure that number of items in the structure and their data types should correspond to columns of query results. To retrieve single row queries in embedded SQL by using data structures, SELECT statement is used in the following form:

exec sql begin declare section;
int emplnum;
struct {
char name[30];
float sale;
} emplinfo;
short empl_ind[3];
exec sql end declare section;
printf(“Enter employee number: “);
scanf(“%d”, &emplnum);
exec sql select name, sale from employees
where empl_num = :emplnum
into :emplinfo :empl_ind;
if (sqlca.sqlcode = = 0) {
printf(“Name: %s\n”,;
if (empl_ind[1] < 0)
printf(“sale is NULL\n”);
printf(“Sale: %f\n”,
else if (sqlca.sqlcode = = 100)
printf(“There is no employee with that employee number.\n”);
printf(“Encountered SQL error: %ld\n”, sqlca.sqlcode);

Leave a Reply