You are on page 1of 2

Attribute data types

-------------------------
1. It is a column data type
2. It is a pointer, it points to same address of the existing table.
3. It is a pointer, it inherits the specification of the one database table column
or entire database table or cursor specification.
4. It is based on the dynamic memory management concept.
5. The main concept of attribute data type is to reduce cost of maintenance.
6. It is classified into 2 types
a) %type
b) %rowtype

%type :- It is used for to declare scalar variable, It inherits the specification


of one database table column.
syntax : <variablename> <tablename>.<columnname>%type
Example : v_dname dept.dname%type;

%rowtype :- It is used for to declare structure variable(also known as record


type variable), it inhertis the specification of enitre database table.
Syntax : <variablename> <tablename>%rowtype;
Example : x emp%rowtype;

x.empno
x.ename
x.sal
x.deptno
--WAP accept a employee no and display his details with annual salary and
experience

declare
v_empno emp.empno%type:=&empno;
v_ename emp.ename%type;
v_job emp.job%type;
v_hdate emp.hiredate%type;
v_sal emp.sal%type;
v_deptno emp.deptno%type;
v_ann_sal number(10,2);
v_exp number(5,2);

begin

select ename,job,sal,hiredate,deptno
into v_ename,v_job,v_sal,v_hdate,v_deptno
from emp where empno=v_empno;
v_ann_sal:=v_sal*12;
v_exp:=trunc(months_between(sysdate,v_hdate)/12,2);
dopl('Empno : '||v_empno);
dopl('Ename : '||v_ename);
dopl('Job : '||v_job);
dopl('Salary : '||v_sal);
dopl('Deptno : '||v_deptno);
dopl('Annual sal : '||v_ann_sal);
dopl('Experience : '||v_exp);
end;
/
--WAP accept a employee no and display his details with annual salary and
experience
declare
e emp%rowtype;
v_ann_sal number(10,2);
v_exp number(5,2);
begin
e.empno:=&empno;

select * into e from emp where empno=e.empno;


v_ann_sal:=e.sal*12;
v_exp:=trunc(months_between(sysdate,e.hiredate)/12,2);
dopl('Empno : '||e.empno);
dopl('Ename : '||e.ename);
dopl('Job : '||e.job);
dopl('Salary : '||e.sal);
dopl('Deptno : '||e.deptno);
dopl('Annual sal : '||v_ann_sal);
dopl('Experience : '||v_exp);
end;
/

--WAP accept a employee number and calculate bonus based on the following
conditions and insert into bonus table.

Sal Bonus amount Additional amount


>=5000 20% on ann_sal 2000
>=3000 && <5000 15% on ann_sal 1500
>=1500 && <3000 12% on ann_sal 1200
<1500 10% on ann_sal 1000
Sql>create table bonus(empno number(5) references emp(empno),
Bonus_amt number(10,2),add_amt number(8,2),iss_dt date);

Declare
v_empno emp.empno%type:=&empno;
v_sal emp.sal%type;
v_ann_sal number(8,2);
b bonus%rowtype;

begin
select sal into v_sal from emp where empno=v_empno;
v_ann_sal:=v_sal*12;
if v_sal>=5000 then
b.bonus_amt:=v_ann_sal*20/100;
b.add_amt:=2000;
elsif v_sal>=3000 then
b.bonus_amt:=v_ann_sal*15/100;
b.add_amt:=1500;
if v_sal>=1500 then
b.bonus_amt:=v_ann_sal*12/100;
b.add_amt:=1200;
else
b.bonus_amt:=v_ann_sal*10/100;
b.add_amt:=1000;
end if;
insert into
bonus(empno,bonus_amt,add_amt,iss_dt)values(v_empno,b.bonus_amt,b.add_amt,sysdate);
commit;
end;
/

You might also like