You are on page 1of 23

Thursday, December 7, 2023 11:17 AM

Akhil (Admin)
Notes Link:
Mobile: 91541 56192 (Whatsapp Only)
https://bit.ly/oracledbnotes

ORACLE installation video link:


https://bit.ly/orainstall

Oracle (SQL & PL/SQL) @ 7:30 PM (IST) By Mr.Shiva Chaitanya


Day-1 https://youtu.be/t4lWbH5iOkk
Day-2 https://youtu.be/7Ox_e71XyXc

ORACLE 730PM Page 1


Wednesday, December 6, 2023 7:50 PM

GOAL: storing business data


BANK

Branches Before 1960s => BOOK


CUSTOMERS In 1960s => File
TRANSACTIONS In 1970s => Database
PRODUCTS
STAFF

Bank DB
Customer
CID CNAME AADHAR PAN MOBILE

Transactions
Tid T_date_time tType amount Acno

Staff
Empno Ename Sal Job

Google Chrome to visit websites


Mozilla Firefox
opera
ORACLE 730PM Page 2
opera

ORACLE to create & maintain the database


SQL SERVER
DB2
MY SQL

ORACLE 730PM Page 3


ORACLE
Wednesday, December 6, 2023 7:47 PM

Data Store => location


Database => data store[location] => business data stored here
DBMS => software => used to create & maintain the DB
RDBMS => software => used to create & maintain the DB in the form of tables
Metadata => data about the data

Data Store:
• the location where data is stored is called
"Data Store".

Data Stores are:


○ File
○ Database => to store business data it is suitable => best way

File:
• is a kind of data store.
• It is suitable for single user only.
• It is suitable to store small amounts of data.
• No Security.

Database:
• is a kind of data store.
• It is suitable for multiple users
• It is suitable to store large amounts of data.
• Security will be there.

• Database is a location. In that complete details of


organization stored permanently in computer hard
disk.

• Database is a collection of interrelated data in an


organized form.

BANK DB COLLEGE DB

ORACLE 730PM Page 4


BANK DB COLLEGE DB

Branches Courses
Customers Students
Transactions Marks
Products Fee
Staff Staff

DBMS:
• DBMS => DataBase Management System / Software.

• DBMS is a software that is used to create and maintain the


database.

Evolution of DBMS:

Before 1960s BOOKS


In 1960s FMS [File management system]
In 1970s Hierarchical DBMS
Network DBMS
In 1976 Relational DBMS Concept => E.F.Codd
LARRY ELLISON => ORACLE founder

1977 => Software Development Laboratories


1979 => Relational Software Inc. => introduced ORACLE software
1983 => ORACLE corporation

RDBMS:
• It is a kind of DBMS.

• RDBMS => relational database management software

• Relation => Table

• RDBMS is a software that is used to create and maintain the


database in the form of tables.
ORACLE 730PM Page 5
database in the form of tables.

• Examples:
ORACLE, SQL SERVER, DB2, MY SQL, Postgre SQL

TABLE:

EMPLOYEE => table / relation / entity


EMPNO ENAME SAL
1001 AAA 6000 ROW / RECORD / ENTITY INSTANCE /
1002 BB 8000 TUPLE

COLUMN / FIELD / PROPERTY /


3 columns
ATTRIBUTE
2 rows

Table is a collection of rows and columns


Column / Field vertical representation of data
holds individual values
Row / Record horizontal representation of data
is a collection of field values

Metadata:
• Metadata can be also called "Data Definition".
• Metadata is the data about the data.

Examples:
Field Name => empno, ename, sal
Table Name => EMPLOYEE
Data type => NUMBER
Field Size => VARCHAR2(10) => 10 is field size

EMPLOYEE

EMPNO NUMBER(4) ENAME VARCHAR2(10) SAL


ORACLE 730PM Page 6
EMPNO NUMBER(4) ENAME VARCHAR2(10) SAL
1000 RAJU 8000
1001 KIRAN 6000

DATA STORE location data is stored


DATABASE DATA STORE organization's business data
[location] stored permanently
DBMS Software used to create & maintain the
database
RDBMS Software used to create & maintain the
database in the form of tables
METADATA Data Definition data about the data

ORACLE 730PM Page 7


ORACLE
Thursday, December 7, 2023 7:48 PM

ORACLE:
• ORACLE is a Relational DataBase management
Software [RDBMS].
• Relation => table

• ORACLE software is used to create & maintain the


database in the form of tables.

• ORACLE software allows us to store, manipulate and


retrieve the data of database.

Manipulate => 3 actions [INSERT / UPDATE / DELETE]

emp joined => INSERT


emp promoted => UPDATE [modify]
emp resigned => DELETE

Retrieve => opening existing data

