Use this as a Reference for the online examination In the last tutorial we have covered the basics and little bit of member functions in this tutorial We are going to focus deeply about methods
Create types and databases Key points Co Dependent Data Types
Emp_t
Mutually needed Due to this reason We can either create empty type and create it later Or we can remove the dependency and alter them later
Step 1:First of all lets just create ordinary types create type depend_t as object( depname varchar2(20), gender char(1), bdate date, relationship varchar2(10))
create type dependtb_t as table of depend_t
Dept_t Emp_t
Step 2: now we can create emp_t create type emp_t as object( eno number(4), enamee varchar2(15), edept ref dept_t, salaray number(8,2), dependents dependtb_t) Step 3: create type dept_t as object( dno number(20), dname varchar2(12), mgr ref emp_t)
create type proj_t as object ( pno number(4), pname varchar2(15), pdept ref dept_t , budget number(10,2))
create type work_t as object( wemp ref emp_t, wproj ref proj_t, since date, hours number(4,2))
create table emp of emp_t(eno primary key )nested table dependents store as dependent_tb
See we have removed the reference because we didnt created a one yet Step 4 :create table dep of dept_t(dno primary key,mgr references emp)
create table dep of dept_t(dno primary key,mgr references emp)
create table proj of proj_t(pno primary key,pdept references dep) create table works of work_t(wemp references emp,wproj references proj)
Step 5 now we have to alter back
alter table emp add constraint fk1 foreign key(edept) references dep
Question (a) Adding member method child allowances alter type emp_t add member function calchild return float cascade
Thinking patern
We need 1.No of childs 2.Salary So to get the no of salary select salaray into sal from emp; to get the no of childs select count(y.depname) into noc from emp s,table(s.dependents) y;
now answer =Salary*0.05*no of childs
create or replace type body emp_t as member function calchild return float is sal float; noc integer; begin select salaray into sal from emp; select count(y.depname) into noc from emp s,table(s.dependents) y; return sal*(5/100)*noc; end; end;
(b) select e.enamee,e.salaray,e.calchild() from emp e not much to explain same theory in tutorial one just calling the method
//Simple inserting method see the tutorial one
(d) First step to alter alter type emp_t add member function bonuscal(rate float) return float cascade
now its so important we already created a member function we dont want to destroy its body so we copy paste same + the new one like this for the new method
we need Salary Rate as a parameter
rate bonus
create or replace type body emp_t as member function calchild return float is sal float; noc integer; begin select salaray into sal from emp; select count(y.depname) into noc from emp s,table(s.dependents) y; return sal*(5/100)*noc; end; member function bonuscal(rate float) return float is sale float; begin select salaray into sale from emp; return sale*rate; end; end;
highlighted one is the new method
e) can be calculated using the same method call we didi in c and last tutorial its upto u guys
Bonus cal f) first altering to the dept_t alter type dep_t add member function numemp return float cascade now we create the body
we create this for the dept type so we havent written methods to dept so completely new create or replace type body dep_t as member function numemp return float is accessing a reference nume integer; begin select count(p.mgr.eno) into nume from dep p; return nume; end; end; select dname,numemp() from dep where dname='academic'
This is to cover the member functions please practice this well and along with any kind of materials Pass the examination well .
(Music and Letters 1973-Oct Vol. 54 Iss. 4) Review by - C. P. - Music and Painting - A Study in Comparative Ideas From Turner To Schoenbergby Edward Lockspeiser (1973) (10.2307 - 734424) - Libgen - Li