Journal PLSQL
Journal PLSQL
Journal PLSQL
-------------
STRUCTURE :-
2) ~ TABLE :- PRODUCT_MASTER
3) ~ TABLE :- SALESMAN_MASTER
---------------
STRUCTURE :-
Name Null? Type
------------------------------- -------- ----
SALESMANNO NOT NULL VARCHAR2(6)
SALESMANNAME NOT NULL VARCHAR2(20)
ADDRESS1 NOT NULL VARCHAR2(30)
ADDRESS2 VARCHAR2(30)
CITY VARCHAR2(20)
PINCODE NUMBER(8)
STATE VARCHAR2(20)
SALAMT NOT NULL NUMBER(8,2)
TGTTOGET NOT NULL NUMBER(6,2)
YTDSALES NOT NULL NUMBER(6,2)
REMARKS VARCHAR2(60)
4) ~ TABLE :- SALES_ORDER
-----------
STRUCTURE :-
Name Null? Type
------------------------------- -------- ----
ORDERNO NOT NULL VARCHAR2(6)
CLIENTNO VARCHAR2(6)
ORDERDATE NOT NULL DATE
DELYADDR VARCHAR2(25)
SALESMANNO VARCHAR2(6)
DELYTYPE CHAR(1)
BILLYN CHAR(1)
DELYDATE DATE
ORDERSTATUS VARCHAR2(10)
5) ~ TABLE :- SALES_ORDER_DETAILS
-------------------
6) ~ TABLE :- CHALLAN_HEADER
--------------
STRUCTURE :-
Name Null? Type
------------------------------- -------- ----
CHALLAN_NO NOT NULL VARCHAR2(6)
ORDER_NO VARCHAR2(6)
CHALLAN_DATE NOT NULL DATE
BILLED_YN CHAR(1)
7) ~ TABLE :- CHALLAN_DETAILS
---------------
1) ~ TABLE :- CLIENT_MASTER
-------------
COMMAND :-
-------
INSERT INTO CLIENT_MASTER(CLIENTNO,NAME,CITY,PINCODE,STATE,BALDUE)
VALUES('C00007','KAVITA PATEL','PUNE',411057,'MAHARASHTRA',8000);
RECORD :-
------
CLIENT NAME ADDRESS1 ADDRESS2 CITY PINCODE STATE BALDUE
------ --------------- --------------- --------------- --------------- --------- ------------ ---------
C00007 KAVITA PATEL PUNE PUNE 411057 MAHARASHTRA 8000
C00008 RAJESH JAIN CHENNAI CHENNAI 600001 TAMIL NADU 12000
C00009 SNEHA SHARMA HYDERABAD HYDERABAD 500001 TELANGANA 9000
C00010 RAMESH KUMAR BANGALORE BANGALORE 560001 KARNATAKA 6000
C00011 PREETI GUPTA MUMBAI MUMBAI 400054 MAHARASHTRA 10000
2) ~ TABLE :- PRODUCT_MASTER
--------------
COMMAND :-
-------
RECORD :-
------
3) ~ TABLE :- SALESMAN_MASTER
---------------
COMMAND :-
-------
VALUES('S00001','AMAN','A/14','WORLI','MUMBAI',400002,'MAHARASHTRA',3000,100,50,'GOOD');
VALUES('S00002','OMKAR','65','NARIMAN','MUMBAI',400001,'MAHARASHTRA',3000,200,100,'GOOD');
VALUES('S00004','ASHISH','A/5','JUHU','MUMBAI',400044,'MAHARASHTRA',3500,200,150,'GOOD');
RECORD :-
------
4) ~ TABLE :- SALES_ORDER
-----------
COMMAND :-
-------
INSERT INTO
SALES_ORDER(ORDERNO,CLIENTNO,ORDERDATE,SALESMANNO,DELYTYPE,BILLYN,DELYDATE,ORDERSTA
TUS) VALUES('019009','C00007','30-JUN-04','S00005','F','Y','03-JUL-02','IN PROCESS');
INSERT INTO
SALES_ORDER(ORDERNO,CLIENTNO,ORDERDATE,SALESMANNO,DELYTYPE,BILLYN,DELYDATE,ORDERSTA
TUS) VALUES('046867','C00008','15-JUL-04','S00006','P','N','17-JUL-02','CANCELLED');
INSERT INTO
SALES_ORDER(ORDERNO,CLIENTNO,ORDERDATE,SALESMANNO,DELYTYPE,BILLYN,DELYDATE,ORDERSTA
TUS) VALUES('019010','C00009','20-AUG-04','S00007','F','Y','24-AUG-02','FULFILLED');
INSERT INTO
SALES_ORDER(ORDERNO,CLIENTNO,ORDERDATE,SALESMANNO,DELYTYPE,BILLYN,DELYDATE,ORDERSTA
TUS) VALUES('046868','C00010','25-SEP-04','S00008','P','N','27-SEP-02','CANCELLED');
INSERT INTO
SALES_ORDER(ORDERNO,CLIENTNO,ORDERDATE,SALESMANNO,DELYTYPE,BILLYN,DELYDATE,ORDERSTA
TUS) VALUES('019011','C00011','30-OCT-04','S00009','F','Y','03-NOV-02','IN PROCESS');
RECORD :-
------
5) ~ TABLE :- SALES_ORDER_DETAILS
-------------------
COMMAND :-
-------
RECORD :-
------
|---------|---------|------------|---------|-------------|
6) ~ TABLE :- CHALLAN_HEADER
--------------
COMMAND :-
-------
RECORD :-
------
|------------|----------|--------------|---|
7) ~ TABLE :- CHALLAN_DETAILS
---------------
COMMAND :-
-------
RECORD :-
------
|------------|---------|----------|
| CH5482 | P94211 | 42 |
| CH5482 | P21988 | 19 |
| CH6543 | P76543 | 81 |
| CH9821 | P45678 | 39 |
| CH9821 | P94321 | 27 |
1) FIND OUT THE NAMES OF ALL THE CLIENTS.
OUTPUT:-
NAME
----------------
Kavita Patel
Rajesh Jain
Sneha Sharma
Ramesh Kumar
Preeti Gupta
OUTPUT:-
OUTPUT:-
NAME CITY STATE
---------------- ---------- ---------------
Kavita Patel Pune Maharashtra
Rajesh Jain Chennai Tamil Nadu
Sneha Sharma Hyderabad Telangana
Ramesh Kumar Bangalore Karnataka
Preeti Gupta Mumbai Maharashtra
OUTPUT:-
DESCRIPTION
------------------------
SWEATSHIRTS
SPORTS SHOES
DRESS MATERIAL
KIDS WEAR
FASHION JEWELLERY
OUTPUT:-
| CLIENT NAME | ADDRESS1 | ADDRESS2 | CITY | PINCODE | STATE | BALDUE |
|--------------|----------|----------|-------|---------|-------------|--------|
| PREETI GUPTA | MUMBAI | MUMBAI | MUMBAI| 400054 | Maharashtra | 10000 |
SALESMANNAME
--------------
OMKAR
RAJ
AMAN
OUTPUT:-
| CLIENT ID | CLIENT NAME | ADDRESS1 | ADDRESS2 | CITY | PINCODE | STATE | BALDUE |
|-----------|-----------------|-------------|-------------|-------------|---------|-------------|--------|
| C00007 | KAVITA PATEL | PUNE | PUNE | BANGALORE | 411057 | MAHARASHTRA |
8000 |
| C00008 | RAJESH JAIN | CHENNAI | CHENNAI | CHENNAI | 600001 | TAMIL NADU | 12000 |
| C00009 | SNEHA SHARMA | HYDERABAD | HYDERABAD | HYDERABAD | 500001 | TELANGANA
| 9000 |
| C00010 | RAMESH KUMAR | BANGALORE | BANGALORE | BANGALORE | 560001 | KARNATAKA
| 6000 |
| C00011 | PREETI GUPTA | MUMBAI | MUMBAI | MUMBAI | 400054 | MAHARASHTRA |
10000 |
OUTPUT:-
| CLIENT ID | CLIENT NAME | ADDRESS1 | ADDRESS2 | CITY | PINCODE | STATE | BALDUE |
|-----------|-----------------|-------------|-------------|-------------|---------|-------------|--------|
| C00007 | KAVITA PATEL | PUNE | PUNE | BANGALORE | 411057 | MAHARASHTRA |
8000 |
| C00008 | RAJESH JAIN | CHENNAI | CHENNAI | CHENNAI | 600001 | TAMIL NADU | 12000 |
| C00009 | SNEHA SHARMA | HYDERABAD | HYDERABAD | HYDERABAD | 500001 | TELANGANA
| 1000 |
| C00010 | RAMESH KUMAR | BANGALORE | BANGALORE | BANGALORE | 560001 | KARNATAKA
| 6000 |
| C00011 | PREETI GUPTA | MUMBAI | MUMBAI | MUMBAI | 400054 | MAHARASHTRA |
10000 |
ANS.:-
UPDATE PRODUCT_MASTER SET COSTPRICE = 950.00 WHERE DESCRIPTION = 'SWEATSHIRTS';
OUTPUT:-
PRODUC | DESCRIPTION | PROFITPERCENT | UNITMEASUR | QTYONHAND | REORDERLVL
| SELLPRICE | COSTPRICE
---------|--------------------|---------------|------------|-----------|------------|-----------|-----------
P11111 | SWEATSHIRTS |5 | PIECE | 150 | 40 | 400 | 950
P22222 | SPORTS SHOES |3 | PAIR | 100 | 30 | 600 | 400
P33333 | DRESS MATERIAL | 4 | METRE | 80 | 20 | 350 | 220
P44444 | KIDS WEAR |5 | PIECE | 70 | 25 | 300 | 200
P55555 | FASHION JEWELLERY | 2 | PIECE | 60 | 15 | 250 | 180
OUTPUT :-
| CLIENT ID | CLIENT NAME | ADDRESS1 | ADDRESS2 | CITY | PINCODE | STATE | BALDUE |
|-----------|-----------------|-------------|-------------|-------|---------|-------------|--------|
| C00007 | KAVITA PATEL | PUNE | PUNE | PUNE | 411057 | MAHARASHTRA | 8000 |
| C00008 | RAJESH JAIN | CHENNAI | CHENNAI | PUNE | 600001 | TAMIL NADU | 12000 |
| C00009 | SNEHA SHARMA | HYDERABAD | HYDERABAD | PUNE | 500001 | TELANGANA | 1000 |
| C00010 | RAMESH KUMAR | BANGALORE | BANGALORE | PUNE | 560001 | KARNATAKA | 6000|
| C00011 | PREETI GUPTA | MUMBAI | MUMBAI | PUNE | 400054 | MAHARASHTRA | 10000 |
OUTPUT:-
| SALESM | SALESMANNAME | ADDRESS1 | ADDRESS2 | CITY | PINCODE | STATE |
SALAMT | TGTTOGET | YTDSALES | REMARKS |
|--------|--------------|----------|------------|---------|---------|-------------|--------|----------|----------|-------
--|
| S00001 | AMAN | A/14 | WORLI | MUMBAI | 400002 | MAHARASHTRA | 3000 |
100 | 50 | GOOD |
| S00002 | OMKAR | 65 | NARIMAN | MUMBAI | 400001 | MAHARASHTRA | 3000 |
200 | 100 | GOOD |
| S00003 | RAJ | P-7 | BANDRA | MUMBAI | 400032 | MAHARASHTRA | 3000 | 200
| 100 | GOOD |
OUTPUT:-
| PRODUCT | DESCRIPTION | PROFITPERCENT | UNITMEASUR | QTYONHAND | REORDERLVL
| SELLPRICE | COSTPRICE |
|---------|------------------|---------------|------------|-----------|------------|-----------|-----------|
| P11111 | SWEATSHIRTS | 5 | PIECE | 150 | 40 | 400 | 950 |
| P33333 | DRESS MATERIAL | 4 | METRE | 80 | 20 | 350 | 220 |
| P44444 | KIDS WEAR |5 | PIECE | 70 | 25 | 300 | 200 |
| P55555 | FASHION JEWELLERY| 2 | PIECE | 60 | 15 | 250 | 180 |
OUTPUT:-
| CLIENT ID | CLIENT NAME | ADDRESS1 | ADDRESS2 | CITY | PINCODE | STATE |
BALDUE |
|-----------|---------------|-------------|-------------|-------|---------|-------------|--------|
| C00007 | KAVITA PATEL | PUNE | PUNE | PUNE | 411057 | MAHARASHTRA | 8000
|
| C00009 | SNEHA SHARMA | HYDERABAD | HYDERABAD | PUNE | 500001 | TELANGANA |
1000 |
| C00010 | RAMESH KUMAR | BANGALORE | BANGALORE | PUNE | 560001 | KARNATAKA
| 6000 |
| C00011 | PREETI GUPTA | MUMBAI | MUMBAI | PUNE | 400054 | MAHARASHTRA |
10000 |
14) ADD A COLUMN CALLED 'TELEPHONE' OF DATA TYPE 'NUMBER'
AND SIZE='10' TO THE CLIENT_MASTER TABLE.
OUTPUT:-
OUTPUT:-
16) LIST THE NAMES OF ALL CLIENTS HAVING 'A' AS THE SECOND
LETTER IN THEIR NAMES.
ANS.:- SELECT NAME FROM CLIENT_MASTER WHERE NAME LIKE'_A%';
OUTPUT:-
| CLIENT_NAME |
|---------------|
| KAVITA PATEL |
| RAMESH KUMAR |
17) LIST THE CLIENTS WHO STAY IN A CITY WHOSE FIRST LETTER IS 'M'.
OUTPUT:-
| CLIENT ID | CLIENT NAME |
|-----------|--------------|
| C00011 | PREETI GUPTA |
ANS.:-
SELECT CLIENTNO,NAME FROM CLIENT_MASTER WHERE CITY = 'BANGALORE' OR CITY =
'MANGALORE';
OUTPUT:-
| CLIENT ID | CLIENT_NAME |
|-----------|--------------|
| C00010 | RAMESH KUMAR |
19) LIST ALL CLIENTS WHOSE BALDUE IS GREATER THAN VALUE 10000.
OUTPUT:-
No clients have a BALDUE greater than 10000
20) LIST ALL INFORMATION FROM THE SALES_ORDER TABLE FOR
ORDERS PLACED IN THE MONTH OF JUNE.
OUTPUT:-
| ORDERNO | CLIENT | ORDERDATE | SALESMAN | DELYTYPE | BILLYN | DELYDATE | ORDERSTATUS |
|---------|--------|-----------|----------|----------|--------|-----------|-------------|
| 019009 | C00007 | 30-JUN-04 | S00005 | F | Y | 03-JUL-02 | IN PROCESS |
OUTPUT:-
| ORDERNO | CLIENT | ORDERDATE | SALESMAN | DELYTYPE | BILLYN | DELYDATE |
ORDERSTATUS |
|---------|--------|-----------|----------|----------|--------|-----------|-------------|
| 019009 | C00007 | 30-JUN-04 | S00005 | F | Y | 03-JUL-02 | IN PROCESS |
| 019010 | C00009 | 20-AUG-04 | S00007 | F | Y | 24-AUG-02 | FULFILLED |
22) LIST PRODUCTS WHOSE SELLING PRICE IS GREATER THAN 500 AND
LESS THAN OR EQUAL TO 750.
ANS.:-
SELECT PRODUCTNO,DESCRIPTION FROM PRODUCT_MASTER WHERE SELLPRICE > 500 AND
SELLPRICE < 750;
OUTPUT:-
| PRODUCTNO | DESCRIPTION |
|-----------|------------------|
| P22222 | SPORTS SHOES |
| P33333 | DRESS MATERIAL |
OUTPUT:-
|PRODUCTNO | DESCRIPTION | SELLPRICE | NEW_PRICE |
|-----------|------------------|-----------|-----------|
| P22222 | SPORTS SHOES | 600 | 90 |
| P33333 | DRESS MATERIAL | 350 | 52.5 |
24) LIST THE NAMES,CITY AND STATE OF CLIENTS WHO ARE NOT IN THE
STATE OF 'MAHARASHTRA'.
OUTPUT:-
OUTPUT:-
| NO. OF ORDERS |
|---------------|
|5 |
26) CALCULATE THE AVERAGE PRICE OF ALL THE PRODUCTS.
OUTPUT:-
| AVERAGE PRICE |
|---------------|
| 500 |
OUTPUT:-
| MAX_PRICE | MIN_PRICE |
|-----------|-----------|
| 600 | 250 |
OUTPUT:-
| NUMBER OF PRODUCTS |
|--------------------|
|4 |
OUTPUT-:
| PRODUCTNO | DESCRIPTION |
|-----------|------------------|
| P33333 | DRESS MATERIAL |
| P44444 | KIDS WEAR |
| P55555 | FASHION JEWELLERY|
OUTPUT:-
| ORDERNO | ORDER_DAY |
|---------|------------|
| 019009 | THURSDAY |
| 046867 | TUESDAY |
| 019010 | FRIDAY |
| 046868 | THURSDAY |
| 019011 | WEDNESDAY |
31) LIST THE MONTH ( IN ALPHABETS) AND DATE WHEN THE ORDERS
MUST BE DELIVERED.
OUTPUT:-
| DELIVERY_MONTH | DELYDATE |
|----------------|----------|
| JULY | 03-JUL-02|
| JULY | 17-JUL-02|
| AUGUST | 24-AUG-02|
| SEPTEMBER | 27-SEP-02|
| NOVEMBER | 03-NOV-02|
OUTPUT:-
| FORMATTED_ORDER_DATE |
|----------------------|
| 30-JUNE-04 |
| 15-JULY-04 |
| 20-AUGUST-04 |
| 25-SEPTEMBER-04 |
| 30-OCTOBER-04 |
OUTPUT:-
34) PRINT THE DESCRIPTION AND TOTAL QTY SOLD FOR EACH
PRODUCT.
OUTPUT:-
| DESCRIPTION | TOTAL_QTY_SOLD |
|------------------|----------------|
| SWEATSHIRTS | 50 |
| SPORTS SHOES | 30 |
| DRESS MATERIAL | 20 |
| KIDS WEAR | 40 |
| FASHION JEWELLERY| 25 |
OUTPUT:-
| PRODUCTNO | DESCRIPTION | SALES PER PRODUCT |
|-----------|------------------|-------------------|
| P11111 | SWEATSHIRTS | 15000.00 |
| P22222 | SPORTS SHOES | 9000.00 |
| P33333 | DRESS MATERIAL | 4000.00 |
| P44444 | KIDS WEAR | 12000.00 |
| P55555 | FASHION JEWELLERY| 3750.00 |
36) CALCULATE THE AVERAGE QTY SOLD FOR EACH CLIENT THAT HAS A
MAXIMUM ORDER VALUE OF 15000.00.
OUTPUT:-
| CLIENTNO | NAME | AVG. SALES |
|----------|----------------|------------|
| C00007 | John Enterprises| 25.00 |
| C00009 | Mike Traders | 30.00 |
37) FIND OUT THE TOTAL OF ALL BILLED ORDERS FOR THE MONTH OF
JUNE.
ANS.:- SELECT
SO.ORDERNO,SO.ORDERDATE,SUM(SOD.QTYORDERED*SOD.PRODUCTRATE)"ORDER BILLED"
FROM SALES_ORDER SO,SALES_ORDER_DETAILS SOD
WHERE SOD.ORDERNO = SO.ORDERNO
AND SO.BILLYN = 'Y'
AND TO_CHAR(ORDERDATE,'MON') = 'JUN'
GROUP BY SO.ORDERNO,SO.ORDERDATE;
OUTPUT:-
OUTPUT:-
| PRODUCTNO | DESCRIPTION |
|-----------|------------------|
| P11111 | SWEATSHIRTS |
39) FIND OUT THE PRODUCTS AND THEIR QUANTITIES THAT WILL HAVE
BE DELIVERED IN THE CURRENT MONTH.
ANS.:- SELECT SOD.PRODUCTNO,PM.DESCRIPTION,SUM(SOD.QTYORDERED)
FROM SALES_ORDER_DETAILS SOD,SALES_ORDER SO,PRODUCT_MASTER PM
WHERE PM.PRODUCTNO = SOD.PRODUCTNO AND SO.ORDERNO = SOD.ORDERNO
AND TO_CHAR(DELYDATE,'MON-YY') = TO_CHAR(SYSDATE,'MON-YY')
GROUP BY SOD.PRODUCTNO,PM.DESCRIPTION;
OUTPUT:-
OUTPUT:-
OUTPUT:-
| CLIENTNO | NAME |
|----------|------|
| | |
42) LIST THE PRODUCTS AND ORDERS FROM CUSTOMERS WHO HAVE
ORDERED LESS THAN 5 UNITS OF
'PULL OVERS'.
OUTPUT:-
| PRODUCTNO | ORDERNO |
|-----------|---------|
| | |
43) FIND THE PRODUCTS AND THEIR QUANTITIES FOR THE ORDERS
PLASED BY 'kavita patel' AND
'rajesh jain'.
OUTPUT:-
| PRODUCTNO | DESCRIPTION | UNITS ORDERED |
|-----------|------------------|---------------|
| P11111 | SWEATSHIRTS | 2 |
44) FIND THE PRODUCTS AND THEIR QUANTITIES FOR THE ORDERS
PLASED BY CLIENTNO 'C00007' AND 'C00009'.
OUTPUT:-
| CLIENTNO | PRODUCTNO | DESCRIPTION | UNITS ORDERED |
|----------|-----------|------------------|---------------|
| C00007 | P11111 | SWEATSHIRTS | 2 |
OUTPUT:-
| PRODUCTNO | DESCRIPTION |
|-----------|------------------|
| P55555 | FASHION JEWELLERY|
OUTPUT:-
| NAME | ADDRESS1 | ADDRESS2 | CITY | STATE | PINCODE |
|--------------|----------|----------|---------|------------|---------|
| KAVITA PATEL | PUNE | PUNE | PUNE | MAHARASHTRA | 411057 |
47) LIST THE CLIENT NAMES THAT HAVE PLACED ORDERS BEFORE THE
MONTH OF MAY'02.
OUTPUT:-
| CLIENTNO | NAME |
|----------|----------------|
| C00007 | KAVITA PATEL |
| C00008 | RAJESH JAIN |
| C00009 | SNEHA SHARMA |
OUTPUT:-
| CLIENTNO | NAME |
|----------|--------------|
| C00007 | KAVITA PATEL |
49) LIST THE NAMES OF CLIENTS WHO HAVE PLACED ORDERS WORTH
Rs.10000 OR MORE.
OUTPUT:-
| NAME |
|--------------|
| KAVITA PATEL |
1) PRINT INFORMATION FROM
PRODUCT_MASTER,SALES_ORDER_DETAILS TABLES IN THE FOLLOWING
FORMAT FOR ALL THE RECORDS:-
{DESCRIPTION} WORTH Rs. {TOTAL SALES FOR THE PRODUCT} WAS
SOLD.
OUTPUT :-
| COLUMN1 |
|--------------------------------------------|
| SWEATSHIRTS WORTH Rs. 15000 WAS SOLD. |
| KIDS WEAR WORTH Rs. 20000 WAS SOLD. |
| DRESS MATERIAL WORTH Rs. 10000 WAS SOLD. |
OUTPUT :-
Ramesh HAS PLACED ORDER 019009 ON 30-JUN-04.
Rajesh HAS PLACED ORDER 046867 ON 15-JUL-04.
Suresh HAS PLACED ORDER 019010 ON 20-AUG-04.
Mahesh HAS PLACED ORDER 046868 ON 25-SEP-04.
Rohan HAS PLACED ORDER 019011 ON 30-OCT-04.
1) CREATE A SIMPLE INDEX IDX_PROD ON PRODUCT COST PRICE FROM
THE PRODUCT_MASTER TABLE.
OUTPUT :-
INDEX CREATED.
OUTPUT :-
SEQUENCE CREATED.
OUTPUT :-
VIEW CREATED.
4) GIVE THE SYNTAX TO CREATE A VIEW VW_PROD ON THE
PRODUCT_MASTER TABLE.GIVE EXAMPLE
FOR INSERTING,UPDATING AND DELETING RECORDS USING THE
VIEW VW_PROD.
⇨ Output:
VIEW CREATED.
SELECT *
FROM ALL_VIEWS
WHERE VIEW_NAME = 'VW_PROD';
⇨ Output:
⇨ Output:
1 ROW INSERTED.
⇨ Output:
UPDATE VW_PROD
SET DESCRIPTION = 'Updated Product'
WHERE PRODUCTNO = 'P12345';
⇨ Output:
1 ROW UPDATED.
⇨ Output:
⇨ Output:
1 ROW DELETED.