You are on page 1of 6

academy.oracle.

com

Database Programming with PL/SQL


3-4: Using Transaction Control Statements Practice
Activities
Vocabulary
Identify the vocabulary word for each definition below:

An inseparable list of database operations, which must be executed

m
Transaction either in its entirety or not at all.

er as
Rollback Used for discarding any changes that were made to the database

co
eH w
after the last COMMIT.

o.
Savepoint Used to mark an intermediate point in transaction processing.
rs e
ou urc
End Keyword used to signal the end of a PL/SQL block, not the end of a
transaction.
o

commit Statement used to make database changes permanent.


aC s
vi y re

Try It / Solve It
ed d

Because our online version of Oracle Application Express (APEX) automatically commits
ar stu

changes as the code runs, the following activities will NOT work as intended unless you are
using an installed/local APEX environment.

1. How many transactions are shown in the following code? Explain your reasoning.
is

BEGIN
Th

INSERT INTO my_savings (account_id, amount)


VALUES (10377, 200);
sh

INSERT INTO my_checking (account_id, amount)


VALUES (10378, 100);
END;
I think that that two transactions are occurring because value is being inserted twice

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.
This study source was downloaded by 100000812466626 from CourseHero.com on 06-08-2021 13:48:05 GMT -05:00

https://www.coursehero.com/file/52512512/PLSQL-3-4-Practice-Vijudocx/
2

Because our online version of Oracle Application Express (APEX) automatically commits
changes as the code runs, the following activities will NOT work as intended unless you are
using an installed/local APEX environment.

2. Create the endangered species table by running the following statement in Application Express:
Unless you are using an installed/local APEX environment, there is no reason to run this code.
If you are using our online version of Oracle Application Express (APEX), you should pretend
this code runs successfully before you try to answer the next question.
CREATE TABLE endangered_species
(species_id NUMBER(4) CONSTRAINT es_spec_pk PRIMARY KEY,
common_name VARCHAR2(30) CONSTRAINT es_com_name_nn NOT NULL,
scientific_name VARCHAR2(30) CONSTRAINT es_sci_name_nn NOT NULL);

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

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.
This study source was downloaded by 100000812466626 from CourseHero.com on 06-08-2021 13:48:05 GMT -05:00

https://www.coursehero.com/file/52512512/PLSQL-3-4-Practice-Vijudocx/
3. Examine the following block of code. If you were to run this block, what data do you think would be
saved in the database?
Unless you are using an installed/local APEX environment, there is no reason to run this code.
If you are using our online version of Oracle Application Express (APEX), you should pretend
this code runs successfully to answer the remaining questions.
BEGIN
INSERT INTO endangered_species
VALUES (100, 'Polar Bear', 'Ursus maritimus');
SAVEPOINT sp_100;
INSERT INTO endangered_species
VALUES (200, 'Spotted Owl', 'Strix occidentalis');
SAVEPOINT sp_200;
INSERT INTO endangered_species

m
er as
VALUES (300, 'Asiatic Black Bear', 'Ursus thibetanus');

co
ROLLBACK TO sp_100;

eH w
COMMIT;

o.
END; rs e
ou urc
I think that only the data that is associated with the polar bear will be saved
o
aC s
vi y re
ed d
ar stu
is
Th
sh

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.
This study source was downloaded by 100000812466626 from CourseHero.com on 06-08-2021 13:48:05 GMT -05:00

https://www.coursehero.com/file/52512512/PLSQL-3-4-Practice-Vijudocx/
3

4. Run the block above to test your theory. Confirm your projected data was added.
Unless you are using an installed/local APEX environment, you should skip this question. The
block above will NOT run as intended in our online version of Oracle Application Express
(APEX) because it automatically commits changes as the code runs.

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

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.
This study source was downloaded by 100000812466626 from CourseHero.com on 06-08-2021 13:48:05 GMT -05:00

https://www.coursehero.com/file/52512512/PLSQL-3-4-Practice-Vijudocx/
5. Examine the following block. If you were to run this block, what data do you think would be saved in
the database? Run the block to test your theory.
Because our online version of Oracle Application Express (APEX) automatically commits
changes as the code runs, the following block will NOT work as intended unless you are using
an installed/local APEX environment.
BEGIN
INSERT INTO endangered_species

m
er as
VALUES (400, 'Blue Gound Beetle', 'Carabus intricatus');

co
eH w
SAVEPOINT sp_400;

o.
INSERT INTO endangered_species

rs e
VALUES (500, 'Little Spotted Cat', 'Leopardus tigrinus');
ou urc
ROLLBACK;
INSERT INTO endangered_species
o
aC s

VALUES (600, 'Veined Tongue-Fern', 'Elaphoglossum nervosum');


vi y re

ROLLBACK TO sp_400;
END;
ed d
ar stu

I think it will result in an error because the code is full of nonsense


is
Th
sh

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.
This study source was downloaded by 100000812466626 from CourseHero.com on 06-08-2021 13:48:05 GMT -05:00

https://www.coursehero.com/file/52512512/PLSQL-3-4-Practice-Vijudocx/
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

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.
This study source was downloaded by 100000812466626 from CourseHero.com on 06-08-2021 13:48:05 GMT -05:00

https://www.coursehero.com/file/52512512/PLSQL-3-4-Practice-Vijudocx/
Powered by TCPDF (www.tcpdf.org)

You might also like