Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: single quote in instr Oracle PL/SQL
You can TRANSLATE the special characters to just one special character,
then REPLACE that one special character with an empty string. You can
use that method directly in SQL or create a user-defined function, as
demonstrated below
scott_at_ORA92> SELECT REPLACE (TRANSLATE ('1234''~!@abcd',
2 '~`!@#$%^&*()_+={}[]|\:;''",.<>?', 3 '~'), 4 '~', 5 '')
REPLACE(
scott_at_ORA92> CREATE OR REPLACE FUNCTION rsc -- remove special
characters
2 (p_string IN VARCHAR2)
3 RETURN VARCHAR2
4 AS
5 BEGIN
6 RETURN REPLACE (TRANSLATE (p_string,
7 '~`!@#$%^&*()_+={}[]|\:;''",.<>?', 8 '~'), 9 '~', 10 '');
Function created.
scott_at_ORA92> SHOW ERRORS
No errors.
scott_at_ORA92> SELECT rsc ('1234''~!@abcd') FROM DUAL
2 /
RSC('1234''~!@ABCD')