PLSQLNotes
PLSQLNotes
PLSQLNotes
LIMATATIONS OF SQL
SQL IS the most powerful and comphrensive database language. Is is flexible and
efficient. SQL is designed for working with relation data.
Even though is powerful and efficient it has certain limitations.
some of the llimitaions are:
-SQL is non procudural
to execute the output from the database use the following commands
--out/put--?
SET SERVEROUTPUT ON;
/
declare
--Single line comment
v1 number:=39;
v2 number:=23;
begin
dbms_output.put_line('Result is '||(v1+v2));
end;
/
--named block
<<OuterBlock>>
declare
v1 number(5):=202;
v2 number(5):=402;
begin
<<InnerBlock>>
declare
v3 number(5):=402;
begin
dbms_output.put_line('Success From Nested Block' ||v1);
dbms_output.put_line('Value From Inner Block' ||InnerBlock.v3);
end;
dbms_output.put_line('Success' ||v1);
end;
/
IF LOOP
declare
v1 number:=94;
v2 number:=32;
temp number;
begin
if(v1>v2) then
temp:=v1;
v1:=v2;
v2:=temp;
end if;
dbms_output.put_line('After swapping values the values are as : '||v1||' '||v2);
end;
/
IF.......ELSE LOOPS
declare
v1 number:=&a;
begin
if(mod(v1,2)=0) then
dbms_output.put_line('The number is even');
else
dbms_output.put_line('The Number is odd');
end if;
end;
/
FOR LOOP
declare
v1 number:=1;
v2 number:=10;
begin
for i in v1..v2
loop
dbms_output.put_line(i);
end loop;
dbms_output.put_line('Success ');
end;
declare
v1 number:=1;
v2 number:=10;
begin
for i in reverse v1..v2
loop
dbms_output.put_line(i);
end loop;
dbms_output.put_line('Success ');
end;
-----
declare
v1 number:=1;
v2 number:=10;
begin
for i in reverse v1..v2
loop
dbms_output.put_line(v2);
v2:=v2-1;
end loop;
dbms_output.put_line('Success ');
end;
-----
declare
v1 number:=1;
v2 number:=10;
begin
for i in v1..v2
loop
if(i=7) or (i=8) then
dbms_output.put_line('');
else
dbms_output.put_line(i);
end if;
end loop;
dbms_output.put_line('Success ');
end;
/
------
------------
Exceptionn handeling
declare
v1 number:=&entervalue;
v2 number:=&entervalue;
result number;
begin
result:=v1/v2;
exception
when zero_divide then
dbms_output.put_line(sqlerrm);
end;
--------------
Explicit Cursors
These are user-defined cursors.
Explicit cursors are defined in the declaration section of the PL/SQL block.
declare
cursor mycursor is
select * from employee1;
empdata mycursor%rowtype;
begin
for empdata in mycursor
loop
dbms_output.put_line(empdata.emp_name);
end loop;
end;
------TRIGGER-------
a database trigger is a PL/SQL program unit, which get fired automatically whenever
the data event such as DML or DDL
or system event such as lagon or startup tskes place on a schema or adtabase.
Types of triggers:
Statement trigger and row trigger.
Statement trigger
A statement trigger is a trigger in which the trigger action is executed once
for the menipulation operation that firs the trigger.
You can use a statement trigger when the trigger action is performed repeatedly
for each row of the table that is affected by the manipuation operation that fires
the trigger.
You use a row trigger when the trigger action is depemdemt om that data
/* -20000 to -20999 */