Snippets

Jonathan Hult SQL - function - replace first

Created by Jonathan Hult last modified
create or replace function REPLACE_FIRST(p_source varchar2,
                                         p_to_replace varchar2,
                                         p_replace_with varchar2) 
return varchar2
is
begin
    return case
		when p_source is not null 
			and p_to_replace is not null
			then
		 		NVL(STUFF(p_source, INSTR(p_source, p_to_replace), LENGTH(p_to_replace), p_replace_with), p_source)
			else p_source
		end;
end;

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.