Using the Function REPLACE
DECLARE
string_type VARCHAR2(60);
old_string string_type%TYPE := 'Apples and oranges';
v_string string_type%TYPE := 'more apples';
-- NULL is a valid argument to REPLACE, but does not match
-- anything so no replacement is done.
new_string string_type%TYPE := REPLACE(old_string,NULL,v_string);
BEGIN
dbms_output.Put_line('Old string = '
||old_string);
dbms_output.Put_line('New string = '
||new_string);
END;
/
If its third argument is null, REPLACE returns its first argument with every occurrence of its second argument removed. For example, the following call to REPLACE removes all the dashes from DASHED_STRING, instead of changing them to another character:
DECLARE
string_type VARCHAR2(60);
dashed string_type%TYPE := 'Gold-i-locks';
-- When the substitution text for REPLACE is NULL,
-- the text being replaced is deleted.
NAME string_type%TYPE := REPLACE(dashed,'-',NULL);
BEGIN
dbms_output.Put_line('Dashed name = '
||dashed);
dbms_output.Put_line('Dashes removed = '
||NAME);
END;
/
If its second and third arguments are null, REPLACE just returns its first argument.
0 comments:
Post a Comment