PL/SQL (javatpoint) Flashcards
Differentiate between %ROWTYPE and TYPE RECORD.
%ROWTYPE is used when a query returns an entire row of a table. TYPE RECORD is used when a query returns column of different tables or views.
Explain uses of cursor.
Cursor is a named private area in SQL from which information can be accessed. It is required to process each row individually for queries which return multiple rows.
Show code of a cursor for loop.
FOR smp_rec in C1 LOOP totalSal = totalSal + smp_rec; END LOOP;
Explain the uses of database trigger.
A PL/SQL program unit associated with a particular database table is called a database trigger. It is used for: 1) Audit of data modifications. 2) Log events transparently. 3) Enforce complex business rules. 4) Maintain replica tables. 5) Derive column values. 6) Implement complex security authorizations.
What are two types of exceptions?
User defined Predefined
List some predefined exceptions.
DUP_VAL_ON_INDEX ZERO_DIVIDE NO_DATA_FOUND TOO_MANY_ROWS CURSOR_ALREADY_OPEN Etc.
Q1 What is PL/SQL?
A procedural language which has interactive SQL, as well as constructs like conditional branching and iteration. Developed by Oracle in early 90s.
Q2 What is PL/SQL table? Why is it used?
Objects of type tables are called PL/SQL that are modeled after database tables. It is a way to provide arrays. They can be used to move bulk data. They simplify moving collections of data.
Q3 What are the datatypes available in PL/SQL?
Scalar: number, varchar2, date, char, long, Boolean, etc. Composite: record, table, etc.
Q4 What is the basic structure of PL/SQL?
PL/SQL uses BLOCK structure as its basic structure. Each PL/SQL program consists of SQL and PL/SQL statements which form a PL/SQL block. Each block contains 3 sections: 1. Declaration (optional) 2. Execution 3. Execution handling (optional)
Q5 What is the difference between FUNCTION, PROCEDURE, and PACKAGE?
Function: Computes and returns a value. Return type is specified and return value must be of that type. Procedure: Similar to a function but with no return value. Package: A schematic object which groups logically related PL/SQL types, variables, functions, and procedures.
Q6 Define exception. What are the types of exceptions?
Exceptions are the error handling part of PL/SQL. pre_defined user_defined
Q7 How is exception different from error?
Whenever an Error occurs an Exception arises. Error is a bug whereas exception is a warning or error condition.
Q8 What is the main reason behind using an index?
Faster access of data blocks in the table.
Q10 What is maximum number of triggers that can be applied on a single table?
12