PL/SQL Flashcards

1
Q

What is the DECLARE keyword?

A

It is an optional section and defines all variables, cursors, subprograms, and other elements to be used in the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the keywords BEGIN and END?

A

keywords BEGIN and END and it is a
mandatory section. It consists of the executable PL/SQL statements of the
program. It should have at least one executable line of code, which may be just
a NULL command to indicate that nothing should be executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Scalar Datatype?

A

Single values with no internal components, such as a NUMBER, DATE, or BOOLEAN.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Numeric Datatype?

A

Data items that have internal components that can be accessed individually. For example, collections and records.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the VARCHAR2 Datatype?

A

Variable-length character string with maximum size of 32,767 bytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a record?

A

A record is a data structure that can hold data items of different kinds. Records consist of different fields, similar to a row of a database table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the context area for?

A

for processing an SQL statement, which contains all the

information needed for processing the statement; for example, the number of rows processed, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A cursor is

A

A cursor is a pointer to this context area.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

PL/SQL controls the context area through a

[Blank[

A

cursor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A cursor holds the [Blank] (one or more) returned by a SQL statement.

A

rows

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an Implicit Cursors?

A

Implicit cursors are automatically created by Oracle whenever an SQL statement is executed, when there is no explicit cursor for the statement. Programmers cannot control the implicit cursors and the information in it. Whenever a DML statement (INSERT, UPDATE and DELETE) is issued, an implicit cursor is
associated with this statement. For INSERT operations, the cursor holds the data that needs to be inserted. For UPDATE and DELETE operations, the cursor identifies the rows that would be affected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an Explicit Cursors?

A

Explicit cursors are programmer-defined cursors for gaining more control over the context
area. An explicit cursor should be defined in the declaration section of the PL/SQL Block.
It is created on a SELECT Statement which returns more than one row.

CURSOR cursor_name IS select_statement;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are Triggers?

A

Triggers are stored programs, which
are automatically executed or fired when some events occur. Triggers are, in fact, written
to be executed in response to any of the following events:
 A database manipulation (DML) statement (DELETE, INSERT, or UPDATE).
 A database definition (DDL) statement (CREATE, ALTER, or DROP).
 A database operation (SERVERERROR, LOGON, LOGOFF, STARTUP, or
SHUTDOWN).
Triggers can be defined on the table, view, schema, or database with which the event is
associated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you create a Trigger?

A
CREATE [OR REPLACE ] TRIGGER trigger_name
{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE}
[OF col_name]
ON table_name
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROW]
WHEN (condition)
DECLARE
Declaration-statements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a database TRANSACTION?

A

A database transaction is an atomic unit of work that may consist of one or more related SQL statements. It is called atomic because the database modifications brought about by the SQL statements that constitute a transaction can collectively be either committed, i.e., made permanent to the database or rolled back (undone) from the database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A transaction ends when one of the following events take place:

A

 A COMMIT or a ROLLBACK statement is issued.
 A DDL statement, such as CREATE TABLE statement, is issued; because in that
case a COMMIT is automatically performed.
 A DCL statement, such as a GRANT statement, is issued; because in that case a
COMMIT is automatically performed.
 User disconnects from the database.
 User exits from SQLPLUS by issuing the EXIT command, a COMMIT is
automatically performed.
 SQL
Plus terminates abnormally, a ROLLBACK is automatically performed.
 A DML statement fails; in that case a ROLLBACK is automatically performed for
undoing that DML statement.

17
Q

Rolling Back Transactions

A

Changes made to the database without COMMIT could be undone using the ROLLBACK command.

ROLLBACK [TO SAVEPOINT < savepoint_name>];

18
Q

When a transaction is aborted due to some unprecedented situation, like system failure,
the entire transaction since a commit is automatically [Blank].

A

rolled back

19
Q

If you are not using savepoint, then simply use the following statement to rollback all the changes:

A

Rollback;

20
Q

What are SavePoints and how do you call it?

A

Savepoints are sort of markers that help in splitting a long transaction into smaller units
by setting some checkpoints. By setting savepoints within a long transaction, you can roll
back to a checkpoint if required. This is done by issuing the SAVEPOINT command.

SAVEPOINT < savepoint_name >;

21
Q

To execute a COMMIT automatically whenever an INSERT, UPDATE or DELETE command is executed, you can set the AUTOCOMMIT environment variable as:

A

SET AUTOCOMMIT ON;