Você está na página 1de 58

ROLL NO 47

ADBT

SYMCA

Practical No. 1 ANALYTICAL & WINDOWING FUNCTIONS Q) Create a table Sales_data having fields Proid number not NULL custid number not NULL timeid date not NULL C char not NULL promid number not NULL quality number not NULL amount number not NULL Perform the following analytical queries. 1)Find out rank with the list sale ranked as one & the highest sale ranked Highest. 2)With the help of partition expression group the following tuples in terms of timeid. 3)Find out the dense_rank for given table. 4)Calculate the top five sales from the given table. 5)Calculate the cumulative distance for the given table. 6)Calculate percent rank & orderthem according to timeid. 7)Using the function Ntile divide the table into four buckets. 8)With the help of functions row_number assign unique rank to each row even if they have the same value.

ROLL NO 47

ADBT

SYMCA

WINDOWING FUNCTION Create table showing daily transactions of particular customer. Proid number not NULL custid number not NULL timeid date not NULL C char not NULL promid number not NULL quality number not NULL amount number not NULL 1)Find out the Cumulative sum of amount channelwise. 2)Find out the sales of last date channelwise. 3)Find out moving average. 4)Calculate seven(7) days moving average. Create a table Sales_data having fields

ROLL NO 47

ADBT

SYMCA

Output:
SQL>create table Sales_data 2 (prodid number(5) NOT NULL, 3 custid number(7) NOT NULL, 4 timeid date NOT NULL, 5 C char(1) NOT NULL, 6 promoid number(5) NOT NULL, 7 quality number(3) NOT NULL, 8 amount number(7,2) NOT NULL); Table created. SQL>insert into Sales_data 98','S',9999,18,9422); 1 row created. SQL>insert into Sales_data 99','S',9998,20,2422); 1 row created. SQL>insert into Sales_data 02','S',9997,12,8422); 1 row created. SQL>insert into Sales_data 98','T',9996,21,8422); 1 row created. SQL>insert into Sales_data 99','T',9995,26,7422); 1 row created. SQL>insert into Sales_data 01','T',9994,15,7422); 1 row created. SQL>insert into Sales_data 97','D',9993,17,6422); 1 row created. SQL>insert into Sales_data 99','D',9992,16,5422); 1 row created. SQL>insert into Sales_data 00','D',9991,11,4422); values(9465,32790,'10-Jan-

