-- Basic Searches

--2
SELECT product_name 
FROM   oe.product_information
WHERE  REGEXP_LIKE (product_name, 'SS[PS]/[VS]') ;

--3
COLUMN non_alpha FORMAT 9999999999
SELECT product_name, REGEXP_INSTR(product_name, '[^[:alpha:]]') non_alpha
FROM   oe.product_information ;

--4
SELECT REGEXP_SUBSTR(cust_email, '[^@]+')
FROM   oe.customers
WHERE  nls_territory = 'SWITZERLAND' ; 

--5
SELECT UNIQUE REGEXP_REPLACE (catalog_url, 'http://([^/]+).*', '\1')
FROM oe.product_information ;

--Multilingual Capabilities

--1
SELECT REGEXP_SUBSTR(to_char(translated_name), '^[a-z]+')
FROM   oe.product_descriptions
WHERE  language_id = 'PT'
AND    translated_name like 'G%' ;

--2
SELECT REGEXP_SUBSTR(TO_CHAR(translated_name), '^[a-z]+', 1, 1, 'i') 
FROM   oe.product_descriptions 
WHERE  language_id = 'PT' 
AND    translated_name like 'G%' ;

--3
ALTER SESSION SET NLS_LANGUAGE=PORTUGUESE ;

SELECT REGEXP_SUBSTR(to_char(translated_name), '^[a-z]+', 1, 1, 'i')
FROM   oe.product_descriptions
WHERE  language_id = 'PT'
AND    translated_name like 'G%' ;

--4
SELECT REGEXP_SUBSTR(i.product_name, '^[a-z]+', 1, 1, 'i') || ' = '
       || regexp_substr(to_char(d.translated_name), '^[a-z]+', 1, 1, 'i')
FROM   oe.product_descriptions d, oe.product_information i
WHERE  d.language_id = 'PT'
AND    d.translated_name like 'G%'
AND    i.product_id = d.product_id ; 

ALTER SESSION SET NLS_LANGUAGE=AMERICAN;

--Check Constraints

INSERT INTO customers VALUES (9999,'Christian','Patel',
   cust_address_typ ('1003 Canyon Road','87501','Santa Fe','NM','US'),
   phone_list_typ ('+1 505 243 4144'),'us','AMERICA','100',
   'ChrisP+creme.com', 149, null, null, null, null, null) ; 


ROLLBACK ;

--2
ALTER TABLE customers 
  ADD CONSTRAINT cust_email_addr 
  CHECK(REGEXP_LIKE(cust_email,'@')) NOVALIDATE ;

--3
INSERT INTO customers
  VALUES (9999, 'Christian', 'Patel',
          cust_address_typ('1003 Canyon Road', '87501', 'Santa Fe',
                            'NM', 'US'),
          phone_list_typ('+1 505 243 4144'), 'US', 'AMERICA', '100',
         'ChrisP+creme.com', 149, null, null, null, null, null);

--4
ALTER TABLE customers DROP CONSTRAINT cust_email_addr ;
