Sie sind auf Seite 1von 32

Create a table CLIENT_MASTER with following column names:

COLUMN NAME DATA TYPE SIZE


CLIENTNO VARCHAR2 6
NAME VARCHAR2 20
ADDRESS1 VARCHAR2 30
ADDRESS2 VARCHAR2 30
CITY VARCHAR2 15
PINCODE NUMBER 8
STATE VARCHAR2 15
BALDUE NUMBER 10,2

And insert the following data in this table:

CLIENTNO NAME CITY PINCODE STATE BALDUE


C0C001 Ivan Bayross Mumbai 400054 Maharashtra 15000
C0C002 Mamta Madras 780001 Tamil nadu 0
Muzumdar
C0C003 Chhaya Bankar Mumbai 400057 Maharashtra 5000
C0C004 Ashwini Joshi Bangalore 560001 Karnataka 0
C0C005 Hansel Colaco Mumbai 400060 Maharashtra 2000
C0C006 Deepak Sharma Mangalore 560050 Karnataka 0

1
Retrieve all the contents of CLIENT_MASTER table:

Create a table PRODUCT_MASTER with following column names:

COLUMN NAME DATA TYPE SIZE


PRODUCTNO VARCHAR2 6
DESCRIPTION VARCHAR2 15

2
PROFITPERCENT NUMBER 4,2
UNITMEASURE VARCHAR2 10
QTYONHAND NUMBER 8
REORDERVAL NUMBER 8
SELLPRICE NUMBER 8,2
COSTPRICE NUMBER 8,2

And insert the following data in this table:

PRODUC DESCRIPTI PROFITPERC UNITMEAS QTYONHA REORDER SELLPRI COSTPRI


TNO ON ENT URE ND LVL CE CE
P00001 T-SHIRTS 5 PIECE 200 50 350 250
P0345 SHIRTS 6 PIECE 150 50 500 350
P06734 COTTON 5 PIECE 100 20 600 450
JEANS
P07865 JEANS 5 PIECE 100 20 750 500
P07868 TROUSERS 2 PIECE 150 50 850 550
P07885 PULL 2.5 PIECE 80 30 700 450
OVERS
P07965 DENIM 4 PIECE 100 40 350 250
SHIRTS
P07975 LYERA 5 PIECE 70 30 300 175
TOPS
P08865 SKIRTS 5 PIECE 75 30 450 300

3
View the whole table after inserting data in PRODUCT_MASTER:

4
Create a table SALESMAN_MASTER with following column names:

COLUMN NAME DATA TYPE SIZE


SALESMANNO VARCHCAR2 6
SALESMANNAME VARCHCAR2 20
ADDRESS1 VARCHCAR2 30
ADDRESS2 VARCHCAR2 30
CITY VARCHCAR2 20
PINCODE NUMBER 8
STATE VARCHCAR2 20
SALAMT NUMBER 8,2
TGTTOGET NUMBER 6,2
YTDSALES NUMBER 6,2
REMARKS VARCHAR2 60

5
Insert the following data in this table SALESMAN_MASTER:

SALES SALESMA ADDR ADDR CITY PINC STATE SAL TGTT YTDS REM
MANNO NNAME ESS1 ESS2 ODE AMT OGET ALES ARKS
S00001 AMAN A/14 WOR MU 4000 MAHAR 3000 100 50 GOO
LI MBA 02 ASHTRA D
I
S00002 OMKAR 65 NARI MU 4000 MAHAR 3000 200 100 GOO
MAN MBA 01 ASHTRA D
I
S00003 RAJ P-7 BAND MU 4000 MAHAR 3000 200 100 GOO
RA MBA 32 ASHTRA D
I
S00004 ASHISH A/5 JUHU MU 4000 MAHAR 3500 200 150 GOO
MBA 44 ASHTRA D
I

Viewing data from table:

6
7
QUERIES(1):
Find out the names of all clients:

Retrieve the list of names, city and the state of all the clients:

Retrieve the entire contents of CLIENT_MASTER table:

8
List the various PRODUCTS available from the PRODUCT_MASTER:

List all the clients who are located in Mumbai.

Find the names of salesman who have salary equal to 3000:

