0% found this document useful (0 votes)
22 views10 pages

Unit V

Uploaded by

Rauank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views10 pages

Unit V

Uploaded by

Rauank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

DATABASE OBJECTS

UNIT-V
VIEWS
• View is a virtual table which is based on select statement.
• It is a logical table which does not occupy space because it does not
have data of its own. It always retrieves record from base tables.
• View is used for following purposes.
• Granting permission on some selected column of a table without
disclosing the table to user.
• Getting record from multiple table without writing the join condition
every time.
• Accessing group function information like sum,min,max column wise
without writing group function every time.
SOME MORE FACTS ON VIEWS
• We can join more than one views.
• If you drop base table on which the view is based does not get
dropped.
• Any operation you do on view it get redirected to base table to
view.
• Details about views are stored in the data-dictionary on views
i.e.. User_ views.
• Syntax
• Create or replace view<name of view>as<select statement>
EXAMPLE ON VIEWS

• Create or replace view v simple as select empno,ename,sal,deptno


from emp;
• Create or replace view deptvw as select ename,sal ,dname ,loc from
emp, dept where emp.deptno=dept.deptno;
• Create or replace view v10 as select * from emp where deptno=10;
• Create or replace view vjob as select * from emp where job=‘CLERK’;
• Create or replace view vsal as select * from emp where sal>5000;
SOME MORE EXAMPLE ON VIEW
Problem:-Create a view which will have sum, minimum, maximum,
average salary of each department.
Solution:- Select deptno, sum(sal)” sum of salary”, min(sal)” minimum
sal” from emp group by deptno;
Problem:- Create view which will have minimum salary,maximum
salary, numuber of emplyee under each job.
Solution:- Create or replace view jobvw as select min(sal)”minimum
sal”,max(sal)” maximum sal”,count(empno)”number of employee”
from emp group by job;
SEQUENCE
• Sequence is a database object which is used to return unique serial
numbers separated by common difference.
• It is used to populate the unique numerical columns of a table for
example acc_no, mobile_no,roll_no, Dl_no.
Syntax
create sequence <name of sequence>
incremented by <any number>
start with <any number>
maxvalue<any number>
cycle cache<any size>;
• Cache means value from sequence will be stored in the cache memory
(buffer) of the current session so that the request session should not go
to database every time across the network to fetch value from sequence.
• Cycle :- is used to repeat the sequence after attaining the highest
value of the sequence by default every sequence is non-cyclic.

• Detail about sequence is stored in data dictionary user_sequence.


• To drop any sequence
• Drop sequence <name of sequence>
To get the values from sequence we need to use pseudo column
NextVal or currval which are two attribute of sequence.
Nextval:- it returns next value available on sequence.
Currval:-it returns current value of the sequence .
we can not use this attribute in any session unless and until the
nextval attribute of the sequence has been used at least once in
the session.
EXAMPLE ON SEQUENCE
• Create sequence s_demo start with 1 increment by 1 Maxval
10 cycle cache 5;
• To see the value from sequence
• Select s_demo.nextval from dual;
• Select s_demo.currval from dual;

Exercise :-Create a table of your choice and sequence and


try to insert value from a sequence to a table.
INDEX
• This is database object which is used to make the execution of queries faster.
• When we create index on any column of any table for that oracle creates a point on
that column which stores the memory location of value of that column.
• Index in used to improve performance of queries.
Precaution:-
• Index a column only if you frequently want to fetch less than 15% of records of a
arge table.
• Do not index small tables with few rows .
• If column contains similar data then don’t create index on that column.
• A unique index is created when we define primary key or unique key in a table.
EXAMPLE ON INDEX.
• Create index emp_email on emp(email).
• This will create an index email column of emp table.

You might also like