Friday, May 15, 2015

Coma Delimiter sub string Program example for Reports



DECLARE
L_STRING VARCHAR2(400):='1,12,123,1234,12345,0,12';
begin
IF L_STRING IS NOT NULL THEN

SELECT LENGTH(L_STRING) into l_length FROM DUAL;

select substr(L_STRING,2,l_length-2) into L_STRING from dual;
srw.message(4,'P_SOURCE_LIN :'||L_STRING);

select (length(L_STRING) - length(replace(L_STRING, ',')))  INTO L_COUNT from dual;
srw.message(5,'l_count :'||l_count);
L_COUNT:=L_COUNT+1;
srw.message(6,'l_count :'||l_count);
FOR i IN 1..L_COUNT
loop

srw.message(8,'i  :'||i);
l_source:=null;
l_f:=0;
l_last:=0;
l_fir:=0;
l_sec:=0;
l_ccc:=0;
l_order_number:=0;
l_line_number:=0;

SELECT INSTR(L_STRING,',', 1,i) into l_f FROM DUAL;
srw.message(9,'l_f  :'||l_f);
if i=1 and l_f =0 then
select L_STRING into l_source FROM DUAL;
elsif i=1 then
SELECT substr(L_STRING, 1,l_f-1) into l_source FROM DUAL;
srw.message(10,'l_source  :'||l_source);

elsif i=L_COUNT and i<>1 then
SELECT INSTR(L_STRING, ',', 1,i-1) into l_last FROM DUAL;
select substr(L_STRING,l_last+1) into l_source FROM DUAL;
else
SELECT INSTR(L_STRING, ',', 1,i-1) into l_fir FROM DUAL;
SELECT INSTR(L_STRING, ',',1, i) into l_sec FROM DUAL;

SELECT substr(L_STRING, l_fir+1,l_sec-l_fir-1) into l_source FROM DUAL;
end if;
srw.message(7,'l_chr :'||l_source);


srw.message(12,'l_ccc :'||l_ccc);
end if;

end loop;

END IF;
END;

1 comment:

  1. Water Hack Burns 2 lb of Fat OVERNIGHT

    More than 160000 men and women are trying a simple and SECRET "liquid hack" to lose 1-2lbs each night as they sleep.

    It is proven and works with everybody.

    This is how to do it yourself:

    1) Go get a drinking glass and fill it with water half full

    2) And now follow this weight loss HACK

    and become 1-2lbs skinnier the very next day!

    ReplyDelete