Comma seperated column

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • orajit
    New Member
    • Nov 2007
    • 75

    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
    Code:
    Declare
          CURSOR c1
         IS
             SELECT column_name
               FROM cols WHERE table_name='EMP';
    
       BEGIN
               dbms_output.put_line('(');
                FOR r1 IN c1
                LOOP
                          dbms_output.put_line(r1.column_name||',');
                       END LOOP;
                          dbms_output.put_line(')');
              END ;
    /
    Output is as below


    (
    ENAME,
    SAL,
    JDATE,
    JOB,
    )

    I wanted output as

    (
    ENAME,
    SAL,
    JDATE,
    JOB
    )


    (job with no comma)
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    that can be easily done by using toad or any other gui tool.

    Comment

    • orajit
      New Member
      • Nov 2007
      • 75

      #3
      Thanks for ur reply ..But I am using SQLplus . Could u tell me is there any other method to get that .

      Comment

      • Saii
        Recognized Expert New Member
        • Apr 2007
        • 145

        #4
        You can use substr function on the output string.

        Comment

        • orajit
          New Member
          • Nov 2007
          • 75

          #5
          can u plz update my code and show me that

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            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.

            Comment

            • orajit
              New Member
              • Nov 2007
              • 75

              #7
              Thank you fr ur help

              Comment

              Working...