How to use REGEXP_LIKE or REGEXP_INSTR in a query

Hello All,
I would like to do a query on a column of a table to see if it has any combination of ALL of up to 5 words. So for example, if I search for (Apple, Banana, Blueberry), I would like to see the following data returned
Apples are better than Bananas and Blueberrys.
Blueberry recipes contain apples and bananas.
Bananas can be baked into bread with Apples but not Blueberrys.
So the criteria I would like to meet are
1. All three words are in the data returned
2. The three words can be in any order
3. There can be any or no other text in between the three words.
4. The query is case insensitive.
So far I have come up with this
    select * from hc_work_items where REGEXP_LIKE(wki_name, '(Apple)', 'i') AND REGEXP_LIKE(wki_name, '(Banana)', 'i') AND REGEXP_LIKE(wki_name, '(Blueberry)', 'i') This does the trick but I am wondering if it looks ok (I am new to REGEXP and also tuning queries for efficiency). I did also try
    select * from hc_work_items where REGEXP_INSTR(wki_name, '(Apples|Blueberrys|Bananas)') > 0 but this was returning only an OR selection of the words, not all three.
Thank you for any advice !
Edited by: 991003 on Feb 28, 2013 8:32 AM
Edited by: 991003 on Feb 28, 2013 8:34 AM

Hi,
Welcome to the forum!
991003 wrote:
Hello All,
I would like to do a query on a column of a table to see if it has any combination of ALL of up to 5 words. So for example, if I search for (Apple, Banana, Blueberry), I would like to see the following data returned
Apples are better than Bananas and Blueberrys.
Blueberry recipes contain apples and bananas.
Bananas can be baked into bread with Apples but not Blueberrys.It doesn't seem like you're really looking for words. In most of these cases, the text you are looking for (e.g. 'Apple') is not a separate word, but is a sub-string embedded in a longer word (e.g., 'Apple<b>s</b>').
What if someone uses the correct plural of 'Blueberry', that is, 'Blueberr<b>ies</b>? You might have to instruct your users to look for only the common part; in this case 'Blueberr'.
So the criteria I would like to meet are
1. All three words are in the data returned
2. The three words can be in any order
3. There can be any or no other text in between the three words.
4. The query is case insensitive.
So far I have come up with this
select * from hc_work_items where REGEXP_LIKE(wki_name, '(Apple)', 'i') AND REGEXP_LIKE(wki_name, '(Banana)', 'i') AND REGEXP_LIKE(wki_name, '(Blueberry)', 'i')
Yes, I think you'll have to do separate searches for each of the 3 targets.
Regular expressions might not be the most efficient way. INSTR or LIKE will probably be faster, e.g.
WHERE     UPPER (wki_name)   LIKE '%APPLE%'
AND     UPPER (wki_name)   LIKE '%BANANA%'
AND     UPPER (wki_name)   LIKE '%BLUEBERRY%'Oracle is smart enough to "short crcuit" compound conditions like this. For example, if if looks for 'Apple' first, and doesn't find it on a given row, then it doesn't waste time looking for the other targets on the same row.
This does the trick but I am wondering if it looks ok (I am new to REGEXP and also tuning queries for efficiency). I did also try
select * from hc_work_items where REGEXP_INSTR(wki_name, '(Apples|Blueberrys|Bananas)') > 0 but this was returning only an OR selection of the words, not all three.Exactly. You could look for any of the 6 possible permutations, but that's really ugly, inefficient, and unscalable. (If you ever need 4 targets, there are 24 permutations; with 5 targets there are 120.) You were better off the first time, with 3 separate conditions.
Oracle Text is a separate product that was designed for jobs like this. It's a separate product, that requires a separate license, and it has Text

