PL/SQL Flashcards
What is the DECLARE keyword?
It is an optional section and defines all variables, cursors, subprograms, and other elements to be used in the program.
What is the keywords BEGIN and END?
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.
What is Scalar Datatype?
Single values with no internal components, such as a NUMBER, DATE, or BOOLEAN.
What is Numeric Datatype?
Data items that have internal components that can be accessed individually. For example, collections and records.
What is the VARCHAR2 Datatype?
Variable-length character string with maximum size of 32,767 bytes
What is a record?
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.
What is the context area for?
for processing an SQL statement, which contains all the
information needed for processing the statement; for example, the number of rows processed, etc.
A cursor is
A cursor is a pointer to this context area.
PL/SQL controls the context area through a
[Blank[
cursor.
A cursor holds the [Blank] (one or more) returned by a SQL statement.
rows
What is an Implicit Cursors?
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.
What is an Explicit Cursors?
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;
What are Triggers?
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 do you create a Trigger?
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
What is a database TRANSACTION?
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
A transaction ends when one of the following events take place:
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.
SQLPlus terminates abnormally, a ROLLBACK is automatically performed.
A DML statement fails; in that case a ROLLBACK is automatically performed for
undoing that DML statement.
Rolling Back Transactions
Changes made to the database without COMMIT could be undone using the ROLLBACK command.
ROLLBACK [TO SAVEPOINT < savepoint_name>];
When a transaction is aborted due to some unprecedented situation, like system failure,
the entire transaction since a commit is automatically [Blank].
rolled back
If you are not using savepoint, then simply use the following statement to rollback all the changes:
Rollback;
What are SavePoints and how do you call it?
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 >;
To execute a COMMIT automatically whenever an INSERT, UPDATE or DELETE command is executed, you can set the AUTOCOMMIT environment variable as:
SET AUTOCOMMIT ON;