You are on page 1of 18

EXPERIMENT NAME :

EXPERIMENT NO : 1 REMARK

DATE SIGN
Experiment no: - 1

Experiment Name: - Introduction of Oracle & Basic SQL Statements

Aim: - Performing practical by using Basic SQL Statements.

Resource Required: - Oracle 9i - iSQLplus

Theory: -

• INTRODUCTION TO ORACLE9I:
SQL consists of two models

- Introduction to Oracle9i: SQL Basics


- Oracle9i: Advanced SQL

• Oracle9i Features:
There are two products, Oracle9i Application server (Oracle9iAS – services for all
different server applications) & Oracle9i Database (stores all data). That provide a complete
and simple infrastructure for Internet applications.

• System Development Life Cycle:


- develop database by using system development life cycle
- this is top-down, systematic approach to database development
1. Strategy and Analysis:

- Study and analyze the business requirements.

- Build models of the system.

2. Design:

- Design database based on the model development in the strategy and analysis phase.

3. Build and document

- Build the prototype system, Create table and develop user


documentation.

4. Transition
- Refine the prototype & make any modification required.

5. Production

- Roll out the system to the users.

• Main types of Database (DBMS):


1. Hierarchical
2. Network
3. Relational
4. Object relational
Relational Database Concept:

- It’s basis for the relational database management system (RDBMS).


- The relational model consists of the following:
- Collection of objects or relations

- Set of operators to act on the relations

- Data integrity for accuracy and consistency.

- A relational database is a collection of relations or two-dimensional tables.

That is a relational database uses relations or two-dimensional tables to


store Information.
• Entity Relationship Model:
In a relational database data is divided into entities. An entity relationship (ER) model is
an illustration of various entities.

It is derived from business specification & built during the analysis phase of the system
development life cycle.

Key Components:

 Entity: A thing of specificance about which information needs to be known. E.g.


Employee.
 Attribute: Something that describes an entity. E.g. for employee entity, the
attributes would be the employee name, number, job title & so on.
 Relationship: A named association between entities.
 Unique Identifiers (UID): Any combination of attributes or relationship that
serves to distinguish occurrences of an entity.
 Relational Database Properties:
- Can be accessed and modified by executing structured query language (SQL)
statements
- Contains a collection of tables with no physical pointers
- Uses a set of operators.

• SQL STATEMENTS:

Basic SELECT Statements:


• - SQL statements aren’t case sensitive.
• - SQL statements can be on one or more lines.
• - Keywords can’t be abbreviated across lines.
• - Clauses are usually placed on separate lines.
• - Indents are used to enhance readability.
SELECT – Retrieves data from the database.

Syntax:-
SELECT *| {[DISTINCT] column | expression [alias] …}

FROM table;

- SELECT identifies what columns


- FROM identifies which table
Example: -

1) SELECT *

FROM departments;
DEPT_ID DEPT_NAME MANAGER_ID LOCATION_ID

10 Administration 200 1700

20 Shipping 201 1800

50 IT 103 1400

Selecting all columns of the table.

2) SELECT dept_id, location_id

FROM departments;

DEPT-ID LOCATION_ID

10 1700

20 1400

Selecting specific columns.

3) Arithmetic Operators & Parentheses

SELECT last_name, salary, 12*(salary+100)

FROM employees;

LAST_NAME SALARY 12*(SALARY+100)

King 24000 269200

Kochhar 17000 205200

Fay 13000 73200

4) Defining column aliases

SELECT last_name AS name, salary*12 as anuual_salary

FROM employees;

NAME ANNUAL_SALARY

King 228800

Kochhar 204000
De Haan 204000

5) Using Concatenation Operator

SELECT last_name || job_id AS “Employees”

FROM employees;

Employees

KingAD_PRES

KochharAD_VP

De HaanAD_VP

HunoldIT_PROG

6) Eliminating Duplicate Rows

SELECT DISTINCT dept_id

FROM employees;

DEPT_ID

10

20

30

7) Displaying Table Structure

DESCRIBE employees

Name Null? Type

EMPLOYEE_ID NOT NULL NUMBER(6)

FIRST_NAME VARCHAR(20)

LAST_NAME NOT NULL VARCHAR(25)

EMAIL NOT NULL VARCHAR(25)

PHONE_NUMBER VARCHAR(20)

HIRE_DATE NOT NULL DATE


Conclusion:

The Oracle9i Server is the database for Internet computing & based on the object
relational database management system.

You should have learned how to write & execute SELECT statements.

EXPERIMENT NAME :
EXPERIMENT NO : 2 REMARK

DATE SIGN

Experiment no: - 2
Experiment Name: - Ret rival Commands-I

Aim: - Performing practical by using restricting, sorting conditions and single-row functions.

Resource required: - Oracle 9i - iSQLplus

Theory: -

• RESTRICTING AND SORTING DATA:


Limiting the Rows Selected:

Syntax:-

SELECT *| {[DISTINCT] column / expression [alias],….}

FROM table

[WHERE condition(s)];

-Restrict the rows returned by using the WHERE clause

Example:

SELECT employee_id, last_name, job_id, department_id

FROM employees

WHERE depertment_id = 90;

EMPLOYEE_ID LAST_NAME JOB_ID DEPARTMENT_ID

100 King AD_PRES 90

101 Kochhar AD_VP 90

102 De Haan AD_VP 90

- Comparison Conditions
1) SELECT last_name, salary

FROM employees

