Concatenation of character values by columns with excluding duplicates

Hi all! Assume, that there is a multi-rows table of the following form (for example):
1|A  |   |B  |C  |   |D  |   |
2|   |   |A  |B  |C  |D  |   |
3|   |A  |B  |   |   |C  |D  |
4|   |   |A  |   |B  |C  |D  |
5|   |   |A  |   |B  |   |C  |i.e. there are NULL and NOTNULL values in VARCHAR2( or NVARCHAR2) format, and the first column is a primary key.
I need to do next:
1. Select some set of certain rows, primary keys of those are initialy known, e.g. 1, 3, 5;
2. Parse this table such way: concatenate values by columns in selected rows, if there are few not-null values in one column, it's necessary to separate concatenated values with comma and whitesbase (it's desirable that's word after comma with whitespace is outputted in lowercase). Finally, it's necessary to insert dot and whitespace character after the last value.
3. Exclude duplicate substrings from the outcoming text values.
Thereafter I need to initialize set of local variables with the values, obtained by forementioned parsing (parsing of one column match the corresponding variable), e.g. columns of 1, 3 and 5 rows.
I.e. result in our case looks like:
variable1 = A.
variable2 = A.
variable3 = B, A.
variable4 = C.
variable5 = B.
variable6 = D, C.
variable7 = D, C.
Does the task will be easier, if the number of parsed rows is known (e.g. 3 as in our case)?
Edited by: 942736 on 02.10.2012 17:17

You missed your db-version. Please give the result from
select * from v$version;When you are on 11.2 you can try this (will not work with 10.x):
with yourtable as
select 1 id, 'A' col1, 'N' col2, 'B' col3, 'C' col4 ,'N' col5, 'D' col6 ,'N' col7 from dual union all
select 2,'N','N','A','B','C','D','N' from dual union all
select 3,'N','A','B','N','N','C','D' from dual union all
select 4,'N','N','A','N','B','C','D' from dual union all
select 5,'N','N','A','N','B','N','C' from dual
select
(select listagg(col1,',') within group (order by id)||'.' from (select distinct col1, min(id) over (partition by col1 order by id) id from yourtable where id in (1,3,5))) v1,
(select listagg(col2,',') within group (order by id)||'.' from (select distinct col2, min(id) over (partition by col2 order by id) id from yourtable where id in (1,3,5))) v2,
(select listagg(col3,',') within group (order by id)||'.' from (select distinct col3, min(id) over (partition by col3 order by id) id from yourtable where id in (1,3,5))) v3,
(select listagg(col4,',') within group (order by id)||'.' from (select distinct col4, min(id) over (partition by col4 order by id) id from yourtable where id in (1,3,5))) v4,
(select listagg(col5,',') within group (order by id)||'.' from (select distinct col5, min(id) over (partition by col5 order by id) id from yourtable where id in (1,3,5))) v5,
(select listagg(col6,',') within group (order by id)||'.' from (select distinct col6, min(id) over (partition by col6 order by id) id from yourtable where id in (1,3,5))) v6,
(select listagg(col7,',') within group (order by id)||'.' from (select distinct col7, min(id) over (partition by col7 order by id) id from yourtable where id in (1,3,5))) v7
from dual;Output with 11.2 is:
V1      V2      V3      V4      V5      V6      V7
A,N.     N,A.     B,A.     C,N.     N,B.     D,C,N.     N,D,C.@ranit B: You missed, that the OP said that only rows 1,3 and 5 shall be used.
Edited by: hm on 01.10.2012 23:09