Similar Messages

  • How to Use separate web template to a query, when default one is configured

    Hi,
       A default template is configured in SPRO. and all the queries display data using this template. Now I want to display a particular query result in a separed template that is customised to suit the need.
    how can I achieve it? When I customise template and attach query to it, it displays the result in this template, when executed from WAD. If I execute from Bex, The result is automatically displayed in the default template mensioned in SPRO.
    Please advise.

    If you want this template to be attached to this query alone - then you will have to have the same as a separate iView on portal.. when you execute from BEx the default template will get executed and by changing the default template all the queries will start using the default template... it is not possible for you to specify the template to be used when executing queries from BEx Query designer..

  • How to Use the Procedures in a Sql Query

    Hi Friends,
    Can anyone help me out whether can we use the procedure in the sql query..
    if yes help me out with an example
    my requirement is
    i have one sql query .. in which i need to use the procedure which returns multiple values... how can i overcome it,can anyone help me out for this..
    for your reference i am pasting the sql query
    SELECT paf.person_id
    FROM per_all_assignments_f paf START WITH paf.person_id = p_person_id
    AND paf.primary_flag = 'Y'
    AND paf.assignment_type IN('E', 'C')
    AND l_effective_date BETWEEN paf.effective_start_date
    AND paf.effective_end_date
    CONNECT BY PRIOR paf.supervisor_id = paf.person_id
    AND paf.primary_flag = 'Y'
    AND paf.assignment_type IN('E', 'C')
    AND l_effective_date BETWEEN paf.effective_start_date
    AND paf.effective_end_date
    and paf.person_id not in (>>>I HAVE TO USE THE PROCEDURE HERE<<<<);
    Thanks in advance

    We never saw your procedure, but maybe you could wrap it in a function
    SQL> create or replace procedure get_members(in_something IN number, out_members OUT sys_refcursor)
    is
    begin
      open out_members for
        'select level member_id from dual connect by level <= :num' using in_something;
    end get_members;
    Procedure created.
    SQL> create or replace type numbers as table of number;
    Type created.
    SQL> create or replace function members(in_something IN number)
    return numbers
    as
      member_cur sys_refcursor;
      members numbers;
    begin
      get_members(in_something, member_cur);
      fetch member_cur bulk collect into members;
      close member_cur;
      return members;
    end;
    Function created.
    SQL> select * from  table(members(4));
    COLUMN_VALUE
               1
               2
               3
               4
    4 rows selected.Variant on same using piplined function
    SQL> create or replace function members_piped(in_something IN number)
    return numbers pipelined
    as
      member_cur sys_refcursor;
      rec number;
    begin
      get_members(in_something, member_cur);
      loop
         fetch member_cur into rec;
         exit when member_cur%notfound;
         pipe row(rec);
      end loop;
      close member_cur;
      return;
    end;
    Function created.
    SQL> select * from  table(members_piped(4));
    COLUMN_VALUE
               1
               2
               3
               4
    4 rows selected.
    SQL> drop function members_piped;
    Function dropped.
    SQL> drop function members;
    Function dropped.
    SQL> drop type numbers;
    Type dropped.
    SQL> drop procedure get_members;
    Procedure droppedEdit:
    Sorry Blu, had not seen you already posted similar thing
    Edited by: Peter on Jan 27, 2011 5:38 AM

  • How to use bind variables in the following query

    CREATE OR REPLACE PROCEDURE MMDB.test IS
    sel_qtn VARCHAR2 (10);
    CURSOR PT_QUANTITY IS select * from mmdb.product_tree WHERE QUANTITY_CHECK ='E'
    AND run_id = 100
    a PT_QUANTITY%ROWTYPE;
    BEGIN
    FOR i IN PT_QUANTITY
    loop
    sel_qtn := i.quanttity-1;
    While sel_qtn>=1
    loop
    insert into mmdb.product_tree (BILLING_ACCOUNT_NO ,S_CODE) values (i.BILLING_ACCOUNT_NO ,i.S_CODE||'E');
    sel_qtn :=sel_qtn -1;
    End loop;
    commit;
    end;

    Don't duplicate threads: How to use bind variables in the following query

  • How to use ABAP Class to modify Web Query Result ??

    Hi all !
    We are using Web Templates to display our Query.
    What I would like to do ( and seems a really important issue for our users! ) is to have a "PAGE BREAK" everytime the value of a charateristics change in the report
    For Example :
    -Page 1-
    Division     Project
       A               1
                        2
                        3
    -Page 2-
    Division     Project
       B               1
                        2
                        3
    and so on....
    I read threads about using ABAP CLASS but no example what so ever...
    We are presently under BW 3.1 but are considering upgrading to 7.0 by the end of the year so if there is a solution to my problem on either version i'd like to know.
    If anyone has any information about how I can do this it would be most appreciated
    Thx
    JB.

    Hi Yong,
    Ravi is right, first check the blogs by Jocelyn, and if you still have specific questions you can ask them. I have used ABAP classes in workflow and I know Mike Pokraka tries to use classes exclusively.
    Regards,
    Martin

  • How to use MAX function in SSAS MDX Query

    I want to run this Query with MAX Condition on LAST_DATA_UPDATE Column .

    Hi Ashishsingh,
    According to your description, you want to know how to use MAX function in SQL Server Analysis Services MDX Query, right? In this case, please refer to the link below which describe the syntax and sample of MDX function.
    http://technet.microsoft.com/en-us/library/ms145601.aspx
    http://www.mdxpert.com/Functions/MDXFunction.aspx?f=64
    Hope this helps.
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to use Field-symbol with dynamic select query

    Can anybody tell me, how to use field-symbols in the dynamic select query.

    FIELD-SYMBOLS <fs> { typing | STRUCTURE struc DEFAULT dobj }.
    1. ... typing
    2. ... STRUCTURE struc DEFAULT dobj
    The FIELD-SYMBOLS statement declares a field symbol <fs>. The name conventions apply to the name fs. The angle brackets of the field symbols indicate the difference to data objects and are obligatory. You can declare field symbols in any procedure and in the global declaration section of an ABAP program, but not in the declaration section of a class or an interface. You can use a field symbol in any operand position in which it is visible and which match the typing defined using typing.
    After its declaration, a field symbol is initial - that is, it does not reference a memory area. You have to assign a memory area to it (normally using the ASSIGN statement) before you can use it as an operand. Otherwise an exception will be triggered.
    eg.
    FIELD-SYMBOLS <fs> TYPE ANY.
    DATA: BEGIN OF line,
            string1(10) VALUE '0123456789',
            string2(10) VALUE 'abcdefghij',
          END OF line.
    WRITE / line-string1+5.
    ASSIGN line-string1+5(*) TO <fs>.
    WRITE / <fs>.
    output:
    56789
    56789
    reward if helpful
    anju

  • How to use IF ELSE statement in one QUERY to MS ACCESS

    System.out.println("Enter Final Exam: ");
    int f = Integer.parseInt(input.readLine());
    command.executeUpdate("UPDATE Students SET Final_Exam='"+f+"',Raw_score=(QT+MT+Final_Exam)/3 WHERE stud_name='"+stdID+"'");
    command.executeUpdate("UPDATE Students SET Raw_score=(QT+MT+Final_Exam)/3 WHERE stud_ID='"+stdID+"'");
    if (rsf==100)
    command.executeUpdate("UPDATE Students SET Final_Grade=1.0 WHERE stud_ID='"+stdID+"'");
    else if(rsf < 100 && rsf > 90)
    command.executeUpdate("UPDATE Students SET Final_Grade=2.0 WHERE stud_ID='"+stdID+"'");
    else
    command.executeUpdate("UPDATE Students SET Final_Grade=5.0 WHERE stud_ID='"+stdID+"'");How can I shorten my code using a IF ELSE statement inside a single query or two? Or is it possible?
    Edited by: ivatanako on Sep 28, 2007 11:55 PM

    Sun has tutorial trail for JDBC, you might want to browse through that; you'll get more details and samples there than here. Here's the link to the section on PreparedStatement: http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • How to use user defined function in select query using Toplink

    Hi Friends
    I am little bit of new in Toplink stuff... so please help me...
    I have to database functions 1. encrypt and 2. decrypt.
    I want to exceute the following sql query using toplink
    select port, database, user_name, decrypt(encrypt('String which is to be encrypt ','password'),'password') from CONFIGURATION
    can anyone tell me , how to write code in toplink which will give the about sql output.
    thanks .....

    The "Specifying a Custom SQL String in a DatabaseQuery" section in the TopLink Developer's Guide may help... http://download-uk.oracle.com/docs/cd/B32110_01/web.1013/b28218/qrybas.htm#BCFHDHBG

  • How to use the result of a sql query for a max () function

    Hi
    I wrote a query on which i wrote
    "select max(id) from users "
    how can i use the returned value.
    if i made the var name ="userid"
    can it be userid.rows[0] or what.
    thnx for any help

    Hi!
    The result of this query will be the max ID of users' IDs.
    Let say we have:
    String sql="select max(users.id) from users";
    Statement st = ctx.conn.createStatement();
    ResultSet rs = st.executeQuery(sql);
    rs.next();     
    So you can get the max Id in the following way:     
    int maxId=rs.getInt("id");
    Regards,
    Rossi

  • How to use SEM_RELATED & SEM_MATCH in a single query

    Hi,
    I am trying to combine RDF and RDBMS data using SEM_RELATED.
    Below sample is working fine but the requirement is i have to add few more conditions in SEM_MATCH
    Please suggest me how to combine sem_match and sem_related in a single query.
    Please provide me the example which use SEM_MATCH and SEM_RELATED in a single query.
    SELECT distinct dg_term_property.CONTEXT_NM FROM dg_term_property,dg_term
    WHERE SEM_RELATED ('<http://www.cs.com/mdm/data_glossary#Facilities>',
    '<http://www.w3.org/2000/01/rdf-schema#subClassOf>',
    '<http://www.cs.com/mdm/data_glossary#Reference_Data_Classes>',
    sem_models('GSR_PR_CURR'), sem_rulebases('owlprime')) = 1
    and DG_TERM.TERM_NM=DG_TERM_PROPERTY.TERM_NM;
    Let me know if you need any other details.
    Regards,
    Kavitha.

    Hi Kavitha,
    I am not sure what exactly you are trying to accomplish with this query but the use of the SEM_RELATED is incorrect. To fulfill your requirement most likely you may not even need to combine SEM_RELATED with SEM_MATCH. Actually those two are not built to be used together.
    Take a look at the SEM_RELATED documentation and see if you can use it to get the results you need. The example that you are providing is not using the SEM_RELATED correctly.
    Here is the documentation:
    http://docs.oracle.com/cd/E11882_01/appdev.112/e25609/owl_concepts.htm#CHDJBGFI
    Go to:
    2.3 Using Semantic Operators to Query Relational Data
    Regards!
    Jorge
    Edited by: jbarba on Aug 20, 2012 10:20 AM
    Edited by: jbarba on Aug 20, 2012 10:21 AM

  • How to use ServerApplicationContext to do a remote query across multiple entities

    Hello everybody,
    My data model is like this:
    "Case" -> one-to-many -> "Document"
    Document has  the fields:
    - "IsFinalised" (boolean)
    -  File (large binary)
    My business rule is: 'a Case is closed if all its documents are finalised'.
    I am trying to do a query which returns whether a case is closed using ServerApplicationContext, but I don't want the query to load the large binaries for each Document into memory for given case.
    Does this do the job?
    int IsCaseClosed(int caseId)
    using (var sac = ServerApplicationContext.CreateContext())
    var relevantCase = sac.DataWorkspaces.ApplicationData.Cases.FirstOrDefault(c => c.Id = caseId);
    return relevantCase.Documents.All(d => d.IsFinalised);

    I think what you have is pretty close.  I would probably write it like this:
    bool IsCaseClosed(int caseId)
    bool isClosed = false;
    if caseId > 0
    using (var sac = ServerApplicationContext.Current ?? ServerApplicationContext.CreateContext())
    isClosed = sac.DataWorkspace.ApplicationData.Cases_Single(caseId).Documents.All(d => d.IsFinalised);
    return isClosed;

  • How to use an array in a SQL Query

    Hi
    I need to use an array of numbers such as a VARRAY or Associated Index Array so that I can do the following SQL:
    select *
    from *
    where array is null or id is in array
    So that if the array is empty it will return all the records, and if the array is not empty then it will return only the rows associated with the ids in the array.
    Is this possible?
    Regards,
    Néstor Boscán

    Actually, solution I posted returns all rows when VARRAY is empty, not when it is null. To return all rows when VARRAY is null, use:
    SQL> select  ename
      2    from  emp
      3    where deptno in (select * from table(cast(sys.OdciNumberList(10,30) as sys.OdciNumberList)))
      4       or sys.OdciNumberList(10,30) is null
      5  /
    ENAME
    ALLEN
    WARD
    MARTIN
    BLAKE
    CLARK
    KING
    TURNER
    JAMES
    MILLER
    9 rows selected.
    SQL> select  ename
      2    from  emp
      3    where deptno in (select * from table(cast(null as sys.OdciNumberList)))
      4       or null is null
      5  /
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    ENAME
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> SY.

  • How to use FMS on OPCH field to query value on a field in PHC1 form?

    Hi All,
    I have a problem. I created a user defined field in the AP Invoice form (parent form-OPCH). Now I would like to use the formatted search to add a query to that field that will select a value from another field also on the same form but at the row level (child form-PCH1). It seems that this is not possible. Any suggestions?
    A general question for this: is their any way that I could use the formatted search to query value on an opening form that is inactive?
    Thanks
    Duc

    Hi Sampath Kumar devunuri,
    Thanks for your reply. It does not work. I have tried to searched through the forum about this topic and it seems that FMS will not work at row level. Not sure if there is any solution to overcome this.
    My query is for example: I want my UDF on OPCH form to capture the description of the first row in PCH1:
    Select $[$39.1.1]
    If I assign it to a UDF at row level it works perfectly.
    If I assign it to the Remark field on OPCH it still works.
    But if I assign it to a UDF at title level it does not (this is what I need)
    This may be because at title level the form name is OPCH which is different with the form name at row level: PCH1
    I cannot think if there is any way that I could set focus on PCH1 to get the value.
    Duc

  • How to use 2 different layouts with media query

    I want to do my site for multiple devices. BUT some sections of the full page I do not want to use in the smartphone version. Responsive design changes the appearence of layout with CSS, but the elements are the same. Any idea?
    Thanks in advance

    Mobile browsers will see the mobile image.
    Desktop browsers will see the desktop image.
    See example below. 
    http://alt-web.com/FluidGrid/Fluid-4.html
    Nancy O.

Maybe you are looking for

  • Flash crashes literally 100% of the time, on all browsers

    OS : Windows 7 Flash version: 15.0.0.239 Browsers tried: Firefox 34.0.5, Chrome, IE Every single time (not exaggerating), when I navigate to a site that has flash, it will get very slow, then a popup saying "Shockwave Flash might be busy...". Waiting

  • Can I use my iMAC as a tape recorder?

    I would like to record my voice, reading a book, and then download it to my ipod.  Nothing fancy...just my voice. 

  • Generate xpath expression from xslt

    How can I generate an xpath expression for a selected node within xslt? I've found ways to get the node name, it's number and so on, but there doesn't seem to be a simple way to just print out the nodes xpath ( besides writing some type of recursive

  • Essbase server is not starting...

    Hi, I'm not able to login to Essbase server. Its already started in windows service. Initially it used to blink and disappears. I have changed the ARBORPATH environment variable to c:\hyperion\analyticservices. Now when I type essbase in command prom

  • Upload through FTP, wheres my files?

    ive made a website on ilife 08 and went to fetch to upload it to my hosting service, I can not find where iweb saved my files! anyone know what I can do? thanks