Regexp_like query

col1
======
computer a
computer b
computer1
computer 2
laptop a
laptopb
laptop c
ipad 1
ipad2
i want to output where name start with 'computer' and 'laptop' with regexp_like

SQL> with t as
  2  (select 'computer1' str from dual union all
  3  select 'computer2' str from dual union all
  4  select 'laptop1' str from dual union all
  5  select 'ipad1' str from dual union all
  6  select 'c' str from dual union all
  7  select 'laptop2' str from dual
  8  )
  9  select *
10  from t
11  where regexp_like (str,'^computer|laptop');
STR
computer1
computer2
laptop1
laptop2However, you can do this without regular expression
with t as
(select 'computer1' str from dual union all
select 'computer2' str from dual union all
select 'laptop1' str from dual union all
select 'ipad1' str from dual union all
select 'c' str from dual union all
select 'laptop2' str from dual
select *
from t
where str like 'computer%'
   or str like 'laptop%'Edited by: 884476 on Mar 22, 2012 1:31 AM

Similar Messages

  • REGEXP_LIKE query's working differently.

    Hi,
    Version :Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    i didn't understand why below query's working differently.
    First one:
                     select 'TRUE' from dual where REGEXP_LIKE( 'a', '[:alnum:]');
    'TRUE'
    TRUE  
           Second one:
                      select 'TRUE' from dual where REGEXP_LIKE( 't', '[:alnum:]');
    no rows selected
           Please clarify.

    Check this...
    WITH xx AS (
        SELECT 'a' AS lvl FROM DUAL union all
        SELECT 'l' AS lvl FROM DUAL union all
        SELECT 'n' AS lvl FROM DUAL union all
        SELECT 'u' AS lvl FROM DUAL union all
        SELECT 'm' AS lvl FROM DUAL union all
        SELECT 'r' AS lvl FROM DUAL union all
        SELECT 's' AS lvl FROM DUAL union all
        SELECT 't' AS lvl FROM DUAL union all
        SELECT 'w' AS lvl FROM DUAL
    select 'TRUE',x.lvl from xx x where REGEXP_LIKE(x.lvl, '[:alnum:]');Any other character than {a,l,n,u,m}, will return FALSE.
    HTH
    Ranit B.

  • 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

  • Using REGEXP_LIKE to query with exclusion

    Dear all,
    how to query a column that doesn't contain value with a particular letter in the middle of it using REGEXP_LIKE? Suppose I have the following:
    SQL> select * from test;
    TEMP
    john
    joni
    jane
    johny
    jonny
    SQL> select temp from test where regexp_like(temp,'[^h]');
    TEMP
    john
    joni
    jane
    johny
    jonny
    SQL> select temp from test where regexp_like(temp,'[a-z]+[^h][a-z]+');
    TEMP
    john
    joni
    jane
    johny
    jonnyThe above code tries to query temp that doesn't contain letter 'h' in the middle (so it querries joni, jane, and jonny) but it cannot be done with
    regexp_like(temp,'[^h]');
    regexp_like(temp,'[a-z]+[^h][a-z]+');since these 2 patterns satisfy all the available rows. What is the solution?
    Best regards,
    Val

    Frank Kulash wrote:
    Hi,
    Valerie Debonair wrote:
    Hi Frank,
    could you give another example, this time involves not equal character ^ instead of using NOT?Why? What's wrong with NOT?
    There are other (more complicated and/or less efficient) ways to get the same results, but whatever objection you have to NOT might apply to those ways, too. Rather than have people suggest solutions one at a time, and wait for you to say "I can't use that", I suggest you explain why you can't use it, so that the next solution won;t have the same problem.
    ^ doesn't mean "not"; it means "something other than" or "anything except". This problem doesn't involve whther or not the string contains something other than 'h'; it only matters whether or not the string conatins 'h'.Hi Frank,
    the purpose of this question is for me to understand the usage of ^ character with REGEXP_LIKE. While your solution solves the particular case that I asked, it didn't fully serve the purpose of the question even though it works well in the real world. In order words, I was focusing on the semantic of regular expression.
    Thanks for the help though, your explanation on ^ character sheds me some light.......

  • Query to apply regexp_like for patterns specified in different table

    Hi all,
    with table trap_store as ( vb clob) and table conf as (patten varchar2(20))
    Need to retrieve records from trap_store where data in vb column matches patterns in conf table.
    Presently planning to use regexp_like function ie; regexp_like(vb,'Start').
    In the above query, have hardcoded the pattern as 'Start'. But, Patterns are present in different conf table. Each row of trap_store table ie; each value of vb column in trap_store table should be matched with all the patterns of conf table.
    How to apply all the patterns of conf table ?

    It's possible to write a script with a LOOP over the pattern table to generate queries or generate a filter, and then execute it via Dynamic SQL (depends on the pattern table size)

  • Query Performance using regexp_like

    I have a question regarding the performance of using regular expression in a sql query.
    Let me explain what I am trying to achieve.
    I have a table, EXPRESSIONS, containing regular expression and its ID.
    I have a table, DATA, containing data that I want to map to a possible regular expression ID.
    Data is being added daily into the DATA table. The rows are marked initially with an invalid expression ID.
    A job runs regularly that selects all the unmapped rows at that point in time in the DATA table and try to map each of them to a regular expression.
    The problem is that as the number of unmapped rows grows, the mapping job does not scale good enough. This is due to the fact that, in the worst case, a data row may need to iterate through all the regular expressions in EXPRESSIONS table.
    The number of expressions would be much much less about 100 compared to 2 million of possible data rows.
    What are my options to speed up the process?
    Is it possible to pre-compile the regular expressions?
    Thanks for you help.

    Your question "Is it possible to pre-compile the regular expressions?" seems to be the answer. You may calculate and store hash values in both EXPRESSIONS and DATA table ,it would make the matching faster.

  • Query help using regexp_like

    kindly help me on this
    DECLARE
        STRING1  VARCHAR2(1000) :='NOT  (   VIP5';
        BEGIN
          if  regexp_like(string1 ,'NOT  \(* VIP5')  then
                 dbms_output.put_line('string1 is correct');
                     dbms_output.PUT_LINE(STRING1);
          end if;
        END;problem is STRING1 can be
    'NOT ( VIP5  '
       OR  can be                                   NOT     (          VIP5'ie between NOT AND VIP5 brackets will be there with spaces or without spaces
    so help me for the output
    S
    Edited by: oraclehema on Mar 1, 2011 3:38 AM

    HAI
    it is working
    using
    declare
         STRING1  VARCHAR2(1000) :='NOT    (      VIP5';
         STRING2  VARCHAR2(1000) :='NOT  (   (    (     VIP5';
         begin
        if REGEXP_LIKE( string2, 'NOT[[:space:]]*\([[:space:]]*\([[:space:]]*\([[:space:]]*VIP5')  then
         dbms_output.put_line('string2 is correct');
          dbms_output.PUT_LINE(STRING2);
          end if;
          end;Edited by: oraclehema on Mar 1, 2011 3:52 AM

  • SQL query - using regexp_like?

    I have a table with 35m rows.
    eg:
    create table table1 as (
      unique_id  number,
      some_data varchar2(10),
      test_column varchar2(10)
    insert into table1 values (1, 'test1','abc');
    insert into table1 values (2, 'test2','abcd');
    insert into table1 values (3, 'test3','abcde');
    insert into table1 values (4, 'test4','jsgkjh');
    insert into table1 values (5, 'test5','abc');
    I need to create a view of the count of the distinct rows where the test_column exists as a start of another row.
    eg
    create view view1
    with t1 as (select distinct some_data, test_column from table1)
    select test_column, count(*)+1 as cnt, 'Partial' as  con_type
    from table1 t2
    inner join t1
    on t1.unique_id = t2.unique_id
    and t1.some_data = t2.some_data
    where (instr(t1.test_column,t2.test_column) = 1
          or instr(t2.test_column,t1.test_column) = 1
    and t1.test_column != t2.test_column
    group by some_data;
    select * from view1;
    test_column, cnt
    abc              3
    abcd            2
    abced          1
    jsgkjh           1
    ............trouble is, it takes ages!  i was wondering if someone knew if a regular expression would be faster (or anything!!).
    Many thanks for any help

    236f2a50-9fb9-4782-a643-3c80c2b10114 wrote:
    I have a table with 35m rows.
    eg:
    create table table1 as (
      unique_id  number,
      some_data varchar2(10),
      test_column varchar2(10)
    insert into table1 values (1, 'test1','abc');
    insert into table1 values (2, 'test2','abcd');
    insert into table1 values (3, 'test3','abcde');
    insert into table1 values (4, 'test4','jsgkjh');
    insert into table1 values (5, 'test5','abc');
    I need to create a view of the count of the distinct rows where the test_column exists as a start of another row.
    eg
    create view view1
    with t1 as (select distinct some_data, test_column from table1)
    select test_column, count(*)+1 as cnt, 'Partial' as  con_type
    from table1 t2
    inner join t1
    on t1.unique_id = t2.unique_id
    and t1.some_data = t2.some_data
    where (instr(t1.test_column,t2.test_column) = 1
          or instr(t2.test_column,t1.test_column) = 1
    and t1.test_column != t2.test_column
    group by some_data;
    select * from view1;
    test_column, cnt
    abc              3
    abcd            2
    abced          1
    jsgkjh           1
    ............trouble is, it takes ages!  i was wondering if someone knew if a regular expression would be faster (or anything!!).
    Many thanks for any help
    It will take ages.  Your testing all 35 millions values against each other, and using INSTR will be anywhere in the string, not just the start of it.  Ramin's answer improves on it by just looking at the start of the strings, but what is it that you are ultimately trying to achieve?  Is this meant to be a regular process or a one-off job?

  • Query help in regular expression

    Hi all,
    SELECT * FROM emp11
    WHERE INSTR(ENAME,'A',1,2) >0;
    Please let me know the equivalent query using regular expressions.
    i have tried this after going through oracle regular expressions documentation.
    SELECT * FROM emp11
    WHERE regexp_LIKE(ename,'A{2}')
    Any help in this regard would be highly appreciated .
       Thanks,
    P Prakash

    please go here
    Introduction to regular expressions ...
    Thanks,
    P Prakash

  • How to improve the query performance or tune query from Explain Plan

    Hi
    The following is my explain plan for sql query. (The plan is generated by Toad v9.7). How to fix the query?
    SELECT STATEMENT ALL_ROWSCost: 4,160 Bytes: 25,296 Cardinality: 204                                         
         8 NESTED LOOPS Cost: 3 Bytes: 54 Cardinality: 1                                    
              5 NESTED LOOPS Cost: 2 Bytes: 23 Cardinality: 1                               
                   2 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 13 Cardinality: 1                          
                        1 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                     
                   4 TABLE ACCESS BY INDEX ROWID TABLE AR.HZ_CUST_ACCOUNTS Cost: 1 Bytes: 10 Cardinality: 1                          
                        3 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.HZ_CUST_ACCOUNTS_U1 Cost: 1 Cardinality: 1                     
              7 TABLE ACCESS BY INDEX ROWID TABLE AR.HZ_PARTIES Cost: 1 Bytes: 31 Cardinality: 1                               
                   6 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.HZ_PARTIES_U1 Cost: 1 Cardinality: 1                          
         10 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                                    
              9 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                               
         15 NESTED LOOPS Cost: 2 Bytes: 29 Cardinality: 1                                    
              12 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                               
                   11 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                          
              14 TABLE ACCESS BY INDEX ROWID TABLE ONT.OE_ORDER_HEADERS_ALL Cost: 1 Bytes: 17 Cardinality: 1                               
                   13 INDEX RANGE SCAN INDEX (UNIQUE) ONT.OE_ORDER_HEADERS_U2 Cost: 1 Cardinality: 1                          
         21 FILTER                                    
              16 TABLE ACCESS FULL TABLE ONT.OE_TRANSACTION_TYPES_TL Cost: 2 Bytes: 1,127 Cardinality: 49                               
              20 NESTED LOOPS Cost: 2 Bytes: 21 Cardinality: 1                               
                   18 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                          
                        17 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                     
                   19 INDEX RANGE SCAN INDEX (UNIQUE) ONT.OE_ORDER_HEADERS_U2 Cost: 1 Bytes: 9 Cardinality: 1                          
         23 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                                    
              22 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                               
         45 NESTED LOOPS Cost: 4,160 Bytes: 25,296 Cardinality: 204                                    
              42 NESTED LOOPS Cost: 4,150 Bytes: 23,052 Cardinality: 204                               
                   38 NESTED LOOPS Cost: 4,140 Bytes: 19,992 Cardinality: 204                          
                        34 NESTED LOOPS Cost: 4,094 Bytes: 75,850 Cardinality: 925                     
                             30 NESTED LOOPS Cost: 3,909 Bytes: 210,843 Cardinality: 3,699                
                                  26 PARTITION LIST ALL Cost: 2,436 Bytes: 338,491 Cardinality: 14,717 Partition #: 29 Partitions accessed #1 - #18          
                                       25 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_AE_HEADERS Cost: 2,436 Bytes: 338,491 Cardinality: 14,717 Partition #: 29 Partitions accessed #1 - #18     
                                            24 INDEX SKIP SCAN INDEX XLA.XLA_AE_HEADERS_N1 Cost: 264 Cardinality: 1,398,115 Partition #: 29 Partitions accessed #1 - #18
                                  29 PARTITION LIST ITERATOR Cost: 1 Bytes: 34 Cardinality: 1 Partition #: 32           
                                       28 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_AE_LINES Cost: 1 Bytes: 34 Cardinality: 1 Partition #: 32      
                                            27 INDEX RANGE SCAN INDEX (UNIQUE) XLA.XLA_AE_LINES_U1 Cost: 1 Cardinality: 1 Partition #: 32
                             33 PARTITION LIST ITERATOR Cost: 1 Bytes: 25 Cardinality: 1 Partition #: 35                
                                  32 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_DISTRIBUTION_LINKS Cost: 1 Bytes: 25 Cardinality: 1 Partition #: 35           
                                       31 INDEX RANGE SCAN INDEX XLA.XLA_DISTRIBUTION_LINKS_N3 Cost: 1 Cardinality: 1 Partition #: 35      
                        37 PARTITION LIST SINGLE Cost: 1 Bytes: 16 Cardinality: 1 Partition #: 38                     
                             36 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_EVENTS Cost: 1 Bytes: 16 Cardinality: 1 Partition #: 39 Partitions accessed #2               
                                  35 INDEX UNIQUE SCAN INDEX (UNIQUE) XLA.XLA_EVENTS_U1 Cost: 1 Cardinality: 1 Partition #: 40 Partitions accessed #2          
                   41 PARTITION LIST SINGLE Cost: 1 Bytes: 15 Cardinality: 1 Partition #: 41                          
                        40 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_TRANSACTION_ENTITIES Cost: 1 Bytes: 15 Cardinality: 1 Partition #: 42 Partitions accessed #2                    
                             39 INDEX UNIQUE SCAN INDEX (UNIQUE) XLA.XLA_TRANSACTION_ENTITIES_U1 Cost: 1 Cardinality: 1 Partition #: 43 Partitions accessed #2               
              44 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_CODE_COMBINATIONS Cost: 1 Bytes: 11 Cardinality: 1                               
                   43 INDEX UNIQUE SCAN INDEX (UNIQUE) GL.GL_CODE_COMBINATIONS_U1 Cost: 1 Cardinality: 1

    damorgan wrote:
    Tuning is NOT about reducing the cost of i/o.
    i/o is only one of many contributors to cost and only one of many contributors to waits.
    Any time you would like to explore this further run this code:
    SELECT 1 FROM dual
    WHERE regexp_like(' ','^*[ ]*a');but not on a production box because you are going to experience an extreme tuning event with zero i/o.
    And when I say "extreme" I mean "EXTREME!"
    You've been warned.I think you just need a faster server.
    SQL> set autotrace traceonly statistics
    SQL> set timing on
    SQL> select 1 from dual
      2  where
      3  regexp_like   (' ','^*[ ]*a');
    no rows selected
    Elapsed: 00:00:00.00
    Statistics
              1  recursive calls
              0  db block gets
              0  consistent gets
              0  physical reads
              0  redo size
            243  bytes sent via SQL*Net to client
            349  bytes received via SQL*Net from client
              1  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              0  rows processedRepeated from an Oracle 10.2.0.x instance:
    SQL> SELECT DISTINCT SID FROM V$MYSTAT;
           SID
           310
    SQL> ALTER SESSION SET EVENTS '10053 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    Session altered.
    SQL> select 1 from dual
      2  where
      3  regexp_like   (' ','^*[ ]*a');The session is hung. Wait a little while and connect to the database using a different session:
    COLUMN STAT_NAME FORMAT A35 TRU
    SET PAGESIZE 200
    SELECT
      STAT_NAME,
      VALUE
    FROM
      V$SESS_TIME_MODEL
    WHERE
      SID=310;
    STAT_NAME                                VALUE
    DB time                                   9247
    DB CPU                                    9247
    background elapsed time                      0
    background cpu time                          0
    sequence load elapsed time                   0
    parse time elapsed                        6374
    hard parse elapsed time                   5997
    sql execute elapsed time                  2939
    connection management call elapsed        1660
    failed parse elapsed time                    0
    failed parse (out of shared memory)          0
    hard parse (sharing criteria) elaps          0
    hard parse (bind mismatch) elapsed           0
    PL/SQL execution elapsed time               95
    inbound PL/SQL rpc elapsed time              0
    PL/SQL compilation elapsed time              0
    Java execution elapsed time                  0
    repeated bind elapsed time                  48
    RMAN cpu time (backup/restore)               0Seems to be using a bit of time for the hard parse (hard parse elapsed time). Wait a little while, then re-execute the query:
    STAT_NAME                                VALUE
    DB time                                   9247
    DB CPU                                    9247
    background elapsed time                      0
    background cpu time                          0
    sequence load elapsed time                   0
    parse time elapsed                        6374
    hard parse elapsed time                   5997
    sql execute elapsed time                  2939
    connection management call elapsed        1660
    failed parse elapsed time                    0
    failed parse (out of shared memory)          0
    hard parse (sharing criteria) elaps          0
    hard parse (bind mismatch) elapsed           0
    PL/SQL execution elapsed time               95
    inbound PL/SQL rpc elapsed time              0
    PL/SQL compilation elapsed time              0
    Java execution elapsed time                  0
    repeated bind elapsed time                  48
    RMAN cpu time (backup/restore)               0The session is not reporting additional CPU usage or parse time.
    Let's check one of the session's statistics:
    SELECT
      SS.VALUE
    FROM
      V$SESSTAT SS,
      V$STATNAME SN
    WHERE
      SN.NAME='consistent gets'
      AND SN.STATISTIC#=SS.STATISTIC#
      AND SS.SID=310;
         VALUE
           163Not many consistent gets after 20+ minutes.
    Let's take a look at the plan:
    SQL> SELECT SQL_ID,CHILD_NUMBER FROM V$SQL WHERE SQL_TEXT LIKE 'select 1 from du
    al%';
    SQL_ID        CHILD_NUMBER
    04mpgrzhsv72w            0
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('04mpgrzhsv72w',0,'TYPICAL'))
    select 1 from dual where regexp_like   (' ','^*[ ]*a')
    NOTE: cannot fetch plan for SQL_ID: 04mpgrzhsv72w, CHILD_NUMBER: 0
          Please verify value of SQL_ID and CHILD_NUMBER;
          It could also be that the plan is no longer in cursor cache (check v$sql_p
    lan)No plan...
    Let's take a look at the 10053 trace file:
    Registered qb: SEL$1 0x19157f38 (PARSER)
      signature (): qb_name=SEL$1 nbfros=1 flg=0
        fro(0): flg=4 objn=258 hint_alias="DUAL"@"SEL$1"
    Predicate Move-Around (PM)
    PM: Considering predicate move-around in SEL$1 (#0).
    PM:   Checking validity of predicate move-around in SEL$1 (#0).
    CBQT: Validity checks failed for 7uqx4guu04x3g.
    CVM: Considering view merge in query block SEL$1 (#0)
    CBQT: Validity checks failed for 7uqx4guu04x3g.
    Subquery Unnest
    SU: Considering subquery unnesting in query block SEL$1 (#0)
    Set-Join Conversion (SJC)
    SJC: Considering set-join conversion in SEL$1 (#0).
    Predicate Move-Around (PM)
    PM: Considering predicate move-around in SEL$1 (#0).
    PM:   Checking validity of predicate move-around in SEL$1 (#0).
    PM:     PM bypassed: Outer query contains no views.
    FPD: Considering simple filter push in SEL$1 (#0)
    FPD:   Current where clause predicates in SEL$1 (#0) :
              REGEXP_LIKE (' ','^*[ ]*a')
    kkogcp: try to generate transitive predicate from check constraints for SEL$1 (#0)
    predicates with check contraints:  REGEXP_LIKE (' ','^*[ ]*a')
    after transitive predicate generation:  REGEXP_LIKE (' ','^*[ ]*a')
    finally:  REGEXP_LIKE (' ','^*[ ]*a')
    apadrv-start: call(in-use=592, alloc=16344), compile(in-use=37448, alloc=42256)
    kkoqbc-start
                : call(in-use=592, alloc=16344), compile(in-use=38336, alloc=42256)
    kkoqbc-subheap (create addr=000000001915C238)Looks like the query never had a chance to start executing - it is still parsing after 20 minutes.
    I am not sure that this is a good example - the query either executes very fast, or never has a chance to start executing. But, it might still make your point physical I/O is not always the problem when performance problems are experienced.
    Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • Error while trying to use '{' in the query

    Hi,
    The below mentioned query is giving Error while trying to use '{'
    Query:
    select s,x from table(SEM_MATCH(
    '{?s rdf:type <http://www.cs.com/sbip/dwh/mdm/data_modeling#Base_Term> .
    ?s ?p ?x}',
    SEM_Models('foundation'),
    SEM_RuleBases('OWLPRIME'),
    SEM_ALIASES(SEM_ALIAS('dm','http://www.cs.com/sbip/dwh/mdm/data_modeling#'),
    SEM_ALIAS('owl','http://www.w3.org/2002/07/owl#')), null, 'INVALID'))
    where regexp_like(x,'Customers','i');
    Error details:
    ORA-29532: Java call terminated by uncaught Java exception: oracle.spatial.rdf.server.TokenMgrError: Lexical error at line 1, column 1. Encountered: "{" (123), after : ""
    ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 178
    ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 67
    ORA-06512: at line 4
    I am unable to use Option, Filter in query.
    Any solution?
    Please let me know do i need to apply any patch?
    Note: I am using Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    Regards,
    Kavitha.

    Hi,
    For OPTIONAL support in 11.1.0.7.0, you need the following patch
    Patch 7600122: CURLY BRACE SYNTAX,VIRTUAL MODELS, NETWORK INDEXES AND HINTO FRAMEWORK SUPPORT
    Support for SPARQL FILTERs in SEM_MATCH is not available for 11.1.0.7.0. You will need version 11.2.0.1.0 or later for FILTER support. With 11.2.0.1.0, we recommend that you apply our latest patch set:
    Patch 9819833: SEMANTIC TECHNOLOGIES 11G R2 FIX BUNDLE 2
    All of the above patches are available through My Oracle Support.
    Thanks,
    Matt

  • Oracle SQL query for getting specific special characters from a table

    Hi all,
    This is my table
    Table Name- Table1
    S.no    Name
    1          aaaaaaaa
    2          a1234sgjghb
    3          a@3$%jkhkjn
    4          abcd-dfghjik
    5          bbvxzckvbzxcv&^%#
    6          ashgweqfg/gfjwgefj////
    7          sdsaf$([]:'
    8          <-fdsjgbdfsg
    9           dfgfdgfd"uodf
    10         aaaa  bbbbz#$
    11         cccc dddd-/mnm
    The output has to be
    S.no    Name
    3          a@3$%jkhkjn
    5          bbvxzckvbzxcv&^%#
    7          sdsaf$([]:'
    8          <-fdsjgbdfsg
    10         aaaa  bbbbz#$
    It has to return "Name" column which is having special characters,whereas some special chars like -, / ," and space are acceptable.
    The Oracle query has to print columns having special characters excluding -,/," and space
    Can anyone help me to get a SQL query for the above.
    Thanks in advance.

    You can achieve it in multiple ways. Here are few.
    SQL> with t
      2  as
      3  (
      4  select 1 id, 'aaaaaaaa' name from dual union all
      5  select 2 id, 'a1234sgjghb' name from dual union all
      6  select 3 id, 'a@3$%jkhkjn' name from dual union all
      7  select 4 id, 'abcd-dfghjik' name from dual union all
      8  select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
      9  select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
    10  select 7 id, 'sdsaf$([]:''' name from dual union all
    11  select 8 id, '<-fdsjgbdfsg' name from dual union all
    12  select 9 id, 'dfgfdgfd"uodf' name from dual union all
    13  select 10 id, 'aaaa  bbbbz#$' name from dual union all
    14  select 11 id, 'cccc dddd-/mnm' name from dual
    15  )
    16  select *
    17    from t
    18   where regexp_like(translate(name,'a-/" ','a'), '[^[:alnum:]]');
            ID NAME
             3 a@3$%jkhkjn
             5 bbvxzckvbzxcv&^%#
             7 sdsaf$([]:'
             8 <-fdsjgbdfsg
            10 aaaa  bbbbz#$
    SQL> with t
      2  as
      3  (
      4  select 1 id, 'aaaaaaaa' name from dual union all
      5  select 2 id, 'a1234sgjghb' name from dual union all
      6  select 3 id, 'a@3$%jkhkjn' name from dual union all
      7  select 4 id, 'abcd-dfghjik' name from dual union all
      8  select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
      9  select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
    10  select 7 id, 'sdsaf$([]:''' name from dual union all
    11  select 8 id, '<-fdsjgbdfsg' name from dual union all
    12  select 9 id, 'dfgfdgfd"uodf' name from dual union all
    13  select 10 id, 'aaaa  bbbbz#$' name from dual union all
    14  select 11 id, 'cccc dddd-/mnm' name from dual
    15  )
    16  select *
    17    from t
    18   where translate
    19         (
    20            lower(translate(name,'a-/" ','a'))
    21          , '.0123456789abcdefghijklmnopqrstuvwxyz'
    22          , '.'
    23         ) is not null;
            ID NAME
             3 a@3$%jkhkjn
             5 bbvxzckvbzxcv&^%#
             7 sdsaf$([]:'
             8 <-fdsjgbdfsg
            10 aaaa  bbbbz#$
    SQL>

  • Query - strings in different format

    I am trying to query data that is not all in the same format. Example: "st. louis" , "st louis", "saint louis". does anyone have any ideas about doing this?

    Hallo,
    -- 1. query with placeholder pattern matching: LIKE with the placeholder (_,%)
    select * from dept where loc like 's%louis';
    -- 2. query with POSIX regular expression matching: REGEXP_LIKE
    select loc from dept where regexp_like(loc, '^s(t|t\.|aint) louis$');
    For further information see the "Oracle Database SQL Reference 10g"
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm
    Your question is not directly related to the HTML DB. You can find similar
    questions in the SQL Forum:
    PL/SQL
    or Ask Tom:
    http://asktom.oracle.com/pls/ask/f?p=4950:1:
    Hope that helps, Willi

  • Looking for a keyword using like query which could contain multiple occurrence in the same column

    I am facing an issue. A bunch of my frontend JSP code has been stored in few tables of my database (65 rows in a table), which I have identified using few like queries. Now I want to update a Href link which is present in all these queries. But since these column entries are very long (50-60 lines long) and it is possible that a few rows may the link (which is to be replaced), multiple times,  I am not sure that if a simple update query using a single like will work for it or not?
    Any suggestion/ideas are welcome.
    Please let me know if you require any more info.

    Hi,
    e5d4d744-cf66-4fe0-8353-bbd8fd826b21 wrote:
    I am facing an issue. A bunch of my frontend JSP code has been stored in few tables of my database (65 rows in a table), which I have identified using few like queries. Now I want to update a Href link which is present in all these queries. But since these column entries are very long (50-60 lines long) and it is possible that a few rows may the link (which is to be replaced), multiple times,  I am not sure that if a simple update query using a single like will work for it or not?
    Any suggestion/ideas are welcome.
    Please let me know if you require any more info.
    Yes; whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible.  For example, if your strings are sometimes up to 4000 characters long, you don't have to post any data that's nearly that long.  You can probably show what you want with strings that are 80 characters long.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002#9362002
    This statement:
    UPDATE table_x
    SET str  = REPLACE ( str
                       , old_link
                       , new_link
    WHERE   str  LIKE  '%' || old_link || '%'
    will change all occurrences of old_link to new_link.  It will only change the rows where old_link occurs, but, aside from that, it doesn't matter how many times old_link occurs in str:  if it appears 2 times in the same str, then both occurrences will be changed to new_link.
    Watch out for the "mother is in chemotherapy" problem.  If old_link is 'bar.com', the statement above will change 'fubar.com'.  You may need REGEXP_REPLACE and/or REGEXP_LIKE if you need to consider what (if anything) comes immediately before 'bar.com' when deciding whether or not to change it.

  • "cannot perform a DML operation inside a query" error when using table func

    hello please help me
    i created follow table function when i use it by "select * from table(customerRequest_list);"
    command i receive this error "cannot perform a DML operation inside a query"
    can you solve this problem?
    CREATE OR REPLACE FUNCTION customerRequest_list(
    p_sendingDate varchar2:=NULL,
    p_requestNumber varchar2:=NULL,
    p_branchCode varchar2:=NULL,
    p_bankCode varchar2:=NULL,
    p_numberOfchekbook varchar2:=NULL,
    p_customerAccountNumber varchar2:=NULL,
    p_customerName varchar2:=NULL,
    p_checkbookCode varchar2:=NULL,
    p_sendingBranchCode varchar2:=NULL,
    p_branchRequestNumber varchar2:=NULL
    RETURN customerRequest_nt
    PIPELINED
    IS
    ob customerRequest_object:=customerRequest_object(
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    condition varchar2(2000 char):=' WHERE 1=1 ';
    TYPE rectype IS RECORD(
    requestNumber VARCHAR2(32 char),
    branchRequestNumber VARCHAR2(32 char),
    branchCode VARCHAR2(50 char),
    bankCode VARCHAR2(50 char),
    sendingDate VARCHAR2(32 char),
    customerAccountNumber VARCHAR2(50 char),
    customerName VARCHAR2(200 char),
    checkbookCode VARCHAR2(50 char),
    numberOfchekbook NUMBER(2),
    sendingBranchCode VARCHAR2(50 char),
    numberOfIssued NUMBER(2)
    rec rectype;
    dDate date;
    sDate varchar2(25 char);
    TYPE curtype IS REF CURSOR; --RETURN customerRequest%rowtype;
    cur curtype;
    my_branchRequestNumber VARCHAR2(32 char);
    my_branchCode VARCHAR2(50 char);
    my_bankCode VARCHAR2(50 char);
    my_sendingDate date;
    my_customerAccountNumber VARCHAR2(50 char);
    my_checkbookCode VARCHAR2(50 char);
    my_sendingBranchCode VARCHAR2(50 char);
    BEGIN
    IF NOT (regexp_like(p_sendingDate,'^[[:digit:]]{4}/[[:digit:]]{2}/[[:digit:]]{2}$')
    OR regexp_like(p_sendingDate,'^[[:digit:]]{4}/[[:digit:]]{2}/[[:digit:]]{2}[[:space:]]{1}[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}$')) THEN
    RAISE_APPLICATION_ERROR(-20000,cbdpkg.get_e_m(-1,5));
    ELSIF (p_sendingDate IS NOT NULL) THEN
    dDate:=TO_DATE(p_sendingDate,'YYYY/MM/DD hh24:mi:ss','nls_calendar=persian');
    dDate:=trunc(dDate);
    sDate:=TO_CHAR(dDate,'YYYY/MM/DD hh24:mi:ss');
    condition:=condition|| ' AND ' || 'sendingDate='||'TO_DATE('''||sDate||''',''YYYY/MM/DD hh24:mi:ss'''||')';
    END IF;
    IF (p_requestNumber IS NOT NULL) AND (cbdpkg.isspace(p_requestNumber)=0) THEN
    condition:=condition|| ' AND ' || ' requestNumber='||p_requestNumber;
    END IF;
    IF (p_bankCode IS NOT NULL) AND (cbdpkg.isspace(p_bankCode)=0) THEN
    condition:=condition|| ' AND ' || ' bankCode='''||p_bankCode||'''';
    END IF;
    IF (p_branchCode IS NOT NULL) AND (cbdpkg.isspace(p_branchCode)=0) THEN
    condition:=condition|| ' AND ' || ' branchCode='''||p_branchCode||'''';
    END IF;
    IF (p_numberOfchekbook IS NOT NULL) AND (cbdpkg.isspace(p_numberOfchekbook)=0) THEN
    condition:=condition|| ' AND ' || ' numberOfchekbook='''||p_numberOfchekbook||'''';
    END IF;
    IF (p_customerAccountNumber IS NOT NULL) AND (cbdpkg.isspace(p_customerAccountNumber)=0) THEN
    condition:=condition|| ' AND ' || ' customerAccountNumber='''||p_customerAccountNumber||'''';
    END IF;
    IF (p_customerName IS NOT NULL) AND (cbdpkg.isspace(p_customerName)=0) THEN
    condition:=condition|| ' AND ' || ' customerName like '''||'%'||p_customerName||'%'||'''';
    END IF;
    IF (p_checkbookCode IS NOT NULL) AND (cbdpkg.isspace(p_checkbookCode)=0) THEN
    condition:=condition|| ' AND ' || ' checkbookCode='''||p_checkbookCode||'''';
    END IF;
    IF (p_sendingBranchCode IS NOT NULL) AND (cbdpkg.isspace(p_sendingBranchCode)=0) THEN
    condition:=condition|| ' AND ' || ' sendingBranchCode='''||p_sendingBranchCode||'''';
    END IF;
    IF (p_branchRequestNumber IS NOT NULL) AND (cbdpkg.isspace(p_branchRequestNumber)=0) THEN
    condition:=condition|| ' AND ' || ' branchRequestNumber='''||p_branchRequestNumber||'''';
    END IF;
    dbms_output.put_line(condition);
    OPEN cur FOR 'SELECT branchRequestNumber,
    branchCode,
    bankCode,
    sendingDate,
    customerAccountNumber ,
    checkbookCode ,
    sendingBranchCode
    FROM customerRequest '|| condition ;
    LOOP
    FETCH cur INTO my_branchRequestNumber,
    my_branchCode,
    my_bankCode,
    my_sendingDate,
    my_customerAccountNumber ,
    my_checkbookCode ,
    my_sendingBranchCode;
    EXIT WHEN (cur%NOTFOUND) OR (cur%NOTFOUND IS NULL);
    BEGIN
    SELECT requestNumber,
    branchRequestNumber,
    branchCode,
    bankCode,
    TO_CHAR(sendingDate,'yyyy/mm/dd','nls_calendar=persian'),
    customerAccountNumber ,
    customerName,
    checkbookCode ,
    numberOfchekbook ,
    sendingBranchCode ,
    numberOfIssued INTO rec FROM customerRequest FOR UPDATE NOWAIT;
    --problem point is this
    EXCEPTION
    when no_data_found then
    null;
    END ;
    ob.requestNumber:=rec.requestNumber ;
    ob.branchRequestNumber:=rec.branchRequestNumber ;
    ob.branchCode:=rec.branchCode ;
    ob.bankCode:=rec.bankCode ;
    ob.sendingDate :=rec.sendingDate;
    ob.customerAccountNumber:=rec.customerAccountNumber ;
    ob.customerName :=rec.customerName;
    ob.checkbookCode :=rec.checkbookCode;
    ob.numberOfchekbook:=rec.numberOfchekbook ;
    ob.sendingBranchCode:=rec.sendingBranchCode ;
    ob.numberOfIssued:=rec.numberOfIssued ;
    PIPE ROW(ob);
    IF (cur%ROWCOUNT>500) THEN
    CLOSE cur;
    RAISE_APPLICATION_ERROR(-20000,cbdpkg.get_e_m(-1,4));
    EXIT;
    END IF;
    END LOOP;
    CLOSE cur;
    RETURN;
    END;

    Now what exactly would be the point of putting a SELECT FOR UPDATE in an autonomous transaction?
    I think OP should start by considering why he has a function with an undesirable side effect in the first place.

Maybe you are looking for