Category: PL/SQL

what is pl/sql?

January 15, 2010 | Filed Under PL/SQL | Leave a Comment

PL/SQL stands for Procedural Language extension of SQL.

PL/SQL supports variables, conditions, loops and exceptions. Arrays are also supported, though in a somewhat unusual way, involving the use of PL/SQL collections.

While programmers can readily embed Data Manipulation Language (DML) statements directly into their PL/SQL code using straight forward SQL statements, Data Definition Language (DDL) requires more complex “Dynamic SQL” statements to be written in the PL/SQL code. However, DML statements underpin the majority of PL/SQL code in typical software applications.

Each PL/SQL program consists of SQL and PL/SQL statements which from a PL/SQL block.

A PL/SQL Block consists of three sections:

  • The Declaration section (optional).
  • The Execution section (mandatory).
  • The Exception (or Error) Handling section (optional).
Article written by urooj

WHAT IS TRIGGER IN ORACLE?

January 14, 2010 | Filed Under PL/SQL | Leave a Comment

A trigger is a pl/sql structure which is fired when a DML statements like Insert, Delete, Update is executed on a database table. A trigger is triggered automatically when an associated DML statement is executed.

(DML-Data Manipulation Language statements are used for

managing data within schema objects…

-{select,insert,update,delete,merge,call,explain,lock table} )…

Syntax of trigger:—-

CREATE OR REPLACE TRIGGER trigger_name

AFTER DELETE OR INSERT OR UPDATE OF column_name

ON table_name

FOR EACH ROW BEGIN
sql statement END;

Types of triggers:-
1-Row trigger and Statement triggers
2-Before and After triggers
3-Instead of triggers
4-Triggers on System events and User events.

Example:–
The total_salary trigger maintains a derived column that
stores the total salary of all members in a department:

CREATE TRIGGER total_salary

AFTER DELETE OR INSERT OR UPDATE OF department_id, salary ON employees

FOR EACH ROW BEGIN

IF DELETING OR (UPDATING AND old.department_id != new.department_id)

THEN UPDATE departments

SET total_salary = total_salary – old.salary

WHERE department_id = old.department_id;

END IF;

IF INSERTING OR (UPDATING AND old.department_id != new.department_id)

THEN UPDATE departments

SET total_salary = total_salary + new.salary

WHERE department_id = new.department_id;

END IF;

IF (UPDATING AND old.department_id = new.department_id AND

old.salary != new.salary )

THEN UPDATE departments

SET total_salary = total_salary – old.salary + new.salary

WHERE department_id = new.department_id;

END IF;

END;

Article written by urooj

how we will define constant in pl/sql?

January 13, 2010 | Filed Under PL/SQL | Leave a Comment

Constant is a value used in a PL/SQL Block that remains unchanged throughout the program. A constant is a user-defined literal value. You can declare a constant and use it instead of actual value.

For example: If you want to write a program which will increase the salary of the employees by 25%, you can declare a constant and use it throughout the program. Next time when you want to increase the salary again you can change the value of the constant which will be easier than changing the actual value throughout the program.

The General Syntax to declare a constant is:

constant_name CONSTANT datatype := VALUE; 


DECLARE 

 salary_increase CONSTANT number(3); 

BEGIN 

 salary_increase := 100; 

 dbms_output.put_line (salary_increase); 

END; 

((The Declaration section of a PL/SQL Block starts with the reserved keyword DECLARE.
The Execution section of a PL/SQL Block starts with the reserved keyword BEGIN and ends with END.))
Article written by urooj

© PHPInterviewQuestion.com 2009 - 2010

eXTReMe Tracker