MySql游標的使用實例
更新時間:2014年06月17日 18:17:31 投稿:shichen2014
這篇文章主要介紹了MySql游標,需要的朋友可以參考下
mysql游標使用的整個過程為:
1.創(chuàng)建游標
復制代碼 代碼如下:
DECLARE calc_bonus CURSOR FOR SELECT id, salary, commission FROM employees;
2.打開游標
復制代碼 代碼如下:
OPEN calc_bonus;
3.使用游標
復制代碼 代碼如下:
FETCH calc_bonus INTO re_id, re_salary, re_comm;
4.關閉游標
復制代碼 代碼如下:
CLOSE calc_bonus;
實例代碼如下所示:
復制代碼 代碼如下:
begin
declare temp_user_id int default null;
declare stop int default 0;
#聲明游標
declare temp_cur cursor for select f_user_id from table_test where f_user_id=1;
#聲明游標的異常處理
declare continue handler for sqlstate '02000' set stop=1;
open temp_cur;
fetch temp_cur into temp_user_id;
#判斷游標是否到達最后
while stop<>1 do
#各種判斷
#讀取下一行的數(shù)據(jù)
fetch temp_cur into temp_user_id;
#循環(huán)結束
end while;
#關閉游標
close temp_cur;
end
相關文章
MySQL中使用innobackupex、xtrabackup進行大數(shù)據(jù)的備份和還原教程
這篇文章主要介紹了MySQL中使用innobackupex、xtrabackup進行大數(shù)據(jù)的備份和還原教程,xtrabackup用來對超過10G數(shù)據(jù)的Mysql進行備份和還原任務,需要的朋友可以參考下2014-09-09利用mysql的inet_aton()和inet_ntoa()函數(shù)存儲IP地址的方法分享
當前很多應用都適用字符串char(15)來存儲IP地址(占用16個字節(jié)),利用inet_aton()和inet_ntoa()函數(shù),來存儲IP地址效率很高,適用unsigned int 就可以滿足需求,不需要使用bigint,只需要4個字節(jié),節(jié)省存儲空間,同時效率也高很多2012-03-03