Return rows in one column

sample my table test:
create table test (
     idsearch number,
     idtest number,
     p_nome varchar2(50),
     p_value varchar2(50),
     primary key(idsearch,idtest)
insert into test values(1,1,'name','alex');
insert into test values(1,2,'age','21');
insert into test values(1,3,'nick','alex');
select * from test;
return :
IDSEARCH IDTEST P_NOME P_VALUE
1 1 name alex
1 2 age 21
1 3 nick alex
how i return so ?
STRING
name=alex&age=21&nick=alex
thanks

A summary of different string aggregation techniques can be found here
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php

Similar Messages

  • How to suppress row when one column has zero  using condition

    Hi Experts,
    How do I suppress row when one column has zero.
    I read it is possible using conditions.
    How ?
    Thankyou.

    Check this
    1. for Query Properties, go to the Display tab and Supress Zeros is "Active"
    2. select the Structure, right-click, select Properties, then click "on" Also Use Zero Suppression for Structure Elements
    http://help.sap.com/saphelp_nw04/helpdata/en/a4/dd3841d132d92be10000000a1550b0/frameset.htm
    Hope it Helps
    Chetan
    @CP..

  • Rows as one column

    Hi all,
    I want to display the rows as one column
    Source Amount
    A 100
    A 200
    B 300
    B 400
    C 500
    C 600
    I want to display like below
    Sum(A) Sum(B) Sum(C)
    300 700 1100
    Is it possible to do in SQL
    Thanks

    SELECT
         SUM(DECODE(source, 'A', amount, 0)) sum_a,
         SUM(DECODE(source, 'B', amount, 0)) sum_b,
         SUM(DECODE(source, 'C', amount, 0)) sum_c
    FROM
         t
       SUM_A    SUM_B    SUM_C
         300      700     1100

  • Collecting data from multiple rows into one column

    I'd like to run a query and put a collection of items into one output column instead of multiple rows. See the example below:
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
    PL/SQL Release 10.2.0.5.0 - Production
    "CORE     10.2.0.5.0     Production"
    TNS for 32-bit Windows: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
         CREATE TABLE "SKIP"."INGREDIENTS"
       (     "INGRED_ID" NUMBER,
         "INGRED_NAME" VARCHAR2(20 BYTE),
         "STORES" VARCHAR2(20 BYTE)
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS" ;
    REM INSERTING into SKIP.INGREDIENTS
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (1,'SEA SALT','Food lion');
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (2,'TABLE SALT','Food lion');
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (3,'FLOUR','Piggly Wiggly');
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (4,'YEAST',null);
    Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (5,'BEER','ABC Store');
      CREATE TABLE "SKIP"."PRETZELS"
       (     "PRETZEL_ID" NUMBER,
         "PRETZEL_NAME" VARCHAR2(20 BYTE),
         "PRETZEL_DESC" VARCHAR2(100 BYTE)
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS" ;
    REM INSERTING into SKIP.PRETZELS
    Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (1,'CLASSIC','Classic knot pretzel');
    Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (2,'THICK STICK','Straight pretzel, abt 1/2" in dia');
      CREATE TABLE "SKIP"."INGRED_XREF"
       (     "PRETZEL_ID" NUMBER,
         "INGRED_ID" NUMBER
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS" ;
    REM INSERTING into SKIP.INGRED_XREF
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,1);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,2);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,4);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,2);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,3);
    Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,5);
    --  Constraints for Table INGRED_XREF
      ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("PRETZEL_ID" NOT NULL ENABLE);
      ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("INGRED_ID" NOT NULL ENABLE);
    {code}
    Desired output (note how the ingredients are all listed in one column, separated by commas):
    {code}
    PRETZEL_ID PRETZEL_NAME     PRETZEL_DESC                        INGREDIENTS
    1          CLASSIC          Classic knot pretzel                SEA SALT, TABLE SALT, YEAST
    2          THICK STICK      Straight pretzel, abt 1/2" in dia   TABLE_SALT, FLOUR, BEER

    See the FAQ : {message:id=9360005}
    Especially links concerning string aggregation.

  • How to select rows whose one column contains some specific characters ?

    These is a table say T1 with a column say C1
    Let the field C1's values be:
    row 1)DE/SPT/A/FWD
    row 2)G/SPT/DE/DE/SPT
    row 3)R/FWD/SPT/A/FWD/FWD
    row 4)A/A/DE/SPT/FWD
    row 5)FWD/SPT/E/DE/A
    How to get only those rows whose C1 column contains FWD in last ?

    We can solve this with the simple use of a wildcard:
        select *
        from t1
        where c1 like '%FWD'
        /Note that this query will execute a full table scan, because any index you may have on C1 will be ignored: indexes are organised on the leading characters.
    cheers, APC

  • Returning two rows with one column containing only one place

    Dear all;
    I have a query that returns two rows similar to this below
    ID      PLACE            PROGRAM
    A       NEWYORK      PROGRAM A
    A       NEWYORK      PROGRAM B
    I would like this instead
    ID      PLACE             PROGRAM
    A       NEWYORK       PROGRAM A
                                   PROGRAM  B
    All help is appreciated. Thank you.Edited by: user13328581 on Mar 22, 2011 11:52 AM

    user13328581 wrote:
    WOW...THanks a lot Solomon, I have never used partitions and row_number in such a manner...can you please explain your logic.Sure:
    row_number() over(partition by id order by place,program)This will take all rows returned by the query andsplit them into buckets (partitions) by id. Inside each bucket it will order rows by place and program and assign them row numbers. So for each ID row number 1 will be row with first (alphabetically) place first programt. And this is the row where we want ID to show up. That is why we wrap the above analytic function in CASE statement which will do exactly that. Now:
    row_number() over(partition by id,place order by program)does pretty much the same just bucket is ID and PLACE combination. So for each such combination we want to show only for the first (alphabetically) programt.
    Now notice in ORDER BY clause I prefix ID and PLACE with table alias. You must do it since otherwise query alias ID and PLACE will take precedence resulting in wrong sort order (remember we nulled all ID and PLACE except for row number 1).
    SY.

  • Dynamic table - some fields of different rows in one column

    Hey guys,
    i have the following problem:
    i habe a itab with some data like:
    name | id | date | number
    pete  | 1 | 27.07 |    2
    pete  | 1 | 28.07 |    2
    pete  | 1 | 30.07 |    2
    ann   | 1 | 28.07 |    3
    ann   | 2 | 30.07 |    2
    the user can define a period of time, e.g. 28-29.07
    so my dynamic table will consist of the "hard" columns name and id and the dynamic added columns for every day:
    name | id | 28.07 | 29.07
    that's what i already have!
    so my problem is, that i have to read the data from the itab into the new dynamic table (field-symbol) like:
    name | id | 28.07 | 29.07
    pete   |  1 |    2     |    2
    ann    |  1 |    3     |    -
    i hope you can understand what i want! please give me code sample or a example report!
    many thanks in adance!
    best regards,
    ludwig

    hey Asik, you have understand what i want!
    here is my table:
    http://img181.imageshack.us/my.php?image=wh20080916113004ym8.png
    after the loop, the 4 rows should be in my field-symbol only one row (no sum)!
    but after the loop, there are to many rows! only one row is needed!
    Look at the screenshot:
    http://img185.imageshack.us/my.php?image=wh20080916113547wl0.png
    So the second row at column "tag20080801" should be initial and with the next loop, the next day "tag20080730" should be filled with the number!
    LOOP AT LT_OUT INTO LS_OUT.
      ASSIGN COMPONENT 'RESSOURCEN' OF STRUCTURE <FS_LINE> TO <fs_field>.
      <fs_field> = 'Ressource'.
      ASSIGN COMPONENT 'NAME' OF STRUCTURE <FS_LINE> TO <fs_field>.
      <fs_field> = LS_OUT-name.
      ASSIGN COMPONENT 'PROJEKT' OF STRUCTURE <FS_LINE> TO <fs_field>.
      <fs_field> = LS_OUT-PROJECTID.
      CONCATENATE 'DATE' LS_OUT-DATE INTO LF_DATE_COL.
      ASSIGN COMPONENT LF_DATE_COL OF STRUCTURE <FS_LINE> TO <fs_field>.
      <fs_field> = LS_OUT-COUNT.
      COLLECT <FS_LINE> INTO <FS_TABLE>.
    ENDLOOP.
    the right output data should look like this:
    Ressourcen | Ludwig Heinz | 20080702LHZ  | 4 | 4 | 4 | 1

  • Multiple Rows Into One Column Field

    Hi All,
           Today I tried one query:
    select wm_concat(ename) from emp
    group by deptno;
    I have a data that looks like this.
    CLARK,KING,MILLER,SREE
    JONES,FORD,ADAMS,SCOTT
    ALLEN,MARTIN,BLAKE,TURNER,JAMES,WARD
    Can someone help me to build an SQL command that would have the output as follows:
    I need per column 3 values....
    CLARK,KING,MILLER,
    SREE,JONES,FORD,
    ADAMS,SCOTT,ALLEN,
    MARTIN,BLAKE,TURNER,
    JAMES,WARD

    StewAshton wrote:
    That's funny, I don't get the same answer
    Why do you think you should?
    Besides, you're not the only one.
    ENAMES
    KING,BLAKE,CLARK
    JONES,SCOTT,FORD
    SMITH,ALLEN,WARD
    MARTIN,TURNER,ADAMS
    JAMES,MILLER
    Regards
    Etbin
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE 11.2.0.3.0 Production
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    It's from my APEX Workspace: first select from the emp table (not touched until now)
    Message was edited by: Etbin

  • Group by returning more than one column in a single query

    Hello,
    Sorry to ask such a simple question I guess, but here is my problem.
    I'm building a query to get say the smallest user_id from employees in the company by department.
    The query goes like :
    select emp..department,
    min(emp.user_id)
    from employee emp
    group by emp.department
    This gives me the smallest user id by department, which is what I want. But how can I also get the name of that person ?
    I know that the "min" condition singles out a unique record (there are no two persons with the same user_id in the department).
    But how can I also get the name without turning the above query in a subquery that I would link to the employee table yet again ?
    I know the following works but I don't think it's the best option:
    select v1.department,
    v1.user_id,
    emp1.name
    from employee emp1,
    ( select emp..department,
    min(emp.user_id)
    from employee emp
    group by emp.department) v1
    where emp1.user_id = v1.user_id
    This is just an example of data. It is the principle that I don't quite get.
    Any advice would be very much appreciated.
    Cyril

    Hi, Cyril,
    To find the name of the person who has the lowest user_id
    SELECT    department
    ,         MIN (user_id)   AS lowest_user_id
    ,         MIN (name) KEEP (DENSE_RANK FIRST ORDER BY user_id)  AS person_with_lowest_user_id
    FROM      emp
    GROUP BY  department;"MIN (name)" above means that if there is a tie for the lowest user_id, then the contender with the first name will be chosen.
    If you want to display several columns from the row with the lowest user_id, you have to have a separate "KEEP (DENSE_RANK ...)" expression for each column. In that case, you may find it easier to use the analytic RANK or ROW_NUMBER in a sub-query, like this:
    WITH  sub_query  AS
         SELECT  department
         ,     user_id
         ,     name
         ,     col2, col3, col4, col5
         ,     RANK () OVER ( PARTITION BY  department
                               ORDER BY          user_id
                        )  AS r_num
         FROM     emp
    SELECT     *     -- or list all columns EXCEPT r_num
    FROM     sub_query
    WHERE     r_num = 1;

  • Highlight complete row if one column is null

    Hi,
    i want to highlight a complete row in my publisher report if a certain column of the
    row is empty (no value at all). I already tried to get forward using the examples in the
    XML Publisher developer guide (i checked the samples installed by xml publisher desktop
    as well) but none of them delivered the desired result.
    Any hints are welcome.
    regards
    Thomas

    Hi,
    You can write the following code to highlight a row if a certain column is null:
    <?if@row:COLUMN-NAME=''?><xsl:attribute name="background-color" xdofo:ctx="incontext">red</xsl:attribute><?end if?>
    You can place this code in a text form field and place in the first column after the for-each statement.
    Hope this helps.
    Thanks.

  • Multilple row in one column ( sql as well as pl/sql)

    hi  sir,Madam
    i have a table emp . it contains 3 column and 5 rows that are following
    empno
    months
    salary
    100
    jan
    8000
    100
    feb
    10000
    100
    mar
    12000
    101
    jan
    20000
    101
    feb
    10000
    my desired output should be like below
    empno
    months
    100
    jan,feb, mar
    101
    jan,feb
    Please help me
    thanks in advanced
    kPrem

    Hi,
    That's called String Aggregation.  This page:
    ORACLE-BASE - String Aggregation Techniques
    shows several ways to do it.
    Which way is best for your data ,your requirements and your version of Oracle?  That depends on your data ,your requirements and your version of Oracle.
    LISTAGG is especially useful.

  • Search one column for value in another column

    Hello,
    I am trying to take the whole value from one column, and see if that string appears anywhere in another colmn. So if one row in one column has the value "cat", I want to see if that string appears anywhere in any row in another column: so a row with the value "The cat sat on the mat" would return true.
    I have tried:
    select term from pic_lib_keywords, csv
    where contains (csv.nhm_field_asset_description,pic_lib_keywords.term) >0;
    But I get the error:
    ORA-20000: Oracle Text error:
    DRG-50901: text query parser syntax error on line 1, column 32
    20000. 00000 - "%s"
    *Cause:    The stored procedure 'raise_application_error'
    was called which causes this error to be generated.
    *Action:   Correct the problem as described in the error message or contact
    the application administrator or DBA for more information.
    Can you use 2 columns in this way, or does the search term have to be a literal? Any suggestions would be appreciated.
    Thank you.

    It works for me, as shown below.
    SCOTT@orcl_11gR2> select * from v$version
      2  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    5 rows selected.
    SCOTT@orcl_11gR2> create table csv
      2    (nhm_field_asset_description  clob)
      3  /
    Table created.
    SCOTT@orcl_11gR2> insert all
      2  into csv values ('The cat sat on the mat.')
      3  into csv values ('The dog sat on the mat.')
      4  select * from dual
      5  /
    2 rows created.
    SCOTT@orcl_11gR2> create table pic_lib_keywords
      2    (term  varchar2(30))
      3  /
    Table created.
    SCOTT@orcl_11gR2> insert all
      2  into pic_lib_keywords values ('cat')
      3  into pic_lib_keywords values ('mouse')
      4  select * from dual
      5  /
    2 rows created.
    SCOTT@orcl_11gR2> create index test_idx
      2  on csv (nhm_field_asset_description)
      3  indextype is ctxsys.context
      4  /
    Index created.
    SCOTT@orcl_11gR2> select term
      2  from   pic_lib_keywords, csv
      3  where  contains
      4             (csv.nhm_field_asset_description,
      5              pic_lib_keywords.term) >0
      6  /
    TERM
    cat
    1 row selected.
    SCOTT@orcl_11gR2>

  • DataGrid alternating row colors per column

    Is there a way to set different alternating colors to each
    column in a DataGrid. I have a datagrid where I want two of the
    columns to have different alternating row colors, one column (red
    and light red) and the other (green and light green).
    Many thanks

    You can simply set the DataGridColumn property to the
    approprate colors.
    ex.
    <mx:DataGrid y="0" x="0" width="100%">
    <mx:columns>
    <mx:DataGridColumn id="col1" backgroundColor="0x640000"
    dataField="col1"/>
    <mx:DataGridColumn id="col1" backgroundColor="0xFF0000"
    dataField="col1"/>
    <mx:DataGridColumn id="col1" backgroundColor="0x006600"
    dataField="col1"/>
    <mx:DataGridColumn id="col1" backgroundColor="0x33CC33"
    dataField="col1"/>
    </mx:columns>
    </mx:DataGrid>
    or you can use the setStyle:
    col1.setStyle("backgroudColor", 0x640000)

  • Dropdownbykey. data is missing in one column

    Hi,
    I am facing issue in dropdownbykey UI element.
    When pushbutton is clicked, there is table showing up. but the first column in the table is missing. There is no value. This column values are expected to be like hyperlink so that when any one is clicked that is selected and the field is populated by this value.
    I have found the dropdownbykey UI element on the view and trying to find the code for this UI element.
    I dont know anything about the dropdownbykey ui element as i am new to web dynpro. I am reading the sap help material but its not addressing very basic understanding
    Could you please help get answers to following
    1) When we click pushbutton of dropdownbykey ui element we see a table from which we can click on one of the rows (only one column of the table is link which we can click) How are the columns in the table determined ?
    2) Which key of the table is selectable ?
    3) From where are the values of the table fetched ? u2013 backend.  so obviously will have to pick data type linked to the ui element from some model rite ? it cant be string.
    4) Why is there a value-set ? is it for the dropdown part of the ui element ? is it mandatory to code them as contants when we make a ui element dropdownbykey on our view or there is any other way of fetching this value-set data?
    thank you

    Hi Yogesh,
    Its perfectly alright.
    Could you please tell me what is SVS code ?
    Is it so that by using this I will have all the methods needed for coding required for dropdownbykey ui element ?
    I dont want to go by dropdownbyindex because I am not developing any application, there is this problem in an already developed application which I have to investigate
    My above questions were based on understanding that when we include dropdownbykey ui element in our view , the dropdown list, pushbutton and screen with all values are inbuilt. This is written in the sap help on the link -
    http://help.sap.com/saphelp_nw04/helpdata/en/5c/1b76bc3da0504e8b535cf3e154eaa7/frameset.htm
    But now I have seen in my system that there is actually a separate view for displaying values is created for the pop up.
    there is linktoaction ui element in the view where the dropownbykey is put and this linktoaction calls the view for displaying values.
    I am now checking inside the code which passes data to this pop up view , why the first column in the table is missing.
    thanks

  • Update column with subquery returning more than one row

    Hi Everybody,
    Please let me know how to handle this. I am writing update statement in procedure with subquery and it is returning multiple rows. Please help me, how i can handle this :
    UPDATE TABLEA A
    SET A.ERROR_MESSAGE = (Select B.XERROR_MESSAGE from TABLEB B, TABLEA A WHERE B.id = A.id)
    WHERE A.id = (Select B.id from TABLEB B, TABLEA A WHERE B.id = A.id);
    (Select B.XERROR_MESSAGE from TABLEB B, TABLEA A WHERE B.id = A.id) --- This subquery is returning more than one rows. How i can handle this in Pl/SQL?
    Please let me know. I will be very thankful to you all.
    I will really appreciate your replies and comments.
    Thank you

    Try getting rid of tablea in your subqueries. You already have it in the UPDATE statement.
    UPDATE TABLEA A
    SET    A.ERROR_MESSAGE = (Select B.XERROR_MESSAGE
                              from   TABLEB B
                              WHERE  B.id = A.id
    WHERE  A.id = (Select B.id
                   from   TABLEB B
                   WHERE  B.id = A.id);You can also try a simple MERGE:
    merge into tablea a
    using tableb b
    on    (a.id = b.id)
    when  matched then update
          set a.error_message = b.xerror_message;

Maybe you are looking for

  • Mail App 4.3 crashes when selecting individual email for reading

    Does anyone have experience with this problem? Does anyone have a solution for this problem?

  • How can I populate a date field when document is signed?

    I have 4 digital signature fields in a PDF form.  Next to each signature field is a date field (m/d/yyyy format).  I would like it so when the user signs the signature box that the date field next to it populates with todays date, then changes to rea

  • Adobe Photoshop CS4 Extended

    I am trying to install Photoshop CS4 extended on my computer running Vista Business without unistalling Photoshop CS3 extended. The installation installed Photoshop CS4, Adobe media, adobe air, Bridge etc but failed to install other components such a

  • [solved] maximizing window results in white screen

    hi, using xfce4 and gdm with nvidia driver (from Arch), 64 bit, using compiz while in the GUI if i maximize a window, say Thunderbird, the app only shows a white screen. the window decorations are still there and i can restore it down and everything

  • Java.lang.OutOfMemoryError: PermGen space Not able to open applications

    Hi , I am facing issue in running the application when I deploy 10 applications successfully to the Integrated weblogic server [in jdev]. Then after some time I am not able to open any of the application. Thanks and Regards, Vivek Pemawat