Program Structure II
Program Structure II
Program Structure II
EMPNO LASTNAME
000030 KWAN
000290 PARKER
000300 SMITH
empno name
EMPNO LASTNAME FETCH
000030 KWAN
000290 PARKER
000300 SMITH 000030 KWAN
empno name
EMPNO LASTNAME
FETCH
000030 KWAN
000290 PARKER
000300 SMITH 000290 PARKER
empno name
© Copyright IBM Corporation 2005
Structured
Programming - Sequential File Read
1. ?
2. ?
file
3. ?
while (not EOF)
{
< process file >
start
4. ?
} process
5. ? end
DEFINITION
DECLARE K9 CURSOR FOR
SELECT EMPNO, LASTNAME
FROM TEMPL
WHERE DEPTNO = :dpt;
EXECUTION
EXEC SQL
FETCH K9 INTO :empno, :name;
OPEN MAT
:
EXEC SQL OPEN CE ;
EXEC SQL
FETCH CX INTO :empno, :name;
-RESTRICTIONS-
Show me all
people named
"Brown"
DB2
There are 500
people with that
name
Show me all
people named
"Brown", but I am
not going to look
at more than 100
DB2
There are 500
people with that
name
POSITIONING
OPEN
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
CLOSE
To REUSE a CURSOR
OPEN
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
EXEC SQL
DECLARE C1 CURSOR Unique INDEX on
X required.
WITH HOLD FOR
SELECT X,Y,Z FROM T1 Cannot use
WHERE X> :storx FOR UPDATE OF
ORDER BY X;
CTR=0;
EXEC SQL
FETCH C1
INTO :storx,:story,:storz;
COMMIT;
END COMPOUND;
© Copyright IBM Corporation 2005
Compound SQL Restrictions
Only NOT ATOMIC supported with DB2 Connect
Can only include static SQL statements
Must be Embedded Static SQL