SlideShare uma empresa Scribd logo
1 de 56
Baixar para ler offline
Lab of the Database
System
Sulieman Khudruj
Database : a collection of organized data , or set
of tables with relations.
Why oracle ??
 High capacity.
 Performance.
 Security
 Web ready
Oracle :
1)Databse
a.SQL : Structured Query Langauge
b.PL/SQL.
2)Developer
a.Forms
b.Reports
Other Tools:
 Designer
 Portals
 Jdevelopers
 Discoverer
 EM
 Grid controls
Certifications
SQL+PL/SQL  OCA
Forms  OCP
DBA
Entity Relation Ship Diagram
(ERD)
Symbol Meaning
Entity type
Weak Entity type
Relationship type
Identifying
Relationship type
attribute
Key attribute
Multi valued attribute
Composite attribute
Derived attribue
Simple Example
Database contains 2 tables
Table 1: Emplyee
Empno Ename Sal Birthdate Mobile# Age
1 Ali 5000 14/2/1977 05467756
Table 1: Dept
Deptno Deptname
10 Computer
20 Research
30 Sales
40 Accounting
Empn
o
Enam
e
Employee
s
Sal
Mobile
#
Birthdat
e
Age
Dept
Dento
n
Deptname
Wor
k
1
M
SQL
Commands Types
 DDL : Data Definition language
Create, Drop, Alter, Rename,….
 DML: Data Manipulation language
Insert, Delete, Update, select
 DCL : Data Control Language
Grant, Revoke, …….
 Transactions : Commit, Rollback, Save
point,…
Constraints
 Not null : we must enter a value but duplication
is allowed.
 Unique : duplication is not allowed but null
values is acceptance.
 Check : Any values but must have a condition.
 Primary key : Not null and Unique
 Foreign key : it is a primary key or unique key
from a nother table.
Data Types
 Number (5) , can be upto 5
 Number (6,2)
 Number , it can reserve to the highest value
but it is not recommended
 Char (10) , Ahamed- - - -
 Varchar2(20)
 Date : Store Date in many formats
1) Create user , grant create session , grant connect,
resource
2.Create table
3.Select * from tab
4.desc name_table
5.drop table, show recyclebin, flashback
6. drop table table_name purge
7. insert
Dept table
Deptno Depname
10 Computer
20 Resaech
30 Accounting
40 Marketing
Employee
Empno Ename Sal Birthdate Mobile#
1 abdulelah 5000 14/2/1977 054545454
2 omar 6000 14/4/1993 054564645
3 khaled 8000 1/4/1990 054564564
4 mubark 5500 1/1/1990 054645646
5 saad 9000 1/1/1994 056456445
6 adel 29000 13/11/1993 045645644
7 Abd allah 30000 14/5/1996 056456564
8 amer 16000 5/7/1992 045564454
9 Abd aziz 55000 7/4/1979 045645645
10 hamad 50000 4/5/1993 045645666
8. alter
a) add column
b)modify length of column
c)drop column
d)drop more than one column
e) add more than one column
9. Rename table
10. Browsing data (select)
- Firstly create the following table (empdata)
- Then enter the data
Empno Ename Sal Birthdate Mobile# nationality
1 Abdullah 5000 14/2/1977 054545454 Saudi
2 omar 6000 14/4/1993 054564645 Saudi
3 khaled 8000 1/4/1990 054564564 Saudi
4 mubark 5500 1/1/1990 054645646 Saudi
5 saad 9000 1/1/1994 056456445 Saudi
6 saad 29000 13/11/1993 045645644 Jordanian
7 Abd allah 30000 14/5/1996 056456564 Jordanian
8 Amer 16000 5/7/1992 045564454 Egyptian
9 Amer 55000 7/4/1979 045645645 Egyptian
10 hamad 60000 4/5/1993 045645666 Suadi
Until empno=10
a) select * from empdata
b) select ename,sal,nationality from empdata
c) select ename, sal*12 as ann_sal from empdata
d) select sysdate from dual;
e) select 545*87 from dual;
f) select ename || ' earns ' || sal || ' every month '
info from empdata
g) select * from empdata
where empno=10;
Note
Type Symbol meaninig
Logical operators
= equal
< > , != , ^ = Not equal
> Less than
< Greater than
>= Less than or equal
<= Greater than or equal
Logical Bitwise and , or , not Contacts between
conditions
h) select * from empdata
where sal >5000 and nationality='Saudi';
i) select ename, sal , mobile
from empdata
where sal between 10000 and 60000
j) select ename , sal , nationality
from empdata
where ename like '%m%'
k) select * from empdata
where ename like 'm%';
L) select * from empdata
where ename like '%h';
m) select ename, sal
from empdata
where ename like '_b%';
n) select * from empdata
where ename like '____';
o) select * from empdata
where ename like 'o__r';
p) select * from empdata
where sal in (6000,5000,55000,60000)
q) select * from empdata
where ename in ('omar','Amer')
r) select ename,sal ,mobile from empdata
order by sal asc
Revision (1)
A)
1)Create table “Student_info” as follows :
Filed Name Type
Student_no Number(4) , primary key
Student_name Varchar2(20)
Student_mobile Number (10)
Student_age Number(4)
1) Insert 2 rows to this table
Student_no Student_name Student_mobile Student_age
100 Ali 054465477 29
101 Omar 059089035 32
3)Display the fields with properties
B)
1) list the steps to create new (RCC with password
KSU) user and
a) log in to user System / Manager
b) write  create user RCC identified by KSU
2) give RCC user all the privileges
grant create session to RCC
grant connect, resource to RCC
c)
study to the following empdata and answer the quesions
a) modify length of filed nationality to 50
alter table empdata
modify nationality varchar2(50)
b) rename the name of table to empinfo
rename empdata to empinfo;
c) delete the column birthdate
alter table empinfo
drop column birthdate;
d) drop the table to recyclein
drop table empinfo;
e) show the contents of the recyclein
show recyclein ;
d)
study the following table and answer the quesions
a) calculate the annual salary for each employee with
column alias "emp_ann_sal”, and display the name
and the annual salary
select ename , sal*12 as emp_ann_sal from empinfo;
b) display the records of empno = 6 and empno=9
select * from empinfo
where empno in (6,9);
c) display all records of employee who earn salary
between 8000 to 16000
select * from empinfo
where sal between 8000 and 16000
d) display all records , that names contain d letter
select * from empinfo
where ename like ‘%d%’;
e)display all records , that names contain 8 letters
select * from empinfo
where ename like ‘________’;
f) return the system date
select sysdate from dual;
g) return the value of 18*35
select 18*35 from dual;
Functions
1) Single
2) Group
2) Single
a. Character
b. Number
c. Date
d. General
e. Conversion
I. Character
a. Upper
b. Lower
c. Initcap
d. Substr
e. Instr
f. Replace
g. Translate
h. Lpad ,rpad ,ltrim ,rtrim
i. length
a)
select ename, upper(ename), lower(ename), initcap(ename)
from empdata
b)
select * from empdata
where upper(ename) like '%S%';
c)
select ename, substr(ename,1,3) from empdata;
d) select ename, instr(ename,'a',1) from empdata
e) select ename, instr(ename,'a',1,2) from empdata;
f) select ename ,replace(ename,'Abdullah','Abdulelah')
from empdata
g) select ename ,translate(ename,'ah','ox')
from empdata
h) select ename, lpad(sal,10,'*') , rpad(sal,10,'*') from empdata;
i) select ename , length (ename), ltrim(ename,'A'), rtrim (ename,'h')
from empdata
II) Number Function
a. Mod
b. Round
c. Trunk
a. select mod (1.5,1), mod (5,2) , mod (5,1) from dual
b. select round (137.74), trunc(137.74) from dual
III) Date Functions and Conversation functions
‘dd-mon-yy’  default , example : 15-jun-02
Rules :
a. date1-date2 = number of days
b. date1(+/-) number of days = date2
c. date1 (+/-) hours/24=date2
d. date+date = not allowed
a. select months_between ('02-12-2013', '04-6-2013') from
dual
b. select add_months ( '2-7-2013',2) from dual
c. select next_day ('2-7-2013', 1) from dual
note : 1(Saturday) , 2( Sunday),………..
d. select last_day ('2-7-2013') from dual
e. select to_char (sysdate, 'dd/mm/yy') from dual;
IV) General Functions
a.
insert into empdata (empno,ename,birthdate,mobile,nationality)
values (11,'Ali','4/6/1990',054546454,'Egyption');
select ename, nvl(sal,0) as " annual salary" from empdata
b. select ename, nullif (sal,60000) from empdata
c. select to_char(sysdate, 'HH:MI:SS AM ') from dual;
IIV) Group functions
a. select count (sal), sum (sal), avg(sal) from empdata
b. select min(sal), max(sal) from empdata
b. suppose this table
no name salary deptno job
1 Ali 5000 10 programmer
2 Khaled 6000 10 analyst
3 Omar 40000 10 designer
4 Sami 55000 20 manager
5 Amer 70000 20 manager
6 Nasser 5440 20 accouter
7 Rami 45400 20 programmer
8 Mubark 20000 30 advisor
9 anas 15000 30 programmer
10 mostafa 22000 30 analyst
c. select deptno ,sum(salary) from empcomp
group by deptno;
d. select deptno,job, sum(salary) from empcomp
group by deptno,job;
d. select job ,sum(salary) from empcomp
group by job;
e. select deptno,job,sum(salary) from empcomp
where deptno <> 30
having sum(salary)>10000
group by deptno, job;
c.
select nationality, sum (sal)
from empdata
group by nationality;
delete rows , update data
a. delete from empdata
where empno=11;
d.
update empdata
set nationality ='Saudi'
where empno =10;
Constraints
 Not null : we must enter a value but duplication
