mysql初學 儲存過程 游標

2021-08-28 13:06:38 字數 904 閱讀 7676

@mysql初學–儲存過程–游標

drop procedure if exists test;#若有儲存過程,刪除

delimiter $$

create procedure test()#建立儲存過程

begin

#定義變數

declare done boolean default 0;

declare code1 int(11);

declare value1 varchar(20);

declare code_value_description1 varchar(50);

declare cursor_m cursor for

select code,value,code_value_description from code_value;

declare continue handler for not found set done=1;

begin

open cursor_m;#開啟游標

repeat

fetch next from cursor_m into code1,value1,code_value_description1;#用游標往變數裡賦值

if done!=1 then

select code1,value1,code_value_description1;#查詢出結果

set done=0;

end if;

until done end repeat;

close cursor_m;#關閉游標

end;

end;

$$delimiter;

call test();#呼叫儲存過程

結果是這樣的:

問題?[只有10個結果]

mysql 游標 儲存過程

1.首先需要注意的是mysql中游標必須要建立在儲存過程中 2.直接上sql 查詢當天資料 select in flow out flow from water meter data where 1 1 and date sys read time curdate 1 order by in flo...

MySQL 儲存過程 游標

儲存過程 本儲存過程有特殊執行迴圈數量的要求,是對security market history表進行修正 判斷儲存過程是否存在 drop procedure if exists proc security market history update create procedure proc se...

mysql 儲存過程 游標

宣告游標 declare cursor name cursor for select statement 這個語句宣告乙個游標。也可以在子程式中定義多個游標,但是乙個塊中的每乙個游標必須有唯一的名字。開啟游標 open cursor name 這個語句開啟先前宣告的游標。游標fetch fetch ...