mysql將字串切割後存入資料庫

2021-09-24 23:19:17 字數 1382 閱讀 9278

delimiter $$ 

-- 定義乙個分1號替換符代表 ; 號

use`test`

$$-- 指定資料庫

drop

procedure

ifexists

`split`

$$ -- 刪除該函式

-- 建立儲存過程

create

procedure

`split`

(in _string varchar

(300))

begin

# 求分割符號','的位置

declare _index int

; #使用臨時表儲存分割後的結果

drop

temporary

table

ifexists tmp_strs ;

-- 刪除臨時表

create

temporary

table

tmp_strs

(str varchar(10

));-- 建立乙個臨時表

set _index =

locate

(','

, _string)

;-- 返回,號的位置

while _index >0do

insert

into tmp_strs values

(left

(_string, _index -1)

); #將子字串存入臨時表

set _string =

substr

(_string from _index +1)

;-- 將切割後的字串重新賦值給形參

set _index =

locate

(','

, _string)

;-- 一直迴圈到所有的字串只剩下最後乙個值

endwhile

;-- 迴圈結束

iflength

(_string)

>=

0then

insert

into tmp_strs values

(_string)

;endif;

end$$

delimiter

;call

split

("ad,aaa,dddd,eee,4444,5555");

-- 跨境電商空手道解放了科技 螺絲扣搭街坊看就

select

*from tmp_strs;

這個**的執行結果為:

iOS使用核心文字將字串切割為字串陣列

開發中某些情況下,會遇到一些特殊要求,比如需要將一段文字按照固定寬度分割成字串陣列,這裡提供一段使用核心文字切割字串的方法。import uikit extension string return linesarray 複製 import import nsstring separated.h im...

MYSQL 字串替換,字串後追加字串

表table欄位sn的 20550000001 中的205500替換為nd100 update table set sn replace sn,205500 nd100 ysql 往表中某個欄位的字串後追加字串 update 表名 set 欄位名 concat 欄位名,需新增的值 where 條件 ...

c 切割字串

c 切割字串 1,按單一字元切割 string str org abcdce string str out str org.slipt c foreach string i in str out foreach string i in str out console.writeline i.tost...