Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <pre><code>SELECT c1 FROM t1 WHERE substr(c1,1,1) IN ('A','B','C','D', 'E','F','G','H', 'I','J','K','L', 'M','N','O','P', 'Q','R','S','T', 'U','V','W','X', 'Y','Z') AND substr(c1,2,1) IN ('A','B','C','D', 'E','F','G','H', 'I','J','K','L', 'M','N','O','P', 'Q','R','S','T', 'U','V','W','X', 'Y','Z') AND substr(c1,3,1) IN ('1','2','3','4') / </code></pre> <p>If you want also to match lower letters, then apply the upper() function to the 2 first substr(): eg. where upper(substr(c1,1,1)) in ...</p> <p><strong>Performance</strong></p> <p>I tested the Performance of the query with regexp_like and without. As you can see the query without the regexp_like function was 100% faster. (Note. Both querys did a soft-parse)</p> <pre><code>SQL&gt; select count(*) from t1; COUNT(*) ---------- 458752 Elapsed: 00:00:00.02 SQL&gt; set timing off; SQL&gt; select count(*) from t1; COUNT(*) ---------- 458752 SQL&gt; set timing on; SQL&gt; select count(*) from t1 where regexp_like(c1, '[A-Z][A-Z][1-4].*'); COUNT(*) ---------- 65536 Elapsed: 00:00:02.66 SELECT count(*) FROM t1 WHERE substr(c1,1,1) IN ('A','B','C','D', 'E','F','G','H', 'I','J','K','L', 'M','N','O','P', 'Q','R','S','T', 'U','V','W','X', 'Y','Z') AND substr(c1,2,1) IN ('A','B','C','D', 'E','F','G','H', 'I','J','K','L', 'M','N','O','P', 'Q','R','S','T', 'U','V','W','X', 'Y','Z') AND substr(c1,3,1) IN ('1','2','3','4') 18 / COUNT(*) ---------- 65536 Elapsed: 00:00:01.15 SQL&gt; </code></pre> <p><strong>Second Method</strong></p> <p><strong>Get the ascii values of A,Z,1 and 4</strong></p> <pre><code>SQL&gt; select ascii('A') from dual; ASCII('A') ---------- 65 SQL&gt; select ascii('Z') from dual; ASCII('Z') ---------- 90 SQL&gt; select ascii('1') from dual; ASCII('1') ---------- 49 SQL&gt; select ascii('4') from dual; ASCII('4') ---------- 52 </code></pre> <p><strong>Now you can write your statement a lot shorter</strong></p> <pre><code>SELECT count(* ) FROM t1 WHERE ascii(substr(c1,1,1)) BETWEEN 65 AND 90 AND ascii(substr(c1,2,1)) BETWEEN 65 AND 90 AND ascii(substr(c1,3,1)) BETWEEN 49 AND 52 / </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload