You are on page 1of 19

Lab 1: Introduction To SQL And Installation Process For Oracle

Structured Query Language (SQL) is a standardized programming


language that’s used to manage relational database and perform
various operations on the data in them. The uses of SQL include
modifying database table and index structures; adding, updating and
deleting rows of a database for transaction processing and analytics
applications. Queries and other SQL operations take the form of
commands written as statements – commonly used SQL statements
include select, add, insert, update, delete, create and alter.
Generally, SQL commands are divided into several different types,
among them Data Manipulation Language (DML) and Data Definition
Language (DDL) are commonly used.
Data Manipulation Language (DML) is used to retrieve and manipulate
data whereas Data Definition Language (DDL) is a statement for
defining and modifying database structure.
Oracle Database is a relational database management system for oracle
corporation which is most trusted and widely used relational database
engines for storing, organizing and retrieving data by type while still
maintaining relationships between the various types. Oracle database
allows us to quickly and safely store and retrieve data. Oracle Database
can operate on various hardware across operating system including
windows server, Linux and various other distributions. Oracle is ACID
complaint database that helps maintain integrity and reliability.
Installation Steps For Oracle Database:
 Go to official site for oracle(www.oracle.com) and go to downloads.
 Select database section with your preferred version for download.
 Download it after logging in your Oracle account.
 Unzip the file and click on setup.
 Click next, after the installation window opens.

 Click Next again and on the next window, type the desired username with a
strong password.
 Choose the location and character set and character set, and give a global
database name and password and press next.

 Click install on the next window.


 Wait until it finishes installing.

 After it finishes installing, click close.


After installing we need to run it. We follow the steps below:
 Open the windows command prompt.
 Type SQLPLUS.
 Give your username and password used while installing.
Lab 2: DATA DEFINITION LANGUAGE (CREATE, ALTER, DROP)
Data Definition Language (DDL) is s a computer language that is used to create
and modify the structure of database objects in a database. Such database
objects include views, schemas, tables, indexes, etc. since it describes the fields
and records stored in a database table it is also known as data description
language.
DDL has a pre-defined syntax for describing data. For example, to build a new
table using SQL syntax, CREATE command is used, followed by the parameters for
the table name and column definitions. It can also define the name of each arity
along with its associated data type. After a table is created the table can be
modified using the ALTER command and if the table is no longer needed DROP
command can be used to delete the table.

CREATE:
This command creates a new table and ahs a predefined syntax. Its syntax is:
CREATE TABLE [TABLE NAME] ([column definitions]) [table parameters];

Describe syntax can be used to view the table.


Creating complex table with different constraints:
If we define different types of constraints, various complex data types and
establish relationship between multiple tables by using the concept of primary
key and foreign key constraints while creating the table, we can make a complex
table. For example:

ALTER:
The ALTER command modifies an existing database table. This command can add
up additional column, drop ones that already exist and even change the data type
of columns involved in a database table.
The syntax of ALTER command is:
ALTER object type object name parameters;
DROP:
DROP command is used to delete objects such as a table index or a view. DROP
statement cannot be rolled back, so once an object is destroyed there is no way
to recover or restore it.
It’s syntax is:
DROP object type object name;
LAB 3: DATA MANIPULATION LANGUAGE (INSERT, UPDATE, DELETE)
Data manipulation language is the type of language that permits the user to
change or manipulate the data in the database. Data manipulation includes
inserting data into the database, retrieving the data from existing database,
deleting data of the existing database as well as modifying the data of existing
database. DML is mostly incorporated in SQL databases. Commands like UPDATE,
INSERT INTO and DELETE FROM as given below:
1) INSERT : The insert command is used to add one or more records into the
database table. The syntax for INSERT command is: INSERT INTO [table name]
[column(s)] VALUES [value(s)].
a) Inserting single record:

b) Adding more than one column name:


2) UPDATE: The UPDATE command is used to modify the data of one or more
records. The syntax for UPDATE command is UPDATE[table name] SET[column
name= value] where[condition].