Check balance
Transaction Statement
Online shopping => searching for products
Founder of ORACLE => Larry Ellison

• ORACLE software is the product of ORACLE company.


1977 Software Development Laboratories

• ORACLE software 2nd version released in 1979. 1979 Relational Software Inc. => ORACLE s/w introduced
They didn't release 1st version. 1983 ORACLE

• Latest Version:
For Windows OS ORACLE 21C
For LINUX OS ORACLE 23C

ORACLE => RDBMS


DATABASE
SQL TABLES
PL/SQL ROWS & COLUMNS

To communicate with ORACLE DATABASE we use 2 Languages.


They are:
• SQL => queries
• PL/SQL => programs

SQL: C, Java, C#, Python


• SQL => Structured Query Language
Software
• SQL is a Query Language. In this we write queries. Programs
We write queries to communicate with ORACLE DB

• Query => request / instruction / command


In C:
Function [sub program]:
• Query is a request that is sent to DB Server.
is a set of statements

• SQL is Non-Procedural Language. We will not write any


In Java:
set of statements or programs. Just we write Queries.
Method [sub program]:
is a set of statements
• SQL is Unified language. It is common language to
communicate with many relational databases.
In PL/SQL:

ORACLE 730PM Page 8


In Java:
set of statements or programs. Just we write Queries.
Method [sub program]:
is a set of statements
• SQL is Unified language. It is common language to
communicate with many relational databases.
In PL/SQL:
Procedure [sub program]:
• SQL provides commands to write the queries.
is a set of statements

PL/SQL:
• PL => Procedural Language
• SQL => Structured Query Language

• PL/SQL is a Programming Language. In this we develop


the programs to communicate with ORACLE DATABASE.

• PL/SQL is procedural language.

• PL/SQL = SQL + Programming.

• PL/SQL is extension of SQL.

• All SQL Commands can be written as statements in


PL/SQL program.

ORACLE 730PM Page 9


Thursday, December 7, 2023 8:55 PM

ORACLE SQL SERVER MY SQL


DATABASE DATABASE DATABASE
TABLES TABLES TABLES

SQL SQL SQL

ORACLE 730PM Page 10


ORACLE
Friday, December 8, 2023 7:41 PM

SYLLABUS

SQL

SQL Commands 5 sub languages


DDL
DRL
TCL
DML
DCL

Built-In Functions String Functions


date Functions
Conversion Functions
Aggregate Functions
Analytic Functions
Number Functions
Other Functions

CLAUSES SELECT
FROM
WHERE
ORDER BY
DISTINCT
GROUP BY
HAVING
OFFSET
FETCH

Joins Inner Joins


Equi
ORACLE 730PM Page 11
Equi
Non-Equi
Outer joins
Left outer
Right outer
Full outer
Self join
Cross Join

Sub Queries Non-Correlated sub queries


Single row
Multi row
Scalar
Inline view
Correlated Sub Queries

Constraints PRIMARY KEY


NOT NULL
UNIQUE
CHECK
DEFAULT
REFERENCES [FOREIGN KEY]

SET OPERATORS UNION


UNION ALL
INTERSECT
MINUS
VIEWS

INDEXES

SEQUENCES
SYNONYMS

ORACLE 730PM Page 12


SYNONYMS
M.VIEWS

PL/SQL
PL/SQL Basics Data Types
Declare
Assign
Print
Read
Using SQL commands in PL/SQL

Control Structures
Cursors
Collections
Exception Handling
STORED PROCEDURES
STORED FUNCTIONS
PACKAGES
TRIGGERS
Working with LOBs
Dynamic SQL

ORACLE 730PM Page 13


SQL Commands
Friday, December 8, 2023 7:59 PM

SQL Sub Languages:

SQL provides 5 sub languages. They are:

DDL: CREATE
• Data Definition Language
• Data Definition => Metadata ALTER
• It deals with metadata
DROP
FLASHBACK [ORACLE 10g]
PURGE [ORACLE 10g]

TRUNCATE
RENAME

DRL / DQL: SELECT


• Data Retrieval Language
• Data Query Language

• Retrieve => opening existing data


• Query => request that is sent to DB Server

• it deals with data retrievals

TCL: COMMIT
• Transaction Control Language ROLLBACK
SAVEPOINT
• It deals with transactions

DML: INSERT
• Data manipulation Language UPDATE
DELETE
• Manipulate => 3 actions
INSERT / UPDATE / DELETE INSERT ALL [ORACLE 9i]
MERGE [ORACLE 9i]
It deals with data manipulations

DCL / ACL: GRANT


• Data Control Language REVOKE
• Accessing Control Language

It deals with data accessibility

ORACLE 730PM Page 14


• It deals with data accessibility

ORACLE => RDBMS


DATABASE
TABLES DB Objects:

