Combine several values of rank in a line like comma delimeted string

Hello

I have a requirement to combine several values of rank in a line as the comma delimeted string as below

INDEX_NAME COLUMN_NAME POSITION_COLONNE
EMP_EMAIL_UK EMAIL 1
EMP_EMP_ID_PK EMPLOYE_ID 1
EMP_DEPARTMENT_IX DEPARTMENT_ID 1
JOB_ID EMP_JOB_IX 1
EMP_MANAGER_IX MANAGER_ID 1
EMP_NAME_IX LAST_NAME 1
EMP_NAME_IX FIRST_NAME 2
I write in a SQL and the output I need is, for example EMP_NAME_IX LAST_NAME, FIRST_NAME.

I can't write any function as well.

http://www.Oracle-base.com/articles/Misc/StringAggregationTechniques.php

SELECT index_name,
       ltrim(sys_Connect_by_path(column_name, ','), ',') column_names
  FROM (select index_name,
               column_name,
               row_number() over(partition by index_name order by column_position) rn
          from all_ind_columns
         WHERE table_owner = 'HR')
 WHERE connect_by_isleaf = 1
 START WITH rn = 1
CONNECT BY PRIOR rn = rn - 1
       and prior index_name = index_name

Tags: Database

Similar Questions

  • [8i] need to combine several values in a column

    I work in 8i...

    I have data as follows:
    CREATE TABLE item_year
    (     item_no     CHAR(25)
    ,     year     CHAR(4)
    );
    
    INSERT INTO item_year
    VALUES ('item1','1998');
    INSERT INTO item_year
    VALUES ('item1','2002');
    INSERT INTO item_year
    VALUES ('item1','2003');
    INSERT INTO item_year
    VALUES ('item1','2004');
    INSERT INTO item_year
    VALUES ('item2','1984');
    INSERT INTO item_year
    VALUES ('item2','1991');
    INSERT INTO item_year
    VALUES ('item2','2006');
    INSERT INTO item_year
    VALUES ('item2','2008');
    INSERT INTO item_year
    VALUES ('item2','2010');
    The results that I want are:
    ITEM_NO     YEARS
    ------------------------------
    item1     1998, 2002, 2003, 2004
    item2     1984, 1991, 2006, 2008, 2010
    My inclination is to rotate the results, but my problem is, I don't know how many years will see room for a particular item. In theory, it could it upwards in each year between any point in the past through the current year. In practice, the year is 1997, and I can't think of any situation where an older date occur in the future, because this table is a table of history. Thus, at the present time, the years, I would need to look to be 1997-2010, but of course, would come January, it will be 1997-2011, etc.. So either way is for me to do without having to create a procedure or something?

    Hello

    You can do the slightly simpler query by losing the CONNECT BY. In the example that you copied, CONNECT BY was the only way to get the items that should be grouped together. In your case, a simple query will do:

    SELECT     item_no
    ,     CAST ( MULTISET ( SELECT    year
                            FROM         item_year
                     WHERE         item_no     = all_item_nos.item_no
                     ORDER BY  year
                   )
                AS myArrayType
              )          AS years
    FROM    (
             SELECT DISTINCT  item_no
             FROM             item_year
         ) all_item_nos
    ;
    

    I don't know how to get a simple string (rather than myArrayType) for results without the help of PL/SQL.

    If you use the PL/SQL, you might consider this approach: write a function that takes an id (like item_no) as an argument and returns a string (the list or results). You probably want several similar functions for the different arguments, tables and columns. If Yes, you can isolate the part that actually built the chain to verify that the results are actually in the allocated space, in a generic function (such as concat_query, below) and to call this generic function to a specific function (such as all_years, below) adapted to a specific situation.
    This is a package that contains the generic function:

    CREATE OR REPLACE PACKAGE     string_agg
    AS
    
    TYPE     concat_query_cursor_type     IS     REF CURSOR
         RETURN     dual%ROWTYPE;
    
    FUNCTION concat_query
    (
         in_cursor          IN     concat_query_cursor_type,
         in_separator_txt     IN     VARCHAR2
    )
    RETURN     VARCHAR2
    ;
    
    END     string_agg;
    /
    SHOW ERRORS
    
    CREATE OR REPLACE PACKAGE BODY string_agg
    AS
    
    FUNCTION concat_query
    (
         in_cursor          IN     concat_query_cursor_type,
         in_separator_txt     IN     VARCHAR2
    )
    RETURN     VARCHAR2
    IS
         c_txt          VARCHAR2 (4000);
         return_txt     VARCHAR2 (4000) := '';
         return_max_val     INTEGER := 4000;     -- declared size of return_txt
         row_cnt          INTEGER := 0;          -- number of pa records found so far
    BEGIN
         LOOP
              FETCH  in_cursor  INTO  c_txt;
              EXIT  WHEN  in_cursor%NOTFOUND;
    
              IF  row_cnt > 0
              THEN
                   c_txt := in_separator_txt || c_txt;
              END IF;
    
              IF  LENGTH (return_txt) + LENGTH (c_txt) > return_max_val
              THEN
                   c_txt := SUBSTR
                   (
                        c_txt,
                        1,
                        return_max_val - LENGTH (return_txt)
                   );
              END IF;
    
              return_txt := return_txt || c_txt;
    
              IF  LENGTH (return_txt) >= return_max_val
              THEN
                   EXIT;
              END IF;
    
              row_cnt := row_cnt + 1;
         END LOOP;
         CLOSE in_cursor;
    
         RETURN (return_txt);
    END  concat_query
    ;
    
    END     string_agg;
    /
    SHOW ERRORS
    

    Here is an example of a specific function using this package:

    CREATE OR REPLACE FUNCTION all_years
    (
         in_item_no          IN     item_year.item_no%TYPE
    )
    RETURN     VARCHAR2
    IS
         q_cursor     string_agg.concat_query_cursor_type;
         return_txt     VARCHAR2 (4000);
    BEGIN
         OPEN       q_cursor     FOR
         SELECT       year
         FROM       item_year
         WHERE       item_no     = in_item_no
         ORDER BY  year;
    
         return_txt := string_agg.concat_query
         (
              q_cursor,
              ', '
         );
    
         RETURN (return_txt);
    END  all_years;
    /
    SHOW ERRORS
    

    The all_years above is a stand-alone function. You could also just have a function in a package, or string_agg, or another package, if that suits your needs.
    As you can see, the specific function is quite trivial. You could probably do something with dyanamic SQL, where you write another function, with the text of a query as a string argument, and it calls concat_query and returns this value.

    Here is an example of using the all_years function in a query:

    SELECT     item_no
    ,     all_years (item_no)     AS years
    FROM     (
             SELECT DISTINCT  item_no
             FROM             item_year
         )
    ;
    

    You could SELECT DISTINCT in the main query, but it would be less effective.
    Output:

    ITEM_NO                   YEARS
    ------------------------- ----------------------------------------
    item1                     1998, 2002, 2003, 2004
    item2                     1984, 1991, 2006, 2008, 2010
    
  • Combine several values display in a LOV

    Using Application Express 3.1.0.00.32


    I want to create a dynamic LOV, who will choose a name of employees from a table. The first, last and middle initial are in separate columns in the table. Since I am new to this I tried the following code when you try to create the LOV:

    Select
    emple_no r, middle_initial, first_name, last_name d d d

    of
    Schema.table

    order by
    last_name

    This has created the following error message:
    + 1 error has occurred.
    * LOV query is not valid, a display and a return value is needed, the column names must be different. If your query contains a query online, the first CLAUSE in the SQL statement must not belong to the query online.

    I was unable to find a solution to this specific problem when searching.
    What I'm wanting to create is to have the LOV display employees last name, first name, and the Middle init by registering the employee id in the table to sort by last name.
    select
    last_name || ', ' ||first_name || ' ' || middle_initial d, emple_no r
    
    from
    schema.table
    
  • to display several values in the column as a simple comma separated

    Hello..
    My the source table structure is as
    test_123
    person_id varchar2,
    phone_no varchar2

    A unique person_id can have several phone_nos
    as

    person_id phone_no
    123 1245
    123 1246
    123 1247
    12460 124
    124 12461


    Now I want the output voltage

    person_id phone_no
    123 1245,1246,1247
    124 12460,12461

    How d she?

    I want it in a single query?

    Many many many examples here.

    http://www.Oracle-base.com/articles/Misc/StringAggregationTechniques.php

  • Enter several values in the text box, separated by commas and spaces

    Hello

    I have the following syntax as my request to report to the opening of user_names in the area of text separated by commas, but the user sometimes come with a space between commas, could someone please let me know
    How this can be controlled, both when the user uses the space or not use space as well as the comma recording several user names in the text box?
    select 
    *
    from   DW_RFA_JOBDATA
    where  FINISH_TIME >= :P1_START_DATE 
    and FINISH_TIME < :P1_END_DATE
         AND  instr(',' || :P1_USER || ',', ',' || USER_NAME || ',') > 0
     OR (USER_NAME = USER_NAME AND :P1_USER is null)
    Thank you

    Select
    *
    of DW_RFA_JOBDATA
    where FINISH_TIME > =: P1_START_DATE
    and FINISH_TIME<>
    AND instr ("," |) REPLACE (translate (: P1_USER, '! @# $% ^ & * () _-+= {[]}] |------:; ~ ',' '),' ', "). ',', ',' || USER_NAME | ',') > 0
    OR (USER_NAME = USER_NAME AND: P1_USER is null)

  • How to combine several PDF using PHP on Linux

    Hello

    I would like to know if there is a product from Adobe that can combine several PDF files into a single document and works under Linux? We are developing an application that uses PHP on Linux which must combine PDF files selected and would like to know if there is a tool with api (or command line interface) to allow.

    Not by Adobe, I don't think, but there are a lot of PDF libraries that can do such things, for example in Java.

  • Getting a value from all the selected lines in the method of the AM

    Hi all

    I use JDev 11.1.1.4.0

    I have a table with the selection of several lines. In my module application I want to call a stored procedure with the parameter whose value depends on the selected line in the table.
    For the only selection I can make fallow:
        public void wypiszId() {
            ViewObject vo = findViewObject("ProcsklView1");
            String st = vo.getCurrentRow().getAttribute("IdProcskl").toString();
            System.out.println(st);
    How can I deal with multiple selection?

    Kind regards
    Wojtek.

    Hello

    VO/iterator will hold only selected line at a time. Thus, for multi table enabled selection, the last selected line would be the selected line (vo / Iterator). In order to obtain all the selected lines, you must obtain support bean by linking the Table of the ADF.

    Check out this blog on this goal.

    http://blogs.Oracle.com/aramamoo/2010/12/getting_all_selected_rows_in_adf_table_with_multiple_rows_selection_enabled.html

    Arun-

  • Extract the most several value in a TextArea of the Dummy Table

    Hello

    I have three point 1 selection list for the CODE OF MEDICINE and a 2nd is text field for MEDICINE BACK and 3rd P2_MED_COUNT to add new drugs and created a table with two columns of DUMMY_MEDICINE
    MED_CODE, MED_DOS

    I use a cursor to retrieve several value in the text box, but it shows enter only last value user. I want that enter all data by user
    declare
    p varchar2(200);
    rec DUMMY_MED_LITS%ROWTYPE;
    cursor c1 is select * from DUMMY_MED_LITS;
    begin
    open c1;
    p:=0;
    :P2_MED_COUNT:=0;
    loop
    fetch c1 into rec;
    exit when c1%notfound;
    
    p:=rec.MED_CODE ||'-'||rec.MED_DOS|| CHR(13) || CHR(10);
    :P2_MED_COUNT:=p;
    end loop;
    
    close c1;
    end;
    I created an insert statement on click Add more button medicine
    begin
    insert into DUMMY_MED_LITS values(:P2_MEDICIN_NAME,:P2_MED_DOS);
    end;
    How can I retrieve data from Table in an element.

    How can I do that.

    Thank you
    Ed

    Published by: Ed on April 3, 2010 12:31 AM

    Hi Maury,

    Change this line
    p: = rec. MED_CODE | » -'|| recomm. MED_DOS | CHR (13) | CHR (10);
    TO
    p: = rec. MED_CODE | » -'|| recomm. MED_DOS | CHR (13) | CHR (10) * | p * ;

    In addition, to make the statement P2_MED_COUNT: = p; after the end of the loop...

    Kind regards
    Shijesh

  • How to combine several libraries in a library complete?  And this new global all0 library can be an external hard drive?

    How to combine several libraries in a library complete?  And this new global all0 library can be an external hard drive?

    1. click here for more information.

    2. Yes, if this disk contains a partition image or the drive Mac OS Extended format.

    (142356)

  • Can I combine several old backups located on a portable hard drive in a backup on the same hard drive?

    Can I combine several old backups that are on a portable hard drive in just a backup with all the files, but no duplicates on the same hard drive?

    How did you create these backups?

  • Mr President, how can I enter two rows at the same time with different default values that only the first line to use see?

    Mr President.

    My worm jdev is 12.2.1

    How to enter two rows at the same time with different default values that only the first line to use see?

    Suppose I have a table with four fields as below

    "DEBIT" VARCHAR2(7) , 
      "DRNAME" VARCHAR2(50),
      "CREDIT" VARCHAR2(7) , 
      "CRNAME" VARCHAR2(50),
    

    Now I want that when I click on a button (create an insert) to create the first line with the default values below

    firstrow.png

    So if I click on the button and then validate the second row with different values is also inserted on commit.

    The value of the second row are like the picture below

    tworows.png

    But the second row should be invisible. It could be achieved by adding vc in the vo.

    The difficult part in my question is therefore, to add the second row with the new default values.

    Because I already added default values in the first row.

    Now how to add second time default values.

    Concerning

    Mr President

    I change the code given by expensive Sameh Nassar and get my results.

    Thanks once again dear Sameh Nassar .

    My code to get my goal is

    First line of code is

        protected void doDML(int operation, TransactionEvent e) {    
    
            if(operation != DML_DELETE)
                 {
                     setAmount(getPurqty().multiply(getUnitpurprice()));
                 } 
    
            if (operation == DML_INSERT )
                       {
                               System.out.println("I am in Insert with vid= " + getVid());
                           insertSecondRowInDatabase(getVid(),getLineitem(),"6010010","SALES TAX PAYABLE",
                            (getPurqty().multiply(getUnitpurprice()).multiply(getStaxrate())).divide(100));      
    
                           }
    
            if(operation == DML_UPDATE)
                              {                                                    
    
                                 System.out.println("I am in Update with vid= " + getVid());
                             updateSecondRowInDatabase(getVid(),
                                 (getPurqty().multiply(getUnitpurprice()).multiply(getStaxrate())).divide(100));      
    
                              }                      
    
            super.doDML(operation, e);
        }
        private void insertSecondRowInDatabase(Object value1, Object value2, Object value3, Object value4, Object value5)
                  {
                    PreparedStatement stat = null;
                    try
                    {
                      String sql = "Insert into vdet (VID,LINEITEM,DEBIT,DRNAME,AMOUNT) values " +
                 "('" + value1 + "','" + value2 + "','" + value3 + "','" + value4 + "','" + value5 + "')";  
    
                      stat = getDBTransaction().createPreparedStatement(sql, 1);
                      stat.executeUpdate();
                    }
                    catch (Exception e)
                    {
                      e.printStackTrace();
                    }
                    finally
                    {
                      try
                      {
                        stat.close();
                      }
                      catch (Exception e)
                      {
                        e.printStackTrace();
                      }
                    }
                  }  
    
                  private void updateSecondRowInDatabase(Object value1, Object value5)
                  {
                    PreparedStatement stat = null;
                    try
                    {
                      String sql = "update vdet set  AMOUNT='"+ value5+"' where VID='" + value1 + "'";                     
    
                      stat = getDBTransaction().createPreparedStatement(sql, 1);  
    
                      stat.executeUpdate();
                    }
                    catch (Exception e)
                    {
                      e.printStackTrace();
                    }
                    finally
                    {
                      try
                      {
                        stat.close();
                      }
                      catch (Exception e)
                      {
                        e.printStackTrace();
                      }
                    }                  
    
                  }
    

    Second line code is inside a bean method

        public void addNewPurchaseVoucher(ActionEvent actionEvent) {
            // Add event code here...
    
            BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
                   DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("VoucherView1Iterator");
                   RowSetIterator rsi = dciter.getRowSetIterator();
                   Row lastRow = rsi.last();
                   int lastRowIndex = rsi.getRangeIndexOf(lastRow);
                   Row newRow = rsi.createRow();
                   newRow.setNewRowState(Row.STATUS_NEW);
                   rsi.insertRowAtRangeIndex(lastRowIndex +1, newRow);
                   rsi.setCurrentRow(newRow);
    
                   BindingContainer bindings1 = BindingContext.getCurrent().getCurrentBindingsEntry();
                   DCIteratorBinding dciter1 = (DCIteratorBinding) bindings1.get("VdetView1Iterator");
                   RowSetIterator rsi1 = dciter1.getRowSetIterator();
                   Row lastRow1 = rsi1.last();
                   int lastRowIndex1 = rsi1.getRangeIndexOf(lastRow1);
                   Row newRow1 = rsi1.createRow();
                   newRow1.setNewRowState(Row.STATUS_NEW);
                   rsi1.insertRowAtRangeIndex(lastRowIndex1 +1, newRow1);
                   rsi1.setCurrentRow(newRow1);
        }
    

    And final saveUpdate method is

        public void saveUpdateButton(ActionEvent actionEvent) {
            // Add event code here...
    
            BindingContainer bindingsBC = BindingContext.getCurrent().getCurrentBindingsEntry();      
    
                   OperationBinding commit = bindingsBC.getOperationBinding("Commit");
                   commit.execute(); 
    
            OperationBinding operationBinding = BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding("Commit");
            operationBinding.execute();
            DCIteratorBinding iter = (DCIteratorBinding) BindingContext.getCurrent().getCurrentBindingsEntry().get("VdetView1Iterator");// write iterator name from pageDef.
            iter.getViewObject().executeQuery();  
    
        }
    

    Thanks for all the cooperation to obtain the desired results.

    Concerning

  • I have Acrobat 10 when I try to combine several files with names like 0022_0_ point report, report 0022_2_Item by report 0022_15_Item it combines out of use.  Any ideas?

    This is how it brings together files I have Acrobat 10 when I try to combine several files with names like 0022_0_ point report 0022_2_Item report through report 0022_15_Item it combines out of use.  Any ideas?

    Hi tomp29181935,

    Please refer to this page:placing the pdf of the numerical order when combining (combining files)

    Let us know if you face any problem.

    Thank you!

    Shivam

  • It is possible to combine several PDF in a single pdf file using document cloud

    I would like to combine several PDF files, which are in the clouds of Document into a single PDF file. Is it possible to do in the DC, without first download the files on my desktop computer?

    Hi jay,

    You can do this online if you have the Acrobat DC tickets or you subscription to Adobe PDF pack https://cloud.acrobat.com/combinepdf . Is not possible within the application itself.

    Kind regards
    Nicos

  • How to combine several PDF in a single

    I can't find out how to combine several PDF in a single document with Illustrator.

    Help, please!

    Brooke,

    It depends on your version.

    In older versions (one page PDF), you can

  • I have adobe reader xi and can not find the "create button" in order to combine several files into a single pdf

    I have adobe reader xi and can not find the "create button" in order to combine several files into a single pdf

    Hello

    Reader is software to view PDF' only.

    You must either a pack PDF to perform the function of thin or Acrobat.

    Reader is not the software to perform editing functions.

    Concerning

    Sukrit diallo

Maybe you are looking for

  • The client application streaming

    Is there a good app to play movies/music/photos that are broadcast on the network? HTC offers a pre-installed application ("Media connected") who can do it, but is there something similar on the Android Market? It would be great if we could get XBMC

  • HP Wireless Assistant for laptop G72 C-55DX

    I lost HP Wireless Assistant for 7 can I origional backup DvD s would not work asking me to send it back to HP support and F11 does not help me to recover from a hard disk.

  • How to activate 802.11ac on EA6500

    Bought an EA6500 last year and have now a laptop with an 802.11ac wireless card inside. At work, my laptop shows it's connected ac 802.11.   At home on the EA6500 I can't it connect with ac 802.11. What should I look for?  I don't see any 802.11ac sp

  • You can use a Windows Vista Home Premium 64-bit OEM license to reinstall a retail copy?

    Hello. I currently have a HP machine with licensed Windows Vista Home Premium 64-bit. I intend to back up, format and perform a new Installation. I do have a HP OEM DvD and I wonder if I can use Vista Home Premium 64 - bit RETAIL COPY my sister to re

  • Windows 7 and Windows 8 CP

    I have recently installed windows 8 consumer overview dual boot with windows 7 successfully.when, I started from windows 7, I received a notification on windows 7 such .but "this copy of Windows is not genuine," activate now", I used this copy for a