
470 Appendix A An SQL:1999 Example Using UDTs
4. Out of curiosity, do we have any customers whose extended ZIP code hap-
pens to be equal to the last four digits of their phone numbers?
SELECT cust last name, cust first name
FROM customers
WHERE SUBSTRING ( cust_phone FROM 7 FOR 4 )
= CAST ( cust address.zip.plus4 AS CHARACTER ( 4 ) ) ;
5. How much profit would we make if we sold every DVD copy of every
movie starring Jeff Goldblum?
SELECT SUM ( m.dvds in stock *
( CAST ( m.current_dvd_sale_price AS DECIMAL ( 9, 2 ) )
- CAST ( m.our dvd cost AS DECIMAL ( 9, 2 ) )