Grouping : REGEXP_SUBSTR « Regular Expressions Functions « Oracle PL/SQL Tutorial






SQL>
SQL> -- create demo table
SQL> create table myTable(
  2    id           NUMBER(2),
  3    value        VARCHAR(50)
  4  );

Table created.

SQL>
SQL> insert into myTable(id, value)values(1,'1234 4th St. Vancouver');

1 row created.

SQL> insert into myTable(id, value)values(2,'4 Maple Ct. New York');

1 row created.

SQL> insert into myTable(id, value)values(3,'4321 Green Blvd. London');

1 row created.

SQL> insert into myTable(id, value)values(4,'33 Third St. Toronto');

1 row created.

SQL> insert into myTable(id, value)values(5,'One First Drive. Queen');

1 row created.

SQL> insert into myTable(id, value)values(6,'1664 1/2 Springhill Ave');

1 row created.

SQL> insert into myTable(id, value)values(7,'665 Fall Ave. Linken');

1 row created.

SQL>
SQL> select * from mytable;

        ID VALUE
---------- --------------------------------------------------
         1 1234 4th St. Vancouver
         2 4 Maple Ct. New York
         3 4321 Green Blvd. London
         4 33 Third St. Toronto
         5 One First Drive. Queen
         6 1664 1/2 Springhill Ave
         7 665 Fall Ave. Linken

7 rows selected.

SQL>
SQL> SELECT value, REGEXP_SUBSTR(value,'ird|irs')
  2  FROM myTable;

VALUE                                              REGEXP_SUBSTR(VALUE,'IRD|IRS')
-------------------------------------------------- -------------------------------------------------
-
1234 4th St. Vancouver
4 Maple Ct. New York
4321 Green Blvd. London
33 Third St. Toronto                               ird
One First Drive. Queen                             irs
1664 1/2 Springhill Ave
665 Fall Ave. Linken

7 rows selected.

SQL>
SQL>
SQL>
SQL>
SQL> drop table myTable;

Table dropped.

SQL>
SQL>








18.5.REGEXP_SUBSTR
18.5.1.REGEXP_SUBSTR(x, pattern [, start [, occurrence [, match_option]]]) gets a substring of x that matches pattern, which begins at the position specified by start.
18.5.2.Regexp_Substr returns a string of data type VARCHAR2 or CLOB
18.5.3.Grouping
18.5.4.Group the letters 'ir' together by putting them in parentheses and then parenthesizing the suffix using alternation
18.5.5.Backreference
18.5.6.Search for (