9
Change the CITY of CLIENTNO „C0C005‟ to „BANGALORE‟:

Change the BALDUE of CLIENTNO „C0C001‟ to „1000‟:

Change the size of SELLPRICE column in PRODUCT_MASTER to 10,2:

10
Change the COSTPRICE of „TROUSERS‟ to Rs. 950.00:

Change the CITY of salesman to „PUNE‟:

Delete all salesman from the SALESMAN_MASTER whose salaries are equal to 3500:

Delete all products from PRODUCT_MASTER where the QTYONHAND is equal to 100:

Delete from CLIENT_MASTER where the column STATE holds the value „TAMIL NADU‟:

11
Add a column called „TELEPHONE‟ of data type „NUMBER” and SIZE=‟10‟ to the CLIENT_MASTER
table:

Change the size of SELLPRICE column in PRODUCT_MASTER to 10,2:

Destroy the table along with its data:

Change the name of the SALESMAN_MASTER to SMAN_MAST.

12
13
QUERIES(2):
Create a table CLIENT_MASTER with following column names:

COLUMN NAME DATA TYPE SIZE Attributes


CLIENTNO VARCHAR2 6 Primary key/first letter must start with „C‟
NAME VARCHAR2 20 Not Null
ADDRESS1 VARCHAR2 30
ADDRESS2 VARCHAR2 30
CITY VARCHAR2 15
PINCODE NUMBER 8
STATE VARCHAR2 15
BALDUE NUMBER 10,2

And insert the following data in this table:

CLIENTNO NAME CITY PINCODE STATE BALDUE


C0C001 Ivan Bayross Mumbai 400054 Maharashtra 15000
C0C002 Mamta Madras 780001 Tamil nadu 0
Muzumdar
C0C003 Chhaya Bankar Mumbai 400057 Maharashtra 5000
C0C004 Ashwini Joshi Bangalore 560001 Karnataka 0
C0C005 Hansel Colaco Mumbai 400060 Maharashtra 2000
C0C006 Deepak Sharma Mangalore 560050 Karnataka 0

14
Create a table PRODUCT_MASTER with following column names:

COLUMN NAME DATA TYPE SIZE ATTRIBUTES


PRODUCTNO VARCHAR2 6 PRIMARY KEY/FIRST LETTER MUST START WITH
„P‟
DESCRIPTION VARCHAR2 15 NOT NULL
PROFITPERCENT NUMBER 4,2 NOT NULL
UNITMEASURE VARCHAR2 10 NOT NULL
QTYONHAND NUMBER 8 NOT NULL
REORDERVAL NUMBER 8 NOT NULL
SELLPRICE NUMBER 8,2 NOT NULL,CANNOT BE 0
COSTPRICE NUMBER 8,2 NOT NULL,CANNOT BE 0

And insert the following data in this table:

PRODUC DESCRIPTI PROFITPERC UNITMEAS QTYONHA REORDER SELLPRI COSTPRI


TNO ON ENT URE ND LVL CE CE
P00001 T-SHIRTS 5 PIECE 200 50 350 250
P0345 SHIRTS 6 PIECE 150 50 500 350
P06734 COTTON 5 PIECE 100 20 600 450
JEANS
P07865 JEANS 5 PIECE 100 20 750 500
P07868 TROUSERS 2 PIECE 150 50 850 550
P07885 PULL 2.5 PIECE 80 30 700 450

15
OVERS
P07965 DENIM 4 PIECE 100 40 350 250
SHIRTS
P07975 LYERA 5 PIECE 70 30 300 175
TOPS
P08865 SKIRTS 5 PIECE 75 30 450 300

16
Create a table SALESMAN_MASTER with following column names:

COLUMN NAME DATA TYPE SIZE ATTRIBUTES


SALESMANNO VARCHCAR2 6 PRIMARY KEY/FIRST LETTER MUST START WITH
„S‟
SALESMANNAME VARCHCAR2 20 NOT NULL
ADDRESS1 VARCHCAR2 30 NOT NULL
ADDRESS2 VARCHCAR2 30
CITY VARCHCAR2 20
PINCODE NUMBER 8
STATE VARCHCAR2 20
SALAMT NUMBER 8,2 NOT NULL,CANNOT BE 0
TGTTOGET NUMBER 6,2 NOT NULL,CANNOT BE 0
YTDSALES NUMBER 6,2 NOT NULL
REMARKS VARCHAR2 60

