Eliminating duplicates from a string

Hello

I would delete the duplicates of the coma-separated string using the pl/sql functions.
How can I achieve this?

Thank you

You don't need a plsql

with t as (select 'SCOTT,ALLEN,KING,SCOTT' as in_cls from dual)
, t1 as ( select distinct regexp_substr(in_cls, '[^,]+', 1, rownum) names
                  from t
                  connect by rownum <= length(regexp_replace(in_cls, '[^,]'))+1)
SELECT
    RTrim(xmlagg(xmlelement(a,names||',').extract('//text()')),',') string
from t1
/

STRING
------------------------------------------------
ALLEN,SCOTT,KING

1 row selected.

SS

Tags: Database

Similar Questions

  • inner join is not eliminating duplicates!

    Name of the table is customers

    VALUE CITY SIDE NUMS CNAME
    1 2001 Hoffman 100 1001 London
    2 Rome 2002 200 1003 Giovanni
    3 2003 Liu San Jose 200 1002
    4 2004 grass Berlin 300 1002
    5 2006 Clemens 100 1001 London
    6 2008 Cisneros San Jose 300 1007
    7 2007 perish Rome 100 1004

    Query is
    To find all pairs of customers having the same side

    I tried:

    SELECT c.cname, cb.cname FROM customers c INNER JOIN customers cb WE cb.rating AND c.cname = c.rating! = cb.cname

    CNAME CNAME
    1 perish Hoffman
    2 Clemens Hoffman
    3 Liu Giovanni
    4 Giovanni Liu
    5 Cisneros grass
    6 perira Clemens
    7 Hoffman Clemens
    8 grass Cisneros
    Clemens 9 perish
    10 Hoffman perish


    Ideally, it should up to 5 rows, but it does not return these lines for an e.g. Hoffman perish since I'm Perira Hoffman already. Your answers will be appreciated.

    Thank you
    Vaibhav

    Hi, Vaibhav,

    914683 wrote:
    Name of the table is customers

    VALUE CITY SIDE NUMS CNAME
    1 2001 Hoffman 100 1001 London
    2 Rome 2002 200 1003 Giovanni
    3 2003 Liu San Jose 200 1002
    4 2004 grass Berlin 300 1002
    5 2006 Clemens 100 1001 London
    6 2008 Cisneros San Jose 300 1007
    7 2007 perish Rome 100 1004

    Query is
    To find all pairs of customers having the same side

    I tried:

    SELECT c.cname, cb.cname FROM customers c INNER JOIN customers cb WE cb.rating AND c.cname = c.rating! = cb.cname

    Perhaps what you want is

    SELECT      c.cname
    ,         cb.cname
    FROM          customers  c
    INNER JOIN  customers  cb  ON   c.rating  = cb.rating
                                       AND  c.cname       < cb.cname     -- not !=
    ;
    

    CNAME CNAME
    1 perish Hoffman
    2 Clemens Hoffman
    3 Liu Giovanni
    4 Giovanni Liu
    5 Cisneros grass
    6 perira Clemens
    7 Hoffman Clemens
    8 grass Cisneros
    Clemens 9 perish
    10 Hoffman perish

    The title you chose for this thread is "inner join is not eliminating duplicates!
    Inner joins (or other types of joints) are not supposed to remove duplicates. Use SELECT DISTINCT to remove duplicates, which is exactly the same lines.
    You don't have to duplicate. For example, these lines of your result set:

    `        CNAME     CNAME
    1     Perira     Hoffman
    10     Hoffman     Perira
    

    are not identical; Indeed, the two columns are different.

    Ideally, it should up to 5 rows, but it does not return these lines for an e.g. Hoffman perish since I'm Perira Hoffman already.

    Please report the exact output of the sample data you want. (As said by Hoek, post CREATE TABLE and INSERT statements for the sample data too.)

  • Extract numbers from a string

    Hello
    i'numbers in the neck of string arrecnote

    Please help me in this...

    Published by: smile on October 7, 2010 05:33

    Published by: smile on October 7, 2010 06:14

    Try this to extract the numbers from a string:

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 'hello-cycle monthly settlement;  865.15 SDR
      2  
    multilat net 218.15 (USD) USAWW-USACC-2007/10' col1 from dual) 3 SELECT * FROM 4 (SELECT REGEXP_SUBSTR(col1,'[0-9]+.[0-9]+',1,lvl) col1 FROM 5 (select col1,level lvl 6 from t 7 connect by level <= LENGTH(col1) - LENGTH(REPLACE(col1,' ')) + 1)) 8* WHERE col1 IS NOT NULL SQL> / COL1 -------------------------------------------------------------------------------- 865.15 218.15 2007/10 SQL> -- or if you just want the numbers with its decimal SQL> ed Wrote file afiedt.buf 1 with t as (select 'hello-cycle monthly settlement; 865.15 SDR 2
    multilat net 218.15 124 (USD) USAWW-USACC-2007/10' col1 from dual) 3 SELECT * FROM 4 (SELECT REGEXP_SUBSTR(col1,'[0-9]+[.][0-9]+',1,lvl) col1 FROM 5 (select col1,level lvl 6 from t 7 connect by level <= LENGTH(col1) - LENGTH(REPLACE(col1,' ')) + 1)) 8* WHERE col1 IS NOT NULL SQL> / COL1 -------------------------------------------------------------------------------- 865.15 218.15 SQL>

    Published by: AP on October 7, 2010 05:43

  • How know no.. given occurrences of a sting from a string

    Hi all

    How will I know the No. given occurrences of a sting from a string.

    Your help would be appreciated.

    Thank you
    Srinivas

    calculation of no.. of occurrence of a string
    -------------------------------------------------------
    declare
    str1 varchar2 (100): = 'string. '
    str2 varchar2 (1000): = ' this is the string where the string are placed. This pl/sql is used to find the accurance of a string in another string ";
    Start
    dbms_output.put_line (length (str2) - length (replace (str2, str1, substr (str1, 1, length (str1)-1)));)
    end;
    /

  • How to remove duplicates from comma separated string


    Hi all

    I have an obligation to remove duplicates of string separated by commas:

    Some examples of code (real data can be in millions)

    {code}

    create table test_dup_del (num number (10), dup_val varchar2 (100));

    insert into test_dup_del values (1234, '1, 2, 3, 4, 3, 1');
    insert into test_dup_del values (4567,'1, 2, 2, 4, 4, 1');
    insert into test_dup_del values (7894,'1, 2, 1, 3, 3, 1');
    insert into test_dup_del values (1478, '1, 2, 4, 4, 3, 2');
    insert into test_dup_del values (2589, '1, 2, 1, 2, 1, 2');
    commit;

    (code}

    my output would be:

    1234, 1, 2, 3, 4'

    4567, '1, 2, 4'

    7894, '1, 2, 3'

    1478, 1, 2, 3, 4'

    2589, 1, 2'

    Thank you

    Rachid

    If there is a real need to split the data so that it could be corrected (before split to store correctly... Tip tip!) ...

    SQL > ed
    A written file afiedt.buf

    1 with test_dup_del (num, dup_val) as)
    2 Select 1234, 1, 2, 3, 4, 3, 1' Union double all the
    3 select 4567, 1, 2, 2, 4, 4, 1' Union double all the
    4 Select 7894, 1, 2, 1, 3, 3, 1' Union double all the
    5 Select 1478, 1, 2, 4, 4, 3, 2' of all the double union
    6 select 2589, 1, 2, 1, 2, 1, 2' of the double
    7      )
    8  --
    9. end of test data
    10-
    11, split as)
    12. Select num
    13, trim (regexp_substr(dup_val,'[^,]+',1,level)) as val
    14 from test_dup_del
    15 connect by num = num prior
    16 and level<=>
    17 and prior sys_guid() is not null
    18                )
    19, dist in (select distinct)
    20                      num
    21                      ,val
    22 split
    23              )
    24 select num
    25, listagg (val, ',') within the Group (order by val) as vals
    dist 26
    27 * group by num
    SQL > /.
    NUM OF VALS
    ---------- ------------------------------
    1234 1,2,3,4
    1478 1,2,3,4
    2589 1.2
    4567 1,2,4
    7894 1,2,3

    5 selected lines.

  • the database error duplicate from one server to another server

    Hello

    I'm practicing duplicate database to a single database server to another server. Path material and pilot on 2 machines is the same. Here are my steps:
    -Clone site:
    1 change the listener.ora with content:
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = CIP)(KEY = EXTPROC1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain) (PORT = 1521))
    )
    )

    ADR_BASE_LISTENER = / u01/app/oracle
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (GLOBAL_DBNAME = orcl)
    (ORACLE_HOME = u01/app/oracle/product/11.2.0/db_1)
    (SID_NAME = orcl)
    )
    )
    ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER = WE
    2. stop and start receiving once again, show message as:
    Service "orcl" has 1 instance (s).
    Instance "orcl", status UNKNOWN, has 1 operation for this service...

    The command completed successfully
    3. create pfile from spfile file.
    4. stop and startup nomount with pfile is new pfile create in step 3.
    --------------------------------------- Source site
    1 edit tnsnames.ora with content like:
    VVCOREDB =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain) (PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = vvcoredb)
    )
    )

    ORCL =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP) (HOST = 10.254.1.235) (PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = orcl)
    )
    )
    2 run the command of rman like these:
    RMAN > Connect target sys@vvcoredb
    RMAN > target password database:
    RMAN > Connect auxiliary sys@orcl
    RMAN > database auxiliary password:
    RMAN > DUPLICATE TARGET DATABASE for database orcl active spfile nofilenamecheck.

    Then the result show below:
    From Db double to 24-SEP-12
    using the control file of the target instead of recovery catalog database
    allocated channel: ORA_AUX_DISK_1
    channel ORA_AUX_DISK_1: SID = 63 type device = DISK

    content of Script memory:
    {
    backup that copy reuse
    TargetFile ' / u01/app/oracle/product/11.2.0/db_1/dbs/spfilevvcoredb.ora' auxiliary format
    ' / u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora';
    clone of SQL 'alter system set spfile = "/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora";
    }
    execution of Script memory

    Backup to starting 24-SEP-12
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID = 74 type device = DISK
    Backup finished 24-SEP-12

    SQL statement: alter system set spfile = "/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora"

    content of Script memory:
    {
    clone of SQL 'alter system set = db_name
    "ORCL" comment =
    "reproduce" scope = spfile;
    clone to stop immediately;
    startup nomount clone;
    }
    execution of Script memory

    SQL statement: alter system db_name set = comment "ORCL" = "duplicate" scope = spfile

    Instance Oracle to close

    connected to the auxiliary database (not started)
    RMAN-00571: ===========================================================
    RMAN-00569: = ERROR MESSAGE STACK FOLLOWS =.
    RMAN-00571: ===========================================================
    RMAN-03002: failure of Db in dual at 24/09/2012 17:44:12
    RMAN-03015: an error has occurred in the script stored memory Script
    RMAN-04014: failed to start: ORA-01261: parameter db_recovery_file_dest destination string cannot be translated
    ORA-01262: Stat failed on a destination of the file directory
    Linux-x86_64 error: 2: no such file or directory

    I don't know what wrong with my pfile file? I said to correct my pfile site clone like this:
    ORCL.__db_cache_size = 1476395008
    ORCL.__java_pool_size = 16777216
    ORCL.__large_pool_size = 16777216
    ORCL.__oracle_base='/U01/app/oracle'#ORACLE_BASE the value of the environment
    ORCL.__pga_aggregate_target = 1342177280
    ORCL.__sga_target = 1979711488
    ORCL.__shared_io_pool_size = 0
    ORCL.__shared_pool_size = 436207616
    ORCL.__streams_pool_size = 0
    *.audit_file_dest='/U01/app/Oracle/admin/ORCL/adump '
    * .audit_trail = "db".
    * full = '11.2.0.0.0'
    *.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/flash_recovery_area/orcl/control02.ctl'
    * .db_block_size = 8192
    * .db_domain = "
    * .db_name = "orcl".
    *.db_recovery_file_dest='/U01/app/Oracle/flash_recovery_area/vvcoredb '
    * .db_recovery_file_dest_size = 4070572032
    *.diagnostic_dest='/U01/app/Oracle '
    *. Dispatchers ='(Protocol=TCP) (SERVICE = orclXDB)"
    * .memory_target = 3313500160
    * .open_cursors = 300
    * runoff = 150
    * .remote_login_passwordfile = "EXCLUSIVE."
    * .undo_tablespace = "UNDOTBS1.

    Please suggest me I miss some steps when trying to duplicate database?

    Any suggestions are welcome.

    Thanks in advance!

    P/s: sorry for my bad English.

    This error is because the location of the controlfile specified in your spfile is not present on your server to clone. Change the location of the parameter cntrolfile in spfil or create the same location on the server.

    Published by: Slim on 24 Sep 2012 17:47

  • Structure from case string "&lt;------"-LabVIEW converts the string

    Hello

    I want to parse the string lines read from a data file.  Some chains start with the characters ".<\".  when="" i="" enter="" this="" kind="" of="" string="" as="" a="" case="" in="" a="" case="" structure="" the="" string="" is="" being="">

    For example, I'm going home. "<\C" (upper-case="" c)="" as="" my="" case="" string,="" it="" changes="" to=""><\f".  if="" i="" enter=""><\c" (lower-case="" c)="" as="" the="" string="" it="" becomes="">

    I am currently using LabVIEW 2012.

    Any ideas what's happening?

    Thank you

    Ian

    Some ASCII characters are nonprinting control characters (less than 32 values). These are sometimes encoded using the backslash code and it seems that is what makes the structure of matter - when you type \C, the structure of the performer as "oh, you want the value 0x0C ASCII, which in the code for backslash is represented" as \f (means 'form feed). "When this is the case, you typically use one-to represent the------characters, so you really need set the structure to match on.<>

  • How can I get rid of duplicates from folder?

    I have a HP Win 7 system that I bought in November 2009. I moved all the backed up files, I created a Vista system and saved on an external hard drive and put them in the appropriate in Win 7 folders. Along the way, about a month or two ago, the 'My music' folder decided to duplicate himself in the folder "my pictures." Anything to be added or removed from rehearsals in the other folder as well. I want to delete the one in "My pictures", such that it caused all kinds of freeze ups when you do something in there, caused by the activation of Windows Media Player to go online and search for updates file. This makes any process to become unusable as all the system waits for WMP let go of his prey. It must be the folder the file images who created this music. If I download a clean folder, empty, newly created, the problem does occur.

    Also, when I try to delete one or the other, or move them, it gives a message stating: "the action cannot be performed because the file or the file is open in another program. Close the folder or file and try again. »

    Sometimes even if the Task Manager shows only one of them open at the time of the attempt to remove.

    Hello

    Recent changes on your computer?

    Try the process for my music and my pictures folders (Windows 7 it's just music and images) below.

    1. right click on the folder and select Properties.
    2. click the default button.
    3. click on the OK button.

    Also to run a scan for virus/malware online on the computer.
    http://OneCare.live.com/site/en-us/default.htm
    http://www.Microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ad724ae0-e72d-4f54-9ab3-75b8eb148356
     
    Let us know if it works.

    Thanks and greetings
    Umesh P - Microsoft technical support.

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Remove duplicates from the oracle table using 2 columns

    Hello

    I need to remove the duplicates of an oracle table based on 2 columns in the table.i tried to remove duplicates using the join, but get the error like sql error ora-00933

    Thank you

    Hello

    Here's one way:

    DELETE FROM table_x

    WHERE ROWID NOT IN)

    SELECT MIN (ROWID)

    FROM table_x

    Col_1, col_2

    );

    I hope that answers your question.

    If this isn't the case, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.

    In the case of a DML operation (for example, REMOVE) the sample data should show what look like the paintings before the DML, and results will be the content of the or the tables changed after the DML.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

  • Removing spaces from a string

    I have a string where there is a particular sequence, I want to replace.

    The sequence is ' / p e r.

    I tried replaceAll ("-p e r," ""); Tried to replace the charsequence, but doesn't have too much work.

    I am able to replace / by replaceAll("\\\","")

    Somehow if I put string a = "/ p e r ' and

    a.Replace ("" p e r ", pr) then came out / pr.

    But I read this to a BLOB field and there spaces between the two string operations fail somehow.

    Can someone help me on this please. I'm stuck for some time

    Please also let me know if this isn't the right group, because I don't have an answer during my last post here

    See Delete white spaces from strings in Java - Stack Overflow

  • remove duplicates from CC library?

    I've been creating a CC library for all of my active work by adding all styles of every time I finished a new document. I certainly have not been very careful and have now a bunch of duplicate styles. I waited an easy solution, but am not finding a way to easily remove duplicate styles. Am I missing something?

    You can select from the library and just select the icon to delete or right-click select Remove

  • How to remove special characters from the string using translate() without typing all special characters?

    Hi all

    I am trying to remove special characters without the help of regular expressions.

    translate (the column name or string,'!@#$ & * (* () _) * "" :} {?}) >? /, «, » ')

    I want to eliminate this manual process to give all special characters using a chr() or ascii() function.

    Please show me the way.

    Thanks in advance

    Similar to the solution of Michael...

    SQL > ed
    A written file afiedt.buf

    1 with t as (select "[it comes of the #] [more amazing!") Test @# "$* & $%) assuming chain cost $ 5 000' double Str)
    2, i like (select level 1 c from dual connect by level<=>
    3 less
    4 Select + 32 (level-1) double connect by level<=>
    5 less
    6 select + 58 (level-1) double connect by level<=>
    7 less
    8 select + 91 (level-1) double connect by level<=>
    9 less
    10. Select 123 + (level-1) from dual connect by level<=>
    11 less
    12. Select 255 double
    13            )
    14, ts as (select level r, substr (str, level 1) c
    15 t
    16 connect by level<=>
    17             )
    18, tf as (select row_number() (order for r) r
    19                    ,ts.c
    20 TS
    21 I join on (i.c = ascii (ts.c))
    22             )
    23 select replace (sys_connect_by_path(c,'!'),'! ') Str
    24 TF
    25 where connect_by_isleaf = 1
    26 connect r = prior r + 1
    27 * start with r = 1
    SQL > /.

    STR
    -----------------------------------------------------------------------------------------------------------------------
    Thisisthemostamazingtest¸astringcosting5000

    Or something as horrible as this...

    SQL > ed
    A written file afiedt.buf

    1 with t as (select "[it comes of the #] [more amazing!") Test @# "$* & $%) assuming chain cost $ 5 000' double Str)
    2, I like (select replace (sys_connect_by_path (chr (c), 'A'), 'A') as tr)
    3 of)
    4 select c, rownum r
    5 (select 32 + (level-1) as the double connection by level c<=>
    6                         union
    7 select + 58 (level-1) double connect by level<=>
    8                         union
    9 select + 91 (level-1) double connect by level<=>
    10 the union
    11. Select 123 + (level-1) from dual connect by level<=>
    12 union
    13. Select 255 double
    14 tri 1
    15                        )
    16                  )
    17 where connect_by_isleaf = 1
    18 log r = prior r + 1
    19 start with r = 1
    20            )
    21 select translate (str, 'A' |) TR, 'A') as str
    22 * t, I
    SQL > /.

    STR
    --------------------------------------------------------------------
    Thisisthemostamazingtest¸astringcosting5000

  • Extract the string from the string

    Hello guys,.

    I have a small question. I would like to extract a string to another string. Imagine the following string:

    param1 = value1 param2 = value2, param3 = value3, param4 = value4

    I would like to be able to extract value2 and value3 to this string. I know that the design of the db is not perfect and should be like this. but it is historical and I have to use this way. Any suggestion?

    Thank you

    to retrieve param2

    Select

    substr (s

    , instr (s, '=', 1, 2) + 1

    , instr (s, ',', 1, 2) - instr (s, '=', 1, 2) - 1

    ) r

    from (select "param1 = value1 param2 = value2, param3 = value3, param4 = value4's double)

    or

    Select regexp_substr (your_string, "[^,] +' 1, 4") from your_table

    for example

    Select regexp_substr ("param1 = value1 param2 = value2, param3 = value3, param4 = value4 ',' [^,] +' 1, 4") param2 double

    PARAM2

    'value2 '.

    Post edited by: chris227
    Corrected solution substr (sorry was before the first coffee ;-))

  • REGEXP_REPLACE return strange results and eliminating duplicate characters

    I try using REGEXP_REPLACE to remove all the characters that is not a letter or a number, but I get strange results. It seems to eliminate duplicate characters. The result varies also with the order of the boss. How can I solve this?

    SELECT REGEXP_REPLACE(p_str,'[^[:digit:]][^[:alpha:]]','.') FROM (SELECT 'AAA bb' double p_str);

    > AA.bb

    SELECT REGEXP_REPLACE(p_str,'[^[:alpha:]][^[:digit:]]','.') FROM (SELECT 'AAA bb' double p_str);

    > AAA.b

    Oracle Database 11 g Release 11.2.0.3.0 - 64 bit Production

    to remove all characters which is not a letter or a number

    You can try (it's more flexible for alphabets and numbers)

    [^ [: alnum:]]

    See you soon,.

    Manik.

  • eliminating duplicates except one

    DB and dev rel2 10g,

    Hi all

    suppose I have a table with a lot of duplicate rows,

    what I need is to remove duplicates and keep a row of these duplicates.

    as

    column - with these values...

    Hello

    Hello

    Hello

    How to remove two (of salvation) and retain the third?

    All of it is applied to all the duplicate values in the column

    Thanks in advance

    Hello

    Here's one way:

    REMOVE table_x

    WHERE ROWID NOT IN)

    SELECT MIN (ROWID)

    FROM table_x

    GROUP BY col_1

    )

    ;

    When it ends, exactly 1 row of each col_1 value to.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    If you ask a DML statement, such as DELETE, the sample data will be the content of the or the tables before the DML, and the results will be the State of the or a modified tables when it's all over.
    Explain, using specific examples, how you get these results from these data.
    See the FAQ forum: https://forums.oracle.com/message/9362002

Maybe you are looking for