is allowed.
 Unique : duplication is not allowed but null
values is acceptance.
 Check : Any values but must have a condition.
 Primary key : Not null and Unique
 Foreign key : it is a primary key or unique key
from a nother table.
Example:
Table 1 : patient
Pat_no(pk) Pat_name Pat_db Pat_gender
10 Ali 4/4/1992 M
20 Omar 10/5/1998 M
30 Sami 5/5/1978 M
40 Osman 8/9/1990 M
50 Susan 7/6/1981 F
60 Asma 6/7/1997 F
70 Toni 5/7/1985 M
80 Rania 6/9/1978 F
90 Suad 6/7/1995 M
100 Tareq 5/9/1997 M
references
Table 2: visit
vst_no(pk) Pat_no(FK) vst_date
1 10 1/5/2011
2 40 6/5/2012
3 10 6/5/2011
4 60 8/7/2012
5 80 2/2/2013
6 40 6/6/2012
7 70 9/9/2012
8 80 4/2/2013
Join
1) Cartesian join
select pat_name ,pat_db,vst_date
from patient, visit;
2) Equi join
select pat_name, pat_db,vst_date
from patient,visit
where patient.pat_no=visit.pat_no
order by pat_name
3) Outer join
select pat_name, pat_db,vst_date
from patient,visit
where patient.pat_no (+) =visit.pat_no
4) Non - equi join

Mais conteúdo relacionado

Mais procurados

The Ring programming language version 1.5.4 book - Part 77 of 185
The Ring programming language version 1.5.4 book - Part 77 of 185The Ring programming language version 1.5.4 book - Part 77 of 185
The Ring programming language version 1.5.4 book - Part 77 of 185Mahmoud Samir Fayed
 
Introducing Monads and State Monad at PSUG
Introducing Monads and State Monad at PSUGIntroducing Monads and State Monad at PSUG
Introducing Monads and State Monad at PSUGDavid Galichet
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
 
libcat 콘솔과 함께 하는 아이폰아이패드 앱 개발
libcat 콘솔과 함께 하는 아이폰아이패드 앱 개발libcat 콘솔과 함께 하는 아이폰아이패드 앱 개발
libcat 콘솔과 함께 하는 아이폰아이패드 앱 개발WooKyoung Noh
 
Swift 성능 이해하기
Swift 성능 이해하기Swift 성능 이해하기
Swift 성능 이해하기Hangyeol Lee
 
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy
 