Insert the following data in this table SALESMAN_MASTER:

SALES SALESMA ADDR ADDR CITY PINC STATE SAL TGTT YTDS REM
MANNO NNAME ESS1 ESS2 ODE AMT OGET ALES ARKS
S00001 AMAN A/14 WOR MU 4000 MAHAR 3000 100 50 GOO
LI MBA 02 ASHTRA D
I
S00002 OMKAR 65 NARI MU 4000 MAHAR 3000 200 100 GOO
MAN MBA 01 ASHTRA D

17
I
S00003 RAJ P-7 BAND MU 4000 MAHAR 3000 200 100 GOO
RA MBA 32 ASHTRA D
I
S00004 ASHISH A/5 JUHU MU 4000 MAHAR 3500 200 150 GOO
MBA 44 ASHTRA D
I

Create a table SALES_ORDER with following column names:

COLUMN NAME DATA TYPE SIZ DEFAULT Attributes


E VALUE
ORDERNO VARCHAR2 6 PRIMARY KEY/FIRST LETTER MUST START
WITH „O‟
CLIENTNO VARCHAR2 6 FOREIGN KEY REFERENCES CLIENTNO OF
CLIENT_MASTER TABLE
ORDERDATE DATE NOT NULL
DELYADDR VARCHAR2 25
SALESMANNO VARCHAR2 6 FOREIGN KEY REFERENCES OF
SALESMAN_MASTER TABLE
DELYTYPE CHAR 1 F DELIVERY:P(PART)/F(FULL)
BILLYN CHAR 1
DELYDATE DATE CANNOT E LESS THAN ORDERDATE
ORDERSTATUS VARCHAR2 10 VALUES („IN PROCESS‟, ‟FULFILLED‟,
‟BACKORDER‟, ‟CANCELLED‟)

18
And insert the following data in this table:

ORDERN CLIENTN ORDERDAT SALESMANN DELYTYP BILL DELYTYPE ORDERSTATU


O O E O E YN S
O19001 C00001 12-JUNE-02 S00001 F N 20-JULY-02 IN PROCESS
019002 C00002 25-JUNE-02 S00002 P N 27-JUNE-02 CANCELLED
O46865 C00003 18-FEB-02 S00003 F Y 20-FEB-02 FULFILLED
O19003 C00001 03-APR-02 S00001 F Y 07-APR-02 FULFILLED
O46866 C00004 20-MAY-02 S00002 P N 22-MAY-02 CANCELLED
O19008 C00005 24-MAY-02 S00004 F N 26-JULY-02 IN PROCESS

19
Create a table SALES_ORDER_DETAILS with following column names:

COLUMN NAME DATA TYPE SIZE Attributes


ORDERNO VARCHAR2 6 FOREIGN KEY REFERENCES ORDERNO OF
SALES_ORDER TABLE
PRODUCTNO VARCHAR2 6 FOREIGN KEY REFERENCES CLIENTNO OF
PRODUCT_MASTER TABLE
QTYORDERED NUMBER 8
QTYDISP NUMBER 8
PRODUCTRATE NUMBER 10,2

And insert the following data in this table:

ORDERNO PRODUCTNO QTYORDERED QTYDISP PRODUCTRATE


O19001 P00001 4 4 525
O19001 P07965 1 1 8400
O19001 P07885 1 1 5250
O19002 P00001 0 0 525
O46865 P07868 3 3 3150
O46865 P07885 1 1 5250
O46865 P00001 10 10 525
O46865 P0345 4 4 1050
O19003 P0345 2 2 1050
O19003 P06734 1 1 12000
O46866 P07965 1 0 8400
O46866 P07975 1 0 1050
O19008 P00001 10 5 525
O19008 P07975 5 3 1050

20
21
22
QUERIES(3):
List the names of all the clients having „a‟ as the second letter in their names.

