What   regexp_like do

Hi ,
I am using oracle 10g
there is one query in my code like
select * from tab
where group_id = 1000
and
regexp_like(group_desc,'(^US*)|(^WW*)')
My question is what regexp_like(group_desc,'(^US*)|(^WW*)') will do

Ganesh Srivatsav wrote:
The regexp_like condition you have in your query is same as
WHERE group_desc like 'US%'
OR group_desc like 'WW%'G.not true, the second character is optional in the regexp.
SQL> with t as (select 'US' group_desc from dual
  2             union all
  3             select 'UB' from dual
  4             union all
  5             select 'W' from dual
  6             union all
  7             select 'WWaaahh' from dual
  8             union all
  9             select 'USSSS' from dual)
10  select *
11    from t
12   where regexp_like(group_desc,'(^US*)|(^WW*)') ;
GROUP_DESC
US
UB
W
WWaaahh
USSSS
5 rows selected.
Elapsed: 00:00:00.00
SQL> with t as (select 'US' group_desc from dual
  2             union all
  3             select 'UB' from dual
  4             union all
  5             select 'W' from dual
  6             union all
  7             select 'WWaaahh' from dual
  8             union all
  9             select 'USSSS' from dual)
10  select *
11    from t
12   WHERE group_desc like 'US%'
13        OR group_desc like 'WW%';
GROUP_DESC
US
WWaaahh
USSSS
3 rows selected.

