Regex that validates a list of comma separated emails

I need some help with a regex that validates a list of comma separated (omitting the last) emails allowing arbitrary spaces   commas
[email protected]  , [email protected],  [email protected]
any ideas

I think its best to simply whenever possible, especially when regular expressions are involved.
I would use the String function split() to get an array of email addresses. You can split using a comma, and then use a two stage regex for your validation.
1) strip any whitespace from the start and end of each email
2) validate each email address
Just in terms of code readability I think this might be the preferred approach.
If this post answers your question or helps, please mark it as such.
Greg Lafrance - Flex 2 and 3 ACE certified
www.ChikaraDev.com
Flex / AIR Development, Training, and Support Services

Similar Messages

  • UTL_MAIL does not take comma separated email addresses

    Hi, there,
    I tried email multiple email addresses through UTL_MAIL, but ran into the following error:
    begin
    UTL_MAIL.SEND
    ( sender => '[email protected]'
    , recipients => '[email protected], [email protected]'
    , cc => null
    , subject => 'test'
    , message => 'this is a test');
    end;
    Error starting at line 2 in command:
    begin
    UTL_MAIL.SEND
    ( sender => '[email protected]'
    , recipients => '[email protected], [email protected]'
    , cc => null
    , subject => 'test'
    , message => 'this is a test');
    end;
    Error report:
    ORA-29279: SMTP permanent error: 550 5.7.1 Unable to relay
    ORA-06512: at "SYS.UTL_SMTP", line 20
    ORA-06512: at "SYS.UTL_SMTP", line 98
    ORA-06512: at "SYS.UTL_SMTP", line 240
    ORA-06512: at "SYS.UTL_MAIL", line 414
    ORA-06512: at "SYS.UTL_MAIL", line 608
    ORA-06512: at line 2
    29279. 00000 - "SMTP permanent error: %s"
    *Cause:    A SMTP permanent error occurred.
    *Action:   Correct the error and retry the SMTP operation.
    However, I checked the Oracle UTL_MAIL reference at:
    http://download.oracle.com/docs/cd/B12037_01/appdev.101/b10802/u_mail.htm#996885
    When it comes to 'recipients' parameter, it reads:
    The email addresses of the recipient(s), separated by commas.
    As you can see in my source code, I did use comma to separate the two email addresses. So what's wrong?
    The configuration of UTL_MAIL has been done. In fact, I can use UTL_MAIL to send email to any single email address.
    Thanks!
    Alex

    alexlizn wrote:
    ORA-29279: SMTP permanent error: 550 5.7.1 Unable to relayThis error means that you are specifying an e-mail address that the server refuses to accept, as it would have to relay (forward) the mail message to that domain.
    This is a counter spam measure. Open relay means that the SMTP server accepts mail delivery on behalf of any domain. Which means it can be used to send millions of e-mails to 100's of 1000's of domains.. and this SMTP server will happily accept the mail and deliver it to all these domains. (see http://www.eudora.com/techsupport/kb/1593hq.html for a complete description).
    Today, an open SMTP relay will get you blacklisted/blackholed - meaning that no domain (subscribing to these lists) will accept mail from your SMTP server's domain.
    Have a chat to your mail admin. Your code/data is violating some or other relay rule.

  • Validate from list, do not open lov if value already in lov

    Hi,
    I have an item and want to validate value from Lov because do not need a code in w-v-i trigger. i set property validate from list for the item to yes but when executing the lov opened even if i entered a value which already exists in lov. i thought that validate from list to yes triggers the list only if value do not exist in the list. i do not want list to open if value already exists in the list. Can someone help me with this? Thanks for your ideas.
    Edited by: Tabit7 on 2011-04-08 23:24
    Edited by: Tabit7 on 2011-04-08 23:24

    It only opens the Lov when the value not not unique, e.g. you have two equal entries in the lov. Also be aware that the validation is done against the first visible item in the lov.

  • Obtaining comma-separated list of text values associated with bitwise flag column

    In the table msdb.dbo.sysjobsteps, there is a [flags] column, which is a bit array with the following possible values:
    0: Overwrite output file
    2: Append to output file
    4: Write Transact-SQL job step output to step history
    8: Write log to table (overwrite existing history)
    16: Write log to table (append to existing history)
    32: Include step output in history
    64: Create a Windows event to use as a signal for the Cmd jobstep to abort
    I want to display a comma-separated list of the text values for a row. For example, if [flags] = 12, I want to display 'Write Transact-SQL job step output to step history, Write log to table (overwrite existing history)'.
    What is the most efficient way to accomplish this?

    Here is a query that gives the pattern:
    DECLARE @val int = 43
    ;WITH numbers AS (
       SELECT power(2, n) AS exp2 FROM (VALUES(0), (1), (2), (3), (4), (5), (6)) AS n(n)
    ), list(list) AS (
       SELECT
         (SELECT CASE WHEN exp2 = 1  THEN 'First flag'
                      WHEN exp2 = 2  THEN 'Flag 2'
                      WHEN exp2 = 4  THEN 'Third flag'
                      WHEN exp2 = 8  THEN 'IV Flag'
                      WHEN exp2 = 16 THEN 'Flag #5'
                      WHEN exp2 = 32 THEN 'Another flag'
                      WHEN exp2 = 64 THEN 'My lucky flag'
                 END + ', '
          FROM   numbers
          WHERE  exp2 & @val = exp2
          ORDER BY exp2
          FOR XML PATH(''), TYPE).value('.', 'nvarchar(MAX)')
    SELECT substring(list, 1, len(list) - 1)
    FROM   list
    Here I'm creating the numbers on the fly, but it is better to have a table of numbers in your database. It can be used in many places, see here for a short discussion:
    http://www.sommarskog.se/arrays-in-sql-2005.html#numbersasconcept
    (Only read down to the next header.)
    For FOR XML PATH thing is the somewhat obscure way we create concatenated lists. There is not really any using trying to explain how it works; it just works. The one thing to keep in mind is that it adds an extra comma at the end and the final query strips
    it off.
    This query does not handle that 0 has a special meaning - that is left as an exercise to the reader.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Problem using comma separated list with nested table element

    Hi,
    I have a comma separated list like that:
    H23004,H24005,T7231,T8231,T9231And want to create a function which is creating a where clause for each element with an output like that:
    UPPER('H23004') IN (UPPER(charge))
    OR UPPER('H23005') IN (UPPER(charge))
    OR UPPER('T7231') IN (UPPER(charge))
    OR UPPER('T8231') IN (UPPER(charge))
    OR UPPER('T9231') IN (UPPER(charge))Here is my test function which doesn't work correctly:
    create or replace function FNC_LIST_TO_WHERE_CLAUSE(v_list in VARCHAR2) return varchar2 is
    -- declaration of list type
    TYPE batch_type IS TABLE OF pr_stamm.charge%TYPE;
    -- variable for Batches
    v_batch batch_type := batch_type('''' || replace(v_list,',',''',''') || '''');
    return_script varchar2(1000);
    BEGIN
    -- loop as long as there are objects left
    FOR i IN v_batch.FIRST .. v_batch.LAST
    LOOP
       --DBMS_OUTPUT.PUT_LINE(offices(i));
       -- create where clause
       IF i = 1 THEN
         return_script := 'UPPER(' || v_batch(i) || ') IN (UPPER(charge))';
       ELSE
         return_script := return_script || ' OR UPPER(' || v_batch(i) || ') IN (UPPER(charge))';
       END IF;
    END LOOP;
    return (return_script);
    end;The out put looks like that:
    UPPER('H23004','H24005','T7231','T8231','T9231') IN (UPPER(charge))I have no idea what I do wrong? It calculates the amount of array element wrong! (v_batch.LAST should be 5.)
    v_batch.FIRST = 1
    v_batch.LAST = 1
    Regards,
    Tobias

    try this....
    declare
    text varchar2(1000) := 'H23004,H24005,T7231,T8231,T9231';
    v_where varchar2(1000);
    begin
    text := text||',';
    while instr(text,',') <> 0
    loop
    v_where := v_where || 'UPPER('''||substr(text,1,instr(text,',',1)-1)||''' IN (UPPER(charge)) OR ';
         text := substr(text,instr(text,',',1)+1);
    end loop;
    v_where := substr(v_where,1,length(v_where)-3);
    dbms_output.put_line(v_where);
    end;
    convert this one into function ...

  • Comma separated list for in ()

    I am trying get a comma separated list of numbers (123,345,332,645) from a text field and pass it to a select statement that has in condition. The code looks something like
    select a,b,c from tab1
    where a in (:P1_SEARCH)
    This works when I put only one value in the field. if I put two values like 345,453 it doesn't.
    Can someone please explain this behaviour?
    Thank you,
    Kirtan Desai

    Kirtan,
    Lots of info here: Re: Search on a typed in list of values .
    Scott

  • How to get distinct values in a comma separated list of email addresses?

    Hi Friends,
    I have a cursor which fetches email address along with some other columns. More than one record can have same email address.
    Ex
    CURSOR C1 IS
    SELECT 1 Buyer,'XX123' PO, '[email protected]' Buyer_email from dual
    UNION ALL
    SELECT 2 Buyer,'XX223' PO, '[email protected]' Buyer_email from dual
    UNION ALL
    SELECT 1 Buyer,'XX124' PO, '[email protected]' Buyer_email from dual
    UNION ALL
    SELECT 2 Buyer,'XX224' PO, '[email protected]' Buyer_email from dualNow, i open the cursor write the contents into a file and also form a comma separated list of buyer emails as follows
    for cur_rec in c1
    LOOP
    --write contents into a file
    l_buyer_email_list := l_buyer_email_list||cur_rec.buyer_email||',';
    END LOOP
    l_buyer_email_list := RTRIM(l_buyer_email_list,',');
    The buyer email list will be like: '[email protected],[email protected],[email protected],[email protected]'
    Inorder to avoid duplicate email address in the list, i can store each of this value is a table type variable and compare in each iteration whether the email already exist in the list or not.
    Is there any other simpler way to achieve this?
    Regards,
    Sreekanth Munagala.

    If you are using oracle version 11, you can use listagg function
    with c as
    (SELECT 1 Buyer,'XX123' PO, '[email protected]' Buyer_email from dual
    UNION ALL
    SELECT 2 Buyer,'XX223' PO, '[email protected]' Buyer_email from dual
    UNION ALL
    SELECT 1 Buyer,'XX124' PO, '[email protected]' Buyer_email from dual
    UNION ALL
    SELECT 2 Buyer,'XX224' PO, '[email protected]' Buyer_email from dual
    select buyer, listagg(buyer_email,',') within group (order by  buyer) 
    from c
    group by buyer
    order by buyerFor prior versions
    {cod}
    with c as
    (SELECT 1 Buyer,'XX123' PO, '[email protected]' Buyer_email from dual
    UNION ALL
    SELECT 2 Buyer,'XX223' PO, '[email protected]' Buyer_email from dual
    UNION ALL
    SELECT 1 Buyer,'XX124' PO, '[email protected]' Buyer_email from dual
    UNION ALL
    SELECT 2 Buyer,'XX224' PO, '[email protected]' Buyer_email from dual
    select buyer, rtrim(xmlagg(xmlelement(e,buyer_email||',').extract('//text()')),',')
    from c
    group by buyer
    order by buyer

  • Query on column with comma separated values

    I have a proposed table with unnormalized data like the following:
    ID COLA COLB REFLIST
    21 xxx  zzz  24,25,78,412
    22 xxx  xxx  21
    24 yyy  xxx  912,22
    25 zzz  fff  433,555,22
    .. ...  ...  ...There are 200 million rows. There is maximum of about 10 IDs in the REFLIST, though typically two or three. How could I efficiently query this data on the REFLIST column? e.g. something like:
    SELECT id FROM mytable WHERE :myval in reflistLogically there is a many to many relationship between rows in this table. The REFLIST column contains pointers to ID values elsewhere in the table. The data could be normalized so that the relationship keys are in a separate table (in fact this is the current solution that we want to change).
    ID  REF
    21  24
    21  25
    21  78
    21  412
    22  21
    24  912
    ... ...The comma separated list seems instinctively like a bad idea, however there are various reasons for proposing it. The main reason is because the source for this data has it structured like the REFLIST example. It is an OLTP-like system rather than a data warehouse. The source code (and edit performance) would benefit greatly from not having to maintain the relationship table as the data changes.
    Going back to querying the REFLIST column, the problem seems to be building an approriate index for the data. The ideas proposed so far are:
    <li>Make a materialized view that presents the relationships as normalized (e.g. as in the example with ID, REF columns above), then index the plain column - the various methods of writing the view SQL have been widely posted.
    <li>Use a Oracle Text Index (not something I have ever had call to use before).
    Any other ideas? Its Oracle 10.2, though 11g could be possible.
    Thanks
    Jim

    Something like this ?
    This is test demo on my 11.2.0.1 Windows XP
    SQL> create table test (id number,reflist varchar2(30));
    Table created.
    SQL> insert into test values (21,'24,25,78,412');
    1 row created.
    SQL> insert into test values (22,'21');
    1 row created.
    SQL> insert into test values (24,'912,22');
    1 row created.
    SQL> insert into test values (25,'433,555,22');
    1 row created.
    SQL> select * from test
      2  where
      3  ',' || reflist || ',' like '%,22,%';
            ID REFLIST
            24 912,22
            25 433,555,22
    SQL>Source:http://stackoverflow.com/questions/7212282/is-it-possible-to-query-a-comma-separated-column-for-a-specific-value
    Regards
    Girish Sharma
    Edited by: Girish Sharma on Jul 12, 2012 2:31 PM

  • Comma Separated Tags from BLT?

    Was reading the help documentation and noticed that there is a way to pass in comma separated tags to a query template:
    TagName
    One or more tag names to be queried
    String Or String List
    None
    The name of a tag in the underlying data source.  This parameter can be repeated multiple times in a URL if multiple tags are to be queried, and multiple tags can be passed in a single parameter as a comma-separated list of tag names.
    I tried this from a BLT and it didn't work. What is the trick to get this to work? I have about 50 tags to query and I dont want to hard code the mappings and I would rather not fire 50 individual queries. 
    Any thoughts?

    Brian,
    You can't do it from an APPLET perspective or a standard TagQuery action block in BLS because of the explicit TagName.1 to TagName.128 query properties.  The TagName property you found in the help only works for a direct query to the Illuminator servlet such as:  http://<server:port>/Lighthammer/Illuminator?Server=Simulator&Mode=Current&TagName=L1Speed,L1Yield,AssetUtil1
    If you need to wrap this functionality inside BLS or simply want to use it in an applet, then drop something like this into an XMLQuery template:
    http://localhost/Lighthammer/Illuminator?QueryTemplate=Path/File&StartDate=[SD]&EndDate=[ED]&TagName=[Param.1]&Content-Type=text/xml
    Assumptions would then be that you can bundle your data server and mode information in the query template (or you can keep them explicit with Server and Mode like in the first example and [Param.x] the right side of the equal sign to allow for simple Current/History/HistoryEvent changes).  The [SD] and [ED] tokens will make the XMLQuery known to be time sensitive to an iChart so the default 60 minutes, etc. will go into the http request and give you the convenient VCR controls in the time control bar.
    Regards,
    Jeremy

  • SQL Select with comma separated column value

    Hi All
    ASP VBScript
    I have a DB column named allowed_contracts that stores a
    comma separated
    list of of values e.g. 3, 5, 19, 44, 52
    I need to select records based on a variable called
    varContractList that
    contains another comma separated list i.e. 5, 44, 52
    I only want to select records where the allowed_contracts
    column contains
    each of the varContractList,
    For example only return records that have 5 or 44 or 52 in
    thier
    allowed_contracts column.
    My brain is now in a persistant vegetive state trying to work
    this out so
    any ideas would be much appreciated.
    Regards
    Bren

    Hi Jules
    Cheers for this.
    I was trying to be a bit cute (lazy even) by storing the
    project ID's as a
    comma delimted string but as we see it doesn't always pay to
    be lazy. Serves
    me right for destroying brain cells by drinking the Welshpool
    beer the other
    week whilst visiting mates down that neck of the woods. :-))
    Time for another table me thinks.
    Rgds
    Bren
    "Julian Roberts" <[email protected]> wrote in message
    news:e7i13f$mup$[email protected]..
    > Fatal flaw here Bren. In a relational database, one
    shouldn't really store
    > foreign keys as a comma delimted string. One should have
    a 3 table
    > structure. eg
    >
    > Products:
    > ProductID
    > Product
    >
    > Categories:
    > CategoryID
    > Category
    >
    > ProductCategories:
    > ProductID
    > CategoryID
    >
    > So, from the table ProductCategories, a product can
    belong to many
    > categories. When doing a front end search to find
    products in multiple
    > categories, products can be shown thus:
    >
    > select * from Products where ProductID in (select
    ProductID from
    > ProductCategories where CategoryID in (5,44))
    >
    > --
    > Jules
    >
    http://www.charon.co.uk/charoncart
    > Charon Cart 3
    > Shopping Cart Extension for Dreamweaver MX/MX 2004
    >
    >
    >
    >
    >

  • SharePoint 2013 - Split comma separated Column in to different row items in SharePoint 2013 Workflow or Event Handler

    I have a requirement to take a String column that allows multiple fields i.e. "101;102,103,104",
    and using a SPD 2013 workflow I want to split there values and then insert each Values into different list as separate items.
    Eg:
    I have a LIST A with the columns CustID, CustName and LIST B with the same Column Name with the below values
    LIST A:
    Cust ID
    CustName
    101
    ABC, XYZ, CTSS, WIPROS, TCSS
    I want to insert the above comma separated values in the below format(different Row)
    LIST B:
    CustID
    CustName
    101
    ABC
    101
    XYZ
    101
    CTSS
    101
    WIPROS
    101
    TCSS

    Hi,
    Here is a codeplex solution can meet your reference:
    Plumsail String Workflow Actions for SharePoint 2013 and SharePoint Online
    http://spworkflowactions.codeplex.com/
    We can use Split string workflow action to split the CustName value, then insert it to ListB.
    More information:
    http://www.codeproject.com/Articles/749471/String-processing-workflow-actions-for-SharePoint
    Best Regards
    Dennis Guo
    TechNet Community Support

  • Using Comma-Separated Selector

    I am building a site with products that can have different colors.
    Some products share colors.
    I am using the Comma-Separated Selector to select the available colors for each product from a list.
    My problem is showing each product and the colors available for each product.
    How do I create a recordset that pulls only the colors I need from the colors table based on the comma separated feild from the products table?
    Thanks for any help or point in the right direction.
    RGNelson

    Difficult to say without seeing how your database is planned
    Nested region? - probably not
    take a look at the MYSQL query with uses
    HAVING IN (items in a comma separated list, item, item, etc)
    this is the same approach as the article you mentioned
    also a similar problem (possibly) mentioned here...
    ryanpratt, "Multiple conditions in Querey builder Help" #2, 18 Nov 2008 7:30 am
    atb
    Paul

  • Parse comma separated value and map with other table to get Name and change it back to comma separate.

    Hi,
    I have one existing view(with around 15 fields), in which I have to add few more fields from table called PI.
    Now these fields have values like (55C4444F-D83B-4F96-A011-367A3755BA6C , F52388E2-485B-49DF-8534-FDF46D23F59E , 722432E1-F063-4CBD-B83D-1B97836E82953) 3 values comma separated.(Sometimes only one value and sometimes 4 or 5 or 7-8 depend on user has entered
    on web page)
    Also I have another table called PHA and this tables has 2 fields Values and Name so I have to map this two tables based on VALUES fields and get Name from this PHA table and show in view and that also Comma separated.
    So basically I have to Parse the PI table's Values field 1st, map it with PHA table to get Name and then Make it comma separated in that existing view.
    To make fields comma separate I used below query,
    (SELECT DISTINCT SUBSTRING
                SELECT ','+ PI.[Name]  AS [text()]
                FROM [DB].[dbo].[Table] PHA1
    Inner Join  [DB].[dbo].[Table] PI
    ON PHA.[Value] = PI.[VALUE]
                WHERE PHA1.PId =PHA2.PId and PHA1.CId = PHA2.CId
                ORDER BY PHA1.PId
                For XML PATH ('')
            ), 2, 1000) 
    FROM [DB].[dbo].[Table] PHA2
    Inner Join [cSharpSite_profiles].[dbo].[PetAllergies] PA
    Inner Join  [DB].[dbo].[Table] PI
    ON PHA.[Value] = PI.[VALUE]
    ) [Name]
    Vicky

    Wait, this sounds wrong. You have a view where you group values into a comma-separated list. While that surely will make some purists cringe, I can see that it makes sense from a presentation perspective.
    But if you want to use these concatenated values as atomic values again, you should go back to the base tables and them from there. Building views on views may sometimes be a good idea, but if you are too keen on reuse you can cause a performance disaster.
    So do it right from the beginning.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Result may contain single string or comma separated need to split into rows

    Hi, All... I've searched through the forums and found plenty on splitting comma separated into rows; though I'm struggling applying it to my situation. I have data that looks like the below where I need to split a value into multiple rows if it should be but the same field in the table may also contain a string that should not be separated (indicated by the "Array" field being 0 or 1)...
    WITH t AS
    (SELECT 1 as array, '"Banana", "Apple", "Pear"' as str FROM dual union all
    SELECT 0, 'Fruit is delicious' FROM dual union all
    SELECT 0, 'So are vegetables' FROM dual union all
    SELECT 1, '"Bean", "Carrot", "Broccoli"' FROM dual union all
    SELECT 1, '"Apple", "Banana"' FROM dual)I've looked through many of the connect_by posts on the forum and I haven't come across one that splits a field if it should be but doesn't if it should not be... may have missed it because there are plenty of these requests on the forum!
    If you're feeling even more ambitious - the ultimate goal is to count the number of times a particular answer appears in an array - so notice the last portion of the data contains "Apple", "Banana"... the result would show:
    RESULT
    Banana             2
    Apple              2
    Pear               1
    Bean               1
    Carrot             1
    Broccoli           1
    Fruit is delicious
    So are vegetablesI can always sort them later based on other fields in the table - but the result above would be my ultimate goal!
    Any help is always appreciated. Thanks! 11g

    Hi,
    The examples you found should work for you. Just use a CASE expression to determine if str needs to be split or not, by looking at array.
    Here's one way:
    WITH     got_part_cnt     AS
         SELECT     array, str
         ,     CASE
                  WHEN  array = 0
                  THEN  1
    --              ELSE  1 + REGEXP_COUNT (str, '", "')     -- See note below
                  ELSE  1 + ( ( LENGTH (str)
                                  - LENGTH (REPLACE (str, '", "'))
                         / 4
              END          AS part_cnt
         FROM    t
    ,     cntr     AS
         SELECT  LEVEL     AS n
         FROM     (
                  SELECT  MAX (part_cnt)     AS max_part_cnt
                  FROM    got_part_cnt
         CONNECT BY     LEVEL     <= max_part_cnt
    ,     got_sub_str          AS
         SELECT     CASE
                  WHEN  p.array = 0
                  THEN  p.str
                  ELSE  REGEXP_SUBSTR ( p.str
                                   , '[^"]+'
                             , 1
                             , (2 * c.n) - 1
              END     AS sub_str
         FROM     got_part_cnt  p
         JOIN     cntr           c  ON  c.n <= p.part_cnt
    SELECT       sub_str
    ,       COUNT (*)     AS cnt
    FROM       got_sub_str
    GROUP BY  sub_str
    ORDER BY  cnt          DESC
    ,            sub_str
    {code}
    The only database at hand right now is Oracle 10.2, which doesn't have REGEXP_COUNT.  I had to use a complicated way of counting how many times '", "' occurs in str in order to test this in Oracle 10.  Since you have Oracle 11, you can un-comment the line that uses REGEXP_COUNT in the first CASE expression, and remove the alternate ELSE clause (that is, the next 5 lines, up to END).
    To make sure that this query is really paying attention to array, I added this row to the sample data:
    {code}
    SELECT 0, '"Bean", "Carrot", "Broccoli"' FROM dual union all
    {code}
    Even though str looks just like a delimited list, array=0 tells the query not to split it, so it produces these results:
    {code}
    SUB_STR                               CNT
    Apple                                   2
    Banana                                  2
    "Bean", "Carrot", "Broccoli"            1
    Bean                                    1
    Broccoli                                1
    Carrot                                  1
    Fruit is delicious                      1
    Pear                                    1
    So are vegetables                       1
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Comma Separated columns - Search

    Hi fellow,
    I need to query my db with a comma separated list but the results are not correct...What is the reason?
    My typical db problem_code column has valuas as :
    Problem_code
    1
    2,3
    5,6,7,8
    5
    And the list values I am sending as ("1","3")...etc
    SELECT * from table
    whereproblem_code in ('2','1')problem_code in ('2','1') 
    Thank you in advance..

    If you're sking SQL questions, you'd better off asking on a SQL forum.  But here you are, so let's have a look at it.
    Firstly, the other thing to always mention when raising an SQL question is to articulate what DB system you're using.  Because all of them handle SQL differently, and have their own extensions.
    In fact reading this is probably a good idea: http://www.catb.org/~esr/faqs/smart-questions.html
    Problem_code
    1
    2,3
    5,6,7,8
    5
    And the list values I am sending as ("1","3")...etc
    SELECT * from table
    whereproblem_code in ('2','1')problem_code in ('2','1') 
    Thank you in advance..
    What are you seeing here that's not expected (I presume the double-up of problem_code in ('2','1') is a typo)?
    Are you wanting to get any rows from TABLE which have either 1 or 2 in them?  That's not what you're asking for in your WHERE statement though, is it?
    Really, you should be normalising your data, because whilst you can write contorted logic to do what you need here, it will not perform well and certainly will not scale.  So it for be somewhat poor practice to perpetuate the current situation if it's at all possible not to.   The best thing to do is to normalise your data and refactor your code.  Which will probably mean going to your boss and say "this DB schema is f*cked, and needs reworking.  Needs reworking".
    Depending on your DB system, you're probably going to need to loop over the list you want to filter on and do a "WHERE problem_code LIKE" on each element of the list.  I think Oracle can do the sort of query you want to do - match elements of one list from another list - but I'm not sure.
    Adam

Maybe you are looking for

  • Unit of measure for Standard Value.

    Hi Gurus I have maintained Standard value LABOR in workcenter and maintain deafault value for unit of measure in workcenter Default tab . But that unit of measure is not defaulted in routing when i put some value.

  • How to upload a file in portal

    Hi, I am using submit resume form in which i have one field upload resume.So how can upload resume while using form portlet.Does any have idea how to do that

  • Adf swing form login problem (Frank, look at this please)

    Hi All. I'm using JDeveloper 10.1.3 Can anybody please give me a clue on how to create a simple stand alone adf swing form with a login dialog and the oracle jaas authentication? For me this kind af appllications works well only in design time :(. Wh

  • HT1937 Can I use my iPhone 5 in Europe?

    Hi, I am an exchange student from Hungary. I would like to buy an iPhone 5, but I don't know that I can use it in Hungary or not? An d how much money if I buy one with an American service? Can I change the service when I go back home or can i use wit

  • Parent..child clas type casting???

    Hi All, I have a query, please have a look: I have a parent class :: parent (getting compiled well , it's a simple class only) I have a child class :: child please see the code for child class below: public class child extends parent    public static