Im working on an assignment, the goal being to write a procedure that has 2 inputs a string and a char and remove the char from the string.
Example: RemoveAll(123-456-789, '-') will output: 123456789.
create or replace procedure MyRemoveAll
(p_text varchar2, p_char_1 char) as
v_temp varchar2(100);
BEGIN
v_temp := p_text;
WHILE instr(v_temp, p_char_1) != 0 LOOP
v_temp := substr(v_temp, 1, instr(v_temp, p_char_1)-1)
|| substr(p_text, instr(v_temp, p_char_1)+1);
END LOOP;
dbms_output.put_line (v_temp);
END;
/
exec MyRemoveAll('123456789', '*');
exec MyRemoveAll('123-456789', '-');
exec MyRemoveAll('123*456*789', '*');
I don't get any errors when the procedure is created, and the first two executions work correctly. I've tried just running: dbms_output.put_line (instr(123*456*789, *));
Which gave me an output of 4. So it should register for the condition of the while loop, but SQL Plus just stops at the loop. (Like it's doing an infinite loop, but it isn't).
Anyone have any ideas?
MyRemoveAllwill just implementreplace().charis just a special kind of string, that adds spaces to pad the value out to its maximum length. There is rarely any good use for this and in practice it causes more problems than it solves, which it recommended not to use it, ever.