SlideShare a Scribd company logo
1 of 10
PreparedBy JAVATECH Search us in The World
Chapter DiscussionAbout Database Object, SubQuery, Joining ( 3 chapters inone class)
Database has few objects. They are
1. Table : Basic unit of storage which represented as rows and columns format.
2. View : It is logical subsets of data from more than one table.
3. Sequence : It is used to generate Unique integer number.
4. Synonym : It is an ulternate name for other database objects.
5. Index : Oracle server used index to faster access the rows using pointer.
View : It is logical subsets of data from more than one table. There are two types of view.
1. Simple view
2. Complex View
Why we use view
1. To restrict Data access : View doesnot allows to access all columns from table. It is created selected
columns only. Importants columns hides from other user.
2. Make complex query easy : You don’t need everytime specify join command. Only write once complex
commnd and make view. Then only access that view.
Simple View
The view which consists of only one tble is called simple view. The DML operation can perform with
this view. If you want restrict DML operation you can write WITH READ ONLY statement to avoid DML
operation
Complex View
The view which consists of more than one table is called Complex View. It restricts DML operation.
ROLL NAME DOB MARK
1 A 12-JAN-1990 500
2 B 16-JUN-1992 408
3 C 19-JUL-2000 557
4 D 30-MAY-1997 300
5 E 22-SEP-2000 490
Create View v1 as select roll,mark from student;
Above command create view name v1 consists of two column;
You can define your own column inside view
Create or replace view v1(MyRoll,MyMark) as select roll,mark from student;
Above command updated your view (because i write replace command) with MyRoll and MyMark column.
If you write select statement
Select * from v1;
It display like
MyRoll MyMark
1 500
2 408
3 557
4 300
5 490
You can update view
Update set mark=900 where roll=1;
After select from v1
MyRoll MyMark
1 900
2 408
3 557
4 300
5 490
Same also updated in Table
Select * from student;
ROLL NAME DOB MARK
1 A 12-JAN-1990 900
2 B 16-JUN-1992 408
3 C 19-JUL-2000 557
4 D 30-MAY-1997 300
5 E 22-SEP-2000 490
If you want to restrict DML operation in view then use WITH READ ONLY
E.g.
Create View v2 as select roll,mark from student where roll=2 WITH READ ONLY;
Then when you try to update view v2 whose roll is two it display arror.
Complex view
The view which consists of more than one table is called Complex table. Here DML command is
restriction
See the E.g
Create view v3(MyRoll,MyName,MyDept,Price) as Select stud1.roll,stud1.name,dept.name,dept.price from
stud,dept where stud.roll=dept.roll;
Here you can see view v3 is (MyRoll,MyName,MyDept,Price) is created. It is consists of 4 columns.
Sequence
Sequence is used to create to generate unique integer values. Declaraton of Synnym
Create sequence sequence_name : sequence name
Increment by n - sequence increment by n, specify the interval between sequence number
Strart with n – n is specified by the starting value of sequence
Max value n – n specified where sequence number will be start.
Min value n - n specify the minimum sequence no
Cycle / nocycle – after reach at max valueit will be recycled. Means again starts value from minimum no.
Cache n/ nocace – how many number oracle can allocate memory to store in memory. Numbers are faster
access from memory.
See how created ?
Create sequence s1 //sequence name is s1
Increment by 1 //sequence is incremented by 1
Start with 3 //sequence start value
MaxValue 30 //sequence will stop as it reached 30
MinValue 2 //After reached 30 next time it start from 2. Not again from start value. And minvalue
//should less than start value.
Cycle //cycle means value will be recycled after reach max value.
Error:ORA-04013 Number to Cache must be less than one cycle. So max value should specify 22 or above.
Default cache is 21.
Sequence Created.
To check sequence
Select s1.nextval from dual;
Select s1.currvalue from dual;
To verify user sequence from user_sequence data dictionary
SELECT sequence_name, min_value, max_value, increment_by, last_number FROM user_sequences;
You can also write
Insert into stud values(s1.nextval,’aa’,789);
To drop sequence
Drop sequence sequence_name;
Drop sequence s1;
Synonym
It is called alternate name for table.
E.g.
Create synonym sn for student_sce_dept;
Then instead of write big table name we use it through small name sn.
E.g. select * from sn; it display data from student_sce_dept.
To drop synonym
Drop synonym sn;
Index
Is used by the Oracle server to speed up the retrieval of rows by using a pointer
two types index
Automatically: when we declare primary key or unique key.
Manually: Users can create nonunique indexes on columns to speed up access to the rows.
CREATE INDEX emp_last_name_idx ON employees(last_name);
Index created.
SUB QUERY
It is called inner query. The query which is exists in another query is called inner query. It is also called nested
query.
Features
1. It is enclosed with parenthesis
2. It is written right side of outer query.
3. Inner query first executed then outer query executed.
4. Outer Query executed after result return from inner query.
Two types of inner query
Sometimes inner query returns two types result. First single result second multiple row result. Based upon this
It is two types.
1. Single row return inner query
2. Multi row return inner query
E.g.
Select name from student where mark<(select mark from student where name=’Ramesh’);
Right side is called inner query. First we should know what is mark of Ramesh. Then we select mark those are
below ramesh mark. In bold and underlined mark is called inner query.
Single row returns inner query operator
1. =
2. >
3. <
4. >=
5. <=
6. <>
Multiple rows returns inner queries
1. IN : If outer query matched any value from IN operator then it returns result.
2. ANY : <ANY means Less than the maximum. >ANY means more than the minimum.=ANY is equivalent
to IN
3. ALL : <ALL means less than the minimum and >ALL means more than the maximum.
Select name from student where mark in (300,700,800);
Or
Select name from student where mark in(select mark from student where mark<900);
JOIN command
Join command is used to return query more than one table.
Prior to Join Oracle8i or Prior
1. Cartesian Join
2. Equi-Join same as simple join same as inner join
3. Non-Equi Join
4. Outer Join
5. Self Join
Oracle 9i or Next
1. Cross Join
2. Natural Join
3. Using clause
4. ON clause
5. Full or two sided outer join
CartesianJoin
When we specify join command invalid or ommit then result of cartesian join will be produced
between two table.
E.g.
Selet roll,name,mark,branch from stud,dept;
Here stud has 5 rows and dept has 4 rows. Then total 5*4=20 rows will be ceated.
Equi Join:
It is based upon equality of two values of same column of two different tables. It use the (=) operator.
Select stud.roll,name,mark,branch from stud,dept where stud.roll=dept.roll;
It display roll,name from stud table mark branch from dept table those roll are same to both table. (=)
Table alias
Select s.roll,s.name ,d.mark,d.branch from stud s,dept d where s.roll=d.roll;
Above we specify alias name for both table s & d. S is alternate name for stud table and D is alternate
name for Dept table. Advantages No need to write tablename repeatedly. Only use the shortcut name.
For faster write the query.
Ambiguity inColumn.
Here roll is common column for stud and dept table. When we write query
select roll,name,mark,branch from stud,dept .............
Oracle server will be confuse to take about roll. Because it is common. So we specify which table roll
column we want to display. Modified query is
Select stud.roll , name, mark branch from stud,dept where stud.roll=dept.roll;
Non Equi Join
The operator which are used other than (=) is called Non Equi Join. Operators are used
1. >
2. <
3. <>
4. Between
Select s.name,d.mark from stud s,dept d where s.mark between d.high_mark and g.low_mark;
Left outer Join / Right Outer Join / Full Outer Join
Outer Join-It is an extension of inner join. It returns rows that are matched to both tables. And also returns
those are not matched to another table.
It returns the rows those are missed in join condition. Outer join symbol is (+) sign
e.roll(+)=d.roll //left outer join It returns the rows that are matched to both table except return rows those
that are not matched to the first table.
e.roll=d.roll(+) //right outer join it returns the rows that are matched to both table except returns the rows
that are not matched to the second table.
Full outer join: The join between two tables, that returns the result of an inner join as well as the result of left
outer join and return result of right join is a full outer join.
Full outer join
select name,mark from join7,join8 where join7.roll(+)=join8.roll union all select name,mark from join7,join8
where join7.roll=join8.roll(+)
Right Outer Join
select name,mark from join7,join8 where join7.roll=join8.roll(+);
Left Outer Join
select name,mark from join7,join8 where join7.roll(+)=join8.roll;
Self Join
From Stud d Natural Join Dept d; automatically choose same column name by oracle.
From stud s join dept d using (roll) // using clause is used to specify column name by user choice in join
condition
From stud s join dept d on(s.roll=d.my_roll) on clause is used to specify that have different column name.
Here roll & my_roll is not matched
Left outer join
select s.name,d.mark from join7 s left outer join join8 d on (s.roll=d.roll)
Right outer join
select s.name,d.mark from join7 s right outer join join8 d on (s.roll=d.roll)
Full outer join
select s.name,d.mark from join7 s full outer join join8 d on (s.roll=d.roll)
Prepared By JAVATECH Search us in The World
ASSIGNMENT ON DATABASE OBJECT,SUB-QUERY AND JOIN COMMAND
STUDENT
STU_ROLL NAME DOB MARK BRANCH SECTION
AMIT 13/05/2010 600 SCE IT-1
AJAY 25/09/2009 550 IT IT-2
ROHIT 15/12/2008 450 IT CS-1
MUKESH 02/11/2007 390 SCE CS-2
JOHN 30/03/2005 400 IT CS-3
FACULTY
FACULTY_ID FAC_NAME STU_ROLL FAC_SUBJECT CLASS_ROOM CLASS_DATE_TIME
JOSEPH JAVA C1
STEPHEN C++ C2
RICHARDSON DOTNET C3
JAMES PHP C4
AKS ORACLE C5
TIPS:- CLASS_DATE_TIME DATATYPE IS TIMESTAMP(2) - TIMESTAMP IS USED FOR TO SPECIFY TIME. 2
MEANS AFTER SECOND VALUE FRACTION VALUE WON’T DISPLAY. ONLY TWO DIGIT SECOND DISPLAY.
INSERT INTO TABLE VALUES(TO_DATE(’12-JAN-2001 13:34:56’,’DD-MON-YY HH24:MI:SS’));
1. Enter exact data into student table. But roll should insert using sequence, it should start from 1 and
increment by 1.[total 5 records]
2. Enter exact data into faculty table. But faculty id should insert using sequence, it should start from 1
and increment by 3[total 5 records]. E.g. 1, 4, 7, 10, 13 Also enter exact student roll into faculty table
from referencing student table by using sequence but it should be increment by 2. E.g. 1, 3, 5, 7, 9
[total 5 records]
3. Waq to display sequence name, minimum value, maximum value from all created sequences.
4. Waq to drop these two sequences.
5. Create synonym s55 for student table. And query all rows from synonym. Then drop it.
6. Create view stv1 from student table by selecting roll, name , mark & branch column.
7. Waq to update marks from all rows from stv1 view.
8. Waq to create view stv2 from student table selecting roll, name, dob & mark of rollno 3 which can’t be
deleted from view.
9. Drop these two view from database.
10. Waq to create view st_fa from student & faculty selecting stu_roll, stu name, faculty id, faculty name
where rollno of student table should same to student roll of faculty table.
11. Select and drop st_fa view.
12. Waq to display the student roll, name, dob, mark and faculty name, subject, classroom, from student,
faculty table those student rollno are common to student rollno of faculty table using equi join.
13. Waq to display the all distinct rollno of student table those student rollnos are less than from faculty
table rollno using non equi join.
14. Waq to join student & faculty table without using any join command. And check how many rows
created.
15. Waq to check from faculty table, which student’s rollno and faculty’s id are same. Then display their
faculty names only.
16. Waq to display student roll,name & facult id, fac name from student and faculty tables those are
common roll no by using natural join.
17. Waq to display student’s roll,name and faculty id, fac name from student,faculty table by using ‘using’
clause.
18. Waq to display student roll,name & faculty id, fac name from student, faculty where faculty id and
student roll are same.
19. Waq to display student roll, name, mark, fac id, fac name from student, faculty table those are
common rollno to both table except those rollno of student table are also not matched to faculty
table.
20. Waq to display student roll, name, mark, faculty id, fac name from student,faculty table those are
common rollno except display fac id, fac name of corresponding rows of stu rollno of faculty table
those are not matched to student table rollno.
LIKE OUR FACEBOOK PAGE “JAVATECH 123” TO GET UPDATED NOTE & VIDEOS
Prepared By JAVATECH Search us in The World
**************************BEST OF LUCK***********************
Next – PLSQL will Start
PL-PROGRAMMING LANGUAGE+SQL
PROGRAMMING LANGUAGED USED WITH SQL STATEMENTIS CALLED PLSQL

