查询课程信息,根据用户需要修改某些元组的 TEACHER字段 EXEC SQL BEGIN DECLARE SECTION /*说明宿主变量dept, deptname,Hcno, CName, TEacher,New Teacher * EXEC SQL END DECLARE SECTION gets(dept); deptname=)” strcat(deptname, dept) strcat(deptname, 1%1) EXEC SQL DECLARE CX CURSORFOR/*定义游标* SELECT C#. CNAME TEACHER FROMC WHERE C#LIKE: deptname FOR UPDATE OF TEACHER EXEC SQLOPEN CX/打开游标* While(1) EXEC SQLFETCH cx INTO Hcno, Rename, TEacher;/读数据*/ if( sqlca. sqlcode==100 break;/*结果处理完毕* if( sqlca. sqlcode<0) break;/*出错* printf("%S, %S, %s", Hcno, Cname, HTeacher) printf(“确定要修改 Teacher属性?)
查询课程信息,根据用户需要修改某些元组的 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); yl‖yn==Y) { printi请输入新的 Teacher属性:”); scanf(" %s", &New Teacher) EXEC SQL UPDATEC SET TEACHER=. NewTeacher WHERE CURRENTOF CX,*修改当前元组的 TEACHER属性* EXEC SQL CLOSE Cx
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;