Professional Documents
Culture Documents
SQL> --> create a join view based on product details along with
SQL> --> company information?
SQL>
SQL> create view vw_prod_info
2 as
3 select * from prod_dtls p ,comp_dtls c
4 where p.comp_code=c.comp_code;
select * from prod_dtls p ,comp_dtls c
*
ERROR at line 3:
ORA-00942: table or view does not exist
Table created.
SQL>
SQL> Insert into comp_dtls values('I101','IBM','NEW YORK');
1 row created.
1 row created.
1 row created.
1 row created.
SQL>
SQL> Create table Prod_dtls
2 (
3 prod_code varchar2(10),
4 prod_name varchar2(20),
5 cost number(7,2),
6 mfg date,
7 warrenty varchar2(10)
8 );
Table created.
SQL>
SQL> Insert into Prod_dtls values('ILTPQS','LAPTOP',45000,'11-FEB-12','4 YEARS');
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL>
SQL> ALTER TABLE PROD_DTLS
2 ADD COMP_CODE VARCHAR2(10);
Table altered.
SQL>
SQL> ALTER TABLE PROD_DTLS
2 ADD CONSTRAINT FK_COMP_CODE FOREIGN KEY(COMP_CODE)
3 REFERENCES COMP_DTLS(COMP_CODE)
4 ON DELETE CASCADE;
Table altered.
SQL>
SQL> UPDATE PROD_DTLS
2 SET COMP_CODE='I101'
3 WHERE PROD_CODE LIKE'I%';
3 rows updated.
SQL>
SQL> UPDATE PROD_DTLS
2 SET COMP_CODE='W202'
3 WHERE PROD_CODE LIKE'W%';
2 rows updated.
SQL>
SQL> UPDATE PROD_DTLS
2 SET COMP_CODE='D303'
3 WHERE PROD_CODE LIKE'D%';
3 rows updated.
SQL>
SQL> UPDATE PROD_DTLS
2 SET COMP_CODE='S404'
3 WHERE PROD_CODE LIKE'S%';
4 rows updated.
SQL>
SQL> commit;
Commit complete.
SQL> cl scr;
SQL> ed
Wrote file afiedt.buf
1 create view vw_prodinfo
2 as
3* select * from prod_dtls NATURAL JOIN comp_dtls
4 /
View created.
12 rows selected.
6 rows selected.
MOB