Select with like for multiple results

Hi,
I need to find all the rows of a table that contain the values of another query in the table.
My problem is that the table that I want to verify may contain a list of values and I’m not been able to think on an easy way to do this!
Performance is also an issue because my table2 will have only a short list of values to look for but the table I will search will have a few million rows.
The field that I need to search is a “VARCHAR2(4000 BYTE)” It is not indexed but probably I will need to create an index in it in case the best solution involves it!
My example scenario:
CREATE TABLE TEST_TABLE
(id number,
COL1 CHAR(25));
CREATE TABLE TEST_TABLE2
(COL1 CHAR(25));
insert into TEST_TABLE (id,COL1) values (1,'1;2;3');
insert into TEST_TABLE (id,COL1) values (2,'1');
insert into TEST_TABLE2 (COL1)  values ('1');
insert into TEST_TABLE2 (COL1) values ('2');
select id from TEST_TABLE
where (col1) in ( select col1 from TEST_TABLE2)My results with this are:
Results:
ID
2I need the results to be ( because ID 1 also contains the values from table 2):
Results:
ID
1
2Thanks 
Ricardo Tomás

select  id
  from  test_table t1
  where exists (
                select  1
                  from  test_table2 t2
                  where ';' || trim(t1.col1) || ';' like '%;' || trim(t2.col1) || ';%'
        ID
         1
         2
SQL> Why column COL1 is defined as CHAR? Since CHAR is right blank padded you will have to trim. Use VARCHAR2:
SQL> select  id
  2    from  test_table t1
  3    where exists (
  4                  select  1
  5                    from  test_table2 t2
  6                    where ';' || t1.col1 || ';' like '%;' || t2.col1 || ';%'
  7                 )
  8  /
        ID
         1
         2
SQL> SY.

Similar Messages

  • Case insensitive selects with 'like'

    I use a 10g database (10.2.0.2 same behaviour with 10.2.0.1). What we want is case insensitive selects with 'like' operator in the where clause. NLS_COMP is set to 'LINGUISTIC' and NLS_SORT is set to 'BINARY_CI.
    In a table we have two columns one of type 'varchar2' one of type 'nvarchar2'. The databases national character set is set to UTF8. Case insensitive sorting works with both columns. Select statements with '.... where varchar2col like '%r%' returns also values with upper case 'R' values (that is what I expect).
    The select statements with '.... where nvarchar2col like '%r%' however does not return the row with upper case 'R' values.
    I used SQL*Plus: Release 10.2.0.3.0 and other clients and the behaviour is the same so
    I think it is not client related.
    Is that a known issue or is there any other parameter to set for UTF8 nvarchar columns?
    Any hint is very much appreciated! Here are the nls settings in database, instance and session:
    DPARAMETER      DVALUE IVALUE SVALUE
    NLS_CHARACTERSET WE8ISO8859P1
    NLS_COMP      BINARY LINGUISTIC LINGUISTIC
    NLS_LANGUAGE      AMERICAN AMERICAN AMERICAN
    NLS_NCHAR_CHARACTERSET UTF8
    NLS_RDBMS_VERSION 10.2.0.1.0
    NLS_SORT BINARY BINARY_CI BINARY_CI
    NLS_TERRITORY      AMERICA AMERICA AMERICA

    OK. Found out what the problem is. It is obviously the client.
    While using the instant client and setting the parameters (NLS_SORT=BINARY_CI and NLS_COMP=LINGUISTIC) as environment variables does not work correctly, at least not for nvarchar2 fields. The nls_session_parameters show the correct values, but selects with 'like' operators in the where clause do not return case insensitive. Issuing the 'alter session' commands and again setting the nls parameters solves the problem.
    Using the full client installation also works, in case the parameters are set in the registry on windows systems. With the full client it it not necessary to issue the 'alter session' commands again.
    So obviously the problem is instant client and nvarchar2 field related. That's too bad....

  • Simple query with like return wrong result

    Hi,
    I run simple query with like.
    If I use parameter I get wrong results.
    If I use query without parameter results are ok.
    My script:
    ALTER SESSION SET NLS_SORT=BINARY_CI;
    ALTER SESSION SET NLS_COMP=LINGUISTIC;
    -- drop table abcd;
    create table abcd (col1 varchar2(10));
    INSERT INTO ABCD VALUES ('122222');
    insert into abcd values ('111222');
    SELECT * FROM ABCD WHERE COL1 LIKE :1; -- wrong result with value 12%
    COL1
    122222
    *111222*
    select * from abcd where col1 like '12%'; -- result ok
    COL1
    122222
    I use Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    and query run in Oracle SQL Developer 3.1.07.

    Hi,
    welcome to the forum.
    When you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    You should specify exactly how you run your code.
    If I run this statement in SQL Plus:SQL> ALTER SESSION SET NLS_SORT=BINARY_CI;
    Session altered.
    SQL> ALTER SESSION SET NLS_COMP=LINGUISTIC;
    Session altered.
    SQL>
    SQL> -- drop table abcd;
    SQL> create table abcd (col1 varchar2(10));
    Table created.
    SQL>
    SQL> INSERT INTO ABCD VALUES ('122222');
    1 row created.
    SQL> insert into abcd values ('111222');
    1 row created.
    SQL>
    SQL> SELECT * FROM ABCD WHERE COL1 LIKE :1;
    SP2-0552: Bind variable "1" not declared.
    SQL>
    I got this error. So I wonder how you set value 12%
    Please specify exactly how you run your test as we cannot reproduce your problem.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Cannot select Get Info for multiple tracks

    I  just updated to Lion 10.7.3 and iTunes 10.6.1 and imported my Leopard iTunes Library. I can Get Info on individual tracks but when I shift select or command select multiple tracks the iTunes window turns gray and nothing can be selected. iTunes just freezes until I press the Escape key. So far, everything else works as expected - the only problem is selecting multiple tracks (which worked fine for me on previous OS and iTunes versions).
    I haven't found any reports of similar problems so maybe I'm doing it wrong.
    Any suggestions?

    I solved my own problem - the last time I used iTunes was on a two monitor system. I still have the second monitor connected but it was turned off and the iTunes Get Info window for MULTIPLE selected items was opening on the second monitor. When I did a Get Info on a single selection, the window appeared on the main monitor normally - behavior which never made me think that multiple items would show up in a different window on the turned off monitor.

  • Enhancing standard (single select)search help for Multiple value selection

    Hi,
    Standard search help for Business Partner (in cProjects) allows only single value selection for input fields. I want to make this multiple selection.
    Is there a way to do it.
    I used an OVS and built a similar search but its difficult to get the standard options like saving to personal value list etc in it.
    It would be good if there is a way to modify the standard search help to allow multiple selection. Any ideas??
    Appreciate your help,
    Thanks,
    Sri
    Edited by: Sri on Sep 9, 2010 8:50 PM
    Edited by: Sri on Sep 9, 2010 8:52 PM

    As far as I know you can't make a standard ABAP dictionary search help return multiple entries - where you get this sort of functionality the searches don't use the standard Elementary search help framework (e.g. organisational structure searches)
    Given that the WDA search help relies on these dictionary based searches, I'd think very much that you couldn't enhance it to return multiple. how you could even return multiple entries into a single UI element input field is also confusing to me.
    I'd suggest creating a freely programmed value help, it would certainly take quite some effort to recreate those personal value lists etc, but it could be done - I don't like OVS, but that just me.

  • Select query like For all Entries

    Hi,
    I have a requirement like:
    I need to extract data (BKTXT) from table BKPF based on some criteria, into one internal table and I need to query on REGUP table for the above data, the selection criteria on REGUP as follows:
    BKTXT(Document Header Text with 25 Char) is a combination of DATE and character string.
    Ex: bkpf-bktxt = 20060710-PL02 (YYYYMMDD)
    it is like LAUFD + LAUFI (of table REGUP)
    i.e: LAUFD (REGUP) = 07/10/2006 (MM/DD/YYYY) and LAUFI(REGUP) = PL02
    here I am thinking to use a select query on REGUP using FOR ALL ENTRIES of table i_bkpf..
    How can I change the date format YYYYMMDD to MM/DD/YYYY for my requirement?
    ((    Run-on Date (REGUP-LAUFD) = the first 8 characters in the Document Header Text (BKPF- BKTXT) in MM/DD/YYYY date format (e.g. 07/10/2006)
       Run ID (REGUP-LAUFI) = the 10th character through the 15th character in the Document Header Text (BKPF- BKTXT)

    It is not possible to do in the way you are thinking of doing. "For all entries" requires you to have the itab table field and the database table field to have the same type and length. So something like below <u>will not work</u>.
    TABLES: regup.
    DATA: BEGIN OF itab OCCURS 0,
            text LIKE bkpf-bktxt.
    DATA: END OF itab.
    DATA: BEGIN OF itab_regup OCCURS 0.
            INCLUDE STRUCTURE regup.
    DATA: END OF itab_regup.
    SELECT * INTO TABLE itab_regup
             FROM regup FOR ALL ENTRIES IN itab
            WHERE laufd = itab-text+0(8).
    If you run this code, you will get an error as follows:
    <i>"When using the addition "FOR ALL ENTRIES IN itab", the fields "LAUFD" and "ITAB-TEXT+0(8)" must have the same type and length."</i>

  • Problem with Sourcing for multiple line items SRM 7.0

    Dear All,
    We are in SRM 7.0, extended classic scenerio,
    For sourcing we have selected config "Sourcing is carried out for items without a Assigned source of supply" for all sytems and all product categories
    Our requirement is Catalog items should not go to sourcing, Item with and without assigned source of supply both should go to sourcing and external requirements SC should go to sourcing.
    We have done coding in BADI "DOC SAVE BADI" and "BBP_SRC_DETERMINE" method DETERMINE_SOURCING.
    Now we create SC with line items only using Catalog it is working fine, SC not going to sorcing,
    Create SCfor line items with assigned source of supply only it is working fine, SC going to sourcing,
    and Create SCfor line items without assigned source of supply only it is working fine, SC going to sourcing,
    But problem is with the combination of all items i.e. Catalog, with and w/o assigned source of supply in one SC
    Assigned  source of supply item is not appearing in Sourcing cockpit, and some time catalog items also available for sourcing.
    Please help
    Thanks in Advance
    Vikas
    Edited by: VIKAS CHINCHORE on Oct 4, 2011 11:53 AM
    Any luck?

    Hi
    Please revisit your logic wriiten in this method
    DETERMINE_SOURCING
    Are you checking here sc has item or sc  has supplier or not ( fixed supplier) in the logic? it must be item check.
    As per sap standard , catalog item / fixed source of supply assigned will not venture to cockpit (Sourcing is carried out for items without a Assigned source of supply)

  • Where is selectable "go back" for multiple previous pages?

    the old 3.6 had 2 "go back" arrows, one for the last/prior page loaded and a drop-down showing the prior dozen or so from which i could select any back to the first. i'd like that feature back in 4.0

    I noticed this on my new copy of this version. Am on a mac. For me, I just click on the "back" arrow, and hold it. In a brief moment, a list of the previous dozen or so pages will appear, just as if I had used the old familiar separate arrow for this list. I can then scroll down to the desired link, as before.
    HTH,
    Gandyman

  • Bex - Use of Variable for multiple results

    Hello guys, I need to create a query in Bex with this structure:
    Rows:
    - 0FISCPER
    Columns: Restricted Key Figure
    - 0AMOUNT
    - 0PSTN_DATE (filtered by a variable having the last day of each 0FISCPER).
    I don't know how to give logic to the user exit variable to determine the last day of each 0FISCPER in the rows. I've done similar variables with only one possible value as result, but this is a new scenario for me.
    Is this possible to be done?
    thanks in advance,
    Mariano.

    Hi Mariano
    I think that you have tu use the Function Module 'LAST_DAY_IN_PERIOD_GET ' this module will take Fiscal Year, Fiscal Year Variant and Period as input, and it will give the last day/date of that Fiscal year period
    The step by step will this:
    1) create an exit variable with opcion processing by Customer Exit
    2) If you need create also a variable for user input and make reference to variable with customer exit. If this is not the case forget this step.
    3) Goto CMOD TCode in SAP-BW/BI and then give your Project Name and click on Change button.
    4) Click on Components
    5) Double Click on INCLUDE ZXRSRU01.
    6) there you have to write de abap code using the CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
    If you need i can write you in spanish.
    Hope this helps
    Natalia.

  • Need help with pushview for multiple view files

    Does anyone know how to create a pushview function or changeHandler function that would allow each item on a list when selected to change to a different view?
    Example is that if like has 1, 2, 3 on it selecting 1 would take user to view1.mxml, selecting 2 would send user to view2.mxml, etc.  I do not want to send all list items to the same view and just load different information.
    Thanks!

    I will check that out thanks! 
    In the mean time I did get the answer - see here: http://stackoverflow.com/questions/8936115/how-to-create-multiple-events-in-a-single-list- in-flex

  • Selective IP filtering for multiple servers in a domain?

    Is it possible to have IP filtering on for certain servers in a
    domain, and not for others?
    This is the situation:
    I am deploying two servers in mydomain, so let's call it serverA
    and serverB. I want serverA to accept all connections while
    serverB accepts connections only from certain IPs. I know you
    can do IP filtering using SimpleConnectionFilter in the
    "Connection Filter" option in Security->General tab of the Admin
    console, but this turns on IP filtering for BOTH serverA and
    serverB! How do I turn it on for one, and not the other? Any
    help would be greatly appreciated. Thank you.
    Leon

    Hi,
    Yes you can have muliple servers in a domain. You can create as many managed
    servers as your hardware can handle. When you added the server, did you use the
    startManagedWebLogic.sh (or .cmd) script to start the server. Once you do that,
    you should see the server as running.
    Hope this helps,
    pat
    "MS" <[email protected]> wrote:
    >
    Hello All,
    Is it possible to have multiple servers in a domain?
    When I add a new server, the State is reported in the weblogic console
    as "UNKNOWN".
    What does this mean?
    rgds
    MS

  • HT204380 Facetime with iOS7 for multiple numbers

    How do I use facetime when in my contact other person has multiple numbers and facetime works only for one. Earlier it used to ask me before making a call, but in iOS7 there is no such option

    You can... But.. they will not be able to Contact each other...
    This may be of Value and Interest to you...
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l

  • Enabling Commenting with Reader for multiple files

    Hello,
    I am trying to enable a great amount of files for commenting with Adobe Reader 9. I know how to enable each single file through the comments menu, but doing this for 1000+ files could take me quite a bit of time. Is there any way to automatize this process? Somehow I can't find that option through batch processing... Thanks!

    Specifically, NO, with Acrobat. Adobe sell a high end product, once
    called LiveCycle Reader Extensions but I've lost track of the name,
    which will do this - hence the absence in Acrobat.
    Aandi Inston

  • We need a script that will select clipping path for multiple images in indesign

    this is what we have, but it's not working:
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll; 
    app.doScript(resetAllClippingPathsToActiveDoc, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Reset all Clipping Paths of the Active Document"); 
    function resetAllClippingPathsToActiveDoc(){ 
        var d=app.activeDocument; 
        var allGraphicsInDoc = d.allGraphics; 
        for(var n=0;n<allGraphicsInDoc.length;n++){ 
            if(allGraphicsInDoc[n].hasOwnProperty("clippingPath")){allGraphicsInDoc[n].clippingPath.c lippingType = ClippingPathType.PHOTOSHOP_PATH};
                allGraphicsInDoc[n].clippingPath.appliedPathName = "Path 1"; 

    this is what we have, but it's not working:
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll; 
    app.doScript(resetAllClippingPathsToActiveDoc, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Reset all Clipping Paths of the Active Document"); 
    function resetAllClippingPathsToActiveDoc(){ 
        var d=app.activeDocument; 
        var allGraphicsInDoc = d.allGraphics; 
        for(var n=0;n<allGraphicsInDoc.length;n++){ 
            if(allGraphicsInDoc[n].hasOwnProperty("clippingPath")){allGraphicsInDoc[n].clippingPath.c lippingType = ClippingPathType.PHOTOSHOP_PATH};
                allGraphicsInDoc[n].clippingPath.appliedPathName = "Path 1"; 

  • 104-unsupported wireless network device detected - yet replaced with like for like card!

    Hi,
    I am repairing a friends laptop where their wireless is no longer working.
    I ordered a new card on ebay which is the same model Broadcom BCM4311KFBG however I still get the above message.
    How is it not accepting this card? Surely it's in the whitelist? It is exactly the same card except for the original had a "P20" stamped on the chip (as well as the BCM4311KFBG model number) and this new one had "P11".
    Any help much appreciated.
    Thanks
    This question was solved.
    View Solution.

    HP6715b.
    The one on the left is for HP.
    The one on the right is for DELL.
    Both are BCM4311KFBG.
    http://www.ebay.com/itm/Broadcom-BCM4311KFBG-Mini-PCI-express-Wireless-WLAN-Wifi-Card-802-11-For-HP-...
    Ebay  $7.99 free shipping.
    REO
    HP Expert Tester "Now testing HP Pavilion 15t i3-4030U Win8.1, 6GB RAM and 750GB HDD"
    Loaner Program”HP Split 13 x2 13r010dx i3-4012Y Win8.1, 4GB RAM and 500GB Hybrid HDD”
    Microsoft Registered Refurbisher
    Registered Microsoft Partner
    Apple Certified Macintosh Technician Certification in progress.

Maybe you are looking for

  • 11g - 11.1.0.7.0 - 64bit PL/SQL library cahce pin issue

    We just upgraded our production a couple of months ago to 11.1.0.7.0 - 64bit and having a lots of fun :) The main issue we started to see is that we tried compiling the package the other day (the package which doesn't have any dependency at all) and

  • Issues with Arabic in Mac OS X with Flash 10 / Flex Gumbo

    I've been looking at converting an existing Flex 3 project to have an Arabic language version, so I have been looking at the TLF to help do that. Originally I intended to just use the components for using TLF in 3.2, but it looks like I may need to u

  • Conexant audio device driver won't install on T510 with windows XP SP2

    I am having trouble in installing audio driver for Conexant audio device on an SSD with windows XP SP2 installed already.  After running the installer, it tries for a while, and says media device can't be found.  But booting from the win7-loaded inte

  • How to set up home time zone

    I'm in South Africa and I want to set up Home Time Zone there's no south africa in the options to choose.

  • Cost Component Splitting in Joint Production

    Hello. I meet a trouble in the cost component splitting for the co-product. I tried to creat a BOM like :                              A                       B                               C (CCS1)           D(CCS2) the raw material C&D are in diff