PL/SQL - Delete a character in a VARCHAR2
Question
(I'm sorry for my english...) I'd like to know if I can delete a character in a varchar2 :
FOR FF IN REQ LOOP
IF FF.COLUMN_NAME = ANCIEN THEN
ORDRE_DYN := ORDRE_DYN || ANCIEN;
ELSE
ORDRE_DYN := ORDRE_DYN || FF.COLUMN_NAME;
END IF;
ORDRE_DYN := ORDRE_DYN || ' ' || FF.DATA_TYPE || '(' || FF.DATA_LENGTH;
IF FF.DATA_PRECISION IS NULL THEN
ORDRE_DYN := ORDRE_DYN || ', ' || FF.DATA_PRECISION || '),';
END IF;
END LOOP;
At the last iteration, there is a comma that i want to delete, is it possible ? I know i can do a while loop but i still want to keep the for.
Thank you
Solution
After your loop is done you can RTRIM the comma off:
END LOOP;
ORDRE_DYN := RTRIM(ORDRE_DYN, ',');
If a comma does not exist at the end of the string then no changes are made to the string.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow