宿主变量。
exec sql
update t1
set c1=:newvalue
where c1 = :oldvalue;
Exec sql
select lastname,firstname
into :last,:fist
from t1
where empon=:id;
游标得定义
________________
Exec sql
Declare c1 cursor for
select c1,c2 from t1;
Exec sql open c1;
Exec sql fetch c1 into :id,:name
...
Exec sql close c1;//光标得关闭,或游标得关闭
处理异常情况
SQLSTATE(ANSI标准代码)
SQLCODE (DB2返回代码)
可以在SQLCA中得到代码,成功为0
SQLSTATE=2000表示没FETCH到,宿主变量值不变。
游标--2 Scrollable cursors 可以上下滚动
Exec sql declare cursor c1 scroll for ...;
Exce sql open c1;
Exce sql fetch last from c1 into ...;
Exce sql fetch relative - 10 from c1 into ...;//倒数第十个开始。
Exec sql fetch before from c1 into ....;
Exec sql close c1;
游标--3 Block fetch
1、前提:cursor read only & application bind enabled blocking
2、一次fetch多个,存在