Examples

Example 1: Using a COBOL program statement, put the maximum salary (SALARY) from the EMPLOYEE table into the host variable MAX-SALARY (DECIMAL(9,2)).

   EXEC SQL  SELECT MAX(SALARY)
               INTO :MAX-SALARY
               FROM EMPLOYEE WITH CS
   END-EXEC.

Example 2: Using a Java(TM) program statement, select the row from the EMPLOYEE table on the connection context 'ctx' with a employee number (EMPNO) value the same as that stored in the host variable HOST_EMP (java.lang.String). Then put the last name (LASTNAME) and education level (EDLEVEL) from that row into the host variables HOST_NAME (String) and HOST_EDUCATE (Integer).

   #sql [ctx] {  SELECT LASTNAME, EDLEVEL
                 INTO :HOST_NAME, :HOST_EDUCATE
                 FROM EMPLOYEE
                 WHERE EMPNO = :HOST_EMP   };

Example 3: Put the row for employee 528671, from the EMPLOYEE table, into the host structure EMPREC. Assume that the row will be updated later and should be locked when the query executes.

   EXEC SQL  SELECT *
               INTO :EMPREC
               FROM EMPLOYEE
               WHERE EMPNO = '528671'
               WITH RS USE AND KEEP EXCLUSIVE LOCKS
   END-EXEC.