Similar Messages

  • UPDATE value in column with value in SAME TABLE

    Hi all,
    Here's my issue...
    I have a table which records all incidents for a person.
    The table looks something like this:
    tbl_connect(person_Id NUMBer,
    OLD_ID VARCHAR2(24),
    CASE_NUMBER     VARCHAR2(10),
    CASE_TYPE     VARCHAR2(10),
    PERSON_ROLE     VARCHAR2(30),
    INCIDENT_TYPE     VARCHAR2(40));
    The table is populated from a source table with all fields except person_id. Person_id is a sequence number that gets generated if the person comitting the incident is a NEW PERSON to our system. OLD_Id is the unique identifier between the source table and tbl_connect to identify a person.
    The problem: If an existing person commits a new incident, a new record will be inserted into tbl_connect without PERSON_ID. Since the person already is in the database the person_id already exists in tbl_connect for that person. I now need to UPDATE person_id column with the person_id that already exists for this person. How can i achieve this.
    Ive been trying all sorts of update queries but nothing seems to work. ANy help will be appreciated. Thanks in advance.

    Frank,
    Thanks for the speedy reply. Here is a sample table.
    I know it's a bit confusing. The data that is being dumped into this table is information from a old system. The OLD_ID is in here because it is the relationship between this table and the old table. PERSON_ID is new to this system to identify a person uniquely. That is why i need them both in this table for right now.
    So say my tbl_connect got populated with new info from the old table. As you can see, old_id=567A has comitted another incident. Since he already exists in tbl_connect, now i need to update person_id with the value of 1. Does that make sense now????? If old_id did not exist, all i would do is insert a new row and set person_id to the next sequence number.
    TBL_CONNECT
    PERSON_ID OLD_ID      CASE_NUMBER CASE_TYPE          
    1     567A     12345          IR          
    1     567A     15236          MV
         567A     98547          IR<--newly inserted record of same person

  • How to pass prompt value to columns with formula?

    Hello guys
    I have a situation:
    I have a report with 1 column name 'product' and in this column it has a case statement like 'case when item is ('a','b','c','d') then 'Men' else 'women' end'
    Then I have created a dashboard prompt of the exact same column, and I defined the same case statement in the prompt's column formula as the same.. Then I tested the prompt and it is returning only 2 values 'men', 'women'..
    However, when putting the prompt and report on the same dashboard, the report is not accepting the prompt values..
    Then I set the presentation variable on the prompt and call it 'Product', then in the report I created a filter on 'product' column as equal to presentation variable 'product'--- I tried with and without single quotes.. So the filter itself looks like : case when ...... is equal to / is in @{product}
    However, when I then return back to the dashboard, I am getting the error:
    State: HY000. Code: 388918336. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27005] Unresolved column: "Product". (HY000)
    Could anyone help?
    Thanks

    Hola
    is possible that are you using a BINS agrupation into the Column Formula?
    if you form a CASE statement using a Bins agrupation, in the column Formula, this must be disabled to match statements between columns and DB Prompt
    if you are using a BINS agrupation to form the CASE statement, you have to delete the bins agrupation in the Column but keep the CASE statement
    Regards

  • Null values v IOT with primary constraint

    Hi gurus.
    I've overheard boss' conversation with client, who complaints that one of the columns in a system IOT table with NOT NULL and PRIMARY KEY returns nulls.
    Do you have any ideas? I do not have access to this DB, I just wonder, how it could be and what are these points, that we should start with.
    Thank you in advance,
    Maria.

    ou, sorry if I was not so clear, but I'm absolutely calm and even more: it's not my responsibility at all to fix that problem :-))
    all that I wanted is just to find some weak places where the reason of the problem could exists and give it my boss while he is busy with his time consuming project (in short, i just wanted to help him to resolve it, not waiting while he will ask me to do that). nobody is in panic, everything is ok in a world.
    clear description:
    client has a system table (IOT) that sometimes returns null values from column with NOT NULL and PRIMARY KEY constraint. as I remember from school, it's impossible. client wonders if it's an Oracle 9i bug and upgrade to 10g will fix it, or it's a block corruption. I do't know the answer, that's why I'm asking you, Oracle's gurus.
    Thank you all,
    M.

  • Urgent Help Needed - Joining On Columns with Concatenated Values

    I have a challenging issue where I'm trying to join two tables together with a USER_ID column. The caveat is that in one of the tables, the USER_ID is potentially concatenated.
    For example, TABLE1 has 2 columns:
    1) USER ID
    2) USER NAME
    TABLE2 has 3 columns:
    1) USER ID
    2) USER COUNTRY
    3) USER DATE HIRED
    The resulting SQL query is:
    select * from TABLE1, TABLE2
    where TABLE1.USER_ID = TABLE2.USER_ID
    The problem is that TABLE1.USER_ID is only limited to 1 ID per record. However, TABLE2 potentially has concatenated USER ID's.
    In other words, while TABLE1 has a USER_ID = 'ABC123', that same ID may appear in TABLE2 concatenated as USER_ID = 'ABC123;ABC124'
    Obviously, with a natural join, this individual will be dropped from the SQL result-set.
    Is there a "join function" that I can use to say - "whenever I'm joining these 2 tables, as long as the TABLE1.USER_ID appears *ANYWHERE* in the TABLE2.USER_ID concatenated string (regardless of position), then please include this record in the join??
    As of right now, I have total 80 rows. 55 of them successfully are pulled because they have a one-to-one USER_ID correspondence. The other 25 are dropped out because they have multiple concatenated ID's in TABLE2 and only one ID in TABLE1.
    Any advice/help will be greatly appreciated!

    Hi
    Etbin wrote:
    Maybe
    select *
    from TABLE1,TABLE2
    where instr(TABLE2.USER_ID,TABLE1.USER_ID) > 0Regards
    Etbin
    Edited by: Etbin on 20.4.2012 23:27
    Forgot to mention; <strike>Urgent</strike>How could you forget the "I found love in Slovenia" problem?
    If the keys can be different lengths, then the solution above will match different keys if the one in table1 happens to be a substring of the one in table2. For example, if table1.userid='ABC'1, and table2.userid='ABC123;ABC124', then it will be considered a match.
    To avoid that:SELECT  *
    FROM      table1
    ,     table2
    WHERE      INSTR ( ';' || table2.user_id || ';'
               , ';' || table1.user_id || ';'
               ) > 0And Martijn is right (as usual). Storing several different values in a single column, like you're doing with table2.user_id, will cause lots of problems. Store each one in a separate row of a new table.

  • Match values of 2 columns with other rows

    I want to compare the values of 2 columns with all rows in the sheet.
    If there is a match I want to place a character in the next column, so I can filter on it
    But I need to keep one row for each unique value. (match of 2 columns)

    Hi,
    I'm marking the reply as answer as there has been no update for a couple of days.
    If you come back to find it doesn't work for you, please reply to us and unmark the answer.
    Thanks
    George Zhao
    Forum Support
    Come back and mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback on our support, please click "[email protected]"

  • ORA-01400 - not null column with default value and item with authorization

    I've searched - I would think someone has run into this. APEX 3.0.0.00.20 - I've created a simple form on a table. One of the column is a not null column with a default value. I have a select list on that item, but it has security on it - authorization scheme. So, it checks the user and if that user isn't of the right role, it will not even display that item. However, APEX appears to still send in the column in its sql! So, the default value is useless, it sends in null each time. Even if I set the default at the Item level, I get null. Argg. That's got to be a bug...
    In debug, I do not see the item listed at all. It's not used. That's fine - but why is it trying to insert the value? I would think it would leave it off??? I think because the item is associated with a database column. But, getting around this is ugly. Having to create a hidden item for each one, and then check to see if I need to take the list value... horrible. Any way to get around this???

    I should add - I guess I can always put my own custom process in to replace the DML. Just seems like a simple thing - if the value doesn't appear on the debug, isn't set with any default value... don't include it in the DML.

  • Problem with display of a character (value 65533)

    Hi all, sorry for my english but i don't speak it very well.
    I have a big problem with the visualization of a character.
    I have a binary text that i have to analyze with java. With my utility all works fine, but when i get the character (binary 81) and i analayze this character i obtain an int 65533 or a byte -3 , and after a casting to char i see that java doesn't display correctly this char, infact i obtain a char like this a question mark in a square. Even if a try to write this into a text file, i can see correctly all the other char, but instead of this char i see a question mark.
    Someone know why i obtain this?i have to set some specific character encoding or something like this?
    I don't know if this is usefull, but these are Hebrew char.
    Thanks,bye.

    A character value of 65533 in not in the Unicode range for Hebrew and Java characters are Unicode encoded as UTF16. See http://www.unicode.org/charts/ .
    65533 is not a byte value since bytes have a range -128 to +127 .
    0x81 is not the same as 65533 decimal.
    How are you converting the bytes of the file to characters?
    Edited by: sabre150 on Oct 9, 2008 8:51 AM

  • Sql query slowness due to rank and columns with null values:

        
    Sql query slowness due to rank and columns with null values:
    I have the following table in database with around 10 millions records:
    Declaration:
    create table PropertyOwners (
    [Key] int not null primary key,
    PropertyKey int not null,    
    BoughtDate DateTime,    
    OwnerKey int null,    
    GroupKey int null   
    go
    [Key] is primary key and combination of PropertyKey, BoughtDate, OwnerKey and GroupKey is unique.
    With the following index:
    CREATE NONCLUSTERED INDEX [IX_PropertyOwners] ON [dbo].[PropertyOwners]    
    [PropertyKey] ASC,   
    [BoughtDate] DESC,   
    [OwnerKey] DESC,   
    [GroupKey] DESC   
    go
    Description of the case:
    For single BoughtDate one property can belong to multiple owners or single group, for single record there can either be OwnerKey or GroupKey but not both so one of them will be null for each record. I am trying to retrieve the data from the table using
    following query for the OwnerKey. If there are same property rows for owners and group at the same time than the rows having OwnerKey with be preferred, that is why I am using "OwnerKey desc" in Rank function.
    declare @ownerKey int = 40000   
    select PropertyKey, BoughtDate, OwnerKey, GroupKey   
    from (    
    select PropertyKey, BoughtDate, OwnerKey, GroupKey,       
    RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]   
    from PropertyOwners   
    ) as result   
    where result.[Rank]=1 and result.[OwnerKey]=@ownerKey
    It is taking 2-3 seconds to get the records which is too slow, similar time it is taking as I try to get the records using the GroupKey. But when I tried to get the records for the PropertyKey with the same query, it is executing in 10 milliseconds.
    May be the slowness is due to as OwnerKey/GroupKey in the table  can be null and sql server in unable to index it. I have also tried to use the Indexed view to pre ranked them but I can't use it in my query as Rank function is not supported in indexed
    view.
    Please note this table is updated once a day and using Sql Server 2008 R2. Any help will be greatly appreciated.

    create table #result (PropertyKey int not null, BoughtDate datetime, OwnerKey int null, GroupKey int null, [Rank] int not null)Create index idx ON #result(OwnerKey ,rnk)
    insert into #result(PropertyKey, BoughtDate, OwnerKey, GroupKey, [Rank])
    select PropertyKey, BoughtDate, OwnerKey, GroupKey,
    RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
    from PropertyOwners
    go
    declare @ownerKey int = 1
    select PropertyKey, BoughtDate, OwnerKey, GroupKey
    from #result as result
    where result.[Rank]=1
    and result.[OwnerKey]=@ownerKey
    go
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to Add column with default value in compress table.

    Hi ,
    while trying to add column to compressed table with default value i am getting error.
    Even i tried no compress command on table still its giivg error that add/drop not allowed on compressed table.
    Can anyone help me in this .
    Thanks.

    Aman wrote:
    while trying to add column to compressed table with default value i am getting error.This is clearly explain in the Oracle doc :
    "+You cannot add a column with a default value to a compressed table or to a partitioned table containing any compressed partition, unless you first disable compression for the table or partition+"
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_3001.htm#sthref5163
    Nicolas.

  • Update column with ROW_NUMBER() value

    I have a column that I would like to update with a ROW_NUMBER() value partitioned by a specific column.
    CREATE TABLE ##tmp (id INT NULL,
    value1 VARCHAR(10),
    value2 VARCHAR(10))
    INSERT INTO ##tmp (value1,
    value2)
    VALUES ('A', 'asdfasdf'),
    ('A', 'asdf'),
    ('A', 'VC'),
    ('B', 'aasdf'),
    ('C', 'sdfgs'),
    ('C', 'xdfbhsdty'),
    ('C', '23sdgfg'),
    ('C', '234')
    -- update the ID column with the values below
    SELECT ROW_NUMBER() OVER (PARTITION BY Value1 ORDER BY Value2),
    Value1,
    Value2
    FROM ##tmp
    I have 14 million records.  Can someone explain the best way to do this?  Does the ORDER BY destroy performance for this many records?
    Thanks!

    CREATE TABLE ##tmp (id INT NULL,
    value1 VARCHAR(10),
    value2 VARCHAR(10))
    INSERT INTO ##tmp (value1,
    value2)
    VALUES ('A', 'asdfasdf'),
    ('A', 'asdf'),
    ('A', 'VC'),
    ('B', 'aasdf'),
    ('C', 'sdfgs'),
    ('C', 'xdfbhsdty'),
    ('C', '23sdgfg'),
    ('C', '234')
    -- update the ID column with the values below
    ; with cte as (
    SELECT ROW_NUMBER() OVER (PARTITION BY Value1 ORDER BY Value2) as RowNumber,
    Value1,
    Value2
    FROM ##tmp
    update cte
    set Id = RowNumber;
    Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

  • OBIEE 10g - Logical column with static value

    I created a logical column with static numeric value in it and added it to presentation layer. The column is not showing up in Answers. All other columns I added are showing up. The issue is with this one only.
    I have verified permissions on this column in presentation layer. I tried reloading server metadata in answers, restarting all services but it didn't help.
    One thing I noticed this column is showing fx icon instead of Σ icon.

    Kid,
    The fx means it is a calculated column/formula and the sigma means that you've added some aggregation type to the column.
    Either way it shouldn't matter and your column should be showing up.
    I would attempt to create a new column and in the fx field try entering static text and see if that allows the column to be visible after dragging it to the presentation layer subject area.
    Also what is the value that you are adding?

  • How to update person or group column with peopleeditor control values

    Hi,
    I have created custom aspx page and added "PeopleEditor" control(can select multiple users)  in that page. Now I am trying to update person or group column with peopleeditor control values.I am not getting any error if I select single user
    in PeopleEditor control but getting error if I select more than one user.
    UpdateItem(listItem, "ListColumnName",
    listItem.ParentList.ParentWeb.EnsureUser(peopleeditorId.CommaSeparatedAccounts));
    Can anybody help me out to resolve the issue?
    Thank you in advance!!!
    AA.

    First get all the users/groups from the PeapleEditor by using PeapleEditor.ResolvedEntities
    foreach (PickerEntity pickerEntity in peopleEditor.ResolvedEntities)
    SPPrincipalType principalType = (SPPrincipalType)Enum.Parse(typeof(SPPrincipalType), pickerEntity.EntityData["PrincipalType"].ToString());
    if (principalType == SPPrincipalType.User || principalType == SPPrincipalType.SecurityGroup)
    string loginName = pickerEntity.Key;
    //your code here
    else if (principalType == SPPrincipalType.SharePointGroup)
    string groupName = pickerEntity.Key;
    //your code here
    Add all the users/groups in an instance of SPFieldUserValueCollection
    and then update your list item.
    SPFieldUserValueCollection users = new SPFieldUserValueCollection();
    users.Add(new SPFieldUserValue(web,user.ID,user.Name));
    item["YourUserColumn"] = users;
    item.Update();

  • Hyperlink column with link parameters as region column values

    On my APEX page i have region which has sql query as source and it displays as HTML table the query result to the user.
    I want to display addinonal column with a hyperlink inside, and that hyperlink would have CGI/URL-parameters which contains the other values of the HTML row.
    So, let's say my APEX region queryes columns as "select c1, c2, c3, c4 ..." and displays out values "V1, V2, V3, V4" then i want to have addional output column with such hyperlink:
        a href="f?p=100:7:13467554876288::NO::c1,c2,c3,c4:v1,v2,v3,v4">My link column with CGI-parameters</aHow can i create such hyperlink?
    The overall idea is that the link would forward to a page which loads those values "v1,v2,v3,v4" into form fields and user can proceed from there.
    "Application Express 4.2.1.00.08"
    Edited by: CharlesRoos on 10.04.2013 14:55
    Edited by: CharlesRoos on 10.04.2013 14:55
    Edited by: CharlesRoos on 10.04.2013 14:55

    CharlesRoos wrote:
    On my APEX page i have region which has sql query as source and it displays as HTML table the query result to the user.Is this a standard report region or interactive report region? Or something else? Using standard APEX terms makes it easier to understand your problem.
    I want to display addinonal column with a hyperlink inside, and that hyperlink would have CGI/URL-parameters which contains the other values of the HTML row.
    So, let's say my APEX region queryes columns as "select c1, c2, c3, c4 ..." and displays out values "V1, V2, V3, V4" then i want to have addional output column with such hyperlink:
    a href="f?p=100:7:13467554876288::NO::c1,c2,c3,c4:v1,v2,v3,v4">My link column with CGI-parameters</aHow can i create such hyperlink?This is typically done by creating a column link. This is a very basic APEX technique, covered in the <i>2 Day + Application Express Developer's Guide</i> tutorial.
    <li>Creating a Column Link in an Interactive Report
    <li>Creating a Column Link in a Classic Report

  • Show row/column with empty dimension values.

    I have 2 columns where 1 column is dimension and 1 column is measure.  I need to hide the row when the dimension is empty.
    What I did is at the block I UN-TICK  "Show row/column with empty dimension values".  But it didnt works.
    Thanks.

    click on the block and add a filter with condition dimension isnotnull. this will eliminate the dimension rows with empty values.
    Thanks,
    karthik

Maybe you are looking for

  • Lumia 925 cc3065 not available in saudi arabia

    i recently got the lumia 925 and its ana amzing phone. However i have not been able to find any covers or cases for it in ksa. Even the official cc3065 is not available. Will it be available soon or are there any alternatives?

  • How to connect to Internet through a LAN

    Hi everybody !!! Please show me how to connect to Internet through a LAN (through another computer). On Windows XP system, i use the following informations to do that: + My IP: 192.168 .1.45 +subnet mask: 255.255.255.0 +default getway: 192.168.1.12 (

  • Access Kuler themes in ID cc

    Im probably missing it somewhere.  I am trying to pull up a Kuler theme that I took with my iphone.  It shows up in illustrator.  Now I need colors in ID.  I open Kuler panel and can search for themes.  But its not coming up.  I dont see an option to

  • Alter database open

    Hi, I try to start a database with the commands startup mount alter database noarchivelog everything is ok up to now When I give the command alter database open I obtain ERROR at line 1 ORA-01092 Oracle instance terminated Disconnection forced. Why?

  • JRE vs. JVM et al

    what is the diff. b/w JRE and JVM. Can we have more than two access specifiers for a class ? I would like to thank in advance for the appropriate reply.