PL/SQL (javatpoint) Flashcards

1
Q

Differentiate between %ROWTYPE and TYPE RECORD.

A

%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.

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

Explain uses of cursor.

A

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.

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

Show code of a cursor for loop.

A

FOR smp_rec in C1 LOOP totalSal = totalSal + smp_rec; END LOOP;

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

Explain the uses of database trigger.

A

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.

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

What are two types of exceptions?

A

User defined Predefined

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

List some predefined exceptions.

A

DUP_VAL_ON_INDEX ZERO_DIVIDE NO_DATA_FOUND TOO_MANY_ROWS CURSOR_ALREADY_OPEN Etc.

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

Q1 What is PL/SQL?

A

A procedural language which has interactive SQL, as well as constructs like conditional branching and iteration. Developed by Oracle in early 90s.

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

Q2 What is PL/SQL table? Why is it used?

A

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.

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

Q3 What are the datatypes available in PL/SQL?

A

Scalar: number, varchar2, date, char, long, Boolean, etc. Composite: record, table, etc.

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

Q4 What is the basic structure of PL/SQL?

A

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)

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

Q5 What is the difference between FUNCTION, PROCEDURE, and PACKAGE?

A

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.

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

Q6 Define exception. What are the types of exceptions?

A

Exceptions are the error handling part of PL/SQL. pre_defined user_defined

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

Q7 How is exception different from error?

A

Whenever an Error occurs an Exception arises. Error is a bug whereas exception is a warning or error condition.

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

Q8 What is the main reason behind using an index?

A

Faster access of data blocks in the table.

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

Q10 What is maximum number of triggers that can be applied on a single table?

A

12

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

Q11 How many types of triggers?

A

12 types with combination of: 1. BEFORE or AFTER 2. Row or statement level 3. INSERT, UPDATE, or DELETE

17
Q

Q12 What is stored procedure?

A

A sequence of statements or a named PL/SQL block which performs one or more functions. It is stored in the database and can be repeatedly executed. It is stored as a schematic object. It can be nested, invoked, and parameterized.

18
Q

Q13 How to execute a stored procedures?

A

From SQL prompt: EXECUTE procedure_name; EXEC procedure_name; procedure_name;

19
Q

Q14 Advantages of stored procedure?

A

Modularity, extensibility, reusability, maintainability, and one time compilation

20
Q

Q15 What are the cursor attributes used in PL/SQL?

A

%ISOPEN: checks whether cursor is open or not. %ROWCOUNT: returns number of rows affected by DML operations: INSERT, UPDATE, DELETE, or SELECT %FOUND: checks whether cursor has fetched any row. If yes, TRUE. %NOTFOUND: checks whether cursor has fetched any row. If no, TRUE.

21
Q

Q16 What is consistency?

A

It means that each user sees the consistent view of the data. An example is scenario in which money is transferred from account A to Account B. Only after both debit of A and credit of B are completed will users see any change to each account.

22
Q

Q17 What is cursor and why it is required?

A

It is a temporary work area created in system memory when an SQL statement is executed. A cursor is required to process rows individually for queries.

23
Q

Q18 How many types of cursors are available in PL/SQL?

A

Implicit Explicit

24
Q

What are schema objects?

A

Database objects that contain data or govern or perform operations on data. Each schema object belongs to a specific schema. An Oracle database associates a separate schema with each database user. Example of schema objects: Tables Views Indexes Procedures Functions Packages

25
Q

Q9 what are PL/SQL exceptions? Tell me any three.

A

1) Too_many_rows 2) No_data_found 3) Value_error 4) Zero_error Etc.