List the clients who stay in a city whose first letter is „M‟.

List all clients who stay in „Bangalore‟ or „,‟Mangalore‟.

List all the clients whose BalDue is greater than value 10000.

List all the information from the Sales_Order table for orders placed in the month of june.

List the order information for ClientNo „C00001‟ and „C00002‟.

23
List products whose selling price is greater than 500 and less than or equal to 750.

List products whose selling price is more than 500. Calculate a new selling price as, original selling
price*0.15. Rename the new column in the output of the above query as new_price.

List the names, city and state of clients who are not in the state of „Maharashtra‟.

Count the total number of orders.

Calculate the average price of all the products.

24
Determine the maximum and minimum product prices. Rename the output as max_price and min_price
respectively.

Count the number of products having price less than or equal to 500.

List all the products whose QtyOnHand is less than reorder level.

List the order number and day on which clients placed their order.

List the month (in alphabets) and date when the orders must be delivered.

25
List the OrderDate in the format „DD-Month-YY‟.

List the date, 15 days after today‟s date.

26
VIEWS & INDEXES:
Views
 A view is like a “virtual” table
 Defined by a query, which describes how to compute the view contents on the fly DBMS stores the
view definition query instead of view contents
 Can be used in queries just like a regular table

Why views are created?


 To hide data from users
 To hide complexity from users
 Logical data independence
 If applications deal with views, we can change the underlying schema without affecting applications
 Recall physical data independence: change the physical organization of data without affecting
applications
 To provide a uniform interface for different implementations or sources
 Real database applications use tons of views

Creating Views:
Syntax:
CREATE VIEW <VIEW NAME> AS SELECT <COLUMNNAME1>,<COLUMNNAME2> FROM
<TABLENAME> WHERE <COLUMNNAME>=<EXPRESSION LIST>;
GROUP BY <GROUPING CRITERIA> HAVING <PREDICATE>

For Example:

Modifying views:
 Does not seem to make sense since views are virtual
 But does make sense if that is how users see the database
 Goal: modify the base tables such that the modification would appear to have been accomplished on
the view.

Destroying a View:
Syntax:
DROP VIEW <VIEW NAME>;
For Example:

Updateable views:
 More or less just single-table selection queries
 No join
 No aggregation
 No subqueries

27
 Arguably somewhat restrictive
 Still might get it wrong in some cases
 See the slide titled “An impossible case”
 Adding WITH CHECK OPTION to the end of the view

Indexes:
 An index is an order list of content of a column,(or a group of columns) of a table.Indexing involves
forming a two dimensional matrices completely independent of table on which index is being created.
 This two dimensional matrix will have a single column,which will hold sorted data,extracted from
table columns on which the index is created.
 Another column called the address field identifies the location of record in oracle database.
 The records in the index are sorted in ascending order of index column.

Creation of an index:
An index can be created in one or more columns.Based on the No. of columns included in the index, an index
can be:

 Simple Index
 Composite Index

Creating Simple Index:


Syntax:
CREATE INDEX <INDEX NAME> ON <TABLE NAME>(<COLUMN NAME>);

For example:

Creating Composite Index:


Syntax:
CREATE INDEX <INDEX NAME> ON <TABLE NAME>(<COLUMN NAME1>,<COLUMN NAME2>);

For example:

Creating Unique Index:


Syntax:
CREATE UNIQUE INDEX <INDEX NAME> ON <TABLE NAME>(<COLUMN NAME>);

28
For example:

Dropping Index:

Syntax:
DROP INDEX <INDEX NAME> ;

For example:

29
PL/SQL:
1) Write a PL/SQL code block that will accept an account no from user,check if user balance is less than
the minimum balance,only then deduct RS.100 from the balance.The process is fired on AM_MCA55
table.

30
2) Create a simple loop such that a message is displayed when a loop exceed a particular value.

3) Write a PL/SQL code block to calculate area of circle for a value of radius varying from 3 to 7.Store
the radius and corresponding values of calculated area in an empty table named area_mca52,consisting
of two columns radius and area.

31
4) Write a PL/SQL block of code for inverting a number 5639 to 9365.

32

Das könnte Ihnen auch gefallen