Previous Topic: Example 2Next Topic: DECLARE STATEMENT


Example 3

In this example, the DECLARE CURSOR statement defines the cursor, C1, and orders the results of the SELECT since an ORDER BY clause is included in the definition. The SELECT retrieves the number and name of all employees hired before 1980 in order of seniority. HIREDATE is in the form "yymmdd."

 EXEC SQL
      DECLARE C1 CURSOR FOR
           SELECT EMPNO, LASTNAME, FIRSTNME, HIREDATE
           FROM EMP
           WHERE HIREDATE < 800000
           ORDER BY HIREDATE
 END-EXEC