游標 批量修改資料

2022-03-28 17:01:54 字數 662 閱讀 9088

--批量修改表中資料

declare my_cursor cursor --定義游標

for (select * from table where id='**') --查出需要的集合放到游標中

open my_cursor; --開啟游標

fetch next from my_cursor ; --讀取第一行資料

while @@fetch_status = 0

begin

update table set id = convert(varchar(100),floor(rand()*10000)) where current of my_cursor; --更新

fetch next from my_cursor; --讀取下一行資料

endclose my_cursor; --關閉游標

deallocate my_cursor; --釋放游標

go--輸出字串年月日時分秒加4位隨機數

print convert(varchar(100), getdate(), 112)+''+convert(varchar(100),(replace(convert(varchar(100), getdate(), 8),':',''))) +''+convert(varchar(100),floor(rand()*10000))

游標修改資料

declare updateemtinca rcursor cursor scroll 宣告乙個游標 for select emtincar.id as emtincar id,case when b.yieldtransitstatetype id is null then 3 else b.yi...

SQL批量修改資料

1 批量替換 期中的年份 以替換為2019年為例 update 資料表名 set 期時間字段 stuff convert nvarchar 23 期時間字段,120 1,4,2019 2 批量替換 期中的 份 以替換為6 為例 update 資料表名 set 期時間字段 stuff convert ...

Oracle 批量修改資料 Merge

merge語句是sql語句的一種。在sql server oracle資料庫中可用,mysql postgresql中不可用。merge是oracle9i新增的語法,用來合併update和insert語句。通過merge語句,根據一張表 原資料表,source table 或子查詢的連線條件對另外一...