Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

remove spaces or hyphens from a string

crupperJul 18 2006 — edited Jul 18 2006
hi,

I would like to remove hyphens from a string. It must be stand only one hyphen between the words:

new: ’18-July-2006,-Mr.-Jeorge-Baker-'
old: '18---July---------------2006,----Mr.-----Jeorge--Baker---- '

I wrote a script:

declare
v_sign varchar2(1);
v_next_sign varchar2(1);
v_string varchar2(50):= '18---July---------------2006,----Mr.-----Jeorge--Baker---- ';
v stringnew varchar2(50);


begin
FOR i IN 1..LENGTH(v_string)
LOOP
v_sign:= SUBSTR(v_string, i, 1);
v_next_sign:= SUBSTR(v_string, i+1, 1);

IF(v_sign = '-')
THEN
IF(v_sign = v_next_sign)
THEN
v_sign:= NULL;
END IF;
END IF;

v_string_new:= v_string_new||v_sign;
END LOOP;


DBMS_OUTPUT.ENABLE(1000000);
DBMS_OUTPUT.PUT_LINE(v_string_new);
end;
/

SQL> @RemoveSpacesFromString_01.sql
18-July-2006,-Mr.-Jeorge-Baker-

PL/SQL-Prozedur wurde erfolgreich abgeschlossen.
SQL>


I need the following script in only one select-statement with replace,substr, etc. Does anybody have an idea? We are working with Oracle 9i.

regards,
tom
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 15 2006
Added on Jul 18 2006
4 comments
2,632 views