WHERE salary<= 3000;

LAST_NAME SALARY

Matos 2600

Vargas 2500

2) BETWEEN Condition: display row based on a range of values

SELECT last_name, salary

FROM employees

WHERE salary BETWEEN 2500 AND 3500;

LAST_NAME SALARY

Rajs 3600

Devies 3200

Matos 2600

3) IN Condition: test for values in a list

SELECT employee_id, last_name, salary, manager_id

FROM employees

WHERE manager_id IN (100,101,201);

EMPLOYEE_ID LAST_NAME SALARY MANAGER_ID

202 Fay 6000 201


200 Whalen 4400 101

205 Higgins 120000 100

4) LIKE Condition: Combine pattern-matching character

SELECT last_name

FROM employees

WHERE last_name LIKE ‘_o%’;

LAST_NAME

Kochhars

Mourgas

- Logical Conditions

5) AND & OR operator:

SELECT employee_id, last_name, job_id, salary

FROM employees

WHERE (job_id = ‘SA_REP’

OR job_id = ‘AD_PRES’)

AND salary> 15000;

LAST_NAME JOB_ID SALARY

King AD_PRES 2400


6) NOT operator:

SELECT last_name, job_id

FROM employees

WHERE job_id

NOT IN (‘IT_PROG’, ‘ST_CLERK’, ‘SA_REP’);

LAST_NAME JOB_ID

King AD_PRES

Kichhar AD_VP

Morgus AD_VP

Ziofkey ST_MAN

- ORDER BY Clause: Sort rows

SELECT employee_id, last_name, salary*12 annsal

FROM employees

ORDER BY annsal;

EMPLOYEE_ID LAST_NAME ANNSAL

144 Vargas 30000

143 Matos 31200

141 Davies 37200

107 Rajas 50400

• SINGLE-ROW FUNCTION:
1. Character Function
2. Number Function
3. Date Function
4. Conversion Function
5. General Function
Character-Manipulation Functions

SELECT employee_id, CONCAT (first_name, last_name) NAME,

Job_id, LENGTH (last_name),

INSTR (last_name, ‘a’) “Contains ‘a’?”

FROM employees

WHERE SUBSTR (job_id, 4) = ‘REP’;\

EMPLOYEE_ID NAME JOB_ID LENGTH(LAST_NAME_ Contains’a?

174 EllenAbel SA_REP 4 0

176 JonathonTaylor SA_REP 6 2

178 PatFay MK_REP 5 3

Number Functions

- ROUND: rounds value to specified decimal

SELECT ROUND (45.923, 2), ROUND (45.923, 0) ,

ROUND (45.923, -1)

FROM DUAL;

ROUND(45.923,2) ROUND (45.923, 0) ROUND (45.923, -1)

45.92 46 50

DUAL is a dummy table


- TRUNC: truncates value to specified decimal

SELECT TRUNC (45.923, 2), TRUNC (45.923),

TRUNC (45.923, -2)

FROM DUAL;

TRUNC(45.923 , 2) TRUNC (45.923) TRUNC(45.923,-2)

45.92 45 0

- MOD: returns remainder of division

SELECT last-name, salary, MOD (salary, 5000)

FROM employees

WHERE job_id = ‘SA_REP’;

LAST_NAME SALARY MOD(SLARY, 5000)

Abel 1100 1000

Taylor 6600 3600

Grant 7000 2000

Date Functions

- MONTHS_BETWEEN: Number of months between two dates

MONTHS_BETWEEN (‘01-SEM-95’, ’11-JAN-94’)

ANS: 19.6774194
- ADD_MONTHS: Add calendar months to date

ADD_MONTHS (’11-JAN-94’, 6)

ANS: ’11-Jul-94’

- NEXT_DAY: Next day of month

NEXT_DAY (‘01-SEP-95’, ‘FRIDAY’)

ANS: ’08-SEP-95’

- LAST_DAY: Last day of the month

LAST_DAY (’01-FEB-95’)

ANS: ’28-FEB-95’

- ROUND: Round date

Assume SYSDATE= ’25-JUL-95’:

ROUND (SYSDATE, ‘MONTH’)

ANS: 01-AUG-95

- TRUNC: Truncate date

TRUNC (SYSDATE, ‘YEAR’)

ANS: 01-JAN-95

Conversion Functions

Data type conversion

- from number to character


TO_CHAR (number, ‘format_model’)

- from character to number


TO_NUMBER (char [, ‘format_model’])

- from character to date


TO_DATE (char, ‘format_model’])

- from date to character


TO_CHAR (date, ‘format_model’)

e.g.: SELECT last_name, TO_CHAR (hire date, ‘DD-Mon-YYYY’)

FROM employees
WHERE hire_date < TO_DATE (’01-Jan-90’, ‘DD-Mon-RR’);

LAST_NAME TO_CHAR(HIR

King 17-Jan-1987

Kochhar 21-Sep-1989

Whalen 17-Sep-1987

General Functions

These functions work with any data type and pertain to using nulls.

- NVL (expr1, expr2)

- NVL2 (expr1, expr2, expr3)

- NULLIF (expr1, expr2)

- COALESCE ( expr1, expr2, …., exprn)


Others are Conditional Expressions:

- Use of IF-THEN-ELSE logic within a SQL statement

- Use two methods: CASE expression and DECODE function

Conclusion:

This practical covers topics:

- Selecting, restricting, and sorting data.


- Perform calculations on data using various functions.

You might also like