More Related Content

What's hot (20)

Dialog box in vb6
Dialog box in vb6Dialog box in vb6
Dialog box in vb6
 
Sap abap material
Sap abap materialSap abap material
Sap abap material
 
Java program structure
Java program structure Java program structure
Java program structure
 
joins in database
 joins in database joins in database
joins in database
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
T4 - Query Lanjutan [2]
T4 - Query Lanjutan [2]T4 - Query Lanjutan [2]
T4 - Query Lanjutan [2]
 
4. plsql
4. plsql4. plsql
4. plsql
 
Trigger
TriggerTrigger
Trigger
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs AcademyMySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
 
Oracle: Control Structures
Oracle: Control StructuresOracle: Control Structures
Oracle: Control Structures
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
Plsql task
Plsql taskPlsql task
Plsql task
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
Stored procedure in sql server
Stored procedure in sql serverStored procedure in sql server
Stored procedure in sql server
 
Sap abap modularization interview questions
Sap abap modularization interview questionsSap abap modularization interview questions
Sap abap modularization interview questions
 
Function in PL/SQL
Function in PL/SQLFunction in PL/SQL
Function in PL/SQL
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
 
Sap abap interview questions
Sap abap interview questionsSap abap interview questions
Sap abap interview questions
 
VB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdfVB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdf
 

