Searching for "PL/SQL"

Q:

Define PL/SQL sequences and write syntax for a sequence

Answer

A sequence is a database object that is used to generate sequential number.


CREATE SEQUENCE seqname [increment] [minimum value][maximum value][start][cache][cycle]               Nextval and currval lets us get the next value and current value from the sequence.

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

What is a Trigger? Explain Types of PL/SQL Triggers.

Answer

A database trigger is procedural code that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database.


Syntax:


CREATE OR REPLACE TRIGGER [Trigger Name] [Before / After / Instead Of]


ON [schema].[table]


<PL/SQL subprogram>


 


Types of PL/SQL triggers : 


> Row trigger          - The trigger fires for each ROW affected.


> Statement trigger - The trigger is fired once when the condition is matched


> Before and After trigger - The BEFORE trigger run the trigger action before the insert, update or delete statement. The AFTER trigger runs the trigger action after the insert, update or delete statement is executes.

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

What is a PL/SQL package? what are its Advantages ?

Answer

A package is a collection of related PL/SQL objects. The package contains a body and a specification. The package specification has the declaration which is public and can be used in the PL/SQL sub programs inside the package.


The package body holds the implementation of all the PL/SQL objects declared in the specification.


Example of a PL/SQL Package.


CREATE OR REPLACE PACKAGE emp_data AS 


PROCEDURE add_employee (


      ename VARCHAR2,


      job VARCHAR2,


      mgr NUMBER,


      sal NUMBER,


      deptno NUMBER);


END emp_actions;


 


CREATE OR REPLACE PACKAGE BODY emp_data AS 


PROCEDURE add_employee (


       ename VARCHAR2,


       job VARCHAR2,


       mgr NUMBER,


       sal NUMBER,


       deptno NUMBER) IS


BEGIN


         INSERT INTO emp VALUES (empno_seq.NEXTVAL, ename, job, mgr, SYSDATE, comm, deptno);


END add_employee;


END emp_data;


Advantages of  PL/SQL packages :


Packages are easier for application designing, encapsulating data, additional functionality and better performance. An application has various modules which can be placed in packages and handled easier.


 

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

What are PL/SQL Subprograms? What are its Advantages ?

Answer

Named PL/SQL blocks of code which can be invoked using parameters are called PL/SQL sub programs.


 


Advantages of PL/SQL subprograms are


- The application makes a single call to the database to run a block of statements which improves performance against running SQL multiple times. This will reduce the number of calls between the database and the application.


- PL/SQL is secure since the code resides inside the database thus hiding internal database details from the application. The application will only make a call to the PL/SQL sub program


- PL/SQL and SQL go hand in hand so there would be no need of any translation required between PL/SQL and SQL.

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

Explain how PL/SQL exceptions are raised.

Answer

PL/SQL exceptions are raised using the RAISE command. This command is used when exceptions are defined by programmer and not implicit exceptions.


 


Example:


Declare and raising an exception:


DECLARE


short_of_attendance EXCEPTION;


min_attendance NUMBER(4);


BEGIN


...


IF min_attendance < 10 THEN


RAISE short_of_attendance;


END IF;


EXCEPTION


WHEN short_of_attendance THEN


-- handle the error


END;

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

Explain some of the commonly used Predefined PL/SQL Exceptions.

Answer

1)Divide by zero        – This is raised when any number is attempted to divide by zero.


2)TOO MANY ROWS   - A SELECT INTO statement returns more than one row.


3)CASE_NOT_FOUND - No choice in the WHEN clause of a case statement is selected.


4)LOGIN_DENIED      - An attempt to login with an invalid username or password.


5)PROGRAM_ERROR  - An internal PL/SQL problem.

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

What are Cursors? Explain Types of cursors in PL/SQL

Answer

Cursors help you manipulate the information retrieved by select statements. This can be done by assigning a name to the cursor.


Example:


CURSOR emp_cur 


IS 


SELECT emp_number from employee_tbl where employee_name = name_in;


Types of Cursors:


Implicit cursors- These cursors are not declared by the programmer. They are issued when the SQL statement is executed. The open, close and fetching is done by itself.


Example:


UPDATE employee SET salary = salary * 2.1;


Here, an implicit cursor is issued to identify the set of rows in the table which would be affected by the update.


 


Explicit cursors- These cursors are defined by programmer. They are used in queries that return multiple rows.


Example:


CURSOR emp_cur 


IS 


SELECT emp_number from employee_tbl where employee_name = name_in;

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

What is a PL/SQL Record data type?

Answer

A record data type represents a data type for that row in a database table. It lets u define your own records and not your own fields.

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle