Homework Week2 - PLSQL-variables
Homework Week2 - PLSQL-variables
Homework Week2 - PLSQL-variables
A. An IDENTIFIER is the name given to a PL/SQL object. B. A RESERVED WORD is a word that has special meaning to the Oracle database. C. A DELIMTER is a symbol that has special meaning to the Oracle database.
1 D. A LITERAL is an explicit numeric, character string, date, or Boolean value
2. Identify each of the following identifiers as valid or invalid. If invalid, specify why. Identifier Today Last name Todays_date number_of_days_in_february_this_ year Isleap$year #number NUMBER# Number1to7 Valid (X) X Invalid (X) X X X X X X X # on begining Why Invalid?
4. What kind of lexical unit (for example Reserved word, Delimiter, Literal, Comment) is each of the following? Value SELECT := TEST FALSE -- new process FROM /*select the country with the highest elevation */ V_test 4.09 Lexical Unit RESERVED WORD DELIMITER LITERAL LITERAL COMMENT RESERVED WORD COMMENT LITERAL LITERAL
Value Switzerland 100.20 1053 12-DEC-2005 False Index Last name 1 'Newman' 2 'Raman' 3 'Han' A movie A soundbyte A picture
Data Type
CHARACTER NUMBER NUMBER DATE BOOLEAN PL/SQL SCHEMA
6. Evaluate the variables in the following code. Answer the following questions about each variable. Is it named well? Why or why not? If it is not named well, what would be a better name and why? DECLARE d_country_name VARCHAR2 (50); d_median_age NUMBER(6,2); BEGIN SELECT country_name, median_age INTO d_country_name, d_median_age FROM wf_countries WHERE country_name = United States of America'); DBMS_OUTPUT.PUT_LINE(' The median age in '||d_country_name||' is '||d_median_age||'.'); END; Avoid using column names as identifiers.
10. Write an anonymous PL/SQL block that uses the programmers full name and then returns the number of characters in the name. BEGIN DBMS_OUTPUT.PUT_LINE('Broj slova u imenu Darko Petrovic je:'); DBMS_OUTPUT.PUT_LINE(LENGTH('Darko Petrovic')); END;
12. Examine the following code and then answer the questions. DECLARE x NUMBER(6); BEGIN x := 5 + 3 * 2 ; DBMS_OUTPUT.PUT_LINE(x); END; A. What do you think the output will be when you run the above code? 11 B. Now run the code. What is the output? 11 C. In your own words, explain the results. multiplication takes precedence over the addition