plsql字串擷取

2021-07-11 17:27:56 字數 2066 閱讀 3774



declare

type t_varray is table of varchar2(20);

var_str_devcode_all varchar2(10000):='11#22#33#'; --注意格式:每個字串後面都帶有乙個特殊符號

var_arr_devcode_cstr t_varray:=t_varray(); --宣告集合

var_str_devcode_sign varchar2(2);

var_str_devcode_sign_count number;

var_substr_devcode_lowindex number;

var_substr_devcode_highindex number;

var_substr_devcode_temp varchar(20);

var_str_devtype_all varchar2(10000):='手機#寬頻#手機#'; --注意格式:每個字串後面都帶有乙個特殊符號

var_arr_devtype_cstr t_varray:=t_varray(); --宣告集合

var_str_devtype_sign varchar2(2);

var_str_devtype_sign_count number;

var_substr_devtype_lowindex number;

var_substr_devtype_highindex number;

var_substr_devtype_temp varchar(20);

begin

var_str_devcode_sign_count :=length(var_str_devcode_all)-length(replace(var_str_devcode_all,var_str_devcode_sign,'');

var_substr_devcode_lowindex :=1; -- 擷取的第乙個字串的下標是1

var_substr_devtype_lowindex :=1; -- 擷取的第乙個字串的下標是1

for loop_index in var_str_devcode_sign_count loop

var_substr_highindex :=instr(var_str_devcode_all,var_str_devcode_sign ,1,loop_index);-- 第i個特殊符號所在的位置

var_substr_devcode_temp :=substr(var_str_devcode_all var_substr_devcode_lowindex ,var_substr_devcode_highindex -1) -- 擷取你想要的字串

var_arr_devcode_cstr(loop_index):=var_substr_devcode_temp;

var_substr_devcode_lowindex =instr(var_str_devcode_all ,var_str_devcode_sign,1,loop_index)+1; -- 後移一位

var_substr_highindex :=instr(var_str_devtype_all,var_str_devtype_sign ,1,loop_index);-- 第i個特殊符號所在的位置

var_substr_devtype_temp :=substr(var_str_devtype_all var_substr_devtype_lowindex ,var_substr_devtype_highindex -1) -- 擷取你想要的字串

var_arr_devtype_cstr(loop_index):=var_substr_devtype_temp;

var_substr_devtype_lowindex =instr(var_str_devtype_all ,var_str_devtype_sign,1,loop_index)+1; -- 後移一位

end loop;

-- instr(var_str_all ,var_str_sign ,1,2) --  函式查詢【字段】中從第位開始,第個【#】位置。

-- substr(字段,1,查出的位置-1) 擷取你想要的字串

end;

字串擷取

var 用 擷取 刪除左邊字元,保留右邊字元 echo 其中 var 是變數名,號是運算子,表示從左邊開始刪除第乙個 號及左邊的所有字元 結果 root localhost shell shell.sh 表示從左邊開始刪除最後 最右邊 乙個 號及左邊的所有字元 結果 將變數改為var 結果 輸出為空...

字串擷取

1.定義乙個字串a,擷取a 的某乙個專案組,複製給b,b必須是int型 nsstring a 1.2.30 int b a substringwithrange nsmakerange 4,2 intvalue nslog a n a nslog b d b output 2011 07 05 11...

字串擷取

字串擷取,支援中文和其他編碼 access public param string str 需要轉換的字串 param string start 開始位置 param string length 擷取長度 param string charset 編碼格式 param string suffix 截...