建了一个使用clob的Procedure存储大批量的ID供查询使用,(用varchar2有长度限制,所以想使用Clob),
其中fma_query_id为一个基于session的临时表,(因为In有1000个的限制,所以想用临时表存储)。
CREATE OR REPLACE PROCEDURE INSERT_QUERY_ID(p_input_id in clob)is
result varchar2(40):=null;
id_count number;
tmp_posi number:=0;
begin
select (length(p_input_id)-length(replace(p_input_id,',','')))into id_count from dual;
if(id_count>0)then
for i in tmp_posi..id_count loop
if(i=0)then
select substr(p_input_id,instr(p_input_id,',',i),instr(p_input_id,',',i+1)-1)into result from dual;
insert into fma_query_id values (result) ;
end if;
if(i>0)then
select substr(p_input_id,instr(p_input_id,',',i)+1,instr(p_input_id,',',i+1)-1)into result from dual;
insert into fma_query_id values (result) ;
end if;
end loop;
end if;
exception
when others then
rollback;
end INSERT_QUERY_ID;当我用以下语句调用的时候,发现能够成功。
begin
insert_query_id(to_clob('aa,bb,cc'));
end;
select * from fma_query_id;
但是当传入的字符串太长时就没有任何结果,也不报错,知道的朋友指点一下,感激不尽,先谢谢了!!
其中fma_query_id为一个基于session的临时表,(因为In有1000个的限制,所以想用临时表存储)。
CREATE OR REPLACE PROCEDURE INSERT_QUERY_ID(p_input_id in clob)is
result varchar2(40):=null;
id_count number;
tmp_posi number:=0;
begin
select (length(p_input_id)-length(replace(p_input_id,',','')))into id_count from dual;
if(id_count>0)then
for i in tmp_posi..id_count loop
if(i=0)then
select substr(p_input_id,instr(p_input_id,',',i),instr(p_input_id,',',i+1)-1)into result from dual;
insert into fma_query_id values (result) ;
end if;
if(i>0)then
select substr(p_input_id,instr(p_input_id,',',i)+1,instr(p_input_id,',',i+1)-1)into result from dual;
insert into fma_query_id values (result) ;
end if;
end loop;
end if;
exception
when others then
rollback;
end INSERT_QUERY_ID;当我用以下语句调用的时候,发现能够成功。
begin
insert_query_id(to_clob('aa,bb,cc'));
end;
select * from fma_query_id;
但是当传入的字符串太长时就没有任何结果,也不报错,知道的朋友指点一下,感激不尽,先谢谢了!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货