Entering content frame

 Simplified Notation for Structure and Array Variables 

Use

In SQL statements, you can use a simplified notation for structure variables and array variables, so avoiding the need to list the columns of the database table that are addressed explicitly.

Procedure

·        Specify the name of a structure variable or array variable as !<var>, for example, in the <select_list> of the SELECT statement.

·        You can use the tilde character (~<var>) instead of an exclamation mark.

·        The precompiler derives the column names from the names of the structure components or array elements. The column names can have a maximum of 18 characters.

·        You can specify <[owner.]tablename.> before !<var>. This information is then inserted in front of each column name.

·        Instead of the complete variable !<var>, you can specify a structured component of var of your choice, for example, !var.x.y. In this case, the appropriate subset of column names is generated.

EXEC SQL BEGIN DECLARE SECTION;

  typedef char string8 [8];
  struct {char addr [6];
  struct {string8 lname, fname [3];} name;} person;

EXEC SQL END DECLARE SECTION;

EXEC SQL CREATE TABLE customer
  (cno FIXED(4) key, addr CHAR(5),
  name_lname CHAR(7), name_fname1 CHAR(7),
  name_fname2 CHAR(7), name_fname3 CHAR(7));

/* Get values */

EXEC SQL INSERT INTO customer
  (cno, !person )
  VALUES (100, :person);

/* Has same effect as: */

EXEC SQL INSERT INTO customer
  (cno, addr, name_lname,
  name_fname1, name_fname2, name_fname3)
  VALUES (100, :person.addr,
  :person.name.lname, :person.name.fname[0],
  :person.name.fname[1],
  :person.name.fname[2]);

 

Leaving content frame