values(9466,32791,'11-Jan-

values(9467,32792,'12-APR-

values(9468,32793,'10-MAR-

values(9469,32794,'15-Jan-

values(9470,32795,'10-MAY-

values(9471,32796,'01-Jan-

values(9472,32797,'10-JUL-

values(9473,32798,'20-MAY-

ROLL NO 47

ADBT

SYMCA

1 row created. SQL>insert into Sales_data values(9474,32799,'09-SEP99','P',9990,22,3422); 1 row created.

ROLL NO 47

ADBT

SYMCA

SQL> select * from Sales_data; PRODID CUSTID TIMEID C PROMOID QUALITY AMOUNT ---------- ---------- --------- - ---------- ---------- ---------9465 32790 10-JAN-98 S 9999 18 9422 9466 32791 11-JAN-99 S 9998 20 2422 9467 32792 12-APR-02 S 9997 12 8422 9468 32793 10-MAR-98 T 9996 21 8422 9469 32794 15-JAN-99 T 9995 26 7422 9470 32795 10-MAY-01 T 9994 15 7422 9471 32796 01-JAN-97 D 9993 17 6422 9472 32797 10-JUL-99 D 9992 16 5422 9473 32798 20-MAY-00 D 9991 11 4422 9474 32799 09-SEP-99 P 9990 22 3422 10 rows selected. SQL> select to_char(timeid,'YYYY'),C,to_char(sum(amount), '999,999,999,999.99') from Sales_data group by to_char(timeid,'YYYY'),C; TO_C C TO_CHAR(SUM(AMOUNT) ---------------------1997 D 6,422.00 1998 S 9,422.00 1998 T 8,422.00 1999 D 5,422.00 1999 P 3,422.00 1999 S 2,422.00 1999 T 7,422.00 2000 D 4,422.00 2001 T 7,422.00 2002 S 8,422.00 10 rows selected.

ROLL NO 47

ADBT

SYMCA

1) rank() Find out rank with the list sale ranked as one & the highest sale ranked Highest. SQL> select rank() over (order by sum(amount)) default_rank,to_char(timeid,'YYYY'),C, to_char(sum(amount), '999,999,999,999.99') from Sales_data group by to_char(timeid,'YYYY'),C; DEFAULT_RANK TO_C -----------------------1 1999 2 1999 3 2000 4 1999 5 1997 6 1999 6 2001 8 1998 8 2002 10 1998 10 rows selected C TO_CHAR(SUM(AMOUNT) ---------------------------S 2,422.00 P 3,422.00 D 4,422.00 D 5,422.00 D 6,422.00 T 7,422.00 T 7,422.00 T 8,422.00 S 8,422.00 S 9,422.00

2) PARTITION With the help of partition expression group the following tuples in terms of timeid. SQL> select rank() over(partition by to_char(timeid,'YYYY') order by sum(amount))default_rank, to_char(timeid,'YYYY'),C, to_char(sum(amount),'999,999,999,999.99') from Sales_data group by to_char(timeid,'YYYY'),C; DEFAULT_RANK TO_C C TO_CHAR(SUM(AMOUNT) ------------------ ----- --- ----------------------1 1997 D 6,422.00 1 1998 T 8,422.00 2 1998 S 9,422.00

ROLL NO 47

ADBT

SYMCA

1 2 3 4 1 1 1

1999 1999 1999 1999 2000 2001 2002

S P D T D T S

2,422.00 3,422.00 5,422.00 7,422.00 4,422.00 7,422.00 8,422.00

10 rows selected. 3) DENSE_RANK Find out the dense_rank for given table. SQL> select dense_rank() over(order by sum(amount))default_rank, to_char(timeid,'YYYY'),C,to_char(sum(amount),'999,999,999,99 9.99') from Sales_data group by to_char(timeid,'YYYY'),C; DEFAULT_RANK TO_C C TO_CHAR(SUM(AMOUNT) ------------------ -- -----------------------1 1999 S 2,422.00 2 1999 P 3,422.00 3 2000 D 4,422.00 4 1999 D 5,422.00 5 1997 D 6,422.00 6 1999 T 7,422.00 6 2001 T 7,422.00 7 1998 T 8,422.00 7 2002 S 8,422.00 8 1998 S 9,422.00 10 rows selected.

ROLL NO 47

ADBT

SYMCA

4)TOP_N Calculate the top five sales from the given table. SQL> select * from (select rank() over (order by sum(amount)) default_rank,to_char(timeid,'YYYY'),C, to_char(sum(amount), '999,999,999,999.99') from Sales_data group by to_char(timeid,'YYYY'),C)where default_rank < 6; DEFAULT_RANK TO_C C TO_CHAR(SUM(AMOUNT) ---------------- ---- -----------------------1 1999 S 2,422.00 2 1999 P 3,422.00 3 2000 D 4,422.00 4 1999 D 5,422.00 5 1997 D 6,422.00 5 rows selected. 5)Cummulative Distance=(No. of rows below)/no. of rows Calculate the cumulative distance for the given table. SQL> select rank() over(order by sum(amount))default_rank,cume_dist() over(order by sum(amount))default_dist,to_char(timeid,'YYYY'),C, to_char(sum(amount),'999,999,999,999.99') from Sales_data group by to_char(timeid,'YYYY'),C; DEFAULT_RANK DEFAULT_DIST TO_C C TO_CHAR(SUM(AMOUNT) ----------------- ------------------ ---- --------------------1 .1 1999 S 2,422.00 2 .2 1999 P 3,422.00 3 .3 2000 D 4,422.00 4 .4 1999 D 5,422.00 5 .5 1997 D 6,422.00 6 .7 1999 T 7,422.00 6 .7 2001 T 7,422.00 8 .9 1998 T 8,422.00 8 .9 2002 S 8,422.00

ROLL NO 47

ADBT

SYMCA

10 1 10 rows selected.

1998

9,422.00

ROLL NO 47

ADBT

SYMCA

6)Percent_Rank=(Rank of rows in partition-1)/(Total no. of rows in partition -1) Calculate percent rank & orderthem according to timeid. SQL> select rank() over(order by sum(amount))default_rank, percent_rank() over (order by sum(amount))percent, to_char(timeid,'YYYY'),C,to_char(sum(amount),'999,999,999,99 9.99') from Sales_data group by to_char(timeid,'YYYY'),C; DEFAULT_RANK PERCENT --------------------- ---1 0 2 .111111111 3 .222222222 4 .333333333 5 .444444444 6 .555555556 6 .555555556 8 .777777778 8 .777777778 10 1 10 rows selected. TO_C C TO_CHAR(SUM(AMOUNT) --------------------1999 S 2,422.00 1999 P 3,422.00 2000 D 4,422.00 1999 D 5,422.00 1997 D 6,422.00 1999 T 7,422.00 2001 T 7,422.00 1998 T 8,422.00 2002 S 8,422.00 1998 S 9,422.00

7)Ntile(N) Using the function Ntile divide the table into four buckets. SQL> select rank() over(order by sum(amount))default_rank,ntile(4) over (order by sum(amount))rw_num, to_char(timeid,'YYYY'),C, to_char(sum(amount),'999,999,999,999.99') from Sales_data group by to_char(timeid,'YYYY'),C; DEFAULT_RANK ---------------1 2 3 4 RW_NUM ---------1 1 1 2 TO_C C ---- -1999 S 1999 P 2000 D 1999 D TO_CHAR(SUM(AMOUNT) ------------------2,422.00 3,422.00 4,422.00 5,422.00

ROLL NO 47

ADBT

SYMCA

5 6 6 8 8 10 10 rows selected.

2 2 3 3 4 4

1997 1999 2001 1998 2002 1998

D T T T S S

6,422.00 7,422.00 7,422.00 8,422.00 8,422.00 9,422.00

8)Row_Number With the help of functions row_number assign unique rank to each row even if they have the same value. SQL> select rank() over (order by sum(amount)) default_rank,row_number() over(order by sum(amount)) rw_num, to_char(timeid,'YYYY'),C,to_char(sum(amount),'999,999,999,99 9.99') from Sales_data group by to_char(timeid,'YYYY'),C; DEFAULT_RANK RW_NUM --------------- ------------1 1 2 2 3 3 4 4 5 5 6 6 6 7 8 8 8 9 10 10 10 rows selected. TO_C --1999 1999 2000 1999 1997 1999 2001 1998 2002 1998 C TO_CHAR(SUM(AMOUNT) ------------------S 2,422.00 P 3,422.00 D 4,422.00 D 5,422.00 D 6,422.00 T 7,422.00 T 7,422.00 T 8,422.00 S 8,422.00 S 9,422.00

ROLL NO 47

ADBT

SYMCA

WINDOWING FUNCTIONS
SQL>Create table showing daily transactions of particular customer. 2 create table SalesCust 3 (prodid number(5) NOT NULL, 4 custid number(7) NOT NULL, 5 timeid date NOT NULL, 6 C char(1) NOT NULL, 7 promoid number(5) NOT NULL, 8 quality number(3) NOT NULL, 9 amount number(7,2) NOT NULL); Table created. SQL>insert into SalesCust 10','S',9999,18,9422); 1 row created. SQL>insert into SalesCust 10','S',9998,20,2422); 1 row created. SQL>insert into SalesCust 10','S',9997,12,8422); 1 row created. SQL>insert into SalesCust 10','T',9996,21,8422); 1 row created. SQL>insert into SalesCust 10','T',9995,26,7422); 1 row created. SQL>insert into SalesCust 10','T',9994,15,7422); 1 row created. SQL>insert into SalesCust 10','D',9993,17,6422); 1 row created. SQL>insert into SalesCust 10','D',9992,16,5422); 1 row created. values(9465,3262,'01-Jan-

values(9466,3262,'02-Jan-

values(9467,3262,'03-Jan-

values(9468,3262,'04-Jan-

values(9469,3262,'05-Jan-

values(9470,3262,'06-Jan-

values(9471,3262,'07-Jan-

values(9472,3262,'08-Jan-

ROLL NO 47

ADBT

SYMCA

SQL>insert into SalesCust values(9473,3262,'09-Jan10','D',9991,11,4422); 1 row created. SQL>insert into SalesCust values(9474,3262,'10-Jan10','P',9990,22,3422); 1 row created. SQL>insert into SalesCust values(9474,3262,'11-Jan10','P',9990,22,3442); 1 row created.

ROLL NO 47

ADBT

SYMCA

SQL> select * from SalesCust; PRODID CUSTID AMOUNT ---------------------------9465 3262 9466 3262 9467 3262 9468 3262 9469 3262 7422 9470 3262 7422 9471 3262 6422 9472 3262 5422 9473 3262 4422 9474 3262 3422 9474 3262 11 rows selected. TIMEID --------01-JAN-10 S 02-JAN-10 S 03-JAN-10 S 04-JAN-10 T 05-JAN-10 06-JAN-10 07-JAN-10 08-JAN-10 09-JAN-10 10-JAN-10 11-JAN-10 P -C PROMOID QUALITY

---------9999

---------18 9422 2422 12 8422 8422 26 15 17 16 11 22 22 3442

9998 9997 9996 T T D D D P 9990

20 21 9995 9994 9993 9992 9991 9990

1)Cumulative sum of amounts channelwise Find out the Cumulative sum of amount channelwise. SQL> select timeid,amount,C,sum(amount) over (partition by C order by timeid rows unbounded preceding)cum_amt from SalesCust where custid=3262 and ROWNUM<11 order by 3,1; TIMEID AMOUNT C CUM_AMT ---------------------------07-JAN-10 6422 D 6422 08-JAN-10 5422 D 11844 09-JAN-10 4422 D 16266

ROLL NO 47

ADBT

SYMCA

10-JAN-10 3422 01-JAN-10 9422 02-JAN-10 2422 03-JAN-10 8422 04-JAN-10 8422 05-JAN-10 7422 06-JAN-10 7422 10 rows selected.

P S S S T T T

3422 9422 11844 20266 8422 15844 23266

ROLL NO 47

ADBT

SYMCA

2)last date channelwise Find out the sales of last date channelwise. SQL> select timeid,amount,C,last_value(amount) over(partition by C order by timeid rows between unbounded preceding and unbounded following)cum_amt from SalesCust where custid=3262 and ROWNUM<11 order by 3,1;

TIMEID --------07-JAN-10 08-JAN-10 09-JAN-10 10-JAN-10 01-JAN-10 02-JAN-10 03-JAN-10 04-JAN-10 05-JAN-10 06-JAN-10

AMOUNT ---------6422 5422 4422 3422 9422 2422 8422 8422 7422 7422

C CUM_AMT -----------D 4422 D 4422 D 4422 P 3422 S 8422 S 8422 S 8422 T 7422 T 7422 T 7422

10 rows selected. 3)moving average Find out moving average. SQL> select timeid,amount,C,avg(amount) over (partition by C order by timeid rows unbounded preceding)cum_amt from SalesCust where custid=3262 and ROWNUM<11 order by 1; TIMEID --------01-JAN-10 02-JAN-10 03-JAN-10 04-JAN-10 AMOUNT ---------9422 2422 8422 8422 C CUM_AMT -----------S 9422 S 5922 S 6755.33333 T 8422

ROLL NO 47

ADBT

SYMCA

05-JAN-10 06-JAN-10 07-JAN-10 08-JAN-10 09-JAN-10 10-JAN-10

7422 7422 6422 5422 4422 3422

T T D D D P

7922 7755.33333 6422 5922 5422 3422

10 rows selected.

4)Seven days moving average Calculate seven(7) days moving average. SQL> select timeid,amount,C,sum(amount) over (partition by C order by timeid range interval '7' day preceding)cum_amt from SalesCust where custid=3262 and ROWNUM<11 order by 3,1;

TIMEID --------07-JAN-10 08-JAN-10 09-JAN-10 10-JAN-10 01-JAN-10 02-JAN-10 03-JAN-10 04-JAN-10 05-JAN-10 06-JAN-10

AMOUNT ---------6422 5422 4422 3422 9422 2422 8422 8422 7422 7422

C CUM_AMT -----------D 6422 D 11844 D 16266 P 3422 S 9422 S 11844 S 20266 T 8422 T 15844 T 23266

10 rows selected.

ROLL NO 47

ADBT

SYMCA

3)moving average Find out moving average. SQL> select timeid,amount,C,avg(amount) over (partition by C order by timeid rows unbounded preceding)cum_amt from SalesCust where custid=3262 and ROWNUM<11 order by 1; TIMEID --------01-JAN-10 02-JAN-10 03-JAN-10 04-JAN-10 05-JAN-10 06-JAN-10 07-JAN-10 08-JAN-10 09-JAN-10 10-JAN-10 AMOUNT ---------9422 2422 8422 8422 7422 7422 6422 5422 4422 3422 C CUM_AMT -----------S 9422 S 5922 S 6755.33333 T 8422 T 7922 T 7755.33333 D 6422 D 5922 D 5422 P 3422

10 rows selected.

ROLL NO 47

ADBT

SYMCA

4)Seven days moving average Calculate seven(7) days moving average. SQL> select timeid,amount,C,avg(amount) over (partition by C order by timeid range interval '7' day preceding)cum_amt from SalesCust where custid=3262 and ROWNUM<11 order by 3,1; TIMEID --------07-JAN-10 08-JAN-10 09-JAN-10 10-JAN-10 01-JAN-10 02-JAN-10 03-JAN-10 04-JAN-10 05-JAN-10 06-JAN-10 AMOUNT ---------6422 5422 4422 3422 9422 2422 8422 8422 7422 7422 C -D D D P S S S T T T CUM_AMT ---------6422 5922 5422 3422 9422 5922 6755.33333 8422 7922 7755.33333

10 rows selected.

ROLL NO 47

ADBT

SYMCA

Practical No. 4 Abstract Datatype


Q.1) Create abstract datatype ty_adddress with necessary fields using this datatype create one more abstract datatype ty_person. Create a table customer using ty_person. Insert records in customer table and display distinct states. Query: SQL> create type address_ty as object 2 ( 3 street varchar2(50), 4 city varchar2(50), 5 state char(2), 6 zip number 7 ) 8 ; 9 / Type created. SQL> create or replace type person_ty as object 2 ( 3 name varchar2(25), 4 address address_ty 5 ); 6 / Type created. SQL> create table customer 2 ( cust_id varchar2(4), 3 person person_ty 4 ); Table created.

ROLL NO 47

ADBT

SYMCA

SQL> insert into customer values (100, person_ty ('cus1',address_ty('streetA','cityB','MH',400066))); 1 row created. SQL> insert into customer values (102, person_ty ('cus2',address_ty('streetC','cityR','MH',400063))); 1 row created. SQL> insert into customer values (104, person_ty ('cus3',address_ty('streetX','cityW','GJ',400011))); 1 row created. SQL> insert into customer values (106, person_ty('cus4',address_ty('streetU','cityX','MH',40015))); 1 row created. SQL> select * from customer; CUST --------PERSON (NAME, ADDRESS(STREET, CITY, STATE, ZIP)) -------------------------------------------------------------------------------100 PERSON_TY('cus1', ADDRESS_TY('streetA', 'cityB', 'MH', 400066)) 102 PERSON_TY('cus2', ADDRESS_TY('streetC', 'cityR', 'MH', 400063)) 104 PERSON_TY('cus3', ADDRESS_TY('streetX', 'cityW', 'GJ', 400011)) 106 PERSON_TY('cus4', ADDRESS_TY('streetU', 'cityX', 'MH', 40015))

ROLL NO 47 SQL> select c.person.address.state 2 from customer c 3 group by c.person.address.state; PE ----GJ MH

ADBT

SYMCA

ROLL NO 47

ADBT

SYMCA

Q.2) Create abstract data type student_address with fields. Using this create one more data type stud_marks. Create table student. Insert all records in students. Display all information from students. Query: SQL> create type student_address as object 2 ( 3 street varchar2(50), 4 city varchar2(50), 5 state char(2), 6 pin number); 7 / Type created. SQL> create type student_mark as object 2 ( 3 marks number, 4 address student_address 5 )/ Type created. SQL> create table student 2 ( 3 s_id varchar2(5), 4 name varchar2(25), 5 marks student_mark 6 ) / Table created. SQL> insert into student values ('1','Stud1',student_mark(25,student_address('streetA','cityB','MH', 400066))); 1 row created. SQL> insert into student values ( '2','Stud2',student_mark(50,student_address('streetX','cityM','GJ', 400042))); 1 row created. SQL> insert into student values ( '3','Stud3',student_mark(55,student_address('streetL','cityN','UP', 412066))); 1 row created. SQL> insert into student values ( '4','Stud4',student_mark(45,student_address('streetK','cityJ','MP', 410116))); 1 row created.

ROLL NO 47

ADBT

SYMCA

SQL> insert into student values( '5','Stud5',student_mark(66,student_address('streetO','cityF','CH', 210890))); 1 row created. SQL> select * from student; S_ID NAME ----- ------------------------MARKS(MARKS, ADDRESS(STREET, CITY, STATE, PIN)) -------------------------------------------------------------------------------1 Stud1 STUDENT_MARK(25, STUDENT_ADDRESS('streetA', 'cityB', 'MH', 400066)) 2 Stud2 STUDENT_MARK(50, STUDENT_ADDRESS('streetX','cityM','GJ',400042)) 3 Stud3 STUDENT_MARK(55, STUDENT_ADDRESS('streetL','cityN','UP',412066)) 4 Stud4 STUDENT_MARK(45, STUDENT_ADDRESS('streetK','cityJ','MP',410116)) 5 Stud5 STUDENT_MARK(66, STUDENT_ADDRESS('streetO','cityF','CH',210890))

ROLL NO 47

ADBT

SYMCA

Practical No 6 Grant and Revoke Creating Users akshay & ajay

SQL> connect system Enter password: ***** Connected. SQL> create user akshay identified by kasurde; User created. SQL> create user ajay identified by sutar; User created. SQL> grant create session to akshay; Grant succeeded. SQL> grant create session to ajay; Grant succeeded.

Q 1) Give the user akshay all the data manipulation privileges on the table Sales_data without an option to further grant permission on the emp table to other user
SQL> connect system ; Enter password: ***** Connected. SQL> grant all on Sales_data to akshay; Grant succeeded. SQL> select * from sales_data; PRODID CUSTID TIMEID C PROMOID QUANTITY AMOUNT ---------- ---------- --------- - ---------- ---------- ---------9465 37290 01-JAN-98 S 9999 18 4722

ROLL NO 47

ADBT

SYMCA

SQL> insert into Sales_Data values(1121,12345,'25-Mar12','C',9,1,1); 1 row created. SQL> delete from Sales_Data where ProdId=1121; 1 row deleted.

Q 2)View productid,amount of the tables sales_data that belongs to scott


SQL> connect system; Enter password: ***** Connected. SQL> create view viewfield_47 as select pid,pname,amount from System.Sales_data47; View created. SQL> grant all on viewfield_47 to akshay; Grant succeeded. SQL> grant create session to akshay; Grant succeeded. SQL> connect scott Enter password: ***** Connected. SQL> grant all on viewfield_47 to akshay; SQL> connect akshay; Enter password: ***** Connected. SQL> select * from scott.viewfield_47; no rows selected SQL> insert into scott.viewfield_47values(12,Prathama,35000); 1 rows inserted

ROLL NO 47

ADBT

SYMCA

Q 3)Give the user ajay permission to view records from the 'dept47' table.The tables originally belongs to the user akshay who has granted privilege to grant further privilege on the 'dept' to you
Enter password: ***** Connected. SQL> create table Dept47(did number(2),dname varchar2(20)); Table created. SQL> insert into dept47 values(1,'Govind'); 1 row created. SQL> insert into dept47 values(2,'Sutar'); 1 row created. SQL> connect system Enter password: ***** Connected. SQL> grant all on dept47 to ajay with grant option; Grant succeeded. SQL> grant create session to ajay; Grant succeeded. SQL> connect ajay Enter password: ****** Connected. SQL> grant select on system.dept47 to akshay; Grant succeeded. SQL> connect akshay; Enter password: ***** Connected.

ROLL NO 47

ADBT

SYMCA

ROLL NO 47

ADBT

SYMCA

SQL> select * from system.dept47; DID DNAME ---------- -------------------1 Govind 2 Sutar ---------------------------------

Q 4) Remove all privileges on the tables dept from the user ajay
SQL> connect system Enter password: ***** Connected. SQL> revoke all on dept47 from ajay; Revoke succeeded. SQL> connect ajay Enter password: ****** Connected. SQL> select * from system.dept47; select * from system.dept47 * ERROR at line 1: ORA-00942: table or view does not exist

ROLL NO 47

ADBT

SYMCA

Q.5) The user akshay has the permission to view & delete records from the emp table. Take back the delete permisssion. Scott is the original owner of the emp table. Queries:Grant the privileges SQL> connect scott; Enter password: ***** Connected. SQL> grant select,delete on emp to akshay; Grant succeeded. SQL> connect akshay; Enter password: ***** Connected. SQL> select * from scott.emp; EMP_ID --------------E1 E2 E3 EMP_NAME SAL ------------------------------ajay 15000 govind 12000 deepika 13000