Table
CREATE View
Index
Sequence
Synonym
Materialized View
PROCEDURE
FUNCTION
TRIGGER
PACKAGE
CREATE

EMPLOYEE
EMPNO NUMBER(4) ENAME VARCHAR2(10) SAL MAIL_ID MOBILE

ename => 15 chars

ALTER => Change


• Add the columns
• rename the columns
• drop the columns
• change field size
• change the data type

ORACLE 10g version => RECYCLEBIN


DROP
FLASHBACK
PURGE

RECYCLEBIN
DROP => employee
employee
ORACLE 730PM Page 15
RECYCLEBIN
DROP => employee
employee

FLASHBACK => restore

delete => PURGE

TRUNCATE

EMPLOYEE TABLE
EMPNO ENAME SAL STRUCTURE
1001 ..
1002 .. +
..
DATA
1100

DRL => SELECT

EMP
DML => EMPNO ENAME JOB SAL
1001 AA CLERK 5000
INSERT 1002 BB MANAGER 8000
UPDATE
1003 CC SALESMAN 7000
DELETE

TCL INSERT => 1008 => RAM

Commit COMMIT;
Rollback
Savepoint

ORACLE 730PM Page 16


DCL:

GRANT USER: userA


TABLE EMP
REVOKE
GRANT
REVOKE

USER: userB

ORACLE 730PM Page 17


DDL Commands
Saturday, December 9, 2023 7:44 PM

DDL:
• Data Definition Language
• Data Definition => Metadata
• It mainly deals with metadata

ORACLE SQL provides following DDL commands:


CREATE
ALTER
DROP
FLASHBACK [ORACLE 10g]
PURGE [ORACLE 10g]
TRUNCATE
RENAME

CREATE:
• It is used to create the tables.
<> Any
Syntax to create the table: [ ] Optional

CREATE TABLE <table_name>


(
<field_name> <data_type> [,
<field_name> <data_type>,
.
.]
);

For windows OS, latest version is: ORACLE 21C


For LINUX OS, latest version is ORACLE 23C

Till ORACLE 21C We can create max of 1000 columns


ORACLE 730PM Page 18
Till ORACLE 21C We can create max of 1000 columns
From ORACLE 23C onwards We can create max of 4000+ columns

Data Types in ORACLE SQL:

Data Type:

Data Type tells,


• How much memory has to be allocated.
• Which type of data should be accepted.

ORACLE SQL provides following data types:

Integer related NUMBER(p)


Int
1234 Integer
78
23
789
Floating Point Related NUMBER(p,s)
Float
67.89 Binary_Float
123.4 Binary_Double
5.3
6000.00
5000.85
Character related Char(n)
Varchar2(n)
'RAJU' LONG
'INDIA' CLOB

nChar(n)
nVarchar2(n)
nCLOB

ORACLE 730PM Page 19


Date & Time related Date
Timestamp [ORACLE 9i]
23-NOV-22
9-DEC-23 8:20:15:123456 PM

Binary related BFILE


BLOB
images
audios
videos
animations

NUMBER(p):
• p => precision => max no of digits.

• It is used to hold integers.

• p valid range: 1 to 38

• max size: 21 Bytes

Examples:

empid NUMBER(4) Range: -9999 TO 9999


--------------
1234
1235
1236

ORACLE 730PM Page 20


1236
25
456
7896
9999
10000 => ERROR

Max Marks: 100

Sub1_Marks NUMBER(3)
Range: -999 TO 999
--------------------
67
89
100
123
999
1000 => ERROR

Mobile_Number NUMBER(10)

Aadhar_Number NUMBER(12)

Credit_Card_number NUMBER(16)

AGE NUMBER(2) -99 TO 99


--------
17
20
23
25
24
18
ORACLE 730PM Page 21
18
99
100 => ERROR

Floating point related data types:

NUMBER(p,s):

• p => precision
• s => scale

• it is used to hold floating point values

• max size: 21 Bytes


Max marks: 100
3 subjects
Examples:
300/3 = 100

Avrg NUMBER(5,2) -999.99 TO 999.99


100.00
-----------
56.78
123.45
999.99
p=5 s=2
1000 => ERROR
123.456789234 => 123.46
123.453789234 => 123.45

SALARY NUMBER(8,2) -999999.99 TO 999999.99


100000.00
-----------
p=8
20000
200000
100000.00
999999.99
ORACLE 730PM Page 22
20000
200000
100000.00
999999.99
s=2
1000000 => ERROR

height NUMBER(2,1) -9.9 TO 9.9


---------- 5.2
5.6 5.0
8.9 5.4
9.9
10.0 => ERROR
5.123456 => 5.1
5.178934 => 5.2

ORACLE 730PM Page 23

You might also like