I have a column with values as below:
BOOK # ,7,8
BOOK # ,2
BOOK # ,13,14
I am generating above column with complex xml aggregate function as below:
SELECT
CONCAT('BOOK # ',XMLSERIALIZE(XMLAGG(XMLTEXT(CONCAT(',', SUBSTR(TRIM(TEMP.BOOK_NUM),
LOCATE('.',TEMP.BOOK_NUM)+1)))) AS VARCHAR(1024 )))
FROM TEMP
GROUP BY BOOK_ID
Temp.book_num is of type 123.2, 123.4 in two different rows. So book_id 123 will have two books 2, 4. Thus to extract 2 and 4 out of two rows of same book_id, I had to write above query.
As clear there is an extra ‘,’ comma coming after the words ‘BOOK #’ which is redundant and unrequired.
I am not able to modify above query to remove it.
Is there any way possible to remove the first occurrence of a character (comma here) from a column value which could be accomodated in the query above ?
My output should be:
BOOK # 7,8
BOOK # 2
BOOK # 13,14
Thanks for reading!
Although the wording is almost identical, it’s a lot easier to remove the first character than it is to remove the first occurrence of a specific character. Fortunately, just removing the first character will solve your problem. You can do that by stuffing your
XMLSERIALIZE()expression into aSUBSTR()call like this:Thanks to Serge Rielau for posting this trick in his blog.