SQL> delete from scott. emp where emp_id='E1'; 1 row deleted. SQL> select * from scott.emp; EMP_ID EMP_NAME --------------- --------------E2 govind E3 deepika SAL ---------12000 13000

ROLL NO 47

ADBT

SYMCA

Queries:Take back the privileges SQL> connect scott; Enter password: ***** Connected. SQL> revoke delete on emp from akshay; Revoke succeeded. Output:SQL> connect akshay Enter password: ***** Connected. SQL> select * from scott.emp; EMP_ID --------------E2 E3 EMP_NAME --------------govind deepika SAL ---------12000 13000

SQL> delete from scott.emp; delete from scott.emp * ERROR at line 1: ORA-01031: insufficient privileges

ROLL NO 47

ADBT

SYMCA

Practical No. 7 PARTITIONING

Q 1 ) Create a table bookshelf with the following fields Title,Publisher,Category_name & Rating
SQL> connect system Enter password: ***** Connected. SQL> grant create tablespace to scott; Grant succeeded. SQL> Create table Bookshelf47(Title varchar2(20) primary key,Publisher varchar2(20),Category_name varchar2(20),Rating varchar2(1)); Table created. SQL> insert into Bookshelf47 values('Harry Potter','THM','Kids Worder','A'); 1 row created. SQL> insert into Bookshelf47 values('Chandoba','Rajhans','Kids Worder','A'); 1 row created. SQL> insert into Bookshelf47 values('Thak Thak','THM','Kids Worder','B'); 1 row created. SQL> insert into Bookshelf47 values('Chacha Chodhary','Rajhans','Kids Worder','B'); 1 row created. SQL> insert into Bookshelf47 values('Yayati','','Story Book','A'); 1 row created. SQL> create tablespace part55_2_TS datafile 'C:\Program Files\Oracle\oradata\ncrdsims\akshay55_2' size 32m 2 autoextend on 3 next 32m Maxsize 2048m