λ | Lenses
λ | Lensesλ | Lenses
λ | LensesOpen-IT
 
The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84Mahmoud Samir Fayed
 
CS 151 Classes lecture 2
CS 151 Classes lecture 2CS 151 Classes lecture 2
CS 151 Classes lecture 2Rudy Martinez
 

Mais procurados (15)

Intoduction to php arrays
Intoduction to php arraysIntoduction to php arrays
Intoduction to php arrays
 
The Ring programming language version 1.5.4 book - Part 77 of 185
The Ring programming language version 1.5.4 book - Part 77 of 185The Ring programming language version 1.5.4 book - Part 77 of 185
The Ring programming language version 1.5.4 book - Part 77 of 185
 
Introducing Monads and State Monad at PSUG
Introducing Monads and State Monad at PSUGIntroducing Monads and State Monad at PSUG
Introducing Monads and State Monad at PSUG
 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
ملخص البرمجة المرئية - الوحدة السادسة
ملخص البرمجة المرئية - الوحدة السادسةملخص البرمجة المرئية - الوحدة السادسة
ملخص البرمجة المرئية - الوحدة السادسة
 
libcat 콘솔과 함께 하는 아이폰아이패드 앱 개발
libcat 콘솔과 함께 하는 아이폰아이패드 앱 개발libcat 콘솔과 함께 하는 아이폰아이패드 앱 개발
libcat 콘솔과 함께 하는 아이폰아이패드 앱 개발
 
Arrays in php
Arrays in phpArrays in php
Arrays in php
 
Swift 성능 이해하기
Swift 성능 이해하기Swift 성능 이해하기
Swift 성능 이해하기
 
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
 
Oracle SQL
Oracle SQLOracle SQL
Oracle SQL
 
λ | Lenses
λ | Lensesλ | Lenses
λ | Lenses
 
โปรแกรมภาษาซีเบื้องต้น
โปรแกรมภาษาซีเบื้องต้นโปรแกรมภาษาซีเบื้องต้น
โปรแกรมภาษาซีเบื้องต้น
 
The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84
 
CS 151 Classes lecture 2
CS 151 Classes lecture 2CS 151 Classes lecture 2
CS 151 Classes lecture 2
 

Semelhante a Oracle (SQL), Sulieman Khudruj

90 Informatics Practices.pdf
90 Informatics Practices.pdf90 Informatics Practices.pdf
90 Informatics Practices.pdfvikas500500
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfRahul04August
 
Oren nakdimon oh really... i didn't know it is supported in standard edition
Oren nakdimon   oh really... i didn't know it is supported in standard editionOren nakdimon   oh really... i didn't know it is supported in standard edition
Oren nakdimon oh really... i didn't know it is supported in standard editionOren Nakdimon
 
The Five Best Things To Happen To SQL
The Five Best Things To Happen To SQLThe Five Best Things To Happen To SQL
The Five Best Things To Happen To SQLConnor McDonald
 
Mysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERTMysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERTHarish Gyanani
 
Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentArun Sial
 
Db2考试测试题
Db2考试测试题Db2考试测试题
Db2考试测试题fm2008
 
SQL techniques for faster applications
SQL techniques for faster applicationsSQL techniques for faster applications
SQL techniques for faster applicationsConnor McDonald
 
Objectives 1. using indirect addressing 2. passing parameters.pdf
Objectives 1. using indirect addressing 2. passing parameters.pdfObjectives 1. using indirect addressing 2. passing parameters.pdf
Objectives 1. using indirect addressing 2. passing parameters.pdffcsondhiindia
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql featuresConnor McDonald
 

Semelhante a Oracle (SQL), Sulieman Khudruj (20)

SQL (1).pptx
SQL (1).pptxSQL (1).pptx
SQL (1).pptx
 
90 Informatics Practices.pdf
90 Informatics Practices.pdf90 Informatics Practices.pdf
90 Informatics Practices.pdf
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 
Oren nakdimon oh really... i didn't know it is supported in standard edition
Oren nakdimon   oh really... i didn't know it is supported in standard editionOren nakdimon   oh really... i didn't know it is supported in standard edition
Oren nakdimon oh really... i didn't know it is supported in standard edition
 
