??????????????MySQL?α???????y???????????????????????????ο???
?????????level
????????????:
????createtabletest.level(namevarchar(20));
??????insertЩ????;
?????????
????????????:
????dropprocedureifexistsuseCursor//
?????????洢????create
????????????:
????CREATEPROCEDUREuseCursor()
????BEGIN
????????????????declare
????????????:
????declaretmpNamevarchar(20)default'';
????declareallNamevarchar(255)default'';
????declarecur1CURSORFORSELECTnameFROMtest.level;
????MySQL?α??????
???????????????????tmpname?null?????????
????????????:
????declareCONTINUEHANDLERFORSQLSTATE'02000'SETtmpname=null;
???????α?
????????????:
????OPENcur1;
?????α??????????
????????????:
????FETCHcur1INTOtmpName;
?????????????????MySQL?α???????name????????;????
????????????:
????WHILE(tmpnameisnotnull)DO
????settmpName=CONCAT(tmpName??";");
????setallName=CONCAT(allName??tmpName);
?????α??????????
????????????:
????FETCHcur1INTOtmpName;
?????????????:
????????????:
????ENDWHILE;
????????α?
????????????:
????CLOSEcur1;
???????????
????????????:
????selectallName;
?????????洢????
????????????:
????END;//
????????洢?????
????????????:
????calluseCursor()//
????loop????α?
????????????:
DELIMITER$$
DROPPROCEDUREIFEXITScursor_example$$
CREATEPROCEDUREcursor_example()
READSSQLDATA
BEGIN
DECLAREl_employee_idINT;
DECLAREl_salaryNUMERIC(8??2);
DECLAREl_department_idINT;
DECLAREdoneINTDEFAULT0;
DECLAREcur1CURSORFORSELECTemployee_id??salary??department_idFROMemployees;
DECLARECONTINUEHANDLERFORNOTFOUNDSETdone=1;
OPENcur1;
emp_loop:LOOP
FETCHcur1INTOl_employee_id??l_salary??l_department_id;
IFdone=1THEN
LEAVEemp_loop;
ENDIF;
ENDLOOPemp_loop;
CLOSEcur1;
END$$
DELIMITER;