ROLL NO 47

ADBT

SYMCA

4 extent management local; Tablespace created. SQL> create tablespace part55_1_TS datafile 'C:\Program Files\Oracle\oradata\ncrdsims\akshay55_1.dbf' size 32m 2 autoextend on 3 next 32m Maxsize 2048m 4 extent management local; Tablespace created

List Partitioning Q 1) With the help of a list partitioning partition the table
into 2 one having all the book with rating A & C & other having rating B SQL> create table bookshelf_list 2 (title varchar2(100) primary key not null, 3 publisher varchar2(20), 4 category_name varchar2(20), 5 rating varchar2(2), 6 constraint cat_list foreign key(title) references Bookshelf47(title)) 7 partition by list(rating) 8 (partition part001 values('A','C') tablespace part55_1_ts, 9 partition part002 values('B') tablespace part55_2_ts); Table created. SQL> insert into Bookshelf_List select * from Bookshelf47; 5 rows created. SQL> Select count(*) from Bookshelf_List Partition(PART001); COUNT(*) ---------3 SQL> select * from Bookshelf_List partition(PART001); -------------------------------------------------------------------------------TITLE PUBLISHER CATEGORY_NAME RA --------------------------------------------------------------------------------Harry Potter THM Kids Worder A Chandoba Rajhans Kids Worder A

