学生选课信息查询 EXEC SQL BEGIN DECLARE SECTION /*说明宿主变量Hsno,Hcno, Grade, Graded* EXEC SQL END DECLARE SECTION gets(Hsno) EXEC SQL DECLARE SCX CURSOR FOR/定义游标* SELECT C#. GRADE FROM SC WHERE S#=Hsno EXEC SQLOPEN sCX/打开游标* While(1) EXEC SQLFETCH SCX INTO:Hcno, Grade: Graded;/读取数据* if(sqla. sqlcode==100) break;/结果处理完毕* if(sqla. sqlcode<0) break;陴*出错* EXEC SQL CLOSE SCX,学生选课信息查询: EXEC SQL BEGIN DECLARE SECTION; /* 说明宿主变量 Hsno, Hcno, Hgrade, Gradeid */ … EXEC SQL END DECLARE SECTION; … gets(Hsno); EXEC SQL DECLARE scx CURSOR FOR /*定义游标*/ SELECT C#, GRADE FROM SC WHERE S#=:Hsno; EXEC SQL OPEN scx /*打开游标*/ While(1) { EXEC SQL FETCH scx INTO :Hcno, :Hgrade :Gradeid; /*读取数据*/ if ( sqlca.sqlcode = = 100) break; /*结果处理完毕*/ if ( sqlca.sqlcode < 0) break; /*出错*/ … } EXEC SQL CLOSE scx;