《第11讲3--游标Cursor.pdf》由会员分享,可在线阅读,更多相关《第11讲3--游标Cursor.pdf(16页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、An Introduction to Database System Video 11-3?Cursor An Introduction to Database System ? ? ? ? ?SQL? ? ? ? ? ?SQL? ? An Introduction to Database System ? ? ? ? SQL? ? SQL?SQL? ? ? ? ? ?SQL? ? ? ?SQL? An Introduction to Database System ?SQL? ?SQL? ?SELECT? ?CURRENT?UPDATE? ?CURRENT?DELETE? An Introd
2、uction to Database System 1. ?SELECT? ? ?1? ?2? ?3? ?4? An Introduction to Database System ?1? ? ?DECLARE? ? ? EXEC SQL DECLARE CURSOR FOR ; ? ? ?SELECT? ?select? ? An Introduction to Database System ?2? ? ?OPEN? ? ? EXEC SQL OPEN ; ? ? ?SELECT? ? ? An Introduction to Database System ?3? ? ?FETCH? ?
3、 ? EXEC SQL FETCH INTO ,.; ? ? ? ? An Introduction to Database System ?4? ? ?CLOSE? ? ? EXEC SQL CLOSE ; ? ? ? ? ? ? ? An Introduction to Database System 2. CURRENT?UPDATE/DELETE? ? ?CURRENT?UPDATE?DELETE? ? ? ? ?CURRENT?UPDATE?DELETE? ? ? An Introduction to Database System CURRENT?UPDATE/DELETE? ?
4、CURRENT?UPDATE?DELETE? ? ? ? ?SELECT? ? ?CURRENT?UPDATE?DELETE? ? ?UPDATE?DELETE? WHERE CURRENT OF ? ? An Introduction to Database System CURRENT?UPDATE?DELETE? ? ?CURRENT?UPDATE?DELETE? ? ?SELECT?UNION?ORDER BY? ? ?SELECT? ? ? ? An Introduction to Database System 3. ? ? ?8.1 ? EXEC SQL BEGIN DECLAR
5、E SECTION; /*?*/ char Deptname20; char Hsno9; char Hsname20; char Hssex2; int HSage; int NEWAGE; EXEC SQL END DECLARE SECTION; /*?*/ long SQLCODE; EXEC SQL INCLUDE SQLCA; /*?SQL?*/ An Introduction to Database System ? int main(void) /*C?*/ int count = 0; char yn; /*?yn?yes?no*/ printf(Please choose
6、the department name(CS/MA/IS): ); scanf(%s,deptname); /*?deptname?*/ EXEC SQL CONNECT TO TESTlocalhost:54321 USER SYSTEM/MANAGER; /*?TEST*/ EXEC SQL DECLARE SX CURSOR FOR /*?SX*/ SELECT Sno,Sname,Ssex,Sage /*SX?*/ FROM Student WHERE SDept = :deptname; EXEC SQL OPEN SX; /*?SX?*/ An Introduction to Da
7、tabase System ? for ( ; ; ) /*?*/ EXEC SQL FETCH SX INTO :HSno,:Hsname,:HSsex,:HSage; /*?*/ if (SQLCA.SQLCODE!= 0) /*SQLCODE != 0?*/ break; /*?SQLCA?*/ if(count+ = 0) /*?*/ printf(n%-10s %-20s %-10s %-10sn, Sno“,Sname“,Ssex, Sage); printf(%-10s %-20s %-10s %-10dn“, HSno,Hsname,Hssex,HSage); /*?*/ pr
8、intf(“UPDATE AGE(y/n)?”); /*?*/ doscanf(%c, while(yn != N . An Introduction to Database System ? if (yn = y | yn = Y) /*?*/ printf(INPUT NEW AGE:); scanf(%d, /*?*/ EXEC SQL UPDATE Student /*?SQL?*/ SET Sage = :NEWAGE WHERE CURRENT OF SX; /*?*/ EXEC SQL CLOSE SX; /*?SX?*/ EXEC SQL COMMIT WORK; /*?*/ EXEC SQL DISCONNECT TEST; /*?*/