0% found this document useful (0 votes)
5 views

Oracle Assignment

Computer science

Uploaded by

sohamjashu93
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)
5 views

Oracle Assignment

Computer science

Uploaded by

sohamjashu93
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/ 7

INDEX, VIEWS, SEQUENCE

Objective:- To implement the concept of Indexes and views.

Indexes- An index is an ordered list of content of a column or group of columns in a table. An index created on the single
column of the table is called simple index. When multiple table columns are included in the index it is called composite
index.

Creating an Index for a table:-

Syntax (Simple)

CREATE INDEX index_name ON tablename (column name);

Composite Index:-

CREATE INDEX index_name

ON tablename(columnname,columnname);

Creating an Unique Index:-

CREATE UNIQUE INDEX <indexname >ON tablename(columnname);

Dropping Indexes:-

An index can be dropped by using DROP INDEX

SYNTAX:-

DROP INDEX indexfilename;

Views:-

Logical data is how we want to see the current data in our database. Physical data is how this data is actually placed in our
database.

Views are masks placed upon tables. This allows the programmer to develop a method via which we can display
predetermined data to users according to our desire.

Views may be created for the following reasons:

1. The DBA stores the views as a definition only. Hence there is no duplication of data.

2. Simplifies Queries.

3. Can be queried as a base table itself.

4. Provides data security.

5. Avoids data redundancy.

Creation of Views:-
Syntax:-

CREATE VIEW viewname AS SELECT columnname, columnname FROM tablename

WHERE columnname=expression_list;

Renaming the columns of a view:-

Syntax:-

CREATE VIEW viewname AS SELECT columnname as newcolumnname…. FROM tablename

WHERE columnname=expression_list;

Selecting a data set from a view-

Syntax:-

SELECT columnname, columnname FROM viewname

WHERE search condition;

Destroying a view-

Syntax:-

DROP VIEW viewname;

Sequence:-

Sequence is a set of integers 1, 2, 3, … that are generated and supported by some database systems to produce unique
values on demand.

 A sequence is a user defined schema bound object that generates a sequence of numeric values.
 Sequences are frequently used in many databases because many applications require each row in a table to contain a
unique value and sequences provides an easy way to generate them.
 The sequence of numeric values is generated in an ascending or descending order at defined intervals and can be
configured to restart when max_value exceeds.
Creation of sequence:-
Syntax:-
CREATE SEQUENCE sequence_name
START WITH initial_value
INCREMENT BY increment_value
MINVALUE minimum value
MAXVALUE maximum value
CYCLE|NOCYCLE
[CACHE cache_size | NOCACHE]
[ORDER | NOORDER];
 sequence_name: Name of the sequence.
 initial_value: starting value from where the sequence starts. Initial_value should be greater than or equal
to minimum value and less than equal to maximum value.
 increment_value: Value by which sequence will increment itself. Increment_value can be positive or negative.
 minimum_value: Minimum value of the sequence.
 maximum_value: Maximum value of the sequence.
 cycle: When sequence reaches its set_limit it starts from beginning.
 nocycle: An exception will be thrown if sequence exceeds its max_value.
 CACHE: Specify the number of sequence values that Oracle will preallocate and keep in the memory for faster
access. The minimum of the cache size is 2. The maximum value of the cache size is based on this formula:

(CEIL (MAXVALUE - MINVALUE)) / ABS (INCREMENT)


In case of a system failure event, you will lose all cached sequence values that have not been used in
committed SQL statements.

 ORDER: Use ORDER to ensure that Oracle will generate the sequence numbers in order of request.
This option is useful if you are using Oracle Real Application Clusters. When you are using exclusive mode, then
Oracle will always generate sequence numbers in order.
 NOORDER:Use NOORDER if you do not want to ensure Oracle to generate sequence numbers in order of
request. This option is the default.

To get next value in the sequence use <sequence_name>.nextval command


For current value of the sequence use <sequence_name>.currval command.

Assignment:-

Client_master:

Clientno Name city pincode state bal.due

0001 Ivan Bombay 400054 Maharashtra 15000


0002 Vandana Madras 780001 Tamilnadu 0
0003 Pramada Bombay 400057 Maharashtra 5000
0004 Basu Bombay 400056 Maharashtra 0
0005 Ravi Delhi 100001 2000
0006 Rukmini Bombay 400050 Maharashtra 0

Salesorder table:
S_orderno S_orderdate Client no Dely Bill Salesman no Delay Orderstatus
type yn date
019001 12-jan-96 0001 F N 50001 20-jan- Ip
96
019002 25-jan-96 0002 P N 50002 27-jan- C
96
016865 18-feb-96 0003 F Y 500003 20-feb- F
96
019003 03-apr-96 0001 F Y 500001 07-apr- F
96
046866 20-may-96 0004 P N 500002 22- C
may-96
010008 24-may-96 0005 F N 500004 26- Ip
may-96

Sales_order_details table:

S_order no Product no Qty ordered Qty disp Product_rate


019001 P00001 4 4 525
019001 P07965 2 1 8400
019001 P07885 2 1 5250
019002 P00001 10 0 525
046865 P07868 3 3 3150
046865 P07885 10 10 5250
019003 P00001 4 4 1050
019003 P03453 2 2 1050
046866 P06734 1 1 12000
046866 P07965 1 0 8400
010008 P07975 1 0 1050
010008 P00001 10 5 525

Challan_header
Challan S_order Challan Date Billed
No No
CH9001 019001 12-DEC-95 Y
CH865 046865 12-NOV-95 Y
CH3965 010008 12-OCT-95 Y
Salesman_master
Salesman_ Salesman Address City Pin State Salamt Tgt_to_get Ytd Remark
no name code Sales s
500001 Kiran A/14 Bom 400002 Maharastr 3000 100 50 Good
worli bay a
500002 Manish 65,narim Bom 400001 Maharastr 3000 200 100 Good
an bay a
500003 Ravi P-7 Bom 400032 Maharastr 3000 200 100 Good
Bandra bay a
500004 Ashish A/5 Bom 400044 Maharastr 3500 200 150 Good
Juhu bay a

Q1. Create an index on the table client_master, field client_no.


Q2. Create an index on the sales_order, field s_order_no.
Q3. Create an composite index on the sales_order_details table for the columns
s_order_no and product_no.
Q4. Create an composite index ch_index on challan_header table for the columns
challan no and s_order_no.
Q5. Create an unique index on the table salesman_master, field salesman_no.
Q6. Drop index ch_index on table challan_header.
Q7. Create view on salesman master whose sal_amt is less than 3500.
Q8. Create a view client_view on client_master and rename the columns as name,
add1, add2, city, pcode, state respectively.
Q9. Select the client names from client_view who lives in city ‘Bombay’.
Q10. Drop the view client_view.
Q11. Create sequence inv_seq with the following parameters, increment by
3, cycle, cache 4 and which will generate numbers from 1 to 9999 in
ascending order.

You might also like