Variable Declaration, Initialization and Display - Exercise

Contact Us or call 1-877-932-8228
Variable Declaration, Initialization and Display - Exercise

Variable Declaration, Initialization and Display

Duration: 10 to 15 minutes.
  1. Create a program that prints out a person's name. Declare, initialize and display a character string that contains the name.
  2. Modify the program so that it prints out the person's salary as well. Declare, initialize and display a numeric variable that contains the salary.
  3. Modify the program so that it prints out the current date in addition to the information above. Declare, initialize and display a date variable that contains the current date.
  4. Option: format the information so that it reads: As of <date in MM/DD/YYYY> <NAME> will be paid <$x,xxx.xx>.

Solution:

Declare-Clause/Solutions/name_salary_date.sql
DECLARE
  v_name   VARCHAR2(25) := 'Larry Ellison';
  v_salary NUMBER := 1.00; 
  v_date   DATE   := CURRENT_DATE;
BEGIN
  dbms_output.put_line(v_date || ' ' || v_name || ' ' || v_salary);  
  dbms_output.put_line('As of ' ||
                       to_char(v_date, 'mm/dd/yyyy') || ' ' ||
                       v_name || ' will be paid ' ||
                       to_char(v_salary, '$9,999.00') || '.');
END;

Code Explanation

Next