ROLL NO 47

ADBT

SYMCA

Yayati

Story Book

SQL> select count (*) from Bookshelf_List partition (PART002); COUNT(*) ---------2 SQL> select * from Bookshelf_List Partition(PART002); -------------------------------------------------------------------------------TITLE PUBLISHER CATEGORY_NAME RA Thak Thak THM Kids Worder B Chacha Chodhary B Rajhans Kids Worder

SQL> Create index Bookshelf47_index_list on bookshelf_list(Rating) local(Partition part10 tablespace 2 Part55_1_TS,partition part20 tablespace Part55_2_TS); I index created.

ROLL NO 47

ADBT

SYMCA

Hash Function Partition


Q 2) With the help of a hash function partition the table on the basis of Category using tablespace SQL> Create table Bookshelf47_hash(Title varchar2(20) ,Publisher varchar2(20),Category_name varchar2 (20) primary key,Rating varchar2(1)); Table created. SQL> insert into Bookshelf47_hash values('Harry Potter','THM','Kids Worder','A'); 1 row created. SQL> insert into Bookshelf47_hash values('Chandoba','Rajhans','Wonder','A'); 1 row created. SQL> insert into Bookshelf47_hash values('Yayati','','Story Book','A'); 1 row created. SQL> insert into Bookshelf47_hash values('Thak Thak','THM','Ficticious','B'); 1 row created. SQL> Create table Bookshelf_Hash(Title varchar2(20) primary Key,Publisher varchar2(20),Category_name 2 varchar2(20),Rating varchar2(2),constraint CAT_FKK_KK Foreign Key(Category_name)References 3 Bookshelf47_hash (Category_name))partition by hash(Category_name) 4 (partition PART01 tablespace PART55_1_TS, 5 partition PART02 tablespace PART55_2_TS); Table created. SQL> insert into Bookshelf_Hash select * from Bookshelf47_hash; 3 rows created. SQL> Select count(*) from Bookshelf_Hash partition(PART01); COUNT(*) ----------

ROLL NO 47

ADBT

SYMCA

ROLL NO 47

ADBT

SYMCA

SQL> select * from Bookshelf_Hash partition(PART01); TITLE PUBLISHER CATEGORY_NAME -------------------- -------------------- -------------------- -Yayati Story Book RA A

SQL> select count (*) from Bookshelf_Hash partition (PART02); COUNT(*) ---------3 SQL> select * from Bookshelf_Hash Partition(PART02); TITLE PUBLISHER CATEGORY_NAME -------------------- -------------------- -------------------- -Harry Potter THM Kids Worder Chandoba Rajhans Wonder Thak Thak THM Ficticious RA A A B

ROLL NO 47

ADBT

SYMCA

Range Partitioning
Q 3) With the help of a range partitioning partition the file into 2, 1 having values less than B & the other having values less than the maximum value SQL> Create table Bookshelf_Range(Title varchar2(20) primary Key,Publisher varchar2(20),Category_name 2 varchar2(20),Rating varchar2(2),constraint CAT_FK Foreign Key(Category_name)References Bookshelf47_hash 3 (Category_name)) 4 partition by Range(Rating) 5 (Partition PART1 values less than('B') tablespace PART55_1_TS, 6 Partition PART2 values less than (Maxvalue) tablespace PART55_2_TS); Table created. SQL> insert into Bookshelf_Range select * from Bookshelf47_hash; 4 rows created. SQL> Select count(*) from Bookshelf_Range Partition(PART1); COUNT(*) ---------3 SQL> select * from Bookshelf_Range partition(PART1); TITLE PUBLISHER CATEGORY_NAME RA -------------------- -------------------- -------------------- -Harry Potter THM Kids Worder A Chandoba Rajhans Wonder A Yayati Story Book A SQL> select count (*) from Bookshelf_Range partition (PART2); COUNT(*) ---------1 SQL> select * from Bookshelf_Range Partition(PART2);

ROLL NO 47

ADBT

SYMCA

TITLE PUBLISHER CATEGORY_NAME -------------------- -------------------- -------------------- -Thak Thak THM Ficticious

RA B

ROLL NO 47

ADBT

SYMCA

