When you are constructing l_temp1_clob
, you can only add the rest of the lob, if there is anything to add. Change you code:
l_temp1_clob:=dbms_lob.substr(p_lob,l_temp_number_1-l_temp_number+1 ,l_temp_number +length(p_what) );
To this:
if l_temp_number +length(p_what) < l_temp_number_1
then
l_temp1_clob := dbms_lob.substr(p_lob, l_temp_number_1 - l_temp_number - 1 , l_temp_number +length(p_what) );
end if;
The logic is: if the start of the lob substr is before the end of the lob.
Also, the dd
variable is not declared in your test call:
declare
temp clob;
begin
temp:='replace this #a#';
temp:=lob_replace(dd,'#a#','with this');
end;