title: Format Phone Number in a Table in Oracle
body: <p>I am new to SQL as well as Oracle. I was playing with Oracle. I tried to have a constraint on phone number so it only allows the phone number to be inserted in a specific way.</p>
  
  <p><strong>Below is my table:</strong></p>
  
  <pre><code>CREATE TABLE FIRSTTRY(
  USERID CHAR(9) NOT NULL,
  USERNAME VARCHAR(20) NOT NULL,
  EMAILADDRESS VARCHAR(40),
  PHONENUMBER VARCHAR(12),
  PROFILEPICTURE BLOB,
  PRIMARY KEY(USERID)
  );
  </code></pre>
  
  <p>I put the constraint on phone number like this:</p>
  
  <pre><code>ALTER TABLE FIRST_TRY
  ADD CONSTRAINT FIRSTTRY_PHONENUMBER CHECK 
  (PHONENUMBER LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]' 
  OR PHONENUMBER LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' 
  OR PHONENUMBER LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9]');
  </code></pre>
  
  <p>I am inserting the values to the table like this:</p>
  
  <pre><code>INSERT INTO FIRST_TRY VALUES (1,'ABCD','ABCD@YAHOO.COM','0504562893',NULL);
  </code></pre>
  
  <p>But it gives me an error:
  <strong>Here is the error:</strong></p>
  
  <pre><code>02290. 00000 -  "check constraint (%s.%s) violated"
  *Cause:    The values being inserted do not satisfy the named check
  
  *Action:   do not insert values that violate the constraint.
  </code></pre>
  
  <p>Any ideas, suggestions?</p>