-
Hi all,
In PL/SQL, how do I build a comma-delimited string using multiple rows returned from a query?
Example:
select key_words from table;
key_words
-----------
apple
orange
fruit
banana
But in the output, I would like to store these in a string like:
apple,orange,fruit,banana
for as many key words there as the cursor return.
How do I do that?
Thanks in advance!
-
Hi all,
In PL/SQL, how do I build a comma-delimited string using multiple rows returned from a query?
Example:
select key_words from table;
key_words
-----------
apple
orange
fruit
banana
But in the output, I would like to store these in a string like:
apple,orange,fruit,banana
for as many key words there as the cursor return.
How do I do that?
Thanks in advance! [/B][/QUOTE]
-
Hm, don't know now whos question this is: Zee's or satishsura's
Well, in PL/SQL this is realy trivial:
DECLARE
my_string VARCHAR2(4000);
BEGIN
FOR r IN (SELECT key_words FROM my_table) LOOP
my_string := r.key_words || ',';
END LOOP;
my_string := RTRIM(my_string, ','); -- remove the last trailing comma
DBMS_OUTPUT.PUT_LINE(my_string)
END;
/
The assumption above is that the length of the concatentated string will nod exceed 4000 characters (max VARCHAR2 length in Oracle8). If this assumption is wrong then another approach would be needed (using multiple string variables or a index-by table of strings or simmilar).
Jurij Modic
ASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?
-
My question
dunno what happened to his/her post.
Anyhow got it, thanks! I just initially had a problem with the comma and the fact that the last key_word gets repeated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|