mysql 儲存過程 迴圈修改

2021-09-26 19:49:21 字數 860 閱讀 8415

mysql  迴圈修改  儲存過程

delimiter $$

create procedure my_proc()

begin

declare billid int;

declare moneyorder decimal(10,2);

declare stop int default 0;

declare my_cursor cursor for (select money_order, bill_id from orders where order_time = '2019-07-31');#定義游標並輸入結果集 結果集越少越好

declare continue handler for not found set stop = null;

open my_cursor;#開啟游標 

fetch my_cursor into moneyorder,billid;#將游標當前讀取行的資料順序賦予自定義變數12  

while ( stop is not null) do

update bill set bill_amount = bill_amount - moneyorder,order_num = order_num -1    where id = billid;#更新具體內容,concat中的content是資料表中原有的字段屬性值

fetch my_cursor into moneyorder,billid;

end while;

close my_cursor;

end $$

delimiter ;

call my_proc();#執行儲存過程

drop procedure my_proc;#銷毀該儲存過程

Mysql修改儲存過程

alter procedure 儲存過程名 特徵 指定了儲存過程的特性,可能的取值有 contains sql 表示子程式包含 sql 語句,但不包含讀或寫資料的語句。no sql 表示子程式中不包含 sql 語句。reads sql data 表示子程式中包含讀資料的語句。modifies sql...

mysql儲存過程之迴圈

1.客戶端建立乙個儲存過程,過程名稱為insert corp loop 2.填寫內容 delimiter drop procedure if exists insert corp loop create definer procedure insert corp loop in loop time ...

mysql迴圈(儲存過程)

delimiter drop procedure if exists test create procedure test begin declare i int declare j int set i 11235 set j 02011200 while i 15236 do insert int...