存储过程分割字符串
string ID = Table[0].Rows[0][0].ToString();
sting[] arrID=ID.split(',');
把对象转换成字符串不就可以了吗?呵呵
希望对你有帮助
B. 求助:如何在存储过程中拆分字符串
declare @inputStr varchar(max)set @inputStr='H,SH600,AAA,123,456,567,566,565,H,SH600,ABC,542,34,35,367,765,H,SH600,AAC,52,314,325,3867,7865'declare @divideFlag varchar(20)set @divideFlag='H,'declare @bnname varchar(8)declare @gpdm varchar(8)declare @gpcn intdeclare @ydate intdeclare @yopen intdeclare @yhigh intdeclare @substr varchar(200)declare @pos1 intdeclare @pos2 intdeclare @sql varchar(400)--如果字符串中有分隔符标记while CHARINDEX(@divideFlag,@inputStr,0)0begin set @pos1 = CHARINDEX(@divideFlag,@inputStr,0) print '位置1 '+cast(@pos1 as varchar) set @pos2 = CHARINDEX(@divideFlag,@inputStr,@pos1+1) print '位置2 ' + cast(@pos2 as varchar) if @pos20 begin set @substr = SUBSTRING(@inputStr,@pos1,@pos2-@pos1) print '截取处理串 '+ @substr set @inputStr = SUBSTRING(@inputStr,@pos2,len(@inputStr)) --print @inputStr end else begin set @substr = SUBSTRING(@inputStr,@pos1,len(@inputStr)) print '截取处理串 '+ @substr set @inputStr = 'empty' --print @inputStr end --去掉开头的分割标记 set @substr=substring(@substr,CHARINDEX(@divideFlag,@substr,0)+len(@divideFlag),len(@substr)) print '去掉开头分割标记 ' + @substr if right(@substr,1)=',' begin set @substr = left(@substr,len(@substr)-1) print '去掉末尾的逗号' + @substr end --取得表名称 set @bnname = substring(@substr,1,charindex(',',@substr,0)-1) print @bnname --取表名称后面的字符串 set @substr=substring(@substr,charindex(',',@substr,0)+1,len(@substr)) print @substr --取得第一个字段 set @gpdm = substring(@substr,1,charindex(',',@substr,0)-1) print @gpdm --取得后面的字符串 set @substr=substring(@substr,charindex(',',@substr,0)+1,len(@substr)) print @substr set @gpcn = substring(@substr,1,charindex(',',@substr,0)-1) print @gpcn set @substr=substring(@substr,charindex(',',@substr,0)+1,len(@substr)) print @substr set @ydate = substring(@substr,1,charindex(',',@substr,0)-1) print @ydate set @substr=substring(@substr,charindex(',',@substr,0)+1,len(@substr)) print @substr set @yopen = substring(@substr,1,charindex(',',@substr,0)-1) print @yopen set @substr=substring(@substr,charindex(',',@substr,0)+1,len(@substr)) print @substr set @yhigh = substring(@substr,1,charindex(',',@substr,0)-1) print @yhigh set @substr=substring(@substr,charindex(',',@substr,0)+1,len(@substr)) print @substr -- 拼接 插入的 sql 字符串 set @sql = 'insert into '+@bnname+' (gpdm,gpcn,ydate,yopen,yhigh) values( '''+@gpdm+''','+cast(@gpcn as varchar)+','+cast(@ydate as varchar)+','+cast(@yopen as varchar)+','+cast(@yhigh as varchar)+' )' print @sqlend-- 拷贝到查询分析器执行,可以看到打印出的消息,拼接的字符串应该可以用
C. oracle存储过程怎么截取字符串
之前我保存的经典的方法,你可以参考下
首先创建一张表t_al_test_sy
字段分别为:pid,str_id,str_dm,str_mc;
存储过程如下:
create or replace procere p_al_output
as
str_id varchar(60);
str_dm varchar(60);
str_mc varchar(800);
str_start number;
str_len number;
str_length number;
str_end number;
str_count number;
str_content varchar2(800);
str_partcontent varchar2(800);
str_iscontent number;
D. oracle存储过程传入一个字符串参数'1,2,3,4,5,6,7,8',如何分割并转为数字
create or replace type type_split as table of varchar2(50); --创建一个type,如果为了使split函数具有通用性,请将其size 设大些。
--创建function
create or replace function split
(
p_list varchar2,
p_sep varchar2 := ','
) return type_split pipelined
is
l_idx pls_integer;
v_list varchar2(50) := p_list;
begin
loop
l_idx := instr(v_list,p_sep);
if l_idx > 0 then
pipe row(substr(v_list,1,l_idx-1));
v_list := substr(v_list,l_idx+length(p_sep));
else
pipe row(v_list);
exit;
end if;
end loop;
return;
end split;
使用:
select * from table(split('1,2,3,4,5,6,7,8'
,','));
然后就可以通过“,”来分割数字了
E. 关于SQLserver 存储过程 如何切割一个字符串 转化为数组
Create Function [dbo].[Split](@Sql varchar(8000),@Splits varchar(10))
returns @temp Table (a varchar(100))
As
Begin
Declare @i Int
Set @Sql = RTrim(LTrim(@Sql))
Set @i = CharIndex(@Splits,@Sql)
While @i >= 1
Begin
Insert @temp Values(Left(@Sql,@i-1))
Set @Sql = SubString(@Sql,@i+1,Len(@Sql)-@i)
Set @i = CharIndex(@Splits,@Sql)
End
If @Sql <> ''
Insert @temp Values (@Sql)
Return
End
F. 关于oracle 存储过程 如何切割一个字符串 转化为字符数组,然后遍历该数组: 类似ab,12;cd,55;k,7
给你写了个包,包体代码如下:
CREATE OR REPLACE PACKAGE BODY Pkg_Bai IS
-- 自定义个数组类型
TYPE Typ_Str_Array IS TABLE OF VARCHAR2(200) INDEX BY BINARY_INTEGER;
PROCEDURE Prc_String_To_Array(Pv_i_String IN VARCHAR2,
Pv_i_Identifier IN VARCHAR2,
Pt_o_Array OUT Typ_Str_Array) IS
Lv_Tmpstr VARCHAR2(200);
Lv_Changed_String VARCHAR2(4000);
BEGIN
-- 初始化
Lv_Changed_String := Pv_i_String;
-- 拆分逻辑
-- 1.字符串中没有标识符
IF Instr(Pv_i_String, Pv_i_Identifier, 1, 1) = 0 THEN
Pt_o_Array(Pt_o_Array.Count + 1) := Pv_i_String;
ELSE
-- 2.字符串中有标识符
WHILE Instr(Lv_Changed_String, Pv_i_Identifier, 1, 1) > 0 LOOP
Lv_Tmpstr := Substr(Lv_Changed_String,
1,
Instr(Lv_Changed_String, Pv_i_Identifier, 1, 1) - 1);
Pt_o_Array(Pt_o_Array.Count + 1) := Lv_Tmpstr;
Lv_Changed_String := Substr(Lv_Changed_String,
Instr(Lv_Changed_String, Pv_i_Identifier, 1, 1) + 1,
Length(Lv_Changed_String));
END LOOP;
-- 3.最有一个被拆分出来的字符串中不含标识符
IF NOT Lv_Changed_String IS NULL THEN
-- 将最后一个保存
Pt_o_Array(Pt_o_Array.Count + 1) := Lv_Changed_String;
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
PROCEDURE Prc_Test(Pv_i_Str IN VARCHAR2) IS
--定义数组
Lt_Array Typ_Str_Array;
Ln_Count NUMBER; -- 数组元素个数
Ln_Num NUMBER;
Lv_Value VARCHAR2(30);
BEGIN
Prc_String_To_Array(Pv_i_Str, ';', Lt_Array);
-- 循环数组
FOR i IN 1 .. Lt_Array.Count LOOP
-- 获取每个元素中数值
Ln_Num := To_Number(TRIM(Substr(Lt_Array(i), Instr(Lt_Array(i), ',', -1) + 1)));
IF Ln_Num > 20 THEN
Lv_Value := TRIM(Substr(Lt_Array(i), 1, Instr(Lt_Array(i), ',', -1) - 1));
INSERT INTO a (col_a) VALUES (lv_value);
END IF;
END LOOP;
END;
END Pkg_Bai;
调用Prc_Test来分隔字符串并按要求比较后插入a表。我测试过,没有问题。
需要注意的是,数据的要求:字符串中每组数据间使用英文小写分号分隔,同一组数据字母在前,数字在后,以英文小写逗号分隔。测试一下吧。
欢迎采纳,不采纳你都对不起我这20分钟。呵呵......