SQL>
SQL> -- A function using the LIKE operator to return a phone number's area code.
SQL>
SQL> CREATE OR REPLACE FUNCTION area_code (phone_number IN VARCHAR2)
2 RETURN VARCHAR2 AS
3 BEGIN
4 IF phone_number LIKE '___-___-____' THEN
5
6 RETURN SUBSTR(phone_number,1,3);
7 ELSE
8 --there is no area code
9 RETURN 'none';
10 END IF;
11 END;
12 /
Function created.
SQL>
SQL>
SQL> select area_code('123456789') from dual;
AREA_CODE('123456789')
--------------------------------------------------------------------------------
none
SQL>
SQL>
SQL> select area_code('123-456-7890') from dual;
|