MYSQL Split字串並且插入值

2021-06-26 12:14:34 字數 1551 閱讀 9574

demo

begin

#新增專案資料 3,1,1,2,'1;2'

declare tdocid int;#宣告乙個輸出值

declare s int default 0; #宣告乙個判斷游標到最後的檢測值

declare tyoub cursor for select `value` from zzsplittable;#設定乙個游標

declare continue handler for sqlstate '02000' set s=1; #設定游標到最後的條件

call zzsplist(i_docids,';');#調取函式分割字串

open tyoub; #開啟游標開始遍歷

fetch tyoub into tdocid;

while s <> 1 do

insert into oa_doc_pro(projectid,docid) values(i_proid,tdocid); #輸出值的操作

fetch tyoub into tdocid; #游標到下乙個

end while;

close tyoub; #關閉游標

end

zzsplit儲存過程

create  procedure `zzsplist`(inputstring varchar(1000),

delim char(1))

begin

declare strlen int default length(inputstring);

declare last_index int default 0;

declare cur_index int default 1;

declare cur_char varchar(200);

declare len int;

drop temporary table if exists zzsplittable;

create temporary table zzsplittable(

value varchar(20)

) ;while(cur_index<=strlen) do

begin

if substring(inputstring from cur_index for 1)=delim or cur_index=strlen then

set len=cur_index-last_index-1;

if cur_index=strlen then

set len=len+1;

end if;

insert into zzsplittable(`value`)values(substring(inputstring from (last_index+1) for len));

set last_index=cur_index;

end if;

set cur_index=cur_index+1;

end;

end while;

end

vba 建立txt檔案 並且寫入字串

有的時候,我們在操作excel的時候,最後常常需要輸出乙個記錄的log,這樣可以供後期追溯。主要使用createtextfile方法。private sub createtxtfile dim fso as object dim mytxt as object dim myfname as stri...

mysql擷取字串並且替換更新

最近需要刷乙個資料庫表中的資料。表中的username欄位中的名稱是由下劃線分割的兩個字串,現在需要去掉下劃線後邊的字串,留下需要的姓名 update user set user name substring index user name,1 直接解決問題。用到mysql函式 substring ...

字串轉換為日期型別 ,並且做計算

兩年前做php時候表單傳輸的東西現在都忘了,學習django的時候從頭搞起來昨晚搞到兩點多,今早上型別轉換搞的頭大,閒語少敘,今早想做日起計算,表單傳過來的取完是字串型別,想轉日期型別利用timedelta做計算,google半天發現cookbook有介紹datetime標準庫一下就能解決了,柳暗花...