Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Name

Vertical Bar (|) — Delimits alternative possibilities

Synopsis

The vertical bar (|) is known as the alternation operator. It delimits, or separates, alternative subexpressions that are equally acceptable.

For example, the expression in the following query extracts the name of a fruit from a sentence. In this example the fruit is 'apple', but any of the three listed fruits: 'apple', 'apricot', or 'orange' is equally acceptable as a match:

SELECT REGEXP_SUBSTR(
   'An apple a day keeps the doctor away.',
   'apple|apricot|orange')
FROM dual;

apple

It’s usually wise to constrain your alternations using parentheses. For example, to modify the previous example to return the entire string, you could use:

SELECT REGEXP_SUBSTR(
   'An apple a day keeps the doctor away.',
   'An apple a day keeps the doctor away.' ||
   '|An apricot a day keeps the doctor away.' ||
   '|An orange a day keeps the doctor away.')
FROM dual;

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint