Practice PL - SQL 2-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

www.oracle.

com/academy

Database Programming with PL/SQL


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

VARIABLES
Used for storage of data and manipulation of stored values.

m
PARÁMETROS

er as
Values passed to a program by a user or by another program to
customize the program.

co
eH w
o.
Try It / Solve It
rs e
ou urc
1. Fill in the blanks.

A. Variables can be assigned to the output of a __FUNCIÓN________________.


o
aC s

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


vi y re

block.

C. Variables can be passed as ____ PARÁMETROS ________________ to


subprograms.
ed d
ar stu

2. Identify valid and invalid variable declaration and initialization:


is

number_of_copies PLS_INTEGER; VALIDO


Th

printer_name CONSTANT VARCHAR2(10); VALIDO


sh

deliver_to VARCHAR2(10) := Johnson; INVALIDO

by_when DATE := SYSDATE+1; VALIDO

This study source was downloaded by 100000809939014 from CourseHero.com on 05-26-2021 13:40:18 GMT -05:00

https://www.coursehero.com/file/23153351/PLSQL-2-1-Practice/
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.

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 variable of the VARCHAR2 type.

m
er as
E. The block will give an error because the FNAME variable is not declared.

co
eH w
4. In Application Express:

o.
rs e
ou urc
A. Create the following function:

CREATE FUNCTION num_characters (p_string IN VARCHAR2)


o

RETURN INTEGER AS
aC s

v_num_characters INTEGER;
vi y re

BEGIN
SELECT LENGTH(p_string) INTO v_num_characters
FROM dual;
RETURN v_num_characters;
ed d

END;
ar stu
is
Th
sh

This study source was downloaded by 100000809939014 from CourseHero.com on 05-26-2021 13:40:18 GMT -05:00

https://www.coursehero.com/file/23153351/PLSQL-2-1-Practice/
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;

m
er as
co
eH w
o.
rs e
ou urc
o
aC s

5. Write an anonymous block that uses a country name as input and prints the highest and
vi y re

lowest elevations for that country. Use the COUNTRIES table. Execute your block three
times using United States of America, French Republic, and Japan.
ed d

UNITED STATES OF AMERICA:


ar stu
is
Th
sh

This study source was downloaded by 100000809939014 from CourseHero.com on 05-26-2021 13:40:18 GMT -05:00

https://www.coursehero.com/file/23153351/PLSQL-2-1-Practice/
FRENCH REPUBLIC:

JAPAN:

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

This study source was downloaded by 100000809939014 from CourseHero.com on 05-26-2021 13:40:18 GMT -05:00

https://www.coursehero.com/file/23153351/PLSQL-2-1-Practice/
Powered by TCPDF (www.tcpdf.org)

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