Oracle sql tuning
Oracle sql tuningOracle sql tuning
Oracle sql tuning
 
The Five Best Things To Happen To SQL
The Five Best Things To Happen To SQLThe Five Best Things To Happen To SQL
The Five Best Things To Happen To SQL
 
Beg sql
Beg sqlBeg sql
Beg sql
 
Beg sql
Beg sqlBeg sql
Beg sql
 
Mysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERTMysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERT
 
Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab Assignment
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Db2考试测试题
Db2考试测试题Db2考试测试题
Db2考试测试题
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 
SQL techniques for faster applications
SQL techniques for faster applicationsSQL techniques for faster applications
SQL techniques for faster applications
 
Objectives 1. using indirect addressing 2. passing parameters.pdf
Objectives 1. using indirect addressing 2. passing parameters.pdfObjectives 1. using indirect addressing 2. passing parameters.pdf
Objectives 1. using indirect addressing 2. passing parameters.pdf
 
C++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdfC++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdf
 
Qno 2 (c)
Qno 2 (c)Qno 2 (c)
Qno 2 (c)
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 

Último

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 

Último (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

Oracle (SQL), Sulieman Khudruj

  • 1. Lab of the Database System Sulieman Khudruj
  • 2. Database : a collection of organized data , or set of tables with relations. Why oracle ??  High capacity.  Performance.  Security  Web ready Oracle : 1)Databse a.SQL : Structured Query Langauge b.PL/SQL. 2)Developer a.Forms b.Reports Other Tools:  Designer  Portals  Jdevelopers  Discoverer  EM  Grid controls
  • 4. Entity Relation Ship Diagram (ERD) Symbol Meaning Entity type Weak Entity type Relationship type Identifying Relationship type attribute Key attribute Multi valued attribute Composite attribute Derived attribue Simple Example
  • 5. Database contains 2 tables Table 1: Emplyee Empno Ename Sal Birthdate Mobile# Age 1 Ali 5000 14/2/1977 05467756 Table 1: Dept Deptno Deptname 10 Computer 20 Research 30 Sales 40 Accounting Empn o Enam e Employee s Sal Mobile # Birthdat e Age Dept Dento n Deptname Wor k 1 M
  • 6. SQL Commands Types  DDL : Data Definition language Create, Drop, Alter, Rename,….  DML: Data Manipulation language Insert, Delete, Update, select  DCL : Data Control Language Grant, Revoke, …….  Transactions : Commit, Rollback, Save point,… Constraints  Not null : we must enter a value but duplication is allowed.  Unique : duplication is not allowed but null values is acceptance.  Check : Any values but must have a condition.  Primary key : Not null and Unique  Foreign key : it is a primary key or unique key from a nother table.
  • 7. Data Types  Number (5) , can be upto 5  Number (6,2)  Number , it can reserve to the highest value but it is not recommended  Char (10) , Ahamed- - - -  Varchar2(20)  Date : Store Date in many formats
  • 8. 1) Create user , grant create session , grant connect, resource
  • 9. 2.Create table 3.Select * from tab 4.desc name_table
  • 10. 5.drop table, show recyclebin, flashback 6. drop table table_name purge
  • 11. 7. insert Dept table Deptno Depname 10 Computer 20 Resaech 30 Accounting 40 Marketing Employee Empno Ename Sal Birthdate Mobile# 1 abdulelah 5000 14/2/1977 054545454 2 omar 6000 14/4/1993 054564645 3 khaled 8000 1/4/1990 054564564 4 mubark 5500 1/1/1990 054645646 5 saad 9000 1/1/1994 056456445 6 adel 29000 13/11/1993 045645644 7 Abd allah 30000 14/5/1996 056456564 8 amer 16000 5/7/1992 045564454 9 Abd aziz 55000 7/4/1979 045645645 10 hamad 50000 4/5/1993 045645666
  • 12.
  • 13. 8. alter a) add column b)modify length of column
  • 14. c)drop column d)drop more than one column
  • 15. e) add more than one column 9. Rename table
  • 16. 10. Browsing data (select) - Firstly create the following table (empdata) - Then enter the data Empno Ename Sal Birthdate Mobile# nationality 1 Abdullah 5000 14/2/1977 054545454 Saudi 2 omar 6000 14/4/1993 054564645 Saudi 3 khaled 8000 1/4/1990 054564564 Saudi 4 mubark 5500 1/1/1990 054645646 Saudi 5 saad 9000 1/1/1994 056456445 Saudi 6 saad 29000 13/11/1993 045645644 Jordanian 7 Abd allah 30000 14/5/1996 056456564 Jordanian 8 Amer 16000 5/7/1992 045564454 Egyptian 9 Amer 55000 7/4/1979 045645645 Egyptian 10 hamad 60000 4/5/1993 045645666 Suadi
  • 17. Until empno=10 a) select * from empdata
  • 19. c) select ename, sal*12 as ann_sal from empdata d) select sysdate from dual; e) select 545*87 from dual;
  • 20.
  • 21. f) select ename || ' earns ' || sal || ' every month ' info from empdata
  • 22. g) select * from empdata where empno=10; Note Type Symbol meaninig Logical operators = equal < > , != , ^ = Not equal > Less than < Greater than >= Less than or equal <= Greater than or equal Logical Bitwise and , or , not Contacts between conditions
  • 23. h) select * from empdata where sal >5000 and nationality='Saudi'; i) select ename, sal , mobile from empdata where sal between 10000 and 60000
  • 24. j) select ename , sal , nationality from empdata where ename like '%m%' k) select * from empdata where ename like 'm%';
  • 25. L) select * from empdata where ename like '%h'; m) select ename, sal from empdata where ename like '_b%';
  • 26. n) select * from empdata where ename like '____'; o) select * from empdata where ename like 'o__r';
  • 27. p) select * from empdata where sal in (6000,5000,55000,60000) q) select * from empdata where ename in ('omar','Amer')
  • 28. r) select ename,sal ,mobile from empdata order by sal asc
  • 29. Revision (1) A) 1)Create table “Student_info” as follows : Filed Name Type Student_no Number(4) , primary key Student_name Varchar2(20) Student_mobile Number (10) Student_age Number(4) 1) Insert 2 rows to this table Student_no Student_name Student_mobile Student_age 100 Ali 054465477 29 101 Omar 059089035 32 3)Display the fields with properties B)
  • 30. 1) list the steps to create new (RCC with password KSU) user and a) log in to user System / Manager b) write  create user RCC identified by KSU 2) give RCC user all the privileges grant create session to RCC grant connect, resource to RCC
  • 31. c) study to the following empdata and answer the quesions a) modify length of filed nationality to 50 alter table empdata modify nationality varchar2(50) b) rename the name of table to empinfo rename empdata to empinfo; c) delete the column birthdate alter table empinfo drop column birthdate; d) drop the table to recyclein drop table empinfo; e) show the contents of the recyclein show recyclein ;
  • 32. d) study the following table and answer the quesions a) calculate the annual salary for each employee with column alias "emp_ann_sal”, and display the name and the annual salary select ename , sal*12 as emp_ann_sal from empinfo; b) display the records of empno = 6 and empno=9 select * from empinfo where empno in (6,9); c) display all records of employee who earn salary between 8000 to 16000 select * from empinfo where sal between 8000 and 16000
  • 33. d) display all records , that names contain d letter select * from empinfo where ename like ‘%d%’; e)display all records , that names contain 8 letters select * from empinfo where ename like ‘________’; f) return the system date select sysdate from dual; g) return the value of 18*35 select 18*35 from dual;
  • 34. Functions 1) Single 2) Group 2) Single a. Character b. Number c. Date d. General e. Conversion I. Character a. Upper b. Lower c. Initcap d. Substr e. Instr f. Replace g. Translate h. Lpad ,rpad ,ltrim ,rtrim i. length
  • 35. a) select ename, upper(ename), lower(ename), initcap(ename) from empdata b) select * from empdata where upper(ename) like '%S%';
  • 36. c) select ename, substr(ename,1,3) from empdata; d) select ename, instr(ename,'a',1) from empdata
  • 37. e) select ename, instr(ename,'a',1,2) from empdata; f) select ename ,replace(ename,'Abdullah','Abdulelah') from empdata
  • 38. g) select ename ,translate(ename,'ah','ox') from empdata h) select ename, lpad(sal,10,'*') , rpad(sal,10,'*') from empdata;
  • 39. i) select ename , length (ename), ltrim(ename,'A'), rtrim (ename,'h') from empdata
  • 40. II) Number Function a. Mod b. Round c. Trunk a. select mod (1.5,1), mod (5,2) , mod (5,1) from dual b. select round (137.74), trunc(137.74) from dual
  • 41. III) Date Functions and Conversation functions ‘dd-mon-yy’  default , example : 15-jun-02 Rules : a. date1-date2 = number of days b. date1(+/-) number of days = date2 c. date1 (+/-) hours/24=date2 d. date+date = not allowed a. select months_between ('02-12-2013', '04-6-2013') from dual b. select add_months ( '2-7-2013',2) from dual
  • 42. c. select next_day ('2-7-2013', 1) from dual note : 1(Saturday) , 2( Sunday),……….. d. select last_day ('2-7-2013') from dual
  • 43. e. select to_char (sysdate, 'dd/mm/yy') from dual;
  • 44. IV) General Functions a. insert into empdata (empno,ename,birthdate,mobile,nationality) values (11,'Ali','4/6/1990',054546454,'Egyption'); select ename, nvl(sal,0) as " annual salary" from empdata b. select ename, nullif (sal,60000) from empdata
  • 45. c. select to_char(sysdate, 'HH:MI:SS AM ') from dual; IIV) Group functions a. select count (sal), sum (sal), avg(sal) from empdata
  • 46. b. select min(sal), max(sal) from empdata b. suppose this table no name salary deptno job 1 Ali 5000 10 programmer 2 Khaled 6000 10 analyst 3 Omar 40000 10 designer 4 Sami 55000 20 manager 5 Amer 70000 20 manager 6 Nasser 5440 20 accouter 7 Rami 45400 20 programmer 8 Mubark 20000 30 advisor 9 anas 15000 30 programmer 10 mostafa 22000 30 analyst
  • 47. c. select deptno ,sum(salary) from empcomp group by deptno; d. select deptno,job, sum(salary) from empcomp group by deptno,job;
  • 48. d. select job ,sum(salary) from empcomp group by job; e. select deptno,job,sum(salary) from empcomp where deptno <> 30 having sum(salary)>10000 group by deptno, job;
  • 49. c. select nationality, sum (sal) from empdata group by nationality;
  • 50. delete rows , update data a. delete from empdata where empno=11; d. update empdata set nationality ='Saudi' where empno =10;
  • 51. Constraints  Not null : we must enter a value but duplication is allowed.  Unique : duplication is not allowed but null values is acceptance.  Check : Any values but must have a condition.  Primary key : Not null and Unique  Foreign key : it is a primary key or unique key from a nother table.
  • 52. Example: Table 1 : patient Pat_no(pk) Pat_name Pat_db Pat_gender 10 Ali 4/4/1992 M 20 Omar 10/5/1998 M 30 Sami 5/5/1978 M 40 Osman 8/9/1990 M 50 Susan 7/6/1981 F 60 Asma 6/7/1997 F 70 Toni 5/7/1985 M 80 Rania 6/9/1978 F 90 Suad 6/7/1995 M 100 Tareq 5/9/1997 M references Table 2: visit vst_no(pk) Pat_no(FK) vst_date 1 10 1/5/2011 2 40 6/5/2012 3 10 6/5/2011 4 60 8/7/2012 5 80 2/2/2013 6 40 6/6/2012 7 70 9/9/2012 8 80 4/2/2013
  • 53.
  • 54.
  • 55. Join 1) Cartesian join select pat_name ,pat_db,vst_date from patient, visit; 2) Equi join select pat_name, pat_db,vst_date from patient,visit where patient.pat_no=visit.pat_no order by pat_name
  • 56. 3) Outer join select pat_name, pat_db,vst_date from patient,visit where patient.pat_no (+) =visit.pat_no 4) Non - equi join