3) DELETE: The DELETE command id used to remove one or more than one
records from the table based on the specified condition. The syntax for DELETE
command is: DELETE FROM [table name] where [condition]
LAB 4: DATABASE QUERY LANGUAGE (SELECT, WHERE)

The Oracle statement is used to extract records from one or more than one tables
at once in an Oracle database. The syntax for SELECT statement in Oracle is:
SELECT expression FROM table(s) [WHERE conditions];
Here, Expressions are the columns that you wish to retrieve. * can be used if the
database user wishes to select all columns.
Tables are where the records are retrieved from. At least one table must be listed
in the FROM clause.
Where is the condition, that must be met for the records to be selected from the
table(s) . If no conditions are provided all records will be selected.
Example: create a table customer with attributes (cid, cname, caddress, age) and
insert assumed values.
Select and from clause:
 Details of customer of age between 20 and 35

.
 Select all fields.

 Select specified fields.

 Select distinct statement.


LAB 5: OPERATORS IN WHERE CLAUSE
The following operators can be used in where clause:

1) Equality operator:
Find all customer who are aged 28.

2) Inequality operator:
Find all customers whose age is not 28.
3) Comparison operator(<,>):
Find customer whose age is less 30 and greater than 20.

4) Between operator:
Find the customers with age between 25 and 45.

5) Like operator:
Find customer whose name starts with B.

6) In operator:
Find age and address of customer named maya and kalu.
LAB 6: JOINS IN ORACLE:
Join is a binary operation that lets a database user to cobine two or more tables
into one.
There are 4 different types of joins:
(1) INNER JOIN (also called simple join)
(2) LEFT OUTER JOIN ( sometimes called left join)
(3) RIGHT OUTER JOIN ( sometimes called right join)
(4) FULL OUTER JOIN ( sometimes called full join)
INNER JOIN (simple join):
This is the most commonly used type of join. It returns all rows from multiple
tables where the join condition is fulfilled. The syntax for inner join is:
SELECT columns FROM table 1 INNER JOIN table 2
ON table1.column=table2.column.
The shaded area of the diagram below is the result of inner join or in other words
the intersection of table 1 and table 2.
For example: we have two tables with the following details

Using INNER JOIN:

LEFT OUTER JOIN (left join):


The type of join that returns all rows from the left hand table specified by the ON
condition and only those rows from the other table that fulfill the join conditions
is called a left ouer join. The syntax for left outer join is:
SELECT columns FROM table1 LEFT [OUTER] JOIN table2
ON table1.column = table2.column;
The shaded part of the visual diagram below is the result of left outer join.
Using left outer join:

RIGHT OUTER JOIN (right join):


the type of join that returns all rows from the right hand table specified by the ON
condition and only those rows from the other table that fulfill the join conditions
is called a right outer join. The syntax for left outer join is:
SELECT columns FROM table1 RIGHT [OUTER] JOIN table2
ON table1.column = table2.column;
The shaded part of the visual diagram below is the result of right outer join.

Using right outer join:


FULL OUTER JOIN (full join):
The type of join that returns all rows from the left and right table with null values
where the join conditions are not fulfilled is called a full outer join. The syntax for
full outer join is:
SELECT columns FROM table1 FULL [OUTER] JOIN table2 ON
table1.column = table2.column;
The shaded part of the visual diagram below is the result of full outer join.

Using full outer join:


LAB 7: ORDER BY AND GROUP BY:
ORDER BY:
The ORDER clause is used to rearrange or sort the records of the result set. The
ORDER clause is only used with SELECT statement.
SYNTAX: SELECT expressions FROM tables WHERE conditions
ORDER BY expression [ ASC | DESC];
Here,
ASC is used to sort records in ascending order.
DESC is used to sort records in descending order.

GROUP BY:
The GROUP BY clause is used with select statement to collect data from multiple
records and group the results by one or more columns.
SYNTAX:
SELECT expression1, expression2, ... expression n,
aggregate function (aggregate expression)
FROM tables
WHERE conditions
GROUP BY expression1, expression2, ... expression n;
Consider the table:

Group by with SUM, COUNT, MIN and MAX functions:

You might also like