You are on page 1of 2

create table student (name char(20),roll_no number(5),year number(4),address var

char2(50),phone_no number(12));
insert into student values ('&name',&roll_no,&year,'&address',&phone_no);
create table old_student (name char(20),roll_no number(5),year number(4),address
varchar2(50),phone_no number(12));

declare
x number(5);
begin
select roll_no into x from student where name='rahul';
if (x > 2220) then
dbms_output.put_line('Roll_No Is Greater Then 2220');
else
dbms_output.put_line('Roll_No Is Less Then 2220');
end if;
exception
when no_data_found then
dbms_output.put_line('No Data Found In Database');
end;
/

create or replace trigger uoos


before update on student
for each row
DECLARE
begin
insert into old_student values (:old.name,:old.roll_no,:old.year,:old.ad
dress,:old.phone_no);
end;
/
create or replace trigger roll1
before update on student
for each row
declare
x number(5);
begin
x := length(:new.roll_no);
dbms_output.put_line(x);
if (x>4) then
raise_application_error(-20100,'Not Valid Above Four Digit');
end if;
end;
/
declare
inval exception;
enqno number(5);
begin
enqno:=&enqno;
if(enqno>1) then
raise inval;
end if;
exception
when inval then
dbms_output.put_line('Must be 1');
end;
/
create or replace trigger ic
before update on student
for each row
declare
x char(20);
begin
x:=:new.name;
:new.name:=initcap(x);
end;
/
declare
a number(20);
x number(3);
begin
loop
select year into a from student;
if ( a = 2009 ) then
x:= x+1;
end if;
end loop;
end;
/
declare
x number(3);
y number(3);
z char(10);
begin
x:=&x;
y:=&y;
z:=&z;
if ( z = '+' ) then
dbms_output.put_line(x+y);
elsif ( z = '*' ) then
dbms_output.put_line(x*y);
elsif ( z = '-' ) then
dbms_output.put_line(x-y);
elsif ( z = '/' ) then
dbms_output.put_line(x/y);
else
dbms_output.put_line('Invalid');
end if;
end;
/

You might also like