Practical No. 8 Nested Table Q1. Create nested table project list. Create table emp_pro with required fields. Insert the records in the table and update those records.
Query:Creating Nested table Projectlist: create or replace type Proj_list as table of varchar2(64); Type created. Creating Employee table: dcreate table e_project_s(ename varchar2(10),basic_sal number(10),projects Proj_list)Nested table projects store as project_tab; Table created. Inserting Values: insert into e_project_s values ('Akshay',35000, Proj_list ('XYZproj','PQproj','LMproj')); 1 row created. insert into e_project_s values ('Ajay',45000, Proj_list ('PQRproj','ABproj','LMproj')); 1 row created. insert into e_project_s j values ('Harshal',20000, Proj_list ('XYZproj','IJproj','AFproj')); 1 row created. insert into e_project_s values ('Atul',30000, Proj_list ('UVZproj','NMproj','LMproj')); 1 row created. insert into e_project_s values ('Umesh',55000, Proj_list ('XYZproj','EFproj','KLproj')); 1 row created. select * from employee_proj; Output: ENAME BASIC_SAL PROJECTS --------------------------------------------------------------------------------

ROLL NO 47

ADBT

SYMCA

Akshay Ajay Harshal Atul Umesh

35000 PROJECTLIST('XYZproj', 'PQproj', 'LMproj') 45000 PROJECTLIST('PQRproj', 'ABproj', 'LMproj') 20000 PROJECTLIST('XYZproj', 'IJproj', 'AFproj') 30000 PROJECTLIST('UVZproj', 'NMproj', 'LMproj') 55000 PROJECTLIST('XYZproj', 'EFproj', 'KLproj')

Query:
declarenew_projects Projectlist:=Projectlist('XYZproj','PQproj','LMproj','NGHproj'); begin update employee_proj set projects=new_projects whereename='Akshay'; end; procedure successfully completed.

Output
select * from employee_proj; ENAME BASIC_SAL PROJECTS -------------------------------------------------------------------------------Akshay 35000 PROJECTLIST('XYZproj', 'PQproj', 'LMproj', 'NGHproj') Ajay 45000 PROJECTLIST('PQRproj', 'ABproj', 'LMproj') Harshal 20000 PROJECTLIST('XYZproj', 'IJproj', 'AFproj') Atul 30000 PROJECTLIST('UVZproj', 'NMproj', 'LMproj') Umesh 55000 PROJECTLIST('XYZproj', 'EFproj', 'KLproj')

ROLL NO 47

ADBT

SYMCA

Practical 10 Bitmap Indexing


/*product_dim table*/ create table product_dim(product_dim_id number(10) primary key, prod_cat_name varchar2(20), prod_subcat_name varchar2(20), prod_name varchar2(20), prod_feat_desc varchar2(20), dts date); Insert into product_dim xl,sysdate); Insert into product_dim Insert into product_dim xxl,sysdate); Insert into product_dim Insert into product_dim values(1,apparel,shirt,arrow,arrvalues(2,apparel,shirt,vam,van-l,sysdate); values(3,apparel,shirt,arrow,arrvalues(4,shoe,casual,nike,nike8,sysdate); values(5,shoe,casual,nike,nike9,sysdate);

SQL> select * from product_dim; PRODUCT_DIM_ID PROD_CAT_NAME PROD_SUBCAT_NAME -------------------------------------------------------------------------------------------------------------1 apparel shirt 2 apparel shirt 3 apparel shirt 4 shoe casual 5 shoe casual

ROLL NO 47

ADBT

SYMCA

PROD_NAME

PROD_FEAT_DESC

DTS

-------------------------------------------------------------------arrow arr-xl 01-JAN-04 vam van-l 01-JAN-04 arrow arr-xxl 01-JAN-04 nike nike8 01-JAN-04 nike nike9 01-JAN-04 /*location_dim table*/ SQL> create table location_dim(loc_dim_id number(10) primary key, 2 country_name varchar2(20), 3 state_name varchar2(20), 4 city_name varchar2(20), 5 dts date); Table created. Insert Insert Insert Insert Insert into into into into into location_dim location_dim location_dim location_dim location_dim values(101,'india','MH','mumbai',sysdate); values(102,'india','MH','pune',sysdate); values(103,'india','MP','bhopal',sysdate); values(104,'USA','new jersey','jersey',sysdate); values(105,'USA','new york','NY',sysdate);

SQL> select * from location_dim; LOC_DIM_ID STATE_NAME --------------------------------------------------101 102 103 104 105 COUNTRY_NAME ---------------------------------india india india USA USA MH MH MP new jersey new york

ROLL NO 47

ADBT

SYMCA

CITY_NAME DTS ------------------------------mumbai 01-JAN-04 pune 01-JAN-04 bhopal 01-JAN-04 jersey 01-JAN-04 NY 01-JAN-04 /*time_dim table*/ SQL> create table time_dim(time_dim_id number(10) primary key, 2 year_num number(10), 3 day_of_yr number(10), 4 quarter_num number(5), 5 month_name varchar2(20), 6 month_num number(10), 7 week_num number(2), 8 day_of_week varchar2(10), 9 dts date); Table created. Insert into time_dim values(1001,2009,59,1,'FEB',2,4,'Sat',sysdate); Insert into time_dim values(1002,2009,27,1,'JAN',1,5,'Tue',sysdate); Insert into time_dim values(1003,2008,357,3,'DEC',12,4,'Mon',sysdate); Insert into time_dim values(1004,2009,62,1,'MAR',3,1,'Tue',sysdate); Insert into time_dim values(1005,2009,81,1,'MAR',3,4,'Sun',sysdate); SQL> select * from time_dim; TIME_DIM_ID YEAR_NUM QUARTER_NUM ---------------------------------------------------1001 2009 1002 2009 1003 2008 1004 2009 DAY_OF_YR -----------------------27 357 62 59 1 3 1 1

ROLL NO 47

ADBT

SYMCA

1005

2009

81

1 DAY_OF_WEEK ----------------Sat Tue Mon Tue Sun

MONTH_NAME MONTH_NUM WEEK_NUM DTS --------------------- --------------------- -----------------------FEB 2 4 01-JAN-04 JAN 1 5 01-JAN-04 DEC 12 4 01-JAN-04 MAR 3 1 01-JAN-04 MAR 3 4 01-JAN-04 /*sales_fact table*/

SQL> create table sales_fact(prod_dim_id number(10) references product_dim, 2 loc_dim_id number(10) references location_dim, 3 time_dim_id number(10) references time_dim, 4 sales number(20), 5 dts date); Table created. Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert Insert into into into into into into into into into into into into into into into sales_fact sales_fact sales_fact sales_fact sales_fact sales_fact sales_fact sales_fact sales_fact sales_fact sales_fact sales_fact sales_fact sales_fact sales_fact values(1,101,1001,15000,sysdate); values(1,102,1001,2000,sysdate); values(2,101,1002,65000,sysdate); values(2,101,1005,5000,sysdate); values(2,102,1002,58500,sysdate); values(2,104,1005,4620,sysdate); values(3,103,1002,680,sysdate); values(3,104,1004,8000,sysdate); values(3,101,1002,15450,sysdate); values(4,105,1005,3200,sysdate); values(4,103,1005,8400,sysdate); values(5,103,1005,5400,sysdate); values(5,103,1002,62000,sysdate); values(5,101,1001,45000,sysdate); values(5,105,1003,32000,sysdate);

ROLL NO 47

ADBT

SYMCA

Insert into sales_fact values(5,102,1004,25000,sysdate);

ROLL NO 47

ADBT

SYMCA

SQL> select * from sales_fact; PROD_DIM_ID LOC_DIM_ID DTS --------------------------------------------------1 101 01-JAN-04 1 102 01-JAN-04 2 101 01-JAN-04 2 101 01-JAN-04 2 102 01-JAN-04 2 104 01-JAN-04 3 103 JAN-04 3 104 01-JAN-04 3 101 01-JAN-04 4 105 01-JAN-04 4 103 01-JAN-04 5 103 01-JAN-04 5 103 01-JAN-04 5 101 01-JAN-04 5 105 01-JAN-04 5 102 01-JAN-04 16 rows selected.

TIME_DIM_ID -------------------1001 1001 1002 1005 1002 1005 1002 1004 1002 1005 1005 1005 1002 1001 1003 1004

SALES -----------15000 2000 65000 5000 58500 4620 680 8000 15450 3200 8400 5400 62000 45000 32000 25000 01-

SQL> @ C:\oracle\ora92\rdbms\admin\utlxplan.sql; Table created.

ROLL NO 47

ADBT

SYMCA

SQL> connect / as sysdba; Connected. SQL> @ C:\oracle\ora92\sqlplus\admin\plustrce.sql; SQL> drop role plustrace; Role dropped. SQL> create role plustrace; Role created. SQL> grant select on v_$sesstat to plustrace; Grant succeeded. SQL> grant select on v_$statname to plustrace; Grant succeeded. SQL> grant select on v_$session to plustrace; Grant succeeded. SQL> grant plustrace to dba with admin option; Grant succeeded. SQL> set echo off SQL> set autotrace on;

Q.1) Find sales in given city.


/*simple Query Execution*/ SQL> select sum(S.sales) as totalsale,L.city_name 2 from Sales_Fact S,Location_dim L 3 where S.Loc_dim_id=L.Loc_dim_id 4 and L.city_name='Mumbai' 5 group by L.city_name; Output:TOTALSALE CITY_NAME -----------------------------------------------58000 Mumbai Execution Plan ----------------------------------------------------------

ROLL NO 47

ADBT

SYMCA

0 1 2 3 4 5

SELECT STATEMENT Optimizer=CHOOSE 0 SORT (GROUP BY) 1 NESTED LOOPS 2 TABLE ACCESS (FULL) OF 'SALES_FACT' 2 TABLE ACCESS (BY INDEX ROWID) OF 'LOCATION_DIM' 4 INDEX (UNIQUE SCAN) OF 'SYS_C003065' (UNIQUE)

ROLL NO 47

ADBT

SYMCA

Statistics ---------------------------------------------------------0 recursive calls 0 db block gets 0 consistent gets 0 physical reads 0 redo size 0 bytes sent via SQL*Net to client 0 bytes received via SQL*Net from client 0 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed /*After creating index*/ SQL> create bitmap index BGG42 on sales_fact(L.city_name) 2 from Sales_fact S,Location_dim L 3 where S.Loc_dim_id=L.Loc_dim_id; Index created. SQL> set autotrace on; SQL> select sum(S.Sales) as total_sales,L.city_name 2 from Sales_Fact S,Location_dim L 3 where S.Loc_dim_id=L.Loc_dim_id 4 and L.city_name='mumbai' 5 group by L.city_name; Output:TOTAL_SALES CITY_NAME ----------------------------- ------------------------585450 mumbai Execution Plan ---------------------------------------------------------0 SELECT STATEMENT Optimizer=CHOOSE 1 0 SORT (GROUP BY) 2 1 NESTED LOOPS 3 2 TABLE ACCESS (FULL) OF 'SALES_FACT' 4 2 TABLE ACCESS (BY INDEX ROWID) OF 'LOCATION_DIM' 5 4 INDEX (UNIQUE SCAN) OF 'SYS_C003070' (UNIQUE)

ROLL NO 47

ADBT

SYMCA

Statistics ---------------------------------------------------------0 recursive calls 0 db block gets 21 consistent gets 0 physical reads 0 redo size 448 bytes sent via SQL*Net to client 499 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 1 rows processed

ROLL NO 47

ADBT

SYMCA

Q.2) Find sales in given state for a given product category.


