Sie sind auf Seite 1von 9

academy.oracle.

com

Database Programming with PL/SQL


2-1: Using Variables in PL/SQL
Practice Activities
Vocabulary
Identify the vocabulary word for each definition below:

Used for storage of data and manipulation of stored values.

Values passed to a program by a user or by another program to cus-


tomize the program.

Try It / Solve It
1. Fill in the blanks.

A. Variables can be assigned to the output of a __________________.

B. Variables can be assigned values in the _____________________ section of a PL/SQL block.

C. Variables can be passed as ____________________ to subprograms.

2. Identify valid and invalid variable declaration and initialization:

number_of_copies PLS_INTEGER;
printer_name CONSTANT VARCHAR2(10);
deliver_to VARCHAR2(10) := Johnson;
by_when DATE := SYSDATE+1;

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

3. Examine the following anonymous block and choose the appropriate statement.

DECLARE
fname VARCHAR2(25);
lname VARCHAR2(25) DEFAULT 'fernandez';
BEGIN
DBMS_OUTPUT.PUT_LINE(fname || ' ' || lname);
END;

A. The block will execute successfully and print ‘ fernandez’.


B. The block will give an error because the fname variable is used without initializing.
C. The block will execute successfully and print ‘null fernandez’.
D. The block will give an error because you cannot use the DEFAULT keyword to initialize a vari-
able of the VARCHAR2 type.
E. The block will give an error because the FNAME variable is not declared.

4. In Application Express:

A. Create the following function:

CREATE FUNCTION num_characters (p_string IN VARCHAR2)


RETURN INTEGER AS
v_num_characters INTEGER;
BEGIN
SELECT LENGTH(p_string) INTO v_num_characters
FROM dual;
RETURN v_num_characters;
END;

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

B. Create and execute the following anonymous block:

DECLARE
v_length_of_string INTEGER;
BEGIN
v_length_of_string := num_characters('Oracle Corporation');
DBMS_OUTPUT.PUT_LINE(v_length_of_string);
END;

5. Write an anonymous block that uses a country name as input and prints the highest and lowest
elevations for that country. Use the COUNTRIES table. Execute your block three times using Unit-
ed States of America, French Republic, and Japan.

Copyright © 2019, 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.
academy.oracle.com

Database Programming with PL/SQL


2-2: Recognizing PL/SQL Lexical Units
Practice Activities
Vocabulary
Identify the vocabulary word for each definition below:

An explicit numeric, character string, date, or Boolean value that is not


represented by an identifier.

Symbols that have special meaning to an Oracle database.

Words that have special meaning to an Oracle database and cannot


be used as identifiers.

Describe the purpose and use of each code segment and are ignored
by PL/SQL.

Building blocks of any PL/SQL block and are sequences of characters


including letters, digits, tabs, returns, and symbols.

A name, up to 30 characters in length, given to a PL/SQL object.

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

Try It / Solve It Questions


1. Identify each of the following identifiers as valid or invalid. If invalid, specify why.

Valid Invalid
Identifier Why Invalid?
(X) (X)

Today

Last name

today’s_date

number_of_days_in_february_this_
year

Isleap$year

#number

NUMBER#

Number1to7

2. Identify the reserved words in the following list.


Word Reserved? Y/N

create

make

table

seat

alter

rename

row

number
web

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

3. What kind of lexical unit (for example Reserved word, Delimiter, Literal, Comment) is each of the
following?

Value Lexical Unit

SELECT

:=

'TEST'

FALSE

-- new process

FROM

/* select the country with the high-


est elevation */

v_test

4.09

Copyright © 2019, 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.
academy.oracle.com

Database Programming with PL/SQL


2-3: Recognizing Data Types
Practice Activities
Vocabulary
Identify the vocabulary word for each definition below:

Store large blocks of single-byte or fixed width multi-byte NCHAR data


in the database.

Hold values, called locators, that specify the location of large objects
(such as graphic images) that are stored out of line.

Hold a single value with no internal components.

Store large unstructured or structured binary objects.

Contain internal elements that are either scalar (record) or composite


(record and table)

Store large binary files outside of the database.

Hold values, called pointers, that point to a storage location.

A schema object with a name, attributes, and methods.

Store large blocks of character data in the database.

Try It / Solve It
1. In your own words, describe what a data type is and explain why it is important.

2. Identify the three data type categories covered in this course.

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

3. Identify three data types covered in the Database Programming with SQL course.

4. What data type can be used in PL/SQL, but can’t be used to define a table column?

5. Which data type indicates a large data object that is stored outside of the database?

6. Identify the data type category (LOB, Scalar, or Composite) for each data type. Each category may
be used more than once.

Data Type Data Type Category

CLOB

VARCHAR2

BLOB

NUMBER

BFILE

TIMESTAMP

NCLOB

RECORD

PLS_INTEGER

LONG

TABLE

BOOLEAN

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

7. Enter the data type category and the data type for each value. The first one has been done for
you.

Value Data Type Category Data Type

‘Switzerland’ Scalar VARCHAR2

Text of a resume

100.20

A picture

1053

11-Jun-2016

‘Computer science is the


science of the 21st century.’

Index Last_name

1 'Newman'

2 'Raman'
3 'Han'

A movie

A sound byte

FALSE

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

Das könnte Ihnen auch gefallen