Answers DMS
Answers DMS
Productivity: PL/SQL lets you write compact code for manipulating data.
Tight integration with SQL: PL/SQL is tightly integrated with SQL, the standard
database language.
---------------------------------------------------------------------------------------------------------------
4 Marks Questions
Q.1 Write a trigger which invokes on deletion of record on emp table.
Create or replace trigger deletion_trigger before delete on emp
For each row
Begin
Raise_application_error(-20000,’can’t delete record’);
End;
---------------------------------------------------------------------------------------------------------------
Declaring:
This term is used to declare a cursor so that memory initialization will take place.
A cursor is declared by defining the SQL statement that returns a result set.
Opening: A Cursor is opened and populates data by executing the SQL statement defined by
the cursor.
Fetching: Rows are retrieved from the Cursor using the FETCH statement, which moves the
Cursor to the next row in the result set and makes the row’s data available for processing.
PROCESS THE FETCHED ROW: The data of the fetched row can be processed using the
variable name.
Closing a Cursor: This forces cursor for releasing the allocated memory assigned/ occupied
by cursor.
Example of cursor :
DECLARE
emp_record employees%ROWTYPE;
BEGIN
OPEN emp_cursor;
LOOP
FETCH emp_cursor INTO emp_record;
END LOOP;
CLOSE emp_cursor;
END;
---------------------------------------------------------------------------------------------------------------
Execution section: Executable SQL or PL/SQL Statements are needed to write here
for the execution. It is mandatory block.
Active − This is the state in which a transaction is being executed. Thus, it is like the
initial state of any given transaction.
Partially Committed − A transaction is in its partially committed state whenever it
executes the final operation.
Failed − In case any check made by a database recovery system fails, then that
transaction is in a failed state. Remember that a failed transaction can not proceed
further.
Aborted − In case any check fails, leading the transaction to a failed state, the
recovery manager then rolls all its write operations back on the database so that it can
bring the DB (database) back to the original state (the state where it actually was prior
to the transaction execution). The transactions in this state are known to be aborted. A
DB recovery module can actually select one of these two operations after the abortion
of a transaction –
Re-start
Kill the transaction
Committed − We can say that a transaction is committed in case it actually executes
all of its operations successfully. In such a case, all of its effects are now established
permanently on the DB system.
---------------------------------------------------------------------------------------------------------------