DECLARE @steps LONG VARCHAR;
SET @steps='1200-abc,1300,1400-enhk1,1500'
I need to get @steps as '1200,1300,1400,1500'.
Please let me know how it is possible in stored procedure in PL/SQL
Thanks in advance for your suggestions
You can iterate by occurences regexp_substr, or just select them like this
for item in (SELECT regexp_substr('1200-abc,1300,1400-enhk1,1500', '\w(\d+)\w', 1, LEVEL) val
FROM dual
CONNECT BY regexp_substr('1200-abc,1300,1400-enhk1,1500', '\w(\d+)\w', 1, LEVEL) IS NOT NULL)
loop
dbms_output.put_line(item.val);
end loop;
You can make like this :
declare
i varchar2(4000);
v_array apex_application_global.vc_arr2;
only_numbers varchar2(100) :='';
begin
i := '1200-abc,1300,1400-enhk1,1500';
v_array := apex_util.string_to_table(i, ',');
for e in 1 .. v_array.count loop
only_numbers:=only_numbers || regexp_substr(v_array(e),'[[:digit:]]*') ||',';
end loop;
only_numbers := rtrim( only_numbers, ',' );
dbms_output.put_line(only_numbers); -- output : 1200,1300,1400,1500
end;
create function del_non_numerics(str varchar2)
return varchar2
is
v_return_txt varchar2(3000);
begin
select regexp_replace(str,'[^0-9,]+','') into v_return_txt
from dual;
return v_return_txt;
end;
/
Invoking the above code as del_non_numerics('1200-abc,1300,1400-enhkl,1500') => 1200,1300,1400,1500