0% found this document useful (0 votes)
77 views4 pages

Database Programming With PL/SQL 2-4: Practice Activities: Using Scalar Data Types

Uploaded by

Luis Quintana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views4 pages

Database Programming With PL/SQL 2-4: Practice Activities: Using Scalar Data Types

Uploaded by

Luis Quintana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

www.oracle.

com/academy

Database Programming with PL/SQL


2-4: Using Scalar Data Types
Practice Activities
Vocabulary
Identify the vocabulary word for each definition below:

A datatype that stores one of the three possible values used for logical
calculations: TRUE, FALSE, or NULL.

Attribute used to declare a variable according to another previously


declared variable or database column.

Try It / Solve It
1. Declarations:

A. Which of the following variable declarations are valid?

Declaration Valid or Invalid

a number_of_students PLS_INTEGER;

b STUDENT_NAME VARCHAR2(10) = Johnson;

c stu_per_class CONSTANT NUMBER;

d tomorrow DATE := SYSDATE+1;

B. For the invalid declarations above, describe why they are invalid.

Copyright © 2018, 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.
2

Copyright © 2018, 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.
3

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.

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;

3. Change the declarations in #2 above so they use the %TYPE attribute.

Copyright © 2018, 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

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?

5. Create the following anonymous block:

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:

• A variable named TODAY of datatype DATE. Initialize TODAY with SYSDATE.

• A variable named TOMORROW with the same datatype as TODAY. Use the %TYPE at-
tribute to declare this variable.

B. In the executable section, initialize the TOMORROW variable with an expression that calcu-
lates tomorrow’s date (add 1 to the value in TODAY). Print the value of TODAY and TOMOR-
ROW after printing ‘Hello World’.

Copyright © 2018, 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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy