查询课程信息,根据用户需要修改某些元组的TEACHER字段: EXEC SQL BEGIN DECLARE SECTION; /* 说明宿主变量 dept, deptname, Hcno, HCname, HTeacher, New Teacher */ EXEC SQL END DECLARE SECTION; … gets(dept); deptname = “\’”; strcat(deptname,dept); strcat(deptname, “\%\’”); EXEC SQL DECLARE cx CURSOR FOR /*定义游标*/ SELECT C#, CNAME, TEACHER FROM C WHERE C# LIKE :deptname FOR UPDATE OF TEACHER EXEC SQL OPEN cx /*打开游标*/ While(1) { EXEC SQL FETCH cx INTO :Hcno, :Hcname, :HTeacher; /*读数据*/ if ( sqlca.sqlcode = = 100) break; /*结果处理完毕*/ if ( sqlca.sqlcode < 0) break; /*出错*/ printf(“%s, %s, %s”, Hcno, Hcname, HTeacher); printf(“确定要修改Teacher属性?”); scanf(“%c”,&yn); if (yn == ‘y’ || yn== ‘Y’) {printf(“请输入新的Teacher属性:”); scanf(“%s”, &NewTeacher); EXEC SQL UPDATE C SET TEACHER=:NewTeacher WHERE CURRENT OF cx; /*修改当前元组的TEACHER属性*/ } … } EXEC SQL CLOSE cx;