從字串中提取逐一提取數字id

2021-07-07 03:50:17 字數 876 閱讀 6643

最近在oaf列印時,需要根據頁面所勾選的資料進行列印。

在oaf獲取勾選的行id後,構成乙個字串(如『1,3,5』)後傳入後台處理的pkg中。

故而,需要從這個含有行號的字串分離出行號id。

為了方便處理,特地寫了乙個過程,將行號id,逐一存入一張臨時表中。

procedure get_delivery_plan_id(p_plan in varchar2) is

l_location       number := 0;

l_names_adjusted varchar2(5000);

l_prev_location  number :=0;

begin

l_names_adjusted := p_plan_id||『,』;   --在字串後新增乙個逗號

loop 

l_location := instr(l_names_adjusted,『,』,l_location + 1);   --獲取逗號位置,返回0則表示不存在

exit when l_location = 0;

insert into b_ascp_asn_plan_temp(delivery_plan_id)    --將id 存入臨時表

values (to_number(substr(l_names_adjusted,    --substr 擷取字串,擷取位於兩個逗號之間的數字id

l_prev_location + 1,

l_location - l_prev_location - 1)));

l_prev_location := l_location;

end loop;

end get_delivery_plan_id;

如上的方法便可實現提取id.

從字串中提取數字

下面程式將字串中的連續數字提取出來,並存放到一維陣列中。比如說乙個字串 a284twx234 je3432 把 284 234 3432 這3個連續數字提取出來,分別存放到a 0 a 1 a 2 中。include include include int main buf i 0 sscanf bu...

sqlserver從字串中提取數字

可以通過寫自定義函式實現,以下提供兩種思路來解決 方法一 乙個乙個找出來 create function dbo fun getnumpart str nvarchar max returns nvarchar max asbegin declare start int declare end in...

從字串中提取數字 字元

import restring hello 16天11板的 number re.findall r d string 提取所有整數 print 所有數字 number number re.findall r 天 d string 提取指定字元後數字 print 指定字元後 number number...