PLSQL 2 4 Practice
PLSQL 2 4 Practice
PLSQL 2 4 Practice
com/academy
A datatype that stores one of the three possible values used for
Boolean
logical calculations: TRUE, FALSE, or NULL.
Attribute used to declare a variable according to another
%type
previously declared variable or database column.
Try It / Solve It
1. Declarations:
B. For the invalid declarations above, describe why they are invalid.
En la letra b debería der “:=” y en la letra c se debe de declarer un valor literal
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
C. Write an anonymous block in which you declare and print (on the screen) each of
the variables in 1A above, correcting the invalid declarations and adding
information as needed.
Declare
Number_of_student pls_integer;
Student_name varchar2(10) := ‘Johnson’
Stu_per_class constant number := 1;
Tomorrow date:=sysdate+1;
Begin
Dbms_output.put_line(number_of_student || student_name||
stu_per_class11 tomorrow);
End;
2. 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
country_name VARCHAR2(50); median_age NUMBER(6, 2);
BEGIN
SELECT country_name, median_age INTO country_name, median_age
FROM countries
WHERE country_name = 'Japan';
DBMS_OUTPUT.PUT_LINE('The median age in '|| country_name || ' is '
|| median_age || '.');
END;
DECLARE
V_country_name
countries.county_name%TYPE;
v_median_age
countries.median_age%TYPE;
BEGIN
SELECT country_name, median_age INTO v_country_name, v_median_age
FROM countries
WHERE country_name = 'Japan';
DBMS_OUTPUT.PUT_LINE('The median age in '|| v_country_name || ' is '
|| v_median_age || '.');
END;
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
4. In your own words, describe why using the % TYPE attribute is better than hard-
coding data types. Can you explain how you could run into problems in the future
by hard-coding the data types of the country_name and median_age variables in
question 2?
Es importante porque si declara una variable que tendrá una referencia con una columna de
una tabla, no necesita preocuparse si el tipo de columna o el rango cambian en un futuro
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello World');
END;
A. Add a declarative section to this PL/SQL block. In the declarative section, declare
the following variables:
DECLARE
v_today date := SYSDATE;
v_tomorrow v_today%TYPE := v_today+1;
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello World');
DBMS_OUTPUT.PUT_LINE(V_TODAY);
DBMS_OUTPUT.PUT_LINE(v_tomorrow);END;
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.