1. Write a SELECt statement that returns these colums from the Invoices Table: T
ID: 3548085 • Letter: 1
Question
1. Write a SELECt statement that returns these colums from the Invoices Table:
The invoice_total colum
Use the TO_CHAR function to return the invoice_total colum with 2 digits to the right of the decimal point.
Use the TO_CHAR function to return the invoice_total colum with no digits to the right of the decimal point and no decimal point.
Use the CAST function to return the invoice_total colum as an integer with seven digits.
2. Write a SELECT statement that returns these colums from the Invoices table:
The invoice_date colum
Use the TO_CHAR function to return the invoice_date colum with its full date and time including a four digit year on a 24 hour clock.
Use the TO_CHAR function to return the invoice_date colum with its full date and time including a four digit year on a 12 hour clock with an am/pm indicator.
Use the CAST function to return the invoice_date colum as VARCHAR2(10).
3. Write a SELECT statement that returns these colums from the Vendors table:
The vendor_name colum
The vendor_name colum in all capital letters
The vendor_phone colum
The last four digits of each phone number
Once working, then add the colums that follow to the result set.
** The second word in each vendor name if the name has three or more words, otherwise blank.
**The vendor_phone_colum with the parts of the number separated by dots as in 555.555.5555
Explanation / Answer
--1
SELECT to_char(invoice_total, '9999999999.99') two_decimal,
to_char(invoice_total, '9999999999') no_decimal,
CAST(invoice_total as NUMBER(38, 7)) integer_with_digits
FROM Invoices;
-- 2
SELECT to_char(invoice_date, 'mm/dd/yyyy hh24:mi:ss') full_datetime,
to_char(invoice_date, 'mm/dd/yyyy hh:mi:ss am') full_12datetime,
CAST(invoice_date as VARCHAR2(10)) cast_date
FROM Invoices;
-- 3
SELECT vendor_name, UPPER(vendor_name) all_caps, vendor_phone,
SUBSTR(vendor_phone, LENGTH(vendor_phone) -3, SUBSTR(vendor_phone)) last_four_dig,
CASE WHEN LENGTH(vendor_name) > 3 THEN
(SUBSTR(vendor_name, 2, 1))
ELSE
' '
END second_word,
to_char(vendor_phone_colum, '999.999.999') parts_info
FROM Vendors;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.