Similar Messages

  • REGEXP_LIKE help with literal single-quote

    I'm trying to write a check constraint to validate email addresses that may include an apostrophe in the email address. Such as joe.o'[email protected] Here is my sample setup:
    create table emails
    ( email_address varchar2(150)
    insert into emails values('[email protected]') ;
    insert into emails values('[email protected]') ;
    insert into emails values('joey.o''[email protected]') ;
    commit;
    sql> select * from emails;
    EMAIL_ADDRESS
    [email protected]
    [email protected]
    joey.o'[email protected]
    alter table emails add constraint email_address_format_ck
        CHECK ( REGEXP_LIKE ( email_address, '^[a-z0-9._%-]\'?+@[a-z0-9._%-]+\.mil$','c'));
    ERROR at line 2:
    ORA-00911: invalid characterIt doesn't like *\'?*
    My understanding is this means one or more single-quotes. Anyone know the correct syntax to accept apostrophes?

    Hi,
    jimmyb wrote:
    ... insert into emails values('joey.o''[email protected]') ;
    That's the correct way (actually, that's one correct way) to include a single-quote in a string literal: use 2 single-quotes in a row.
    ... alter table emails add constraint email_address_format_ck
    CHECK ( REGEXP_LIKE ( email_address, '^[a-z0-9._%-]\'?+@[a-z0-9._%-]+\.mil$','c'));Here, the 2nd argument to REGEXP_LIKE is a string literal, just like 'joey.o''[email protected]' was a string literal.
    To include a single-quote in the middle of this string literal, do the same thing you did before: use 2 of them in a row:
    CHECK ( REGEXP_LIKE ( email_address, '^[a-z0-9._%''-]+@[a-z0-9._%-]+\.mil$','c'));There were a couple of other problems, too.
    I'm sure you meant for the apostrophe to be inside the square brackets. Inside square brackets, \ does not function as an escape character. (Actually, single-quote has no special meaning in regular expressions, so there's no need to escape it anyway.)
    I'm not sure what the '?' mark was doing; I left it out.
    Of course, you'll have trouble adding the CHECK constraint if any existing rows violate it.
    Edited by: Frank Kulash on Feb 10, 2012 6:52 PM

  • 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

  • REGEXP_LIKE not returning expected results

    My first attempt at REGEXP_LIKE and I'm obviously missing something. I've tried several suggestions I found in the forum but cannot get the correct results. I need the following query to return only those rows containing only alphabetic characters (no numbers). What I get are rows containing letters and numbers.
    Any help will be greatly appreciated!
    Randy
    SELECT order_number
    FROM order_table
    where REGEXP_LIKE(order_number,'[a-z A-Z]')

    check below the various options which you can use to search different elements
    Character Class   Syntax Meaning
    [:alnum:]             All alphanumeric characters
    [:alpha:]              All alphabetic characters
    [:blank:]              All blank space characters
    [:cntrl:]                All control characters (nonprinting)
    [:digit:]                All numeric digits
    [:graph:]             All [:punct:], [:upper:], [:lower:], and [:digit:] characters
    [:lower:]              All lowercase alphabetic characters
    [:print:]               All printable characters
    [:punct:]              All punctuation characters
    [:space:]             All space characters (nonprinting)
    [:upper:]             All uppercase alphabetic characters
    [:xdigit:]              All valid hexadecimal characters

  • Tuning regexp_like

    the below query is performing slow. it takes upto 3.5 seconds
    the background:the output should have records that start with what the end user enters(query text)
    if no such records are found display records that have the query text anywhere in them
    SELECT PROD_DETAILS,SIGN,ROWNUM FROM( SELECT ROWNUM,PROD_DETAILS,SIGN,
    (CASE WHEN REGEXP_LIKE(PROD_DETAILS,'^ups','i') THEN '1' ELSE '2' END) AS
    SIGN2 FROM (SELECT  ROWNUM,PROD_DETAILS,SIGN FROM 
    MV_PROD_SEARCH_DET2 a WHERE REGEXP_LIKE(PROD_DETAILS,'ups','i'))
    order by SIGN2,SIGN desc) where rownum<15the database version is
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    "CORE     10.2.0.1.0     Production"
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Productionthe parameters relevant to optimizer are as follows
    NAME                                               TYPE        VALUE                                                                                         
    optimizer_dynamic_sampling                         integer     2                                                                                             
    optimizer_features_enable                          string      10.2.0.1                                                                                      
    optimizer_index_caching                            integer     0                                                                                             
    optimizer_index_cost_adj                           integer     100                                                                                           
    optimizer_mode                                     string      ALL_ROWS                                                                                      
    optimizer_secure_view_merging                      boolean     TRUE                                                                                          
    SQL>sho parameterdb_file_multi
    NAME                                               TYPE        VALUE                                                                                         
    db_file_multiblock_read_count                      integer     16                                                                                            
    SQL>sho parameter db_block_size
    NAME                                               TYPE        VALUE                                                                                         
    db_block_size                                      integer     8192                                                                                          
    SQL>sho parameter cursor_sharing
    NAME                                               TYPE        VALUE                                                                                         
    cursor_sharing                                     string      EXACT                                                                                         
    SQL>column sname format a20
    SQL>column pname format a20
    SQL>column pval2 format a20
    SQL>select
                   sname
                 , pname
                 , pval1
                 , pval2
        FROM
                 sys.aux_stats$;     
    SNAME                PNAME                     PVAL1 PVAL2             
    SYSSTATS_INFO        STATUS                          COMPLETED           
    SYSSTATS_INFO        DSTART                          11-23-2011 03:53    
    SYSSTATS_INFO        DSTOP                           11-23-2011 03:53    
    SYSSTATS_INFO        FLAGS                         1                     
    SYSSTATS_MAIN        CPUSPEEDNW           1618.384401                     
    SYSSTATS_MAIN        IOSEEKTIM                    10                     
    SYSSTATS_MAIN        IOTFRSPEED                 4096                     
    SYSSTATS_MAIN        SREADTIM                                            
    SYSSTATS_MAIN        MREADTIM                                            
    SYSSTATS_MAIN        CPUSPEED                                            
    SYSSTATS_MAIN        MBRC                                                
    SYSSTATS_MAIN        MAXTHR                                              
    SYSSTATS_MAIN        SLAVETHR                                            
    ------------------------------SQL TUNING ADVISOR---------------------------------
    ------------------------------SQL TUNING ADVISOR---------------------------------
    GENERAL INFORMATION SECTION
    Tuning Task Name                  : staName79970
    Tuning Task Owner                 : LOOKING4
    Tuning Task ID                    : 13518
    Scope                             : COMPREHENSIVE
    Time Limit(seconds)               : 1800
    Completion Status                 : COMPLETED
    Started at                        : 11/29/2012 15:09:57
    Completed at                      : 11/29/2012 15:09:58
    Number of SQL Restructure Findings: 2
    Schema Name: LOOKING4
    SQL ID     : 0b4qbmsn9b61q
    SQL Text   : SELECT PROD_DETAILS,SIGN,ROWNUM FROM( SELECT
                 ROWNUM,PROD_DETAILS,SIGN,
                  (CASE WHEN REGEXP_LIKE(PROD_DETAILS,'^ups','i') THEN '1' ELSE
                 '2' END) AS
                  SIGN2 FROM (SELECT  ROWNUM,PROD_DETAILS,SIGN FROM 
                  MV_PROD_SEARCH_DET2 WHERE REGEXP_LIKE(PROD_DETAILS,'ups','i'))
                  order by SIGN2,SIGN desc) where rownum<15
    FINDINGS SECTION (2 findings)
    1- Restructure SQL finding (see plan 1 in explain plans section)
      The predicate  REGEXP_LIKE ("MV_PROD_SEARCH_DET2"."PROD_DETAILS",'ups','i')
      used at line ID 7 of the execution plan contains an expression on indexed
      column "PROD_DETAILS". This expression prevents the optimizer from selecting
      indices on table "LOOKING4"."MV_PROD_SEARCH_DET2".
      Recommendation
      - Rewrite the predicate into an equivalent form to take advantage of
        indices. Alternatively, create a function-based index on the expression.
      Rationale
        The optimizer is unable to use an index if the predicate is an inequality
        condition or if there is an expression or an implicit data type conversion
        on the indexed column.
    2- Restructure SQL finding (see plan 1 in explain plans section)
      The predicate  REGEXP_LIKE ("MV_PROD_SEARCH_DET2"."PROD_DETAILS",'ups','i')
      used at line ID 7 of the execution plan contains an expression on indexed
      column "PROD_DETAILS". This expression prevents the optimizer from selecting
      indices on table "LOOKING4"."MV_PROD_SEARCH_DET2".
      Recommendation
      - Rewrite the predicate into an equivalent form to take advantage of
        indices. Alternatively, create a function-based index on the expression.
      Rationale
        The optimizer is unable to use an index if the predicate is an inequality
        condition or if there is an expression or an implicit data type conversion
        on the indexed column.
    ADDITIONAL INFORMATION SECTION
    - The optimizer could not merge the view at line ID 5 of the execution plan.
      The optimizer cannot merge a view that contains a "ROWNUM" pseudo column.
    - The optimizer could not merge the view at line ID 2 of the execution plan.
      The optimizer cannot merge a view that contains a "ROWNUM" pseudo column.
    EXPLAIN PLANS SECTION
    1- Original
    Plan hash value: 1069350749
    | Id  | Operation                  | Name                | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT           |                     |    14 |  7350 |     3  (34)| 00:00:01 |
    |*  1 |  COUNT STOPKEY             |                     |       |       |            |          |
    |   2 |   VIEW                     |                     |    15 |  7875 |     3  (34)| 00:00:01 |
    |*  3 |    SORT ORDER BY STOPKEY   |                     |    15 |  7875 |     3  (34)| 00:00:01 |
    |   4 |     COUNT                  |                     |       |       |            |          |
    |   5 |      VIEW                  |                     |    15 |  7875 |     2   (0)| 00:00:01 |
    |   6 |       COUNT                |                     |       |       |            |          |
    |*  7 |        MAT_VIEW ACCESS FULL| MV_PROD_SEARCH_DET2 |    15 |   630 |     2   (0)| 00:00:01 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$1
       2 - SEL$2 / from$_subquery$_001@SEL$1
       3 - SEL$2
       5 - SEL$3 / from$_subquery$_002@SEL$2
       6 - SEL$3
       7 - SEL$3 / MV_PROD_SEARCH_DET2@SEL$3
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM<15)
       3 - filter(ROWNUM<15)
       7 - filter( REGEXP_LIKE ("PROD_DETAILS",'ups','i'))
    Column Projection Information (identified by operation id):
       1 - "PROD_DETAILS"[VARCHAR2,1000], "SIGN"[VARCHAR2,42], ROWNUM[4]
       2 - "PROD_DETAILS"[VARCHAR2,1000], "SIGN"[VARCHAR2,42]
       3 - (#keys=2) CASE  WHEN  REGEXP_LIKE ("PROD_DETAILS",'^ups','i') THEN '1' ELSE '2'
           END [1], INTERNAL_FUNCTION("SIGN")[42], "PROD_DETAILS"[VARCHAR2,1000]
       4 - "PROD_DETAILS"[VARCHAR2,1000], "SIGN"[VARCHAR2,42]
       5 - "PROD_DETAILS"[VARCHAR2,1000], "SIGN"[VARCHAR2,42]
       6 - "PROD_DETAILS"[VARCHAR2,1000], "SIGN"[VARCHAR2,42]
       7 - "PROD_DETAILS"[VARCHAR2,1000], "SIGN"[VARCHAR2,42]
    --------------------------------THE BELOW IS THE AUTOTRACE OUTPUT----------------------
    --------------------------------THE BELOW IS THE AUTOTRACE OUTPUT----------------------
    Autotrace Enabled
    Shows the execution plan as well as statistics of the statement.
    Plan hash value: 1069350749
    | Id  | Operation                  | Name                | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT           |                     |    14 |  7350 |     3  (34)| 00:00:01 |
    |*  1 |  COUNT STOPKEY             |                     |       |       |            |          |
    |   2 |   VIEW                     |                     |    15 |  7875 |     3  (34)| 00:00:01 |
    |*  3 |    SORT ORDER BY STOPKEY   |                     |    15 |  7875 |     3  (34)| 00:00:01 |
    |   4 |     COUNT                  |                     |       |       |            |          |
    |   5 |      VIEW                  |                     |    15 |  7875 |     2   (0)| 00:00:01 |
    |   6 |       COUNT                |                     |       |       |            |          |
    |*  7 |        MAT_VIEW ACCESS FULL| MV_PROD_SEARCH_DET2 |    15 |   630 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM<15)
       3 - filter(ROWNUM<15)
       7 - filter( REGEXP_LIKE ("PROD_DETAILS",'ups','i'))
       Statistics
                  54  recursive calls
                  20  db block gets
                  29  consistent gets
                   0  physical reads
                4588  redo size
                 552  bytes sent via SQL*Net to client
                 234  bytes received via SQL*Net from client
                   1  SQL*Net roundtrips to/from client
                   1  sorts (memory)
                   0  sorts (disk)
    Query Run In:Query Result 2------------------------------the below is explain plan output---------------------------------------
    ------------------------------the below is explain plan output---------------------------------------
    Plan hash value: 103984305
    | Id  | Operation         | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |             |     8 | 88648 |     2   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| PLAN_TABLE$ |     8 | 88648 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("STATEMENT_ID"='MyPlan3')
    Note
       - dynamic sampling used for this statement
    ------------------------------the below is tkprof output---------------------------------------
    ------------------------------the below is tkprof output---------------------------------------
    TKPROF: Release 10.2.0.1.0 - Production on Thu Nov 29 16:40:00 2012
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Trace file: c:\oracle\product\10.2.0\db_1\RDBMS\trace\orcl_ora_684.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    alter session set sql_trace=true
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        1      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    select default$
    from
    col$ where rowid=:1
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          2          0           1
    total        3      0.01       0.00          0          2          0           1
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS   (recursive depth: 1)
    Rows     Row Source Operation
          1  TABLE ACCESS BY USER ROWID COL$ (cr=1 pr=0 pw=0 time=35 us)
    SELECT PROD_DETAILS,SIGN,ROWNUM FROM( SELECT ROWNUM,PROD_DETAILS,SIGN,
    (CASE WHEN REGEXP_LIKE(PROD_DETAILS,'^ups','i') THEN '1' ELSE '2' END) AS
    SIGN2 FROM (SELECT  ROWNUM,PROD_DETAILS,SIGN FROM
    orcl.MV_PROD_SEARCH_DET2 WHERE REGEXP_LIKE(PROD_DETAILS,'ups','i'))
    order by SIGN2,SIGN desc) where rownum<15
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.67       0.74          0        532          0          14
    total        4      0.67       0.75          0        532          0          14
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows     Row Source Operation
         14  COUNT STOPKEY (cr=532 pr=0 pw=0 time=748169 us)
         14   VIEW  (cr=532 pr=0 pw=0 time=748152 us)
         14    SORT ORDER BY STOPKEY (cr=532 pr=0 pw=0 time=748135 us)
         95     COUNT  (cr=532 pr=0 pw=0 time=216517 us)
         95      VIEW  (cr=532 pr=0 pw=0 time=216038 us)
         95       COUNT  (cr=532 pr=0 pw=0 time=215556 us)
         95        MAT_VIEW ACCESS FULL MV_PROD_SEARCH_DET2 (cr=532 pr=0 pw=0 time=214981 us)
    alter session set sql_trace=FALSE
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        2      0.00       0.00          0          0          0           0
    Execute      2      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        4      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    alter session set sql_trace=TRUE
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        1      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    SELECT NAME NAME_COL_PLUS_SHOW_PARAM,DECODE(TYPE,1,'boolean',2,'string',3,
      'integer',4,'file',5,'number',        6,'big integer', 'unknown') TYPE,
      DISPLAY_VALUE VALUE_COL_PLUS_SHOW_PARAM
    FROM
    V$PARAMETER WHERE UPPER(NAME) LIKE UPPER('%SQL_TRA%') ORDER BY
      NAME_COL_PLUS_SHOW_PARAM,ROWNUM
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.01          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.00       0.00          0          0          0           1
    total        4      0.01       0.01          0          0          0           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows     Row Source Operation
          1  SORT ORDER BY (cr=0 pr=0 pw=0 time=2594 us)
          1   COUNT  (cr=0 pr=0 pw=0 time=2555 us)
          1    HASH JOIN  (cr=0 pr=0 pw=0 time=2537 us)
          1     FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=1082 us)
       1381     FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=4153 us)
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        4      0.01       0.02          0          0          0           0
    Execute      6      0.00       0.00          0          0          0           0
    Fetch        4      0.67       0.75          0        532          0          15
    total       14      0.68       0.77          0        532          0          15
    Misses in library cache during parse: 3
    Misses in library cache during execute: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          2          0           1
    total        3      0.01       0.00          0          2          0           1
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
        6  user  SQL statements in session.
        1  internal SQL statements in session.
        7  SQL statements in session.
        0  statements EXPLAINed in this session.
    Trace file: c:\oracle\product\10.2.0\db_1\RDBMS\trace\orcl_ora_684.trc
    Trace file compatibility: 10.01.00
    Sort options: default
          90  sessions in tracefile.
           6  user  SQL statements in trace file.
           1  internal SQL statements in trace file.
           7  SQL statements in trace file.
           6  unique SQL statements in trace file.
       47071  lines in trace file.
          55  elapsed seconds in trace file.
    sql>sho parameter statistics_level
    NAME                                               TYPE        VALUE                                                                                         
    statistics_level                                   string      TYPICAL                                                                                       
    timed_statistics                       string     true
    --------------------------The DBMS_XPLAN.DISPLAY_CURSOR output:-----------------------------
    --------------------------The DBMS_XPLAN.DISPLAY_CURSOR output:-----------------------------
    SELECT /*+ gather_plan_statistics */ PROD_DETAILS,SIGN,ROWNUM FROM( SELECT ROWNUM,PROD_DETAILS,SIGN,
    (CASE WHEN REGEXP_LIKE(PROD_DETAILS,'^ups','i') THEN '1' ELSE '2' END) AS
    SIGN2 FROM (SELECT  ROWNUM,PROD_DETAILS,SIGN FROM 
    MV_PROD_SEARCH_DET2 WHERE REGEXP_LIKE(PROD_DETAILS,'ups','i'))
    order by SIGN2,SIGN desc) where rownum<15;
    select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    SQL_ID  16r9mtafh4x0h, child number 0
    SELECT /*+ gather_plan_statistics */ PROD_DETAILS,SIGN,ROWNUM FROM( SELECT ROWNUM,PROD_DETAILS,SIGN,  (CASE WHEN
    REGEXP_LIKE(PROD_DETAILS,'^ups','i') THEN '1' ELSE '2' END) AS   SIGN2 FROM (SELECT  ROWNUM,PROD_DETAILS,SIGN FROM   
    MV_PROD_SEARCH_DET2 WHERE REGEXP_LIKE(PROD_DETAILS,'ups','i'))   order by SIGN2,SIGN desc) where rownum<15
    Plan hash value: 1069350749
    | Id  | Operation                  | Name                | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |*  1 |  COUNT STOPKEY             |                     |      1 |        |     14 |00:00:00.73 |     532 |       |       |          |
    |   2 |   VIEW                     |                     |      1 |     15 |     14 |00:00:00.73 |     532 |       |       |          |
    |*  3 |    SORT ORDER BY STOPKEY   |                     |      1 |     15 |     14 |00:00:00.73 |     532 |  9216 |  9216 | 8192  (0)|
    |   4 |     COUNT                  |                     |      1 |        |     95 |00:00:00.22 |     532 |       |       |          |
    |   5 |      VIEW                  |                     |      1 |     15 |     95 |00:00:00.22 |     532 |       |       |          |
    |   6 |       COUNT                |                     |      1 |        |     95 |00:00:00.22 |     532 |       |       |          |
    |*  7 |        MAT_VIEW ACCESS FULL| MV_PROD_SEARCH_DET2 |      1 |     15 |     95 |00:00:00.22 |     532 |       |       |          |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM<15)
       3 - filter(ROWNUM<15)
       7 - filter( REGEXP_LIKE ("PROD_DETAILS",'ups','i',HEXTORAW('8CE32E5554A4C4010000000000000000000000000000000013000000ACE32E55
                  02000000000000000000000085000000') ))
    the previous query used to be
    SELECT count(*) FROM MV_PROD_SEARCH_DET2 WHERE REGEXP_LIKE(PROD_DETAILS,'^" + prefixText + "','i')
    if the above returns less than 7
    SELECT PROD_DETAILS,SIGN FROM (SELECT PROD_DETAILS,SIGN FROM MV_PROD_SEARCH_DET2 order by sign desc) WHERE CATSEARCH(PROD_DETAILS,'" + prefixText + "*',NULL)> 0 AND ROWNUM <= 15
    else( if it returns more than 7)
    select prod_details,sign from(select prod_details,sign from mv_prod_search_det2 where regexp_like(prod_details,'^u','i') order by length(prod_details)) where rownum<15
    we reduced it to the query on top of the page
    I'm looking forward for suggestions how to improve the performance of this statement.
    thanks in advance
    lastly
    few records in the materialized view
    something     K-14483
    anything     S-99
    everything     C-12065
    desc mv_prod_search_det2
    Name         Null Type          
    PROD_DETAILS      VARCHAR2(1000)
    SIGN              VARCHAR2(42)   Edited by: 946207 on Nov 29, 2012 6:59 PM

    REGEXP_LIKE is by nature slower than LIKE. Now in your case all you want is to check if PROD_DETAILS starts with UPS regardless of case, right? So use:
    SELECT  PROD_DETAILS,
            SIGN,
            ROWNUM
      FROM  (
             SELECT  ROWNUM,
                     PROD_DETAILS,
                     SIGN,
                     CASE
                       WHEN LOWER(PROD_DETAILS) LIKE 'ups%' THEN '1'
                       ELSE '2'
                     END AS SIGN2
              FROM  (
                     SELECT  ROWNUM,
                             PROD_DETAILS,
                             SIGN
                       FROM  MV_PROD_SEARCH_DET2 a
                       WHERE LOWER(PROD_DETAILS) LIKE 'ups%'
              ORDER BY SIGN2,
                       SIGN desc
    WHERE ROWNUM < 15
    /And, if needed, you can create function based index on LOWER(PROD_DETAILS), then oprimizer would use it (if needed). Also, SIGN is a keyword and it is not a good idea to use it as column alias. And ROWNUM in inner SELECT is not ROWNUM in outer SELECT. If you want to carry it to outer level you need to alias inner ROWNUM and use that alias in outer SELECT.
    SY.

  • Doubt in Regexp_like ?

    Hi i am using the following query
    select m from
    (select '[email protected]' m from dual union all
    select '[email protected]' m from dual union all
    select 'dfdf3' m from dual union all
    select 'dfff' m from dual
    where regexp_like(m,'\w+@\w+(\.\w+)+')I want only on email pattern string.
    I think what i written it is correct. but it is not comming.
    I need the output.
    [email protected]
    [email protected] help me.
    kanish

    Kanish wrote:
    Nothing different i doing same query.
    my version banner
    Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Prod 
    PL/SQL Release 10.1.0.2.0 - Production 
    CORE 10.1.0.2.0 Production 
    TNS for 32-bit Windows: Version 10.1.0.2.0 - Production 
    NLSRTL Version 10.1.0.2.0 - Production I am running in isql*plus 10g.
    kanishWhat if you run it in SQL*Plus rather than iSQL*Plus?
    10.1 should be ok with that code, though you really should consider upgrading to at least 10.2.0.4 as many bug fixes were done.

  • Address Matching Using REGEXP_LIKE

    Hey all,
    I am a newbie to REGEXP and have an issue where I have 2 spatial tables, for each object in table1 and am doing an SDO_NN to find the nearest 2 objects in table2. I also have an address column for each spatial table. I am trying to compare address1 (from table1) to both addresses (address2 from table2) to find the most likely match candidate.
    After reading about REGEXP it seemed to me the REGEXP_LIKE was most likely best way of achieving my matches.
    What I have come up with works alot of times but not always and I don't quite understand it.
    Here is an example where I don't understand what is going on where I used REGEXP_LIKE as this
    REGEXP_LIKE(address1,replace(address2,' ','|'))
    SELECT
      id, 
      address1,
      address2,
      CASE
        WHEN address1=address2 THEN 'EXACT MATCH'
        WHEN REGEXP_LIKE(address1,replace(address2,' ','|')) THEN 'PROBABLE MATCH'
        ELSE 'NON MATCH'
      END AS TEST
    FROM
      SELECT
        1 ID, '930 OLD STEESE HWY' address1, '930 OLD STEESE HWY' address2
      FROM
        DUAL 
      UNION SELECT
        3 ID, '930 OLD STEESE HWY' address1, '920 OLD STEESE HWY' address2
      FROM
        DUAL   
      UNION SELECT
        3 ID, '930 OLD STEESE HWY' address1, '99 COLLEGE RD' address2
      FROM
        DUAL   
      UNION SELECT
        4 ID, '930 OLD STEESE HWY' address1, '80 5TH ST' address2
      FROM
        DUAL     
    RESULTS
    ID ADDRESS1            ADDRESS2            TEST
    1  930 OLD STEESE HWY  930 OLD STEESE HWY  EXACT MATCH
    2  930 OLD STEESE HWY  920 OLD STEESE HWY  PROBABLE MATCH
    3  930 OLD STEESE HWY  99 COLLEGE RD       NON MATCH
    4  930 OLD STEESE HWY  80 5TH ST           PROBABLE MATCHI am really confused as to the 4th line in the results?
    Any thoughts and or suggestions?
    Appreciate it!
    Cheers,
    Eric

    Second and fourth row match because there is a word in address2 that is present (at least as substring) in address1: For the fourth row ST is substring of STEESE.
    If you want a PROBALE MATCH only when there's a word in address2 that is present as a word in address1, you can change this way:
    SQL> SELECT
      2    id,
      3    address1,
      4    address2,
      5    CASE
      6      WHEN address1=address2 THEN 'EXACT MATCH'
      7      WHEN REGEXP_LIKE(address1,'(^| )'||replace(address2,' ','|')||'($| )') THEN 'PROBABLE MATCH'
      8      ELSE 'NON MATCH'
      9    END AS TEST
    10  FROM
    11    (
    12    SELECT
    13      1 ID, '930 OLD STEESE HWY' address1, '930 OLD STEESE HWY' address2
    14    FROM
    15      DUAL
    16    UNION SELECT
    17      3 ID, '930 OLD STEESE HWY' address1, '920 OLD STEESE HWY' address2
    18    FROM
    19      DUAL
    20    UNION SELECT
    21      3 ID, '930 OLD STEESE HWY' address1, '99 COLLEGE RD' address2
    22    FROM
    23      DUAL
    24    UNION SELECT
    25      4 ID, '930 OLD STEESE HWY' address1, '80 5TH ST' address2
    26    FROM
    27      DUAL
    28    );
            ID ADDRESS1           ADDRESS2           TEST
             1 930 OLD STEESE HWY 930 OLD STEESE HWY EXACT MATCH
             3 930 OLD STEESE HWY 920 OLD STEESE HWY PROBABLE MATCH
             3 930 OLD STEESE HWY 99 COLLEGE RD      NON MATCH
             4 930 OLD STEESE HWY 80 5TH ST          NON MATCHIn Oracle 11g you can use REGEXP_COUNT to count the common words between address1 and address2:
      2    id,
      3    address1,
      4    address2,
      5    CASE
      6      WHEN address1=address2 THEN 'EXACT MATCH'
      7      WHEN REGEXP_LIKE(address1,'(^| )'||replace(address2,' ','|')||'($| )') THEN 'PROBABLE MATCH'
      8      ELSE 'NON MATCH'
      9    END AS TEST,
    10    regexp_count(address1,'(^| )'||replace(address2,' ','|')||'($| )') common_words
    11  FROM
    12    (
    13    SELECT
    14      1 ID, '930 OLD STEESE HWY' address1, '930 OLD STEESE HWY' address2
    15    FROM
    16      DUAL
    17    UNION SELECT
    18      3 ID, '930 OLD STEESE HWY' address1, '920 OLD STEESE HWY' address2
    19    FROM
    20      DUAL
    21    UNION SELECT
    22      3 ID, '930 OLD STEESE HWY' address1, '99 COLLEGE RD' address2
    23    FROM
    24      DUAL
    25    UNION SELECT
    26      4 ID, '930 OLD STEESE HWY' address1, '80 5TH ST' address2
    27    FROM
    28      DUAL
    29    );
            ID ADDRESS1           ADDRESS2           TEST           COMMON_WORDS
             1 930 OLD STEESE HWY 930 OLD STEESE HWY EXACT MATCH               4
             3 930 OLD STEESE HWY 920 OLD STEESE HWY PROBABLE MATCH            3
             3 930 OLD STEESE HWY 99 COLLEGE RD      NON MATCH                 0
             4 930 OLD STEESE HWY 80 5TH ST          NON MATCH                 0Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]
    Edited by: Massimo Ruocchio on Dec 29, 2009 10:48 PM
    Added regexp_count example.

  • What is the best way to do a case insensitive search?

    Hi Guys,
    hopefully a quick one, anyone know what the best way to perform a case-insensitive search is? at the moment many of our stored procedures perform selects against un-indexed fields (e.g. product title) and to avoid casing problems we have an UPPER around the field name and the variable e.g.
    AND (nvcproducttitle IS NULL OR
    UPPER(p.NVCTITLE) LIKE '%' || UPPER(nvcproducttitle) || '%')
    This seems to work just fine but on a large catalogue (10 million+) it can take 50-60 seconds to return.
    Any pointers would be appreciated,
    J

    user7186902 wrote:
    Hi Guys,
    hopefully a quick one, anyone know what the best way to perform a case-insensitive search is? at the moment many of our stored procedures perform selects against un-indexed fields (e.g. product title) and to avoid casing problems we have an UPPER around the field name and the variable e.g.
    AND (nvcproducttitle IS NULL OR
    UPPER(p.NVCTITLE) LIKE '%' || UPPER(nvcproducttitle) || '%')
    This seems to work just fine but on a large catalogue (10 million+) it can take 50-60 seconds to return.
    Any pointers would be appreciated,
    JYou could either ensure you have a function based index for your column e.g.
    create or replace index fn_idx on prodtable (upper(nvctitle));
    nb. syntax not checked
    or you could use regular expressions. REGEXP_LIKE allows for case insensitive like searches.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm#SQLRF00501

  • REGEXP_LIKE runs away when pattern is not found

    I am using the following in my pl/sql code:
    regexp_like(l_formatted, '^[\_]*([a-z0-9]+(\.|\_*)?)+@([a-z][a-z0-9\-]+(\.|\-*/.))+[a-z]{2,6}$')
    It validates e-mail addresses. When the pattern is found (the e-mail is valid) the performance is fine. When the pattern is not found the query takes at least 50 seconds and in a few cases has actually "run away". Has anyone else exprienced this problem?

    When the pattern is found (the e-mail is valid) the performance is fine. What's the execution plan?
    When the pattern is not found the query takes at least 50 seconds and in a few cases has actually "run away". Are you using Con*Text indexes?
    http://www.dba-oracle.com/t_regular_expressions_tuning_index.htm
    In some cases you can also index regex with FBI's. But regular expression are notorious for causing full-table scans on multi-million rows tables, and special care must be given to creating matching function-based indexes to keep performance at an acceptable level.
    From a performance perspective it’s important to properly index the Oracle tales so that regular expression validation does not cause problematic full-table scans. Oracle syntax allows the use of function-based indexes (FBI’s) to minimize the amount of database I/O associated with a invocation of a regular expression.
    Function-based indexes cannot work for all regular expressions, however, and it can be tricky to remove unnecessary full-table scans on some regular expressions, especially regexp_like.
    Hope this helps . . .
    Donald K. Burleson
    Oracle Press author
    Author of "Oracle Tuning: The Definitive Reference"
    http://www.rampant-books.com/book_2005_1_awr_proactive_tuning.htm

  • Regexp_like [:digit:]{10}

    hi
    i have to columns in a table of type varchar2
    having names as tel1 and tel2
    both columns contains mobile no or other land line phones no.
    occassionaly user inputs alphabets also
    in India we have ten digit format for cellno starting with 9
    i am trying to select only mobile no from col1 and col2 using regexp_like expresssion
    as follows
    SELECT LBRCODE,PRDACCTID,
    *(case when regexp_like (tel1,'^[[:digit:]{10}]') then*
    tel1
    when
    *regexp_like (tel2,'^[[:digit:]{10}]') THEN*
    TEL2
    else
    *'NOT A CELLNO'*
    END
    FROM addresses
    WHERE PRDACCTID IN (SELECT PRDACCTID FROM ac_mast
    WHERE ACCTSTAT<>3 AND PRDACCTID LIKE 'SB%')
    what is wrong that i am doing here?
    please help

    You can also use the compact (Perl-influenced) regular expression "\d", if you have 10gR2 or higher:
    test@ORA10G>
    test@ORA10G> @ver1
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    1 row selected.
    test@ORA10G>
    test@ORA10G> --
    test@ORA10G> with addresses as (
      2    select 1 lbrcode, '9876543210' tel1, '9012345678' tel2 from dual union all
      3    select 2, '9123456780', '9A76543210' from dual union all
      4    select 3, 'X876543210', '9234567890' from dual union all
      5    select 4, 'XX76543210', '9Y76543210' from dual)
      6  --
      7  SELECT lbrcode,
      8         (CASE
      9             WHEN REGEXP_LIKE (tel1, '^9\d{9}')
    10                THEN tel1
    11             WHEN REGEXP_LIKE (tel2, '^9\d{9}')
    12                THEN tel2
    13             ELSE 'NOT A CELLNO'
    14          END
    15         ) cell_num
    16    FROM addresses;
       LBRCODE CELL_NUM
             1 9876543210
             2 9123456780
             3 9234567890
             4 NOT A CELLNO
    4 rows selected.
    test@ORA10G>
    test@ORA10G>isotope

  • REGEXP_LIKE help

    Hello,
    Been scouring the web looking for some help using the REGEXP_LIKE syntax. Haven't found a precise answer, but I think I wrote my own correctly and just wanted to get some validation from other users.
    Running Oracle 10.2
    Sample Data:
    create table test(data varchar2(10));
        insert into test values('01W00012');
        insert into test values('50321070');
        insert into test values('A1391010');
        insert into test values('ZZ260010');
        insert into test values('29374C01');
        insert into test values('A938523A');
        insert into test values('23W48AC3');
        insert into test values('DKFUGHCK');
        insert into test values('09W00032');
        insert into test values('94857283');
        insert into test values('AB-29348');
        insert into test values('98W-8923');
        insert into test values('0AW00005');
        insert into test values('04300W05');
        commit;What I'm trying to do:
    I have a table containing millions of work orders. They are all of length 8. I want to find all work orders where the first 2 characters are a digit only, the third character is a 'W', and the last 5 characters are digits only. Anything else I want to throw away. I think I came up with a working expression... but I'm always hesitant when running it against millions of rows. Here was what I did:
    select * from test
        where regexp_like(data, '(^[0-9]{2}W{1}[[:digit:]]{5})');There are exactly 2 occurrences from up above that match the criteria I'm trying to meet.
    Is this expression properly written?
    Any help would be greatly appreciated.... reg expressions always make my head spin :(

    Hi,
    dvsoukup wrote:
    Running Oracle 10.2
    Sample Data: ...Thanks for posting that; it's really helpful!
    What I'm trying to do:
    I have a table containing millions of work orders. They are all of length 8. I want to find all work orders where the first 2 characters are a digit only, the third character is a 'W', and the last 5 characters are digits only. Anything else I want to throw away. I think I came up with a working expression... but I'm always hesitant when running it against millions of rows. Here was what I did:
    select * from test
    where regexp_like(data, '(^[0-9]{2}W{1}[[:digit:]]{5})');There are exactly 2 occurrences from up above that match the criteria I'm trying to meet.
    Is this expression properly written?Yes, that's a good regular expression. However, a very important thing about regular expressions is that you should only use them when you really need to. In this case, you can get the results you want more efficiently, and at least as easily, without regular expressions. Here's one way:
    SELECT  *
    FROM     test
    WHERE   TRANSLATE ( data
                , '012345678'
                , '999999999'
                )          = '99W99999'
    ;This will be more efficient than using REGEXP_LIKE, and it sounds like efficiency is important in this case.
    If you really want to use a regular expression, there are a couple of small things you can do to make it clearer. (With regular expressions, every little bit helps.)
    (a) If you're certain that data is always exactly 8 characters, then you don't need the ^ anchor at the beginning. If you want the regular expression to check that the length is 8 characters, then keep the ^ anchor at the beginning, but use a $ anchor at the end, too, as in the example below. As you posted it, the expression will be TRUE when data is longer than 8 characters, as long as the first 8 characters fit the pattern.
    (b) [0-9] is equivalent to [[:digit:]]. Either one is fine, but I find it confusing to use both in the same expression. Use one or the other in both places.
    (c) {1} is the default. I would just say 'W' instead of 'W{1}'
    (d) You don't need the parentheses in this expression. If parentheses are not needed, but they improve clarity, then it's okay to include them. In this case, I don't think they add anything.
    There are exactly 2 occurrences from up above that match the criteria I'm trying to meet.It helps if you post exactly what results you want. For example:
    DATA
    01W00012
    09W00032In this case, I found your description very clear, but it doesn't hurt to post the actual results anyway.
    Is this expression properly written?You might consider writing it this way, particularly if you think you'll need to debug it:
    SELECT  *
    FROM      test
    WHERE      REGEXP_LIKE ( data
                  , '^'          || -- beginning of string
                    '[0-9]{2}'     || -- 2 digits
                    'W'          || -- a capital W
                    '[0-9]{5}'     || -- 5 more digits
                    '$'             -- end of string
    ;As mentioned before, you only need the ^ and $ if you're not sure all the strings are exactly 8 characters.
    ... reg expressions always make my head spin All the more reason to use TRANSLATE.
    Edited by: Frank Kulash on Jul 26, 2012 2:42 PM

  • Need help on regexp_like

    Hi Folks,
    Please help me out on my requirement which is based on regexp_like
    Example:
    prod_id and prod_desc are having values like
    1,'SAMUSUNG,NOKIA'
    2,'NOKIA,SAMUSUNG,APPLE'
    3,'NOKIA,APPLE,SAMUSUNG,HTC'
    4,'SAMUSUNG,NOKIA,APPLE,HTC,CELLKON'
    I want to fetch the values of prod_id and prod_desc as
    prod_desc should have SAMSUNG AND NOKIA BUT NOT HTC
    answer is :
    1,'SAMUSUNG,NOKIA'
    2,'NOKIA,SAMUSUNG,APPLE'

    Greg.Spall wrote:
    Easy enough using the documentation as reference:
    http://docs.oracle.com/cd/B12037_01/server.101/b10759/conditions018.htm
    WITH D AS(SELECT 1 prod_id, 'SAMUSUNG,NOKIA'  prod_desc FROM DUAL UNION ALL   
        SELECT 2,'NOKIA,SAMUSUNG,APPLE' FROM DUAL UNION ALL   
        SELECT 3,'NOKIA,APPLE,SAMUSUNG,HTC' FROM DUAL UNION ALL   
        SELECT 4,'SAMUSUNG,NOKIA,APPLE,HTC,CELLKON' FROM DUAL )   
    SELECT PROD_ID,PROD_DESC FROM D   
    WHERE NOT REGEXP_LIKE ( prod_desc, '*HTC*', 'i') 
      PROD_ID PROD_DESC                     
            1 SAMUSUNG,NOKIA                 
            2 NOKIA,SAMUSUNG,APPLE           
    2 rows selected.
    What if the string contains 'AHTCK'? Would that still be excluded? or only where 'HTC' exists between the commas?
    SQL> WITH D AS(SELECT 1 prod_id, 'SAMUSUNG,NOKIA'  prod_desc FROM DUAL UNION ALL 
    2  SELECT 2,'NOKIA,SAMUSUNG,APPLE' FROM DUAL UNION ALL 
    3  SELECT 3,'NOKIA,APPLE,SAMUSUNG,HTC' FROM DUAL UNION ALL 
    4  SELECT 4,'NOKIA,SAMUSUNG,AHTCK,APPLE' FROM DUAL UNION ALL 
    5  SELECT 5,'HTC,NOKIA,SAMUSUNG,APPLE' FROM DUAL UNION ALL 
    6  SELECT 6,'NOKIA,SAMUSUNG,APPLE,HTC' FROM DUAL UNION ALL 
    7  SELECT 7,'SAMUSUNG,NOKIA,APPLE,HTC,CELLKON' FROM DUAL UNION ALL 
    8  SELECT 8,'HTC' FROM DUAL ) 
    9  SELECT PROD_ID,PROD_DESC FROM D
    10  WHERE NOT regexp_like(PROD_DESC,',HTC,')
    11    AND NOT regexp_like(PROD_DESC,'^HTC,')
    12    AND NOT regexp_like(PROD_DESC,',HTC$')
    13    AND NOT regexp_like(PROD_DESC,'^HTC$')
    14  ; 
    PROD_ID PROD_DESC
    1 SAMUSUNG,NOKIA       
    2 NOKIA,SAMUSUNG,APPLE       
    4 NOKIA,SAMUSUNG,AHTCK,APPLE

  • Help with REGEXP_LIKE

    Hi, I am on oracle 11g release 1.
    I have the following requirement.
    I need to display data the following way from the column,
    One alphabet followed by 2 digits (like A00, B20, C12), I know I have to use REGEXP_LIKE, but i am not able to get the correct result.
    my first attempt at this is
    WITH t1
    as
    (select '01G50' investor_number from dual
      union all
      select 'A00' from dual
      union all
      select 'B20' from dual
      union all
      select '1234' from dual
    select investor_number from t1
    where  REGEXP_LIKE(investor_number, '[[:alpha:]]');
    but this gives
    investor_number
    01G50
    A00
    B20
    but I want only,
    investor_number
    A00
    B20how do i do that?
    Thanks
    Billu.

    Hi, Billu,
    If you only want to consider the letters that come at the beginning of the string, then anchor the pattern to the beginning of the string, like this:
    SELECT  investor_number
    FROM     t1
    WHERE     REGEXP_LIKE ( investor_number
                  , '^[[:alpha:]][[:digit:]]{2}'
    ;You could also write it this way, for clarity:
    SELECT  investor_number
    FROM     t1
    WHERE     REGEXP_LIKE ( investor_number
                  , '^'          || -- Right at the beginning of the string, there must be
                    '[[:alpha:]]'     || -- one letter, followed by
                    '[[:digit:]]{2}'        -- two numerals
    ;It doesn't matter what (if anything) comes after the 2 digits: another digit ('B209'), a letter ('B20XYZ'), any other character ('B20-9-XYZ'), or nothing (that is, the end-of-string) are all okay.
    If you want to find strings that contain only the pattern, and nothing after that, then anchor the patttern to the end-of-string ('$') also:
    SELECT  investor_number
    FROM     t1
    WHERE     REGEXP_LIKE ( investor_number
                  , '^'          || -- Right at the beginning of the string, there must be
                    '[[:alpha:]]'     || -- one letter, followed by
                    '[[:digit:]]{2}'     || -- two numerals, and then
                    '$'             -- the string must end
    ;Edited by: Frank Kulash on Sep 7, 2010 12:48 PM

  • Help with REGEXP_LIKE statement

    Hello Experts
    I am having little problem in solving the problem with REGEXP_LIKE as shown below.
    All the records are giving me the desired result except the last one where it has alph and numeric and spaces in between.
    Can I please have the solution please. I tried with INSTR but it didn't work too.
    Thanks in advance
    Rajesh
    WITH T AS
    (SELECT '000 444$888' STUDENT_ID FROM DUAL UNION ALL
    SELECT '^^^^^^^^^^ ' STUDENT_ID FROM DUAL UNION ALL
    SELECT 'ABCDEFGH&' STUDENT_ID FROM DUAL UNION ALL
    SELECT '!@@@@@@@ ' STUDENT_ID FROM DUAL UNION ALL
    SELECT '123456*891 ' STUDENT_ID FROM DUAL UNION ALL
    SELECT 'AAA 77BBBBB ' STUDENT_ID FROM DUAL
    SELECT student_id FROM T
    WHERE not REGEXP_LIKE(trim(STUDENT_ID), '^[[:alnum:]]*$')

    Rb2000rb65 wrote:
    Thanks Sven. But as you mentioned it did not solve my problem.My first two variants didn't work? Maybe you should start again and explaining which lines you want to see, which not and why.
    So far you only mentioned, that the last line gives you trouble. Whatever that means.
    /* this is your output */
    WITH T AS
    (SELECT '000 444$888' STUDENT_ID FROM DUAL UNION ALL
    SELECT '^^^^^^^^^^ ' STUDENT_ID FROM DUAL UNION ALL
    SELECT 'ABCDEFGH&' STUDENT_ID FROM DUAL UNION ALL
    SELECT '!@@@@@@@ ' STUDENT_ID FROM DUAL UNION ALL
    SELECT '123456*891 ' STUDENT_ID FROM DUAL UNION ALL
    SELECT 'AAA 77BBBBB ' STUDENT_ID FROM DUAL
    SELECT student_id FROM T
    WHERE not REGEXP_LIKE(trim(STUDENT_ID), '^[[:alnum:]]*$')
    000 444$888
    ^^^^^^^^^^
    ABCDEFGH&
    123456*891
    AAA 77BBBBB
    /* this is my output */
    WITH T AS
    (SELECT '000 444$888' STUDENT_ID FROM DUAL UNION ALL
    SELECT '^^^^^^^^^^ ' STUDENT_ID FROM DUAL UNION ALL
    SELECT 'ABCDEFGH&' STUDENT_ID FROM DUAL UNION ALL
    SELECT '!@@@@@@@ ' STUDENT_ID FROM DUAL UNION ALL
    SELECT '123456*891 ' STUDENT_ID FROM DUAL UNION ALL
    SELECT 'AAA 77BBBBB ' STUDENT_ID FROM DUAL
    SELECT student_id FROM T
    WHERE REGEXP_LIKE(STUDENT_ID, '[^[:alnum:] ]')
    000 444$888
    ^^^^^^^^^^
    ABCDEFGH&
    123456*891 As you can see the last line is missing now. I thought that is what you wanted?
    Edited by: Sven W. on Oct 12, 2012 6:42 PM

  • Need help in REGEXP_LIKE

    Hi All,
    i need a help in REGEXP_LIKE for following condition as follows.
    a column has value as
    ALLOW
    TO ALL PERSON
    ALLOW ME
    in this i have check the following condition.
    excepted result:
    if i give
    REGEXP_LIKE(column_name,'ALL')
    Result:
    1 row selected
    if i give
    REGEXP_LIKE(column_name,'ALLOW THIS PERSON')
    Result:
    0 rows selected.
    Thanks & Regards
    Sami
    Edited by: Sami on Nov 2, 2010 6:08 PM
    Edited by: Sami on Nov 2, 2010 6:09 PM

    Please use the {noformat}{noformat}tag and post formatted data.
    For example, when you type (or copy/paste):
    {noformat}select *
    from dual;
    {noformat}
    it will appear as:select *
    from dual;
    on this forum.
    See for FAQ for more tags: http://forums.oracle.com/forums/help.jspa
    Regarding your question: what is your exect desired output? It's not 100% clear to me what you want.
    If I use your first 'example' I get three rows:SQL> -- generating sample data:
    SQL> with t as (
    2 select 'ALLOW' col from dual union
    3 select 'TO ALL PERSON' from dual union
    4 select 'ALLOW ME' from dual
    5 )
    6 --
    7 -- actueal query:
    8 --
    9 select col
    10 from t
    11 where regexp_like(col, 'ALL');
    COL
    ALLOW
    ALLOW ME
    TO ALL PERSON
    3 rows selected.

Maybe you are looking for

  • TV shows are not syncing with iCloud

    Two questions. The first is really bugging me: 1. Several years ago I purchased a series of TV shows through iTunes. When I got an iPad about a year ago, and configured all my settings, I was able to play those episdoes on that device (I presume that

  • Capture nx 2 sharpening and DNG profiles..

    I recently have had an (albeit quick) fiddle with nx 2 and was wondering if anyone else had noticed what I have... 1. The sharpening in NX2 seems to yeild much nicer details and less "criss cross" artefacts. 2. The DNG profile for nikon (in my case D

  • Third Party Interface

    Hi Experts. I want some clarification, we are implementing BPM - Solution Manager. I was checking the BPM Monitors Catalog. I didnt find any thirdparty interface monitoring. Our client has SAP and it has got some thirdparty interface such as Vertex,

  • Discoverer Desktop 10.1 and Excel

    I have a report that is creating an output of 589,000 rows. I have both Excel 2003 and 2007 loaded to my desktop. Unfortunaltey, when I export to Excel, my output file has only 65536 rows, which of course is the Excel 2003 limitation. Excel 2007 has

  • Indesign CS4 - Fehlende Fonts?

    Hallo zusammen, ein Mitarbeiter in unserem Netzwerk bekamm einen neuen Rechern. Von 2000 zu Win7. Dieser benötigt Indesign für Plakate etc. Doch auf seinem neuen Win7 Rechner werden die Plakate nicht korrekt angezeigt, siehe: Dies liegt wohl, laut fo