Similar to Database object, sub query, Join Commands & Lab Assignment

Similar to Database object, sub query, Join Commands & Lab Assignment (20)

ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Oracle
OracleOracle
Oracle
 
Dbms question
Dbms questionDbms question
Dbms question
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
Chapter8 my sql revision tour
Chapter8 my sql revision tourChapter8 my sql revision tour
Chapter8 my sql revision tour
 
Spufi
SpufiSpufi
Spufi
 
30 08 Final Sql
30 08 Final Sql30 08 Final Sql
30 08 Final Sql
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
 
Commands
CommandsCommands
Commands
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
Module03
Module03Module03
Module03
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 

Recently uploaded

WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 

Recently uploaded (20)

WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 

Database object, sub query, Join Commands & Lab Assignment

  • 1. PreparedBy JAVATECH Search us in The World Chapter DiscussionAbout Database Object, SubQuery, Joining ( 3 chapters inone class) Database has few objects. They are 1. Table : Basic unit of storage which represented as rows and columns format. 2. View : It is logical subsets of data from more than one table. 3. Sequence : It is used to generate Unique integer number. 4. Synonym : It is an ulternate name for other database objects. 5. Index : Oracle server used index to faster access the rows using pointer. View : It is logical subsets of data from more than one table. There are two types of view. 1. Simple view 2. Complex View Why we use view 1. To restrict Data access : View doesnot allows to access all columns from table. It is created selected columns only. Importants columns hides from other user. 2. Make complex query easy : You don’t need everytime specify join command. Only write once complex commnd and make view. Then only access that view. Simple View The view which consists of only one tble is called simple view. The DML operation can perform with this view. If you want restrict DML operation you can write WITH READ ONLY statement to avoid DML operation Complex View The view which consists of more than one table is called Complex View. It restricts DML operation. ROLL NAME DOB MARK 1 A 12-JAN-1990 500 2 B 16-JUN-1992 408 3 C 19-JUL-2000 557 4 D 30-MAY-1997 300 5 E 22-SEP-2000 490 Create View v1 as select roll,mark from student; Above command create view name v1 consists of two column; You can define your own column inside view Create or replace view v1(MyRoll,MyMark) as select roll,mark from student;
  • 2. Above command updated your view (because i write replace command) with MyRoll and MyMark column. If you write select statement Select * from v1; It display like MyRoll MyMark 1 500 2 408 3 557 4 300 5 490 You can update view Update set mark=900 where roll=1; After select from v1 MyRoll MyMark 1 900 2 408 3 557 4 300 5 490 Same also updated in Table Select * from student; ROLL NAME DOB MARK 1 A 12-JAN-1990 900 2 B 16-JUN-1992 408 3 C 19-JUL-2000 557 4 D 30-MAY-1997 300 5 E 22-SEP-2000 490 If you want to restrict DML operation in view then use WITH READ ONLY E.g. Create View v2 as select roll,mark from student where roll=2 WITH READ ONLY; Then when you try to update view v2 whose roll is two it display arror.
  • 3. Complex view The view which consists of more than one table is called Complex table. Here DML command is restriction See the E.g Create view v3(MyRoll,MyName,MyDept,Price) as Select stud1.roll,stud1.name,dept.name,dept.price from stud,dept where stud.roll=dept.roll; Here you can see view v3 is (MyRoll,MyName,MyDept,Price) is created. It is consists of 4 columns. Sequence Sequence is used to create to generate unique integer values. Declaraton of Synnym Create sequence sequence_name : sequence name Increment by n - sequence increment by n, specify the interval between sequence number Strart with n – n is specified by the starting value of sequence Max value n – n specified where sequence number will be start. Min value n - n specify the minimum sequence no Cycle / nocycle – after reach at max valueit will be recycled. Means again starts value from minimum no. Cache n/ nocace – how many number oracle can allocate memory to store in memory. Numbers are faster access from memory. See how created ? Create sequence s1 //sequence name is s1 Increment by 1 //sequence is incremented by 1 Start with 3 //sequence start value MaxValue 30 //sequence will stop as it reached 30 MinValue 2 //After reached 30 next time it start from 2. Not again from start value. And minvalue //should less than start value. Cycle //cycle means value will be recycled after reach max value. Error:ORA-04013 Number to Cache must be less than one cycle. So max value should specify 22 or above. Default cache is 21. Sequence Created. To check sequence Select s1.nextval from dual; Select s1.currvalue from dual; To verify user sequence from user_sequence data dictionary SELECT sequence_name, min_value, max_value, increment_by, last_number FROM user_sequences;
  • 4. You can also write Insert into stud values(s1.nextval,’aa’,789); To drop sequence Drop sequence sequence_name; Drop sequence s1; Synonym It is called alternate name for table. E.g. Create synonym sn for student_sce_dept; Then instead of write big table name we use it through small name sn. E.g. select * from sn; it display data from student_sce_dept. To drop synonym Drop synonym sn; Index Is used by the Oracle server to speed up the retrieval of rows by using a pointer two types index Automatically: when we declare primary key or unique key. Manually: Users can create nonunique indexes on columns to speed up access to the rows. CREATE INDEX emp_last_name_idx ON employees(last_name); Index created. SUB QUERY It is called inner query. The query which is exists in another query is called inner query. It is also called nested query. Features 1. It is enclosed with parenthesis 2. It is written right side of outer query. 3. Inner query first executed then outer query executed.
  • 5. 4. Outer Query executed after result return from inner query. Two types of inner query Sometimes inner query returns two types result. First single result second multiple row result. Based upon this It is two types. 1. Single row return inner query 2. Multi row return inner query E.g. Select name from student where mark<(select mark from student where name=’Ramesh’); Right side is called inner query. First we should know what is mark of Ramesh. Then we select mark those are below ramesh mark. In bold and underlined mark is called inner query. Single row returns inner query operator 1. = 2. > 3. < 4. >= 5. <= 6. <> Multiple rows returns inner queries 1. IN : If outer query matched any value from IN operator then it returns result. 2. ANY : <ANY means Less than the maximum. >ANY means more than the minimum.=ANY is equivalent to IN 3. ALL : <ALL means less than the minimum and >ALL means more than the maximum. Select name from student where mark in (300,700,800); Or Select name from student where mark in(select mark from student where mark<900); JOIN command Join command is used to return query more than one table. Prior to Join Oracle8i or Prior 1. Cartesian Join 2. Equi-Join same as simple join same as inner join 3. Non-Equi Join 4. Outer Join 5. Self Join
  • 6. Oracle 9i or Next 1. Cross Join 2. Natural Join 3. Using clause 4. ON clause 5. Full or two sided outer join CartesianJoin When we specify join command invalid or ommit then result of cartesian join will be produced between two table. E.g. Selet roll,name,mark,branch from stud,dept; Here stud has 5 rows and dept has 4 rows. Then total 5*4=20 rows will be ceated. Equi Join: It is based upon equality of two values of same column of two different tables. It use the (=) operator. Select stud.roll,name,mark,branch from stud,dept where stud.roll=dept.roll; It display roll,name from stud table mark branch from dept table those roll are same to both table. (=) Table alias Select s.roll,s.name ,d.mark,d.branch from stud s,dept d where s.roll=d.roll; Above we specify alias name for both table s & d. S is alternate name for stud table and D is alternate name for Dept table. Advantages No need to write tablename repeatedly. Only use the shortcut name. For faster write the query. Ambiguity inColumn. Here roll is common column for stud and dept table. When we write query select roll,name,mark,branch from stud,dept ............. Oracle server will be confuse to take about roll. Because it is common. So we specify which table roll column we want to display. Modified query is Select stud.roll , name, mark branch from stud,dept where stud.roll=dept.roll;
  • 7. Non Equi Join The operator which are used other than (=) is called Non Equi Join. Operators are used 1. > 2. < 3. <> 4. Between Select s.name,d.mark from stud s,dept d where s.mark between d.high_mark and g.low_mark; Left outer Join / Right Outer Join / Full Outer Join Outer Join-It is an extension of inner join. It returns rows that are matched to both tables. And also returns those are not matched to another table. It returns the rows those are missed in join condition. Outer join symbol is (+) sign e.roll(+)=d.roll //left outer join It returns the rows that are matched to both table except return rows those that are not matched to the first table. e.roll=d.roll(+) //right outer join it returns the rows that are matched to both table except returns the rows that are not matched to the second table. Full outer join: The join between two tables, that returns the result of an inner join as well as the result of left outer join and return result of right join is a full outer join. Full outer join select name,mark from join7,join8 where join7.roll(+)=join8.roll union all select name,mark from join7,join8 where join7.roll=join8.roll(+) Right Outer Join select name,mark from join7,join8 where join7.roll=join8.roll(+); Left Outer Join select name,mark from join7,join8 where join7.roll(+)=join8.roll;
  • 8. Self Join From Stud d Natural Join Dept d; automatically choose same column name by oracle. From stud s join dept d using (roll) // using clause is used to specify column name by user choice in join condition From stud s join dept d on(s.roll=d.my_roll) on clause is used to specify that have different column name. Here roll & my_roll is not matched Left outer join select s.name,d.mark from join7 s left outer join join8 d on (s.roll=d.roll) Right outer join select s.name,d.mark from join7 s right outer join join8 d on (s.roll=d.roll) Full outer join select s.name,d.mark from join7 s full outer join join8 d on (s.roll=d.roll) Prepared By JAVATECH Search us in The World
  • 9. ASSIGNMENT ON DATABASE OBJECT,SUB-QUERY AND JOIN COMMAND STUDENT STU_ROLL NAME DOB MARK BRANCH SECTION AMIT 13/05/2010 600 SCE IT-1 AJAY 25/09/2009 550 IT IT-2 ROHIT 15/12/2008 450 IT CS-1 MUKESH 02/11/2007 390 SCE CS-2 JOHN 30/03/2005 400 IT CS-3 FACULTY FACULTY_ID FAC_NAME STU_ROLL FAC_SUBJECT CLASS_ROOM CLASS_DATE_TIME JOSEPH JAVA C1 STEPHEN C++ C2 RICHARDSON DOTNET C3 JAMES PHP C4 AKS ORACLE C5 TIPS:- CLASS_DATE_TIME DATATYPE IS TIMESTAMP(2) - TIMESTAMP IS USED FOR TO SPECIFY TIME. 2 MEANS AFTER SECOND VALUE FRACTION VALUE WON’T DISPLAY. ONLY TWO DIGIT SECOND DISPLAY. INSERT INTO TABLE VALUES(TO_DATE(’12-JAN-2001 13:34:56’,’DD-MON-YY HH24:MI:SS’)); 1. Enter exact data into student table. But roll should insert using sequence, it should start from 1 and increment by 1.[total 5 records] 2. Enter exact data into faculty table. But faculty id should insert using sequence, it should start from 1 and increment by 3[total 5 records]. E.g. 1, 4, 7, 10, 13 Also enter exact student roll into faculty table from referencing student table by using sequence but it should be increment by 2. E.g. 1, 3, 5, 7, 9 [total 5 records] 3. Waq to display sequence name, minimum value, maximum value from all created sequences. 4. Waq to drop these two sequences. 5. Create synonym s55 for student table. And query all rows from synonym. Then drop it. 6. Create view stv1 from student table by selecting roll, name , mark & branch column. 7. Waq to update marks from all rows from stv1 view. 8. Waq to create view stv2 from student table selecting roll, name, dob & mark of rollno 3 which can’t be deleted from view. 9. Drop these two view from database. 10. Waq to create view st_fa from student & faculty selecting stu_roll, stu name, faculty id, faculty name where rollno of student table should same to student roll of faculty table. 11. Select and drop st_fa view. 12. Waq to display the student roll, name, dob, mark and faculty name, subject, classroom, from student, faculty table those student rollno are common to student rollno of faculty table using equi join.
  • 10. 13. Waq to display the all distinct rollno of student table those student rollnos are less than from faculty table rollno using non equi join. 14. Waq to join student & faculty table without using any join command. And check how many rows created. 15. Waq to check from faculty table, which student’s rollno and faculty’s id are same. Then display their faculty names only. 16. Waq to display student roll,name & facult id, fac name from student and faculty tables those are common roll no by using natural join. 17. Waq to display student’s roll,name and faculty id, fac name from student,faculty table by using ‘using’ clause. 18. Waq to display student roll,name & faculty id, fac name from student, faculty where faculty id and student roll are same. 19. Waq to display student roll, name, mark, fac id, fac name from student, faculty table those are common rollno to both table except those rollno of student table are also not matched to faculty table. 20. Waq to display student roll, name, mark, faculty id, fac name from student,faculty table those are common rollno except display fac id, fac name of corresponding rows of stu rollno of faculty table those are not matched to student table rollno. LIKE OUR FACEBOOK PAGE “JAVATECH 123” TO GET UPDATED NOTE & VIDEOS Prepared By JAVATECH Search us in The World **************************BEST OF LUCK*********************** Next – PLSQL will Start PL-PROGRAMMING LANGUAGE+SQL PROGRAMMING LANGUAGED USED WITH SQL STATEMENTIS CALLED PLSQL