How to search for a particular text values separated by commas

Hello

I have a table for example. TB_Fruits.
In that I have a FruitsName (Varchar) column
In this column I store the string of values separated by commas.
Select FruitsName in the tb_fruits;
Result: orange, banana, Apple

Now the question is suppose that if I try inserting one of these fruits once again name, then it must not allow me to insert.

Suppose that now if I try to insert ('grapes, banana')
or
(Apple, grape")

the orange, banana, Apple may be in any position.

How to check if one of these names exist already or not in the fruitsname column?
I can't use INstr function here as or. because the position is not fixed chain even not.

Appreciate any help.

Hmm, OK, the BASIC_LEXER in the documentation is specified is useful to "spaces separate languages". So not really a good suggestion from my side ;-)

Okay, so a few different choices, you can play with:

SQL> create table tb_fruits (
  2     fruitsname  varchar2(60)
  3  )
  4  /

Table created.

SQL> begin
  2     insert into tb_fruits values ('BANANA,APPLE');
  3     insert into tb_fruits values ('YELLOW BANANA,ORANGE');
  4     insert into tb_fruits values ('GREEN APPLE,YELLOW ORANGE');
  5     insert into tb_fruits values ('APPLE,GREEN BANANA');
  6     commit;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Option 1:

Make a outdated AS operator. It just won't be fast because it's more likely will be full table scan (or scan restricted index full).

SQL> select fruitsname
  2    from tb_fruits
  3   where ','||fruitsname||',' like '%,'||'APPLE'||',%'
  4  /

FRUITSNAME
------------------------------------------------------------
BANANA,APPLE
APPLE,GREEN BANANA

SQL> select fruitsname
  2    from tb_fruits
  3   where ','||fruitsname||',' like '%,'||'BANANA'||',%'
  4  /

FRUITSNAME
------------------------------------------------------------
BANANA,APPLE

SQL> select fruitsname
  2    from tb_fruits
  3   where ','||fruitsname||',' like '%,'||'YELLOW BANANA'||',%'
  4  /

FRUITSNAME
------------------------------------------------------------
YELLOW BANANA,ORANGE

Option 2:

Transform your data and replace the spaces with underscores. Which may or may not be a possibility for you. If your other data contains no underscores, you might fool your user interface using a view that replaces underscores with spaces when you select and a trigger before insert that replaces spaces with underscores to insert or update. Then, you can use the TEXT index.

SQL> create table tb_fruits2 as
  2  select replace(fruitsname,' ','_') fruitsname
  3    from tb_fruits
  4  /

Table created.

SQL> begin
  2     ctx_ddl.create_preference('mylex', 'BASIC_LEXER');
  3     ctx_ddl.set_attribute('mylex', 'printjoins', '_-');
  4  end;
  5  /

PL/SQL procedure successfully completed.

SQL> create index fruitsname_idx on tb_fruits2 (fruitsname)
  2  indextype is ctxsys.ctxcat
  3  parameters (
  4  'stoplist ctxsys.empty_stoplist
  5  LEXER mylex'
  6  )
  7  /

Index created.

SQL> select fruitsname
  2    from tb_fruits2
  3   where catsearch(fruitsname,replace('YELLOW BANANA',' ','_'),null) > 0
  4  /

FRUITSNAME
------------------------------------------------------------
YELLOW_BANANA,ORANGE

(I used CTXCAT rather then CONTEXT indexes to keep simple search syntax, avoid SYNCHRONIZATION problems and others. You can use CONTEXT or CTXCAT as desired.)

Option 3:

Transform your data in XML format instead of values separated by commas. Then create a XMLIndex.

SQL> create table tb_fruits3 as
  2  select xmltype(''||replace(fruitsname,',','')||'') fruitsname
  3    from tb_fruits
  4  /

Table created.

SQL> create index fruitsname_xmlidx on tb_fruits3 (fruitsname)
  2  indextype is xdb.xmlindex
  3  /

Index created.

SQL> select fruitsname
  2    from tb_fruits3
  3   where xmlexists('$f/l[w="YELLOW BANANA"]' passing fruitsname as "f")
  4  /

FRUITSNAME
--------------------------------------------------------------------------------
YELLOW BANANAORANGE

(I used just 'l' for 'list of the words' and 'w' for 'word').

Option 4:

Create your own [url http://docs.oracle.com/cd/E11882_01/text.112/e24436/cdatadic.htm#i1008347] USER_LEXER instead of a variant of BASIC_LEXER. This would require allows you to create your own stored procedures for the index to be used, in which case you have complete control over what you set in the form of a token.

That's the different options I can think of right now ;-)

Tags: Database

Similar Questions

  • How to search for a particular word by selecting multiple text files

    Hello

    I have hundreads of text files and I need to search a particular word in these bunch of txt files.

    How do so by selecting all files and search for the word. I do not want to open each file and search for the word.

    I use Windows 7 here.

    Please suggest.

    Thank you...

    Anand

    I don't think that we are able to select the files to search, but what you can do, is have all files in a folder that is searched for.  Open a window for the folder that contains the files and use the Windows search box in the upper right of this window.  If you are looking for 'bread', enter:

    content: bread

    At the same time, if you want to restrict the search to the txt files, then enter

    content: bread ext:txt

    For more details you can read my reply to

    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-files/how-do-i-search-all-of-my-documents-for-a-specific/7ba6c244-07fd-4F52-988d-e2e303b4bec9

  • How to search for and remove text in the Arial Narrow font?

    Hello

    I wonder if someone can help me with a problem.

    I have a great CS5 ID doc (Win 7) that has thousands of lines in the following format:

    Example: reach, reach to yari togemasu (togeru)

    In each line the first, or the words is in English all formatted in Arial Black. then, there is a space followed by words in a foreign language (in the Japanese case). These words are all in Arial condensed format.

    I would like to be able to delete all the words automatically formatted in Arial condensed (Japanese words).

    There should be a way to do that in FIND/REPLACE, but I don't see an option to find words in a specific font and then delete them.

    Can anyone suggest how this can be done automatically, so I can't do the manual removal?

    Thanks in advance for any help that anyone may be able to offer.

    Jane.

    What version of InDesign are you using?

    If you go to find the change

    Then let empty 'Search' and ' change to ' white

    Go to the 'FindForma' t and insert the font that you want to change

    Do not fill in 'Change of Format'

  • How to search for text in all of the PDF files on a mobile device?

    How to search for text in all of the PDF files on a mobile device?

    Not possible on mobile devices.

  • Please, give me an advise how to search for a number in a file xml (as3.0)

    Hello! Sorry for the troubling.

    Please, give me an advice how to search for a number in a file xml (as3.0)

    Thank you!

    My answer was based on your question to find numbers anywhere in the data to an xml file.  If you know that the data is digital data and the names of the nodes that contains this data, you do not have to check the characters and can only check numerical data using string values...

    function searchXMLFile(Event:MouseEvent):void
    {
    searchDisplay.text = "";
    var pageList:XMLList = xmlFileToSearch.receipt.number;
    searchDisplay.text = "false";
       
    for (var i: int = 0; i< pagelist.length();="">
    {

    If (pageList [i] == searchInput.text) {}
    searchDisplay.text = "true";
    }

    }
    }

    Even if you are looking for individual digital characters in the previous code that you would have always done by a false exit due having the line 'false' always cancel the real line...

    If (t.toString () .indexOf (m_sSearchTerm)! = - 1).

    {

    searchDisplay.text = "true";

    }

    searchDisplay.text = "false";  This will always overwrite the textfield

  • How to search for a Word document in Windows 8?

    I'm stumbling around Windows 8 that came pre-loaded on my new laptop.  I ordered Windows and Excel to be included in the package.  I saved a number of documents in Word, and now I need to get these documents for a particular.  I looked on the Internet and found a lot of no-help, that is to say, 'go in search of a file'.  Excuse me, but if I could find searching a file, I could probably find out how to search for the file, Huh?  Thus,.

    Could someone please help me with: how to find a Word document (1) and (2) where is the infamous "search"?

    I did the thing 'sweep to the right side of the screen"to get those things shadow to appear, and click on the magnifying glass (which I think the engineers forgot to change when they changed everything!) and if I wanted to search for apps, I'd be in great shape.  But his files I'm looking for, Word documents.  The designers of this 'new' version improved - well, new, in all cases seem to have forgotten those of use who use computers for productive work and not socialize or play games.

    Sorry for the hike and whining, but I'm very frustrated that the tasks that were once very simple are now extremely difficult to fill.

    It's pretty easy, at the beginning screen just type the name of your document and right it will bring the search screen and you select files (files, settings, Apps). Take a look at:

    http://Windows.Microsoft.com/en-us/Windows-8/search-apps-files-settings

  • How to search for a photo album?

    I tried several options to search for a particular album. Using the name of the album in the box search brings no results. Searching with phrases such as: "Images I edited yesterday" works in a nondeterministic way - sometimes doesn't return all results, sometimes it works as expected.

    Is there a detailed manual explaining what keywords should be used in spotlight to search for photos, including the album names?

    What words to use to refine the result of a single album?

    Way the easiest way is to show the sidebar (menu display == > display the sidebar)-right click on the 'albums' title and sort by name - then go to the album of your choice and click on it to view photos

    LN

  • need help for where and how to search for apps you want in windows store 8

    I just bought a SAMSUNG ATIV TAB 3 (XE300TZC), it has WINDOWS 8.  I went to the store Windows on my windows 8 to start the download of all my apps that I like and I found some of the apps and downloaded. But many of the apps I want to I don't think because I've noticed that it is not an option or small box for me to be able to get all the apps... I guess my question is how a search for specific applications on my STORE of WINDOWS 8?

    Hi Brandi,

    Thanks for posting your question on the Microsoft community.

    Thank you for details on the issue.

    Please see suggestions from HairyFool said on June 4, 2013 and check.
    http://answers.Microsoft.com/en-us/Windows/Forum/windows_8-Winapps/how-do-i-search-the-Windows-apps-store-on-my/75390438-4DBA-4a77-93cd-aa3b2153efce

    I hope this information helps.

    Please let us know if you need more help.

    Thank you

  • How to get the values separated by commas of multiple records in table

    How to get the values separated by commas of multiple records in table

    for example

    name address age sex
    a 12 m e
    b hh 12 f
    BB c 13 h

    I need to get output as a, b, c from a query

    Use the query as below he works for me, change the names of tables and columns

    SELECT SUBSTR (SYS_CONNECT_BY_PATH (PROXY_EMAIL, ','), 2) csv FROM (SELECT PROXY_EMAIL, ROW_NUMBER () ON the rn (ORDER OF PROXY_EMAIL), COUNT (*) NTC (STARS_PROXY_ASSIGNMENT) WHERE EMPLID = #EMPLID) WHERE rn = cnt START WITH rn = 1 CONNECT BY rn = rn + 1 ADVANCE

  • How to store the values separated by commas

    Hi all

    I have a table named discount, with discount_id (number data type) as one of the columns.
    The user gives an entry as the value separated by commas, (ex: '123,27890,3543')
    I use built-in proc that separates the values separated by commas.
    DECLARE
       l_input   VARCHAR2 (4000) := '123,27890,3543';
       l_count   BINARY_INTEGER;
       l_array   DBMS_UTILITY.lname_array;
    BEGIN
       DBMS_UTILITY.comma_to_table (
          list     => REGEXP_REPLACE (l_input, '(^|,)', '\1x'),
          tablen   => l_count,
          tab      => l_array);
       DBMS_OUTPUT.put_line (l_count);   
    
       FOR i IN 1 .. l_count
       LOOP
          DBMS_OUTPUT.put_line (
                'Element '
             || TO_CHAR (i)
             || ' of array contains: '
             || SUBSTR (l_array (i), 2));
       END LOOP;
    END;
    
    Result:
    3
    Element 1 of array contains: 123
    Element 2 of array contains: 27890
    Element 3 of array contains: 3543
    Result set is stored in a table.
    I would like to do a select on the table of discounts
    Select * discount where discount_id (123, 27890 3543).

    I am looking for options,
    I need to create a new physical table as
    Create table new_table (identification number) and bulk insert in this table.
    Select * discount where discount_id in (select distinct id of new_table).
    or
    Is there a better way?

    THX
    Rod.

    Hello, SamFisher.
    May be the recursive subquery factoring help you?

    WITH test(f1, n) AS (select '12, 15, 235', 1 from dual
                         UNION all
                         select f1, n + 1 from test where n < regexp_count('12, 15, 235', ',') + 1)
    SELECT regexp_substr(f1, '[^, ]+', 1, n) f
    FROM test
    
  • Column value separated by commas to convert to another value separated by commas and happening as a component of output sys_refcursor

    Hello

    I have 3 tables with the following structure.

    create table a_os_lang_stls

    (ID NUMBER )

    SWB_NUMBER VARCHAR2 (30),

    Pc_NUMBER VARCHAR2 (30),

    PC_FLAG TANK (1),

    INSTALLATION_ord NUMBER ,

    SP_OR_LATER_VSN TANK (1),

    Platform VARCHAR2 (4000),

       OS VARCHAR2 (4000),

    LANG VARCHAR2 (4000),

    LOSS_OF_FUNC_REASON_TXT VARCHAR2 (4000),

    CREATION_DATE DATE ,

    MODIFIED_DATE DATE ,

    CREATED_BY VARCHAR2 (100 BYTE),

    MODIFIED_BY VARCHAR2 (100 BYTE)

    );



    Insert in a_os_lang_stls

    values (1 'SWB1' 'SWB0','P',1 of ','11118,14,16,234,124' '12,26,17,24,35''34,28,45,67,123,95',USER, NULL, NULL, NULL, SYSDATE);

    Insert in a_os_lang_stls

    values (2,'SWB1' 'SWB2','P',2 of ','111,20,14,16,124''11,26,18,24,35''35,27,42,67,123,95', SYSDATE, NULL, NULL, NULL, USER);

    insert into a_os_lang_stls

    values (3,'SWB1','SWB3','C', 1,'','11118,14,16,234,124','12,26,17,24,35',' 35,27,42,67,123,95', SYSDATE, NULL, NULL, NULL, USER);

    insert into a_os_lang_stls

    values (4,'SWB1','SWB4','C', 2,'','111,20,14,16,124','11,26,18,24,35'' 34,28,45,67,123,95, SYSDATE, NULL, NULL, NULL, USER)



    CREATE TABLE os_dtls

    (

      OSCODE                 VARCHAR2 (10 BYTE),

    ID NUMBER DEFAULT NULL,                                     

    AG_OSCODE VARCHAR2 (250 BYTE),

    );


    insert into os_dtls

    values ('HUX', 12, 'HP UNIX');

    insert into os_dtls

    values('SUX',26,'SOLARIS');

    insert into os_dtls

    values ('LUX', 17, 'LINUX');

    CREATE TABLE lang_dtls

    (

    LANGCD TANK (2 BYTE),

    LANGNAME VARCHAR2 (255 BYTE),

    ID NUMBER DEFAULT 1 NOT NULL                                                          

    );


    insert into lang_dtls

    values ('ENG', 'ENGLISH UK', 35);

    insert into lang_dtls

    values ('UEG', 'USA ENGLISH', 27);

    insert into lang_dtls

    values('FR','FRENCH',45);

    Information on the database:

    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    PL/SQL version 11.1.0.7.0 - Production

    Production base 11.1.0.7.0

    AMT for Linux: Version 11.1.0.7.0 - Production

    NLSRTL Version 11.1.0.7.0 - Production

    I have to write a procedure like this

    procedure os_lang_info (P_SB_NO IN varchar2, p_pcur sys_refcursor, p_ccur, sys_refcursor );

    The requirement is to get the details for a given swb_no where pc_flag is P or C pass like 2 different sys_refcursor. But the value of column of bones and lang I need to map to the os_dtls and lang_dtls tables to get the ag_oscode and langname respectively for the corresponding id then through sys_refcursor.

    So sys_refcursor structure will be

    Open the p_pcur for

    Select * from a_os_lang_stls

    where swb_number = p_sb_no

    and PC_FLAG = 'P' ;


    so the output will resemble the following

    1 , « SWB1 » , « SWB0 » , 'P' , 1 , 'S' , '11118,14,16,234,124' , «HP UNIX,SOLARIS,LINUX,... « , "UK ENGLISH,US ENGLISH,FRENCH,...» ', NULL, NULL, NULL, USER, SYSDATE

    I must get the id separated by commas of column bone and lang and map to the corresponding table to get the names separated by commas of the bones and langs and pass it as a component of sys_refcursor.

    Open the p_ccur for

    Select * from a_os_lang_stls

    where swb_number = p_sb_no

    and PC_FLAG = 'C';



    Could someone please help me how to convert the value separated by commas in a comma separated value new map to another table and pass it as part of the sys_refcursor.



    Thanks in advance.


    Kind regards

    SB2011



    Hello. Here are the queries for the two sys_refcursors.

    (1) FOR THE FLAG = 'P '.

    SELECT T1.ID,

    T1. SWB_NUMBER,

    T1. PC_NUMBER,

    T1. PC_FLAG,

    T1. INSTALLATION_ORD,

    T1. SP_OR_LATER_VSN,

    T1. PLATFORM,

    T1. OS_CODE,

    T2. LANG_CODE

    DE)

    SELECT T1.ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    PLATFORM,

    RTRIM (XMLAGG (XMLELEMENT(A,AG_OSCODE,',')). Extract ('//Text ()'), ',') OS_CODE

    FROM (SELECT ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    PLATFORM,

    (COLUMN_VALUE). GETNUMBERVAL() os_id

    Of a_os_lang_stls t, xmltable (os) t1) T1.

    OS_dtls T2

    WHERE T2.ID = T1. OS_ID

    GROUP OF T1.ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    T1 PLATFORM),

    (SELECT T1.ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    PLATFORM,

    RTRIM (XMLAGG (XMLELEMENT(A,LANGNAME,',')). Extract ('//Text ()'), ',') LANG_CODE

    FROM (SELECT ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    PLATFORM,

    (COLUMN_VALUE). GETNUMBERVAL() lang_id

    Of a_os_lang_stls t, xmltable (lang) t1) T1.

    lang_dtls T2

    WHERE T2.ID = T1.lang_id

    GROUP OF T1.ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    T2 PLATFORM)

    WHERE T1.ID = T2.ID

    AND T1. SWB_NUMBER = T2. SWB_NUMBER

    AND T1. PC_NUMBER = T2. PC_NUMBER

    AND T1. INSTALLATION_ORD = T2. INSTALLATION_ORD

    AND T1. PLATFORM = T2. PLATFORM

    AND T1. PC_FLAG = "P";

    (2) PC_FLAG FOR = 'C '.

    SELECT T1.ID,

    T1. SWB_NUMBER,

    T1. PC_NUMBER,

    T1. PC_FLAG,

    T1. INSTALLATION_ORD,

    T1. SP_OR_LATER_VSN,

    T1. PLATFORM,

    T1. OS_CODE,

    T2. LANG_CODE

    DE)

    SELECT T1.ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    PLATFORM,

    RTRIM (XMLAGG (XMLELEMENT(A,AG_OSCODE,',')). Extract ('//Text ()'), ',') OS_CODE

    FROM (SELECT ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    PLATFORM,

    (COLUMN_VALUE). GETNUMBERVAL() os_id

    Of a_os_lang_stls t, xmltable (os) t1) T1.

    OS_dtls T2

    WHERE T2.ID = T1. OS_ID

    GROUP OF T1.ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    T1 PLATFORM),

    (SELECT T1.ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    PLATFORM,

    RTRIM (XMLAGG (XMLELEMENT(A,LANGNAME,',')). Extract ('//Text ()'), ',') LANG_CODE

    FROM (SELECT ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    PLATFORM,

    (COLUMN_VALUE). GETNUMBERVAL() lang_id

    Of a_os_lang_stls t, xmltable (lang) t1) T1.

    lang_dtls T2

    WHERE T2.ID = T1.lang_id

    GROUP OF T1.ID,

    SWB_NUMBER,

    PC_NUMBER,

    PC_FLAG,

    INSTALLATION_ORD,

    SP_OR_LATER_VSN,

    T2 PLATFORM)

    WHERE T1.ID = T2.ID

    AND T1. SWB_NUMBER = T2. SWB_NUMBER

    AND T1. PC_NUMBER = T2. PC_NUMBER

    AND T1. INSTALLATION_ORD = T2. INSTALLATION_ORD

    AND T1. PLATFORM = T2. PLATFORM

    AND T1. PC_FLAG = 'C ';

  • Left join of the two tables and multiple values into a single value separated by commas

    Hello

    I have following tables with their structures and their data as below.

    CREATE TABLE 'BETODI '. "" BETINFO ".

    (

    VARCHAR2 (8 BYTE) "CURRENTPRESS."

    ENABLE 'TYPEIDCONTAINER' VARCHAR2 (30 BYTE) NOT NULL

    )

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24D', 'Pensky-MARTENS');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A25D", "CMP");

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A25G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26D', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A32G", "V-BFC3");

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A32D', "V-BFC2");

    CREATE TABLE 'BETODI '. "" BETMASTER ".

    (

    ACTIVATE THE "CUREPRESS" TANK (5 BYTES) NOT NULL,

    ACTIVATE THE "TYPE" VARCHAR2 (5 BYTE) NOT NULL,

    NUMBER (5.0) "LASTPCIRIM".

    )

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A24', '45 M 8', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A25', 42 16', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A26", 16' 45, 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A27", '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A28', '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A29', '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A30', '45MCH', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A31", "45MCH", 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A32', '45MCH', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A33', '45MCH', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A34", "45MCH", 16);

    These two tables have left join as

    BETMASTER. CUREPRESS = substr (BETINFO. CURRENTPRESS, 1, 3)

    now I want to have the data in the two tables with fields Curepress, Lastpcirim, typeidcontainer.

    Also something like

    Make a group of typeidcontainer if this value is greater than 1 by press separated the values of semicolon (;)

    So, for example above, we should be given as

    A24 PMC 15; PENSKY-MARTENS

    A25 15 PMC

    A26 15 PMC

    A27 16 (NULL)

    A28 16 (NULL)

    A30 15 (NULL)

    A31 16 (NULL)

    A32 16 BFC2-V; V BFC3

    A33 16 (NULL)

    A34 16 (NULL)

    How could do?

    My current request is as

    Select distinct Curepress, lastpcirim, typeidcontainer

    BETMASTER STD left join INF BETINFO

    on the trim (STD. CUREPRESS) = substr (trim (INF. CURRENTPRESS), 1, 3)

    but I am unable to get the values separated by commas.

    Any help would be appreciated.

    Thank you

    Mahesh.

    Hi, Mahesh,

    If you want to only 1 row of output for each distinct combination of currentpress and lastpcirim?  This sounds like a job for GROUP BY.

    And you want the row to contain a list of all different typidcontainers-delimited?  This sounds like a job for the aggregate LISTAGG function.

    WITH joined_data AS

    (

    SELECT DISTINCT

    MST.curepress, mst.lastpcirim, inf.typeidcontainer

    OF betmaster STD

    LEFT JOIN betinfo ON TRIM (mst.curepress) inf = SUBSTR (TRIM (inf.currentpress)

    1

    3

    )

    )

    SELECT curepress, lastpcirim

    LISTAGG (typeidcontainer, ',')

    THE Group (ORDER BY typeidcontainer) AS container_list

    OF joined_data

    Curepress GROUP, lastpcirim

    ;

    Unfortunately, you can't say LISTAGG (DISTINCT ...), so you should always get the separate containers how you already are.  (Note that the subquery is just what you posted).

    Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.  Don't forget to tell what version of Oracle you are using.  LISTAGG was new in Oracle 11.2.

    Why not add CHECK constraints (and perhaps triggers) to your tables, so that curepress and currentpress are not stored with the head or trailing spaces?  Then you wouldn't need to use the PAD in queries like this, and your code would be simpler and more effective.

  • Value separated by commas in a table column to get each field separtely?

    Hello

    I have the table that a column has values separated by commas in it. This table is populated using SQL LOADER, which is staging table.

    I need to retrieve the records of these values separated by commas.

    format of. CSV file is as -

    A separate file of pipes.

    DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2|

    DHCP-1-1-2. WNLB-CMTS-03-3,WNLB-CMTS-04-4,WNLB-CMTS-05-5|

    DHCP-1-1-3. WNLB-CMTS-01-1.

    DHCP-1-1-4. WNLB-CMTS-05-8,WNLB-CMTS-05-6,WNLB-CMTS-05-0,WNLB-CMTS-03-3|

    DHCP-1-1-5 | WNLB-CMTS-02-2,WNLB-CMTS-04-4,WNLB-CMTS-05-7|

    CREATE TABLE link_data (dhcp_token VARCHAR2 (30), cmts_to_add VARCHAR2 (200), cmts_to_remove VARCHAR2 (200));

    insert into link_data values ('dhcp-1-1-1','wnlb-cmts-01-1,wnlb-cmts-02-2',null);

    insert into link_data values ('dhcp-1-1-2','wnlb-cmts-03-3,wnlb-cmts-04-4,wnlb-cmts-05-5',null);

    insert into link_data values ('dhcp-1-1-3','wnlb-cmts-01-1',null);

    insert into link_data values ('dhcp-1-1-4','wnlb-cmts-05-8,wnlb-cmts-05-6,wnlb-cmts-05-0,wnlb-cmts-03-3',null);

    insert into link_data values ('dhcp-1-1-5','wnlb-cmts-02-2,wnlb-cmts-04-4,wnlb-cmts-05-7',null);

    Here the cmts_to_add column has comma separted

    I need values such as -.

    > for wnlb-cmts-01-1,wnlb-cmts-02-2 > > wnlb-CMTS-01-1

    > > wnlb-CMTS-02-2

    > for wnlb-cmts-03-3,wnlb-cmts-04-4,wnlb-cmts-05-5 > > wnlb-CMTS-03-3

    > > wnlb-CMTS-04-4

    > > wnlb-CMTS-05-5

    And so on...

    I do this because it's the staging table and I load data into the main tables using this table.

    This second field contain different values as the simple comma-delimited string.

    I need to write a PLSQL block to insert into the main table after checking as if dhcp-1-1-1 and wnlb-CMTS-01-1 is present in the main table so not to introduce other insert a new record.

    To meet this requirement, I need to get the distinct value of the cmts_to_add column to insert into DB.

    the value will be inserted as dhcp-1-1-1_TO_wnlb-cmts-01-1 and dhcp-1-1-1_TO_wnlb-cmts-02-2 for the first row of the array of link_data.

    The process will also be same for the rest of the lines.

    I use the function substrt and instr for this problem, but its does not work.

    declare

    cursor c_link is select * from link_data.

    l_rec_link link_data % rowtype;

    l_dhcp varchar2 (30);

    l_cmts varchar2 (20000);

    l_cmts_1 varchar2 (32000);

    Start

    Open c_link;

    loop

    extract the c_link in l_rec_link;

    l_cmts: = l_rec_link.cmts_to_add;

    loop

    l_cmts_1: = substr (l_cmts, 1, instr(l_cmts,',')-1);

    dbms_output.put_line (l_cmts_1);

    end loop;

    dbms_output.put_line(l_dhcp||) e '|| l_cmts);

    When the output c_link % notfound;

    end loop;

    exception

    while others then

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    end;

    Its a peusdo code I write, but it also gives me the wrong answer it gives me error ORA-20000: ORU-10027: buffer overflow, limit of 20000 bytes

    I am using-

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    Please tell me if my problem isn't clear!

    Hello

    little 'trick': Add a comma at the end of the chain... So it's easier to deal with the fact that there are zero, one, or N components...

    CREATE TABLE link_data (dhcp_token VARCHAR2 (30), cmts_to_add VARCHAR2 (200), cmts_to_remove VARCHAR2 (200));
    insert into link_data values ('dhcp-1-1-1','wnlb-cmts-01-1,wnlb-cmts-02-2',null);
    insert into link_data values ('dhcp-1-1-2','wnlb-cmts-03-3,wnlb-cmts-04-4,wnlb-cmts-05-5',null);
    insert into link_data values ('dhcp-1-1-3','wnlb-cmts-01-1',null);
    insert into link_data values ('dhcp-1-1-4','wnlb-cmts-05-8,wnlb-cmts-05-6,wnlb-cmts-05-0,wnlb-cmts-03-3',null);
    insert into link_data values ('dhcp-1-1-5','wnlb-cmts-02-2,wnlb-cmts-04-4,wnlb-cmts-05-7',null);
    COMMIT;

    SET SERVEROUT ON
    DECLARE
    l_cmts VARCHAR2 (200 CHAR);
    l_cmts_1 VARCHAR2 (200 CHAR);
    BEGIN
    FOR r IN (SELECT dhcp_token, cmts_to_add |) ',' cmts
    OF link_data
    )
    LOOP
    l_cmts: = r.cmts;
    l_cmts_1: = SUBSTR (l_cmts, 1, INSTR (l_cmts, ",") - 1);
    While l_cmts_1 IS NOT NULL
    LOOP
    DBMS_OUTPUT. Put_line (r.dhcp_token |) '|' || l_cmts_1);
    l_cmts: = SUBSTR (l_cmts, INSTR (l_cmts, ",") + 1);
    l_cmts_1: = SUBSTR (l_cmts, 1, INSTR (l_cmts, ",") - 1);
    END LOOP;
    END LOOP;
    END;
    /
    DHCP-1-1-1. WNLB-CMTS-01-1
    DHCP-1-1-1. WNLB-CMTS-02-2
    DHCP-1-1-2. WNLB-CMTS-03-3
    DHCP-1-1-2. WNLB-CMTS-04-4
    DHCP-1-1-2. WNLB-CMTS-05-5
    DHCP-1-1-3. WNLB-CMTS-01-1
    DHCP-1-1-4. WNLB-CMTS-05-8
    DHCP-1-1-4. WNLB-CMTS-05-6
    DHCP-1-1-4. WNLB-CMTS-05-0
    DHCP-1-1-4. WNLB-CMTS-03-3
    DHCP-1-1-5 | WNLB-CMTS-02-2
    DHCP-1-1-5 | WNLB-CMTS-04-4
    DHCP-1-1-5 | WNLB-CMTS-05-7

    Best regards

    Bruno Vroman.

  • have a column that has values separated by commas... and I'm s

    Have a column that has values separated by commas... and I'm trying to separate.
    I am trying to create a stored procedure... The 11g xe version. apex .and version 4...
    Here is the part of the code... I can't do a procedure. causes my intervention consist with the clause...

    create or replace procedure ins_adv_invoice
    (mmagazine_no number, madvtno number, missueno number, varchar2, varchar2, varchar2 msalesman_code mpagenumber msection)
    is

    cursor cx is with testa as
    (select name of the advertiser pagenumber)
    Select regexp_substr (pagenumber, ' [^,] +', 1, rownum) result
    the advertiser
    connect by level < = length (regexp_replace (pagenumber, ' [^,] + "")) + 1
    where advt_no = madvtno;


    Start
    for xxx CX
    loop
    insert into adv_invoice (magazine_no, advtno, adissue, section, opinion, salesman_code)
    values (mmagazine_no, madvtno, missueno, msection, xxx.result, msalesman_code);

    end loop;

    end;


    But when I run the present... it creates no procedure. . I receive he following error...
    LINE/COL ERROR
    -------- ----------------------------------------------------
    5/14 PL/SQL: statement ignored
    9/69 PL/SQL: ORA-00933: SQL not correctly completed command
    SQL >
    Still not able to understand... If anyone can help...
    Thank you

    Change the query to swap the last two lines:

    ...
    cursor cx is with testa as
    (select pagenumber name from advertiser)
    select regexp_substr(pagenumber, '[^,]+', 1, rownum) result
    from advertiser
    where advt_no = madvtno
    connect by level <= length(regexp_replace(pagenumber, '[^,]+')) + 1;
    ...
    
  • Extract values separated by commas in xquery string

    Hello

    We get a string with values separated by comma Ex: a, b, c.

    Our requirement is to mark the string and transform values to an XML using xquery.

    I'm new to xquery. Can someone help me on this please.

    Thank you
    Chauvin

    Hi Jacky,.

    You can use the function "mark".
    For example:

    let $str := "a,b,c"
    return 
    {
     for $i in tokenize($str,",")
     return     { $i }
    }
    
    

    will return:

    
       a
       b
       c
    
    

Maybe you are looking for

  • Can I read out the channel of AI to control ao channel?

    Hello I use a USB-6211 to acquire two voltage signals synchronized to an LVDT (ai0) and a load cell (ai1). LVDT signal and load cell already amplified and conditioned before travelling in the ADF. LVDT and scale read displacement and force on a rod h

  • infrared 6008 or stepper motor control

    HY! I want to try to control an engine with NI6008 and an infrared receiver TSOP3848. I want to start the engine with the "play button" on TV remote and stop the engine with the button 'stop' at a distance. The problem is that my infrared receiver 38

  • install Microsoft wireless laser mouse 6000

    Hi, I bought used ms laser 6000 wireless mouse, this one: http://www.microsoft.com/hardware/en-us/d/wireless-laser-mouse-6000 and now I can't find it on the bluetooth on my laptop, I have Bluetooth v2. The mouse requires installing with usb receiver

  • CLI to stop VM?

    Both my ESXi and vCenter freeze after a vMotion of storage on the VM vCenter mentioned here: http://communities.vmware.com/message/1818399#1818399Before I reboot my ESXi host, I need to stop all running virtual machines on this host. Y at - it a comm

  • need to disable cs dead computer

    System has crashed and need to disable CS support to reinstall on the new system.