/*simple Query Execution*/ SQL> select sum(S.Sales) as totalSale,L.state_name,P.prod_cat_name 2 from Sales_Fact S,Location_dim L,Product_dim P 3 where S.Loc_dim_id=L.Loc_dim_id 4 and L.state_name='MH' 5 and S.Prod_dim_id=P.Product_dim_id 6 and P.Prod_cat_name='apparel' 7 group by L.state_name,P.Prod_cat_name; Output:TOTALSALE STATE_NAME PROD_CAT_NAME -------------------------------------------------------------------------------------116950 MH apparel Execution Plan ---------------------------------------------------------0 SELECT STATEMENT Optimizer=CHOOSE 1 0 SORT (GROUP BY) 2 1 NESTED LOOPS 3 2 NESTED LOOPS 4 3 TABLE ACCESS (FULL) OF 'SALES_FACT' 5 3 TABLE ACCESS (BY INDEX ROWID) OF 'PRODUCT_DIM' 6 5 INDEX (UNIQUE SCAN) OF 'SYS_C003069' (UNIQUE) 7 2 TABLE ACCESS (BY INDEX ROWID) OF 'LOCATION_DIM' 8 7 INDEX (UNIQUE SCAN) OF 'SYS_C003070' (UNIQUE) Statistics ---------------------------------------------------------0 recursive calls 0 db block gets 32 consistent gets 0 physical reads 0 redo size 512 bytes sent via SQL*Net to client 499 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 1 rows processed /* After creating Bitmap Index*/

ROLL NO 47

ADBT

SYMCA

SQL> create Bitmap Index BT42 on Sales_Fact 2 (L.state_name,P.Prod_cat_name) 3 from Sales_Fact S,Location_dim L,Product_dim P 4 where S.Loc_dim_id=L.Loc_dim_id 5 and S.Prod_dim_id=P.Product_dim_id; Index created. SQL> select sum(S.Sales) as totalsale,L.state_name,P.Prod_cat_name 2 from Sales_Fact S,Location_dim L,Product_dim P 3 where S.Loc_dim_id=l.Loc_dim_id 4 and L.state_name='MH' 5 and S.Prod_dim_id=P.Product_dim_id 6 and P.Prod_cat_name='apparel' 7 group by L.state_name,P.Prod_cat_name; Output:TOTALSALE PROD_CAT_NAME ---------------------------------------------------------116950 MH STATE_NAME --------------------------apparel

