Dbms Ex4 Output
Dbms Ex4 Output
Dbms Ex4 Output
Table dropped.
Table dropped.
Table dropped.
Table dropped.
Table dropped.
Table dropped.
SQL>
SQL>
2 (
3 CONT_ID NUMBER(1),
4 CONTINENT VARCHAR2(15),
6 );
Table created.
SQL>
2 (
3 COUNTRYID NUMBER(2),
4 COUNTRYNAME VARCHAR2(20),
5 CONTINENT NUMBER(2),
6 CONSTRAINT PKEY5 PRIMARY KEY(COUNTRYID),
8 );
Table created.
SQL>
2 (
3 ID NUMBER(2),
4 MAKER VARCHAR2(20),
5 FULLNAME VARCHAR2(30),
6 COUNTRY NUMBER(1),
9 );
Table created.
SQL>
SQL>
2 (
3 MODELID NUMBER(3),
4 MAKER NUMBER(3),
8 );
Table created.
SQL>
2 (
3 ID NUMBER(3),
4 MODEL VARCHAR2(20),
5 DESCRIPTION VARCHAR2(40),
8 );
Table created.
SQL>
2 (
3 ID NUMBER(3),
5 CYLINDERS NUMBER(2),
6 EDISPL NUMBER(3),
7 HORSEPOWER NUMBER(3),
8 WEIGHT NUMBER(4),
9 ACCELERATE NUMBER(3,1),
10 YEAR NUMBER(4),
13 );
Table created.
SQL> Rem 1. Create a view named Datsun_Cars, which display the car id, model and descriptions of
Datsun model.
SQL>
2 SELECT *
View created.
SQL> REM DELETE FROM Datsun_Cars WHERE MAKE LIKE 'datsun D';
SQL> SELECT *
2 FROM Datsun_Cars;
ID MODEL DESCRIPTION
ID MODEL DESCRIPTION
ID MODEL DESCRIPTION
23 rows selected.
SQL>
Savepoint created.
SQL>
SQL>
1 row created.
SQL>
ID MODEL DESCRIPTION
SQL>
SQL>
1 row updated.
SQL>
2 WHERE ID=800;
ID MODEL DESCRIPTION
SQL>
SQL>
24 rows deleted.
SQL>
no rows selected
SQL>
Rollback complete.
SQL>
SQL>
SQL> SELECT *
2 FROM user_updatable_columns
3 WHERE table_name='DATSUN_CARS';
OWNER TABLE_NAME
------------------------------ ------------------------------
SYSTEM DATSUN_CARS
SYSTEM DATSUN_CARS
SYSTEM DATSUN_CARS
SQL>
SQL> Rem 2.Create a view called Car_List that shows the car id, model, description and operational
parameters of all cars produced during 1974. Make sure that, the year should not be reassigned to
any other value through views.
SQL>
2 SELECT
CAR_NAMES.ID,MODEL,DESCRIPTION,MPG,CYLINDERS,EDISPL,HORSEPOWER,WEIGHT,ACCELERATE,
YEAR
4 WHERE CAR_DETAILS.YEAR=1974;
View created.
SQL> SELECT *
2 FROM Car_List;
---------- ---------- ---------- ---------- ---------- ---------- -------- -------------------- ------------ ---------------- -------
133 plymouth plymouth duster 20 6 198 95 3102 16.5 1974
134 ford ford maverick 21 6 200 28 75 17 1974
135 amc amc horne 19 6 232 100 2901 16 1974
136 chevrolet chevrolet nov 15 6 250 100 3336 17 1974
141 chevrolet chevrolet chevelle malibu classic 16 6 250 100 3781 17 1974
142 amc amc matador 16 6 258 110 3632 18 1974
143 plymouth plymouth satellite sebring 18 6 225 105 3613 16.5 1974
145 buick buick century luxus (sw) 13 8 350 150 4699 14.5 1974
146 dodge dodge coronet custom (sw) 14 8 318 150 4457 13.5 1974
147 ford ford gran torino (sw) 14 8 302 140 4638 16 1974
148 amc amc matador (sw) 14 8 304 150 4257 15.5 1974
149 audi audi fox 29 4 98 83 2219 16.5 1974
27 rows selected.
SQL>
Savepoint created.
SQL>
SQL>
ERROR at line 1:
ORA-01776: cannot modify more than one base table through a join view
SQL>
27 rows updated.
SQL>
SQL> SELECT
CAR_NAMES.*,CAR_DETAILS.MPG,CAR_DETAILS.CYLINDERS,CAR_DETAILS.EDISPL,CAR_DETAILS.HOR
SEPOWER,CAR_DETAILS.WEIGHT,CAR_DETAILS.ACCELERATE,CAR_DETAILS.YEAR
3 WHERE YEAR=1974;
---------- ---------- ---------- ---------- ---------- ---------- --------- -------------------- ------------ --------------- -------
27 rows selected.
SQL>
SQL>
27 rows deleted
SQL>
Rollback complete.
SQL>
SQL> SELECT *
2 FROM user_updatable_columns
3 WHERE table_name='CAR_LIST';
10 rows selected.
SQL>
SQL> Rem 3. Create a view named European_Makers that will display the maker name, full name
and the country name of car makers from Europe.
SQL>
View created.
SQL> SELECT *
2 FROM European_Makers;
opel Opel 2
bmw BMW 2
volkswagen Volkswagen 2
renault Renault 3
peugeaut Peugeaut 3
citroen Citroen 3
fiat Fiat 5
volvo Volvo 6
saab Saab 6
triumph Triumph 7
11 rows selected.
SQL>
Savepoint created.
SQL>
SQL>
ERROR at line 1:
SQL>
2 FULLNAME='Updated';
11 rows updated.
SQL>
3 WHERE CONTINENTS.CONTINENT='europe';
triumph Updated uk
11 rows selected.
SQL>
SQL>
11 rows deleted.
SQL>
3 WHERE CONTINENTS.CONTINENT='europe';
no rows selected
SQL>
Rollback complete.
SQL>
SQL>
SQL>
SQL> SELECT *
2 FROM user_updatable_columns
3 WHERE table_name='EUROPEAN_MAKERS';
OWNER TABLE_NAME
------------------------------ ------------------------------
COLUMN_NAME UPD INS DEL
SYSTEM EUROPEAN_MAKERS
SYSTEM EUROPEAN_MAKERS
SYSTEM EUROPEAN_MAKERS
SQL>
SQL>
SQL> Rem 4. Create a view named Cars_Count which displays total number of cars manufactured
by each country.
SQL>
3 WHERE C.COUNTRYID=CM.COUNTRY
4 GROUP BY COUNTRYNAME;
View created.
SQL> SELECT *
2 FROM Cars_Count;
COUNTRYNAME COUNT
-------------------- ----------
sweden 2
korea 2
japan 5
uk 1
germany 4
italy 1
usa 4
france 3
8 rows selected.
SQL>
3 ON C.COUNTRYID=CM.COUNTRY
4 GROUP BY COUNTRYNAME;
View created.
SQL> SELECT *
2 FROM Cars_Count;
COUNTRYNAME COUNT
-------------------- ----------
sweden 2
korea 2
japan 5
uk 1
germany 4
italy 1
usa 4
france 3
8 rows selected.
SQL>
Savepoint created.
SQL>
SQL>
ERROR at line 1:
SQL>
SQL>
2 COUNTRYNAME='India';
ERROR at line 1:
SQL>
SQL>
SQL> rem DELETE CHECK
SQL>
ERROR at line 1:
SQL>
Rollback complete.
SQL>
SQL>
SQL> SELECT *
2 FROM user_updatable_columns
3 WHERE table_name='CARS_COUNT';
OWNER TABLE_NAME
------------------------------ ------------------------------
SYSTEM CARS_COUNT
COUNTRYNAME NO NO NO
SYSTEM CARS_COUNT
COUNT NO NO NO
SQL>
SQL>
SQL> Rem 5. Create a view Car_List_VU from Car_List that shows only the car id, model, description
and mileage of cars.
SQL>
View created.
SQL> SELECT *
2 FROM Car_List_VU;
ID MODEL DESCRIPTION
MPG
----------
20
21
19
ID MODEL DESCRIPTION
MPG
----------
15
31
26
ID MODEL DESCRIPTION
MPG
----------
32
25
16
ID MODEL DESCRIPTION
MPG
----------
16
143 plymouth plymouth satellite sebring
18
16
ID MODEL DESCRIPTION
MPG
----------
13
14
14
ID MODEL DESCRIPTION
MPG
----------
14
29
150 volkswagen volkswagen dasher
26
ID MODEL DESCRIPTION
MPG
----------
26
31
32
ID MODEL DESCRIPTION
MPG
----------
28
24
26
ID MODEL DESCRIPTION
MPG
----------
24
26
31
27 rows selected.
SQL>
Savepoint created.
SQL>
SQL>
ERROR at line 1:
ORA-01776: cannot modify more than one base table through a join view
SQL>
3 WHERE YEAR=1974;
ID MODEL DESCRIPTION
MPG
----------
20
21
19
ID MODEL DESCRIPTION
MPG
----------
15
31
138 ford ford pinto
26
ID MODEL DESCRIPTION
MPG
----------
32
25
16
ID MODEL DESCRIPTION
MPG
----------
16
18
16
ID MODEL DESCRIPTION
MPG
----------
13
14
14
ID MODEL DESCRIPTION
MPG
----------
14
29
26
ID MODEL DESCRIPTION
----------
26
31
32
ID MODEL DESCRIPTION
MPG
----------
28
24
26
ID MODEL DESCRIPTION
MPG
----------
26
31
27 rows selected.
SQL>
SQL>
2 DESCRIPTION='India';
27 rows updated.
SQL>
3 WHERE YEAR=1974;
ID MODEL DESCRIPTION
MPG
----------
20
134 ford India
21
19
ID MODEL DESCRIPTION
MPG
----------
15
31
26
ID MODEL DESCRIPTION
MPG
----------
32
25
141 chevrolet India
16
ID MODEL DESCRIPTION
MPG
----------
16
18
16
ID MODEL DESCRIPTION
MPG
----------
13
14
14
ID MODEL DESCRIPTION
MPG
----------
14
29
26
ID MODEL DESCRIPTION
MPG
----------
26
31
32
ID MODEL DESCRIPTION
----------
28
24
26
ID MODEL DESCRIPTION
MPG
----------
24
26
31
27 rows selected.
SQL>
SQL>
27 rows deleted.
SQL>
3 WHERE YEAR=1974;
no rows selected
SQL>
Rollback complete.
SQL>
SQL>
SQL> SELECT *
2 FROM user_updatable_columns
3 WHERE table_name='CAR_LIST_VU';
OWNER TABLE_NAME
------------------------------ ------------------------------
SYSTEM CAR_LIST_VU
SYSTEM CAR_LIST_VU
OWNER TABLE_NAME
------------------------------ ------------------------------
SYSTEM CAR_LIST_VU
SQL>
SQL> Rem 6. Create a sequence named Maker_No_Seq which generates the Maker number starting
from 24, increment by 1, to maximum of 99.
SQL> Include options of cycle, cache and order. Use this sequence to populate the rows of
car_makers table.
SQL>
ERROR at line 1:
2 START WITH 24
3 INCREMENT BY 1
4 MAXVALUE 99
5 CYCLE;
Sequence created.
SQL> ORDER;
SQL>
Savepoint created.
SQL>
1 row created.
1 row created.
1 row created.
SQL>
2 WHERE ID IN('24','25','26','27');
SQL>
Rollback complete.
SQL>
SQL> Rem 7. Create a synonym named Car_Op_Data for the CAR_DETAILS relation. Perform the DML
operations on it.
SQL>
ERROR at line 1:
SQL>
SQL> CREATE OR REPLACE SYNONYM Car_Op_Data FOR CAR_DETAILS;
Synonym created.
SQL>
Savepoint created.
SQL>
SQL>
ERROR at line 1:
SQL>
3 WHERE YEAR=1974;
ID MODEL DESCRIPTION
MPG
----------
20
134 ford ford maverick
21
19
ID MODEL DESCRIPTION
MPG
----------
15
31
26
ID MODEL DESCRIPTION
MPG
----------
32
25
141 chevrolet chevrolet chevelle malibu classic
16
ID MODEL DESCRIPTION
MPG
----------
16
18
16
ID MODEL DESCRIPTION
MPG
----------
13
14
14
ID MODEL DESCRIPTION
MPG
----------
14
29
26
ID MODEL DESCRIPTION
MPG
----------
26
31
32
ID MODEL DESCRIPTION
----------
28
24
26
ID MODEL DESCRIPTION
MPG
----------
24
26
31
27 rows selected.
SQL>
SQL>
SQL> UPDATE Car_Op_Data SET
2 DESCRIPTION='India';
DESCRIPTION='India'
ERROR at line 2:
SQL>
3 WHERE YEAR=1974;
ID MODEL DESCRIPTION
MPG
----------
20
21
19
ID MODEL DESCRIPTION
MPG
----------
136 chevrolet chevrolet nova
15
31
26
ID MODEL DESCRIPTION
MPG
----------
32
25
16
ID MODEL DESCRIPTION
MPG
----------
16
143 plymouth plymouth satellite sebring
18
16
ID MODEL DESCRIPTION
MPG
----------
13
14
14
ID MODEL DESCRIPTION
MPG
----------
14
29
150 volkswagen volkswagen dasher
26
ID MODEL DESCRIPTION
MPG
----------
26
31
32
ID MODEL DESCRIPTION
MPG
----------
28
24
26
ID MODEL DESCRIPTION
MPG
----------
24
26
31
27 rows selected.
SQL>
SQL>
SQL>
SQL>
3 WHERE YEAR=1974;
no rows selected
SQL>
Rollback complete.
SQL>
SQL>
2 ON CAR_NAMES(ID,MODEL);
Index created.
SQL>
SQL>
2 FROM user_ind_columns
INDEX_NAME TABLE_NAME
------------------------------ ------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
BMODEL CAR_NAMES
ID
BMODEL CAR_NAMES
MODEL
SQL>
SQL>
View dropped.
View dropped.
View dropped.
View dropped.
View dropped.
Sequence dropped.
Synonym dropped.
SQL> DROP INDEX BModel;
Index dropped.
SQL>
SQL>
SQL>
SQL> Rem