Professional Documents
Culture Documents
Null?
Type
OID
VARCHAR2(40)
CITY
VARCHAR2(30)
PRODUCT
VARCHAR2(30)
CITY
PRODUCT
CITY
PRODUCT
CITY
PRODUCT
CITY
PRODUCT
Alter table name: - this function is adding some column into the current table name
Alter table a12
add mobile_no varchar2(10)
The mobile_no column is added in my table see in this table.
OID
CITY
PRODUCT
MOBILE_NO
CITY
MOBILE_NO
Primary key
This is a key which protect the table and it will not allowed any duplicate value to enter into the
table
Primary key
create table m1
(Reg_number varchar2(20)not null primary key,
name varchar2(10)not null,
section_id varchar2(10)not null,
roll_number varchar2(14)not null,
city varchar2(45)not null
);
This is a table which data is not enter into table
Name
Null?
Type
REG_NUMBER
NOT NULL
VARCHAR2(20)
NAME
NOT NULL
VARCHAR2(10)
SECTION_ID
NOT NULL
VARCHAR2(10)
ROLL_NUMBER
NOT NULL
VARCHAR2(14)
CITY
NOT NULL
VARCHAR2(45)
REG_NUMBER
NAME
SECTION_ID
ROLL_NUMBER
CITY
11312200
mohammad 2307
b-25
pulamalm
113230
waheed
b-25
paktia
2308
NAME
SECTION_ID
ROLL_NUMBER
CITY
234
ahmad
2309
parwan
23324
mohammad
2309
parwan
Foreign key
Is the key which showing the relation of the two table from example there is tow table M23 and M24 the
relation here reg>number
create table m23
(Reg_number varchar2(20)not null primary key,
name varchar2(10)not null,
section_id varchar2(10)not null,
roll_number varchar2(14)not null,
city varchar2(45)not null,
check(roll_number between 2 and 23)
);
create table m24
(teacher_id varchar2(90)not null,
faculty_name varchar2(49)not null,
subject_code varchar2(10)not null,
Reg_number varchar2(20)not null,
foreign key(Reg_number)references m23(Reg_number)
);
Name
Null?
Type
REG_NUMBER
NOT NULL
VARCHAR2(20)
NAME
NOT NULL
VARCHAR2(10)
SECTION_ID
NOT NULL
VARCHAR2(10)
ROLL_NUMBER
NOT NULL
VARCHAR2(14)
CITY
NOT NULL
VARCHAR2(45)
Name
Null?
Type
TEACHER_ID
NOT NULL
VARCHAR2(90)
FACULTY_NAME
NOT NULL
VARCHAR2(49)
SUBJECT_CODE
NOT NULL
VARCHAR2(10)
REG_NUMBER
NOT NULL
VARCHAR2(20)
REG_NUMBER
1131
NAME
ahmad
SECTION_ID
ROLL_NUMBER
2309
5
CITY
parwan
1141
waheed
2309
paktia
11561
wahedfded
2309
paktia
TEACHER_ID
FACULTY_NAME
SUBJECT_CO
REG_NUMBER
2309
ankit
qtt201
1131
2309
preetpal
qtt201
1141
2309
preafetpal
qtt201
11561
Default constants
create table aaa
(employee_id varchar2(10),
employee_name varchar2(30),
departement varchar2(10)default'business',
city varchar2(10)default'CHD'
);
When inserting the values
EMPLOYEE_I D
EMPLOYEE_NAME
DEP ARTEMENT
CITY
attuallah
11312431
business
CHD
rafi
11312142
business
CHD
zekria
11312145
business
CHD
shakir
11312200
business
CHD
Ishaq
11413432
business
CHD
sayed-aman
11311941
business
CHD
CITY
SAL ARY
ahmad
kabul
25000
zekria
logar
75000
Rafi
parwan
20000
Amanullah
badgheis
40000
shakir
logar
10000
attullah
wardak
60000
4.this function shows the total number of people from that table
5.this function is showing the average salary of the employee from that table
6.this function is show the employee name and salary which (more than, less than and equal by
putting this points =, < and >) the average salary
SAL ARY
Zekria
75000
Amanullah
40000
Attullah
60000
10
Character function
create table c123
(name varchar2(30),
roll_no varchar2(20),
last_name varchar2(40)
)
This is the table which created
NAME
ROLL_NO
LAST_NAME
arhu
sharma
abdol
rehmah
mohit
sigh
ras
verama
1this function is showing the name of the person in upper word (capital word)
select upper(name)
From c123;
UPPER(NAME)
ARHU
ABDOL
MOHIT
RAS
2this function showing the name in lower alphabet
Select lower(name)
From c123;
LOWER(NAME)
arhu
abdol
mohit
ras
11
INITCAP(NAME)
Arhu
Abdol
Mohit
Ras
4..this function is showing the name and last name of the person to together
select concat(name,last_name)
From c123;
CONCAT(NAME,LAST_NAME)
arhusharma
abdolrehmah
mohitsigh
rasverama
5this function shows that the three alphabet of the name and the position of the a in the table.
select substr(name,1,3),instr(name,'a')
From asad:
SUB
INSTR(NAME,'A')
wah
raf
zek
aha
12
6When the any column is not having the salary or ect.. it will add some numbers
NAME
ahamd
1213
ahamd
1141
zekria
1213
ahamd
112131
rafi
SALARY
230000
CITY
parwan
parwan
50000
logar
parwan
60000
parwan
NAME
ahamd
NVL(SALARY,'10000')
230000
ahamd
10000
zekria
50000
ahamd
10000
rafi
60000
13
NAME
CGPA
rahul
5.2
raja
9.1
sohn
6.4
smith
7.1
1..This function is using for the round off method related to math
Select round (cgpa)
From c1234;
ROUND(CGPA)
5
9
6
7
14
3...This function showing just the positive and negative view of the CGPA if it is positive>0 it will +1
and if CGPA is less than<0 it will show -1
Select sign (cgpa)
From c1234;
SIGN(CGPA)
1
1
1
1
4This function is rised the power of cgpa with the number which we wants for example
Select power (cgpa,5)
From c1234;
POWER(CGPA,5)
3802.04032
62403.2145
10737.4182
18042.2935
15
Like
This function is showing the name which start with r
Select*from c1234
Where name like('s%');
NAME
CGPA
sohn
6.4
smith
7.1
NAME
CGPA
sohn
6.4
This function is showing the name and details where and is coming in between of the city
select*from q123
where city like('%and%')
STUDENT_NAME
CITY
ahmad
jalandhar
shakir
jalandhar
Select name
From table name
Where name like(%a%e%);
Where name like(__c%).
16
Joins
Who we are joining two table
This is the function
select a12.product, b12.employee_name
from a12
inner join b12
on a12.oid=b12.oid;
now create two table
create table a12
(oid varchar2(40),
city varchar2(30),
product varchar2(30)
);
create table b12
(oid varchar2(10),
employee_name varchar2(30)
);
This is table a12
OID
CITY
PRODUCT
OID
EMPLOYEE_NAME
ahmad
waheed
rafi
17
After the process two table is joining and the table is this one
PRODUCT
CITY
EMPLOYEE_NAME
ahmad
waheed
rafi
18
ENAME
DEPNO
DEPTN AME
JOB
attuallah
14
businss
clerk
50000
SAL ARY
zekria
14
businss
clerk
30000
rafi
14
businss
cse
20000
ishaq
23
engineer
clerk
6000
shakir
45
ENG
CSE
45000
waheed
45
PSY
CSE
5000
razwan
45
PSY
CSE
1000
DEPTN AME
attuallah
businss
zekria
businss
rafi
businss
ishaq
engineer
shakir
ENG
waheed
PSY
razwan
PSY
2Find the name of those employees who are earning more than 20,000
Select ename
From employee
Where salary>20000
ENAME
attuallah
zekria
shakir
Select ename,
From employee
where job=CSE AND deptname =PSY
ENAME
DEPTN AME
JPB
attuallah
businss
clerk
zekria
businss
clerk
19
4Write a query to display the name and salary of employees earning more than 25000.
Select name, salary
From employee
Where salary > 25000
ENAME
SAL ARY
attuallah
50000
zekria
30000
shakir
45000
5Write a query to display the employee name and department number for employee number 5.
Select E_id,name, dept_id
From employee
Where e_id =5;
E_ID
5
ENAME
shakir
DEPNO
45
6...Write a query to display the name and salary for all the employees whose salary is not in the range of Rs
20000 and 46000.
Select ename, salary
From employee
Where salary NOT BETWEEN 20000 AND 46000
ENAME
SAL ARY
attuallah
50000
ishaq
6000
waheed
5000
razwan
1000
7Write a query to display the name and department number of all the employees in department number 8
and 12 in an alphabetical order by name.
Select ename,depno
From employee
Where depno='14' or depno='45'
Order by ename;
ENAME
DEPNO
attuallah
14
rafi
14
razwan
45
shakir
45
waheed
45
zekria
14
20
8Write a query to display the employee name, job and joining date of employees joined between June 11,
2010 and July 15, 2010. Also order the result in ascending order of joining date.
ENAME
JOB
zekria
clerk
rafi
cse
shakir
CSE
ishaq
clerk
waheed
CSE
9Write a query to display the name, job and salary of all the employees whose job is clerk or CSE and
whose salary is not equal to 50000.
select ename, job, salary
From employee
Where job='clerk' or job='CSE' AND Salary! =50000;
ENAME
JOB
SAL ARY
attuallah
clerk
50000
zekria
clerk
30000
ishaq
clerk
6000
shakir
CSE
45000
waheed
CSE
5000
razwan
CSE
1000
21
TRIGGER
Is a statement which automatically execute
End
22
Distinct command
This a table
NAME
ID
CITY
AM
CHD
CHD
AM
BM
AM
BM
Finish
23