Execution Plan ---------------------------------------------------------0 SELECT STATEMENT Optimizer=CHOOSE 1 0 SORT (GROUP BY) 2 1 NESTED LOOPS 3 2 NESTED LOOPS 4 3 TABLE ACCESS (FULL) OF 'SALES_FACT' 5 3 TABLE ACCESS (BY INDEX ROWID) OF 'PRODUCT_DIM' 6 5 INDEX (UNIQUE SCAN) OF 'SYS_C003069' (UNIQUE) 7 2 TABLE ACCESS (BY INDEX ROWID) OF 'LOCATION_DIM' 8 7 INDEX (UNIQUE SCAN) OF 'SYS_C003070' (UNIQUE)

ROLL NO 47

ADBT

SYMCA

Statistics ---------------------------------------------------------0 recursive calls 0 db block gets 32 consistent gets 0 physical reads 0 redo size 512 bytes sent via SQL*Net to client 499 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 1 rows processed Q.3) Find sales in a given state.

Simple Query Execution


SQL> select sum(S.Sales) as totalsale,L.state_name 2 from Sales_Fact S,Location_dim L 3 where S.Loc_dim_id=L.Loc_dim_id 4 and L.state_name='MH' 5 group by L.state_name; Output:TOTALSALE -----------------------186950 STATE_NAME ---------------------------MH

Execution Plan ---------------------------------------------------------0 SELECT STATEMENT Optimizer=CHOOSE 1 0 SORT (GROUP BY) 2 1 NESTED LOOPS 3 2 TABLE ACCESS (FULL) OF 'SALES_FACT' 4 2 TABLE ACCESS (BY INDEX ROWID) OF 'LOCATION_DIM' 5 4 INDEX (UNIQUE SCAN) OF 'SYS_C003070' (UNIQUE)

ROLL NO 47

ADBT

SYMCA

Statistics ---------------------------------------------------------0 recursive calls 0 db block gets 21 consistent gets 0 physical reads 0 redo size 443 bytes sent via SQL*Net to client 499 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 1 rows processed After creating bitmap index SQL> create bitmap index BTT on Sales_Fact(L.state_name) 2 from Sales_Fact S,Location_dim L 3 where S.Loc_dim_id=L.Loc_dim_id; Index created. SQL> select sum(S.Sales) as totalsale,L.state_name 2 from Sales_Fact S,Location_dim L 3 where S.Loc_dim_id=L.Loc_dim_id 4 and L.state_name='MH' 5 group by L.state_name; Output:TOTALSALE STATE_NAME --------------------------------------------------186950 MH Execution Plan ---------------------------------------------------------0 SELECT STATEMENT Optimizer=CHOOSE 1 0 SORT (GROUP BY) 2 1 NESTED LOOPS 3 2 TABLE ACCESS (FULL) OF 'SALES_FACT' 4 2 TABLE ACCESS (BY INDEX ROWID) OF 'LOCATION_DIM' 5 4 INDEX (UNIQUE SCAN) OF 'SYS_C003070' (UNIQUE)

ROLL NO 47

ADBT

SYMCA

Statistics ---------------------------------------------------------0 recursive calls 0 db block gets 21 consistent gets 0 physical reads 0 redo size 443 bytes sent via SQL*Net to client 499 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 0 rows processed Q.4) Find Sales in given city for a given product name. /*Simple Query Execution*/ SQL> select sum(S.Sales) as Sales,L.city_name,P.Prod_Feat_desc 2 from Sales_Fact S,Location_dim L,Product_dim P 3 where S.Loc_dim_id=L.Loc_dim_id 4 and L.city_name='bhopal' 5 and S.Prod_dim_id=P.Product_dim_id 6 and P.Prod_Feat_desc='nike9' 7 group by L.city_name,P.Prod_Feat_desc; Output:SALES CITY_NAME --------------------- -----------------------67400 bhopal PROD_FEAT_DESC -------------------------------------nike9

Execution Plan ---------------------------------------------------------0 SELECT STATEMENT Optimizer=CHOOSE 1 0 SORT (GROUP BY) 2 1 NESTED LOOPS 3 2 NESTED LOOPS 4 3 TABLE ACCESS (FULL) OF 'SALES_FACT' 5 3 TABLE ACCESS (BY INDEX ROWID) OF 'PRODUCT_DIM' 6 5 INDEX (UNIQUE SCAN) OF 'SYS_C003069' (UNIQUE) 7 2 TABLE ACCESS (BY INDEX ROWID) OF 'LOCATION_DIM' 8 7 INDEX (UNIQUE SCAN) OF 'SYS_C003070' (UNIQUE)

ROLL NO 47

ADBT

SYMCA

Statistics ---------------------------------------------------------0 recursive calls 0 db block gets 28 consistent gets 0 physical reads 0 redo size 509 bytes sent via SQL*Net to client 499 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 1 rows processed

After creating bitmap index

SQL> create Bitmap Index BMP on Sales_Fact(L.city_name,P.Prod_Feat_desc) 2 from Sales_Fact S,Location_dim L,Product_dim P 3 where S.Loc_dim_id=L.Loc_dim_id 4 and S.Prod_dim_id=P.Product_dim_id; Index created. SQL> select sum(S.Sales) as Sale,L.city_name,P.Prod_Feat_desc 2 from Sales_Fact S,Location_dim L,Product_dim P 3 where S.Loc_dim_id=L.Loc_dim_id 4 and L.city_name='bhopal' 5 and S.Prod_dim_id=P.Product_dim_id 6 and P.Prod_Feat_desc='nike9' 7 group by L.city_name,P.Prod_Feat_desc;

ROLL NO 47

ADBT

SYMCA

Output:SALE CITY_NAME ------------- ------------------------67400 bhopal PROD_FEAT_DESC -----------------------------------nike9

Execution Plan ---------------------------------------------------------0 SELECT STATEMENT Optimizer=CHOOSE 1 0 SORT (GROUP BY) 2 1 NESTED LOOPS 3 2 NESTED LOOPS 4 3 TABLE ACCESS (FULL) OF 'SALES_FACT' 5 3 TABLE ACCESS (BY INDEX ROWID) OF 'PRODUCT_DIM' 6 5 INDEX (UNIQUE SCAN) OF 'SYS_C003069' (UNIQUE) 7 2 TABLE ACCESS (BY INDEX ROWID) OF 'LOCATION_DIM' 8 7 INDEX (UNIQUE SCAN) OF 'SYS_C003070' (UNIQUE) Statistics ---------------------------------------------------------0 recursive calls 0 db block gets 28 consistent gets 0 physical reads 0 redo size 508 bytes sent via SQL*Net to client 499 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 1 rows processed