Strip(i.e. remove) special character(s)

/* Strip(remove) special character(s) from a string.
Parameters -1-: String to process
-2-: Special character to strip
Note: If second parameter is null then the following list is used:
<tab>, <single quote>, <double quote>, <>, <|>, <`>, <~>, <^>
*/
FUNCTION strip_spc_character ( in_string IN varchar2,
in_chars  IN varchar2 DEFAULT null )
return varchar2
is
tab	              char(      1 ) := chr(9);
double_quote        char(      1 ) := chr(34);
single_quote        char(      1 ) := chr(39);
mask                varchar2( 80 ) := '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
v_special_chars     varchar2( 80 ) := '`~^|'||double_quote||single_quote||tab;
begin
if in_chars is not null then
v_special_chars := in_chars;
end if;
return translate( in_string, mask || v_special_chars, mask );
exception
when others then
return in_string;
end strip_spc_character;

source

Leave a Reply