Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 13th, 2008, 07:32 AM
Member
 
Join Date: Nov 2007
Posts: 67
Default Comma seperated column

Hi,
I wanted to list the all columns of a emp table .
The output should be comma seperated and list of column should come in brakets like (enam,sal,jdate,job). The below code gives me proper result.
But I am facing problem with last column name .It comes with coma and then braket . I dont want that comma with last column name .
Can u tell me how to achieve that .

Please refer below code ..

Thanks in advance
Expand|Select|Wrap|Line Numbers
  1. Declare
  2.       CURSOR c1
  3.      IS
  4.          SELECT column_name
  5.            FROM cols WHERE table_name='EMP';
  6.  
  7.    BEGIN
  8.            dbms_output.put_line('(');
  9.             FOR r1 IN c1
  10.             LOOP
  11.                       dbms_output.put_line(r1.column_name||',');
  12.                    END LOOP;
  13.                       dbms_output.put_line(')');
  14.           END ;
  15. /
  16.  
Output is as below


(
ENAME,
SAL,
JDATE,
JOB,
)

I wanted output as

(
ENAME,
SAL,
JDATE,
JOB
)


(job with no comma)
Reply
  #2  
Old August 13th, 2008, 07:51 AM
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 6,867
Default

that can be easily done by using toad or any other gui tool.
Reply
  #3  
Old August 13th, 2008, 07:55 AM
Member
 
Join Date: Nov 2007
Posts: 67
Default

Thanks for ur reply ..But I am using SQLplus . Could u tell me is there any other method to get that .
Reply
  #4  
Old August 13th, 2008, 05:09 PM
Saii's Avatar
Expert
 
Join Date: Apr 2007
Posts: 130
Default

You can use substr function on the output string.
Reply
  #5  
Old August 14th, 2008, 11:07 AM
Member
 
Join Date: Nov 2007
Posts: 67
Default

can u plz update my code and show me that
Reply
  #6  
Old August 14th, 2008, 02:46 PM
Administrator
 
Join Date: Sep 2006
Posts: 11,312
Default

Quote:
Originally Posted by orajit
can u plz update my code and show me that
Why don't you look up the sustr function, try the code and post your code if you still get errors.
Reply
  #7  
Old September 1st, 2008, 08:17 AM
Member
 
Join Date: Nov 2007
Posts: 67
Default

Thank you fr ur help
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles