declare
str varchar2(2000) := :inputstr;
v_len number;
currChar CHAR(1);
begin
v_len := length(str);
for i in 1..v_len
Loop
currChar := substr(str,i,1);
if currChar = 1 then
dbms_output.put_line('curr index' || i);
end if;
End loop;
end;
When I pass '000111000' as input to IN_STRING variable , it trims the string and behaves very unusually.Please suggest some good approaches to iterate over binary strings like this.I am expecting output as 4,5,6 from above operation.
EDIT1: Please don't directly input the string as str varchar2(2000) := '000111000'; Instead input it from bind variable as I mentioned above.
Your code works so long as you pass in a
VARCHAR2
data type (and not aNUMBER
).You can also tidy up the code passing in the bind variable only once and using
CONSTANT
s to hold the values that are constant:Which outputs:
db<>fiddle here