Mysql 指令碼迴圈更新資料

2021-10-22 18:24:44 字數 1108 閱讀 4115

-- 使用資料庫

usedatabase

;-- 刪除舊的儲存過程(相當於函式)

drop

procedure

ifexists

`generatepoint`

;-- 定義結束語句

delimiter $$

-- 定義新的儲存過程

create

procedure

`generatepoint`()

begin

-- 定義結束標誌

declare flag int

default0;

declare pid int

;/* 每條記錄的臨時id */

-- 獲取迴圈範圍

declare idlist cursor

for(

select id from world_county)

;-- 當idlist迴圈完畢,設定結束標誌flag為1

declare

continue

handler

fornot found set flag =1;

-- 開始迴圈idlist

open idlist;

repeat

-- 拉取idlist的值到pid

fetch idlist into pid;

ifnot flag then

-- 更新資料

update world_county set location = pointfromtext(concat(

'point('

,lon,

' ',lat,

')')

)where id = pid;

endif

;-- 結束迴圈

until flag end

repeat

;close idlist;

end $$

delimiter

;-- 執行函式

call generatepoint();

-- 刪除函式

drop

procedure generatepoint;

mysql資料庫密碼更新指令碼

注意事項指令碼為更新密碼,對應被更新使用者 目前為 gin,根據實際情況修改 需要有在對應linux伺服器上的登入許可權 執行方式 alter mysql.sh 123457 123458 第乙個引數為當前 舊 的登入密碼,第二個引數為新的密碼 grant all privileges 根據需要調整...

Mysql指令碼迴圈批量插入陣列資料

首次寫部落格,不知道說點啥,直接上點乾貨,希望大家指出不足之處,共同進步。儲存過程 巢狀迴圈 mysql陣列概念 變數 擷取字串 字串去掉指定字元 資料表中涉及到某一列必填唯一值,唯一值的處理 清除ordersn中唯一值時間的小數點 update ecjia order info set order...

MySQL更新資料

更新資料,是指對錶中的記錄進行修改,mysql中,更新資料使用update語句 update 表名 set 欄位名1 值1 欄位名2 值2,where 條件表示式 欄位1,欄位2,用於指定要更新的欄位名稱 值1,值2,表示字段更新的新資料 where條件表示式,可選引數,用於指定更新資料需要滿足的條...