Oracle 715am
Oracle 715am
Data Store
Database
DBMS
RDBMS
Metadata
RUN or ANALYZE
BANK
Products
Places order RUN
Customers
Delivers products
Sellers
Orders
Wishlist
ANALYZE
. In 2023 ?
. In 2024 ?
GOAL:
Storing business data permanently.
Variable:
• Variable is used to store the data.
• Variable is temporary.
x
int x;
30
x=30;
Object:
• Object is used to store the data.
• Object is temporary.
e1
File • It is permanent
Database • It is permanent
[best way]
File Database
• It is suitable for single user. • It is suitable for multiple users
Data Store:
• Data Store is a location where data is available.
Database:
• Database is a kind of data store.
• Database is a location where organization's
business data stored permanently.
Examples:
COLLEGE DB BANK DB
COURSES BRANCHES
STUDENTS CUSTOMERS
MARKS TRANSACTIONS
FEE .
. .
.
BANK DB
TABLE Customers
TABLE Employee
Transactions Branches
TXNI T_DATE_TIM T_TYPE ACN IFSC_CODE CITY STATE COUNTRY
D E O
DBMS:
Evolution of DBMS:
RDBMS:
Examples:
ORACLE, SQL SERVER, DB2, Postgre SQL, MY SQL
7.20 to 8.50
ORACLE
SQL
Metadata PL/SQL
Database Data store => loc => org bus data stored permanently
Examples:
ORACLE, SQL SERVER, DB2, …..
TABLE:
• TABLE is a collection of rows and columns.
Example:
Table / Relation / Entity
EMPLOYEE
EMPID ENAME SAL Column / Field / Attribute / Property
1234 KIRAN 20000
1235 SAI 15000 Row / Record / Tuple / Entity Instance
Metadata:
• Metadata is the data about the data.
• It tells about the data.
• It can be also called as "Data Definition".
Examples:
Column name, Table name, data type, field size
EMPLOYEE
oracle 715am Page 7
EMPLOYEE
EMPID ENAME SAL
Number(4)
1234 KIRAN 20000
RAJU error
25-DEC-24 error
123
123456 ERROR
ORACLE
Module-2: PL/SQL
SQL DEVELOPER
ORACLE:
SQL:
Notes link:
bit.ly/oracledbnotes
BANK DB
Branches Table
IFSC_CODE CITY STATE
Customers
Custid Cname Aadhar PAN .. ..
Transactions
Txn_Id T_type T_date_time Acno Amount
Employees
Empid Ename Job Sal
.
.
DDL Create
Alter
• DDL => Data Definition Language
• Data Definition => Metadata Drop
Flashback [oracle 10g]
• It deals with metadata Purge [oracle 10g]
Truncate
Rename
DML Insert
Update
• Data Manipulation Language Delete
TCL Commit
Rollback
• Transaction Control Language Savepoint
CREATE:
ORACLE DB OBJECTS:
TABLES
VIEWS
INDEXES
SEQUENCES
MATERIALIZED VIEWS
SYNONYMS
PROCEDURES
FUNCTIONS
PACKAGES
TRIGGERS
Till ORACLE 21c A table can have max of 1000 columns only
In ORACLE 23ai A table can have max of 4096 columns
Examples:
1234, 78, 567, 17
Examples:
20000.00, 5000.80, 67.89
Examples:
17-FEB-24
6-MAR-25 10.30.15.123456 AM
Char(n):
• n => max num of chars
• It is used to hold strings.
• It is fixed length data type.
• It is used to hold fixed length chars.
• Extra memory will be filled with spaces.
• Default size: 1
• Max memory: 2000 Bytes [2000 chars]
Varchar2(n):
• n => max num of chars
• It is used to hold strings.
• It is variable length data type.
• It is used to hold variable length chars.
• Extra memory will be removed.
Default size: no default size
T1
F1 CHAR(10) F2 VARCHAR2(10)
10 RAJU6spaces RAJU 4
10 NARESH4spaces NARESH 6
Fixed Variable
length length
Examples:
LONG:
• It is used to hold large amounts of chars.
• It is variable length data type.
• It has some restrictions:
○ A table can have only 1 column as LONG type
○ We cannot use built-in functions on LONG type
• Max memory: 2 GB
CLOB:
• CLOB => Character Large Object.
• It is used to hold large amounts of chars.
• It is variable length data type.
• A table can have multiple columns as CLOB type.
• We can use built-in functions on CLOB type.
• Ma memory: 4 GB
Examples:
Feedback CLOB
Product_features CLOB
Experience_summary CLOB
n => national
In C:
char ch='A'; // 1Byte ASCII code char data type
In Java:
char ch='A'; // 2Bytes UNI code char data type
ASCII:
• It is a coding system.
• 256 chars coded.
• Ranges from 0 to 255.
• ASCII = English letters + digits + special chars
• 255 => 1111 1111 [1 Byte]
UNI:
It is a coding system.
oracle 715am Page 22
• It is a coding system.
• Extension of ASCII.
• 65536 chars coded.
• Ranges from 0 to 65535.
• UNI = ASCII + other language chars
• 65535 => 1111 1111 1111 1111 [2 Bytes]
EMP
Number(p):
Examples:
-9999 TO 9999
EMPID NUMBER(4) MOBILENUM NUMBER(10)
-------------
1001 AADHAR_NUMBER NUMBER(12)
1002
123 Credit_card_number NUMBER(16)
9999
10000 ERROR
-999 TO 999
Max marks: 100
oracle 715am Page 23
-999 TO 999
Max marks: 100
Maths_marks NUMBER(3)
----------------------
56
678
999
1000 ERROR
-99 TO 99
AGE NUMBER(2)
-------
17
21
20
19
31
99
100 ERROR
NOTE:
INTEGER = INT = NUMBER(38)
DESC t25
Output:
NAME TYPE
------------------------------------------
oracle 715am Page 24
------------------------------------------
F1 NUMBER(38)
F2 NUMBER(38)
F3 NUMBER(38)
NUMBER(p,s):
Examples:
-999999.99 TO -999999.99
-9.9 TO 9.9
Height NUMBER(2,1)
--------------
5.3
5.8
5.6
6.5
9.9
10 ERROR
Float 21 Bytes
Binary_float 4 Bytes
Binary_double 8 Bytes
Date:
• It is used to hold date values.
• Default date format: DD-MON-YY.
• Fixed length data type.
• Max memory: 7 Bytes.
• It can hold up to seconds only.
• It cannot hold fractional seconds.
• It does not display time by default.
• Default time: 12.00.00 AM
Examples:
Date_of_joining DATE
Ordered_date DATE
Delivered_date DATE
Timestamp:
• Introduced in oracle 9i.
• It is used to hold date and time values.
• Default timestamp format: DD-MON-YY HH.MI.SS.FFFFFF AM.
• Fixed length data type.
• Max memory: 11 Bytes.
• It can hold up to fractional seconds.
• It display time by default.
• Default time: 12.00.00.000000 AM
Examples:
Txn_date_time TIMESTAMP
Ordered_date_time TIMESTAMP
Delivered_date_time TIMESTAMP
Login_date_time TIMESTAMP
date
timestamp
7 bytes
11 bytes
EMPLOYEE
oracle 715am Page 27
EMPLOYEE
ATTENDANCE
EMPID LOG_IN_DATE_TIME
NUMBER(4) TIMESTAMp
1234 11-MAR-25 7.30.15.123456 AM
Instance DB
SQL PLUS / requests
Query processing emp
Runs services Cust
TOAD /
responses .
ORACLE:
• ORACLE is a Server side software.
• Using it, we can maintain the DB in the form of tables.
• It contains 2 memories:
○ INSTANCE [RAM]
○ DATABASE [HARD DISK]
DB SERVER = INSTANCE + DB
oracle 715am Page 29
DB SERVER = INSTANCE + DB
SQL PLUS:
NOTE:
When we install ORACLE software along with
ORACLE SQL PLUS software will be installed.
Creating User:
Syntax:
Example:
Login as DBA:
Username: system
Password: nareshit
[at the time of ORACLE installation you have given password]
Syntax:
CONN[ECT] <username>/<password>
Example:
Syntax:
DISC[ONNECT]
SQL> DISC
TO clear screen:
Syntax:
CL[EAR] SCR[EEN]
Example:
SQL> CL SCR
SQL Commands:
Truncate
Rename
Create:
• It is used to create the tables.
Syntax:
Insert:
• It is used to insert the records [rows].
• Using Insert command we can:
○ Insert single record
○ Insert limited column values
○ Insert multiple records using parameters
Syntax:
Example-1:
STUDENT
SID SNAME AVRG
1001 ABC 67.89
1002 XY 55.66
1002 XY 55.66
COMMIT;
--changes in instance will
Be moved to DB [save]
1003 AA
1004 89.23
COMMIT;
Parameter:
It is used to read the value
Syntax:
&<text>
/
Output:
Enter value for sid: 1006
Enter value for sname: C
Enter value for avrg: 66.55
/
Output:
Enter value for sid: 1007
Enter value for sname: D
Enter value for avrg: 92.13
NOTE:
/ R[UN] It runs recent command in memory [above command]
Example-2:
EMPLOYEE
EMPID ENAME STATE SAL DOJ
1234 KIRAN MH 20000.00 17-AUG-20
1235 SAI TG 18000.00 25-DEC-23
string
DOJ DATE
------------ Implicit conversion
17-AUG-20 date
NOTE:
Types of conversions:
2 types:
• Implicit Conversion
• Explicit Conversion
Implicit Conversion:
If conversion is done implicitly by ORACLE
Explicit Conversion:
If conversion is done using built-in function
DOJ DATE
To_date()
----------------
Explicit conversion
25-DEC-23 date
Sysdate:
• It is a built-in function.
• It returns current system date.
COMMIT;
Example-3:
ATTENDANCE
EMPID LOGIN_DATE_TIME
1234 13-MAR-25 10.30.0.0 AM
1235 13-MAR-25 2.20.0.0 PM
1236 Today's date current time
Implicit conversion
Login_date_time timestamp
---------------------------------------------
13-MAR-25 10.30.0.0 AM timestamp
COMMIT;
Systimestamp:
• It is a built-in function.
• It returns current system date and time
Syntax:
DESC[RIBE] <table_name>
Example:
DESC student
Output:
NAME TYPE
SID NUMBER(4)
SNAME VARCHAR2(10)
AVRG NUMBER(5,2)
User_tables:
• It is a system table / readymade table / built-in table.
• It maintains tables information.
DESC user_tables
Setting pagesize:
Syntax:
SET PAGES[IZE] <value>
Example:
SQL> SET PAGES 300
Syntax:
SET LINES[IZE] <value>
Example:
SQL> SET LINES 200
Column Alias:
It is used to change column heading in output.
Syntax:
<column> [AS] <column_alias>
Example:
DRL / DQL:
SELECT:
• SELECT command is used to retrieve the data
from table.
• Using SELECT command we can select:
○ All columns, all rows
○ All columns, specific rows
○ Specific columns, all rows
○ Specific columns, specific rows
Syntax:
SELECT <column_list>
FROM <table_name>
[WHERE <condition>];
SQL ENGLISH
QUERIES SENTENCES
CLAUSES WORDS
NOTE:
Till ORACLE 21c, FROM clause is mandatory.
In ORACLE 23ai, FROM clause is optional.
Example:
In ORACLE 21c SELECT 100+200; --error
Examples on SELECT:
* All columns
SELECT *
FROM student
WHERE sid=1002;
Operator:
Operator is a symbol that is used to perform operations like
arithmetic or logical operations.
Arithmetic + - * /
Special / IN NOT IN
Comparison BETWEEN AND NOT BETWEEN AND
LIKE NOT LIKE
IS NULL IS NOT NULL
ANY
ALL
EXISTS
Concatenation ||
Arithmetic operators:
+ - * /
Output:
ENAME SAL Annual Salary
Assignment:
STUDENT
SID SNAME M1 M2 M3
1001 A 50 80 70
1002 B 66 55 89
Syntax:
<column> <relational operator> <value>
NOTE:
SQL is not case sensitive language.
String comparison is case sensitive.
oracle 715am Page 51
String comparison is case sensitive.
1-JAN-1981
.
31-DEC-1981
1-JAN-1982
2-JAN-1982 > '31-DEC-1981'
.
.
ENAME HIREDATE
.
< '1-JAN-1981'
30-DEC-1980
31-DEC-1980
1-JAN-1981
.
.
31-DEC-1981
ENAME HIREDATE
Logical Operators:
AND:
It is used to perform logical AND operations.
Syntax:
<condition1> AND <condition2>
OR:
It is used to perform logical OR operations.
Syntax:
<condition1> OR <condition2>
Truth table:
C1 => condition1
C2 => condition2
C1 C2 C1 AND C2 C1 OR C2
T T T T
T F F T
F T F T
F F F F
Display the emp records who are working in deptno 20and 30:
ENAME SAL DEPTNO
SELECT *
FROM emp
WHERE empno=7499 AND empno=7698 AND empno=7788;
EMPNO
------------
7369
7499
7698
7900
Display the emp records whose salary is b/w 2000 and 3000
(or)
Display the emp records whose salaries are 2000 or more and
yhat should be 3000 or less:
ENAME SAL
1-JAN-1982
2-JAN-1982
.
31-DEC-1982
Display the managers and clerks whose salaries are more than 2500:
ENAME JOB SAL
SELECT *
FROM emp
WHERE NOT(job='MANAGER' OR job='CLERK');
DEPTNO
----------
20
30
IN:
Syntax:
<column> IN(<value_list>)
(or)
Display the emp records who are working in deptno 10 and 20:
ENAME SAL DEPTNO
Display the emp records who are not working in deptno 10 and 20:
ENAME SAL DEPTNO
BETWEEN AND:
Syntax:
<column> BETWEEN <lower> AND <upper>
(or)
Example:
TRANSACTIONS
Txn_Id T_date ACNO T_type Amount
123456 5-DEC-24 1234 D 50000
123457 5-DEC-24 1235 D 70000
123458 7-DEC-24 1234 W 20000
Display the emp records whose salary is less than 2000 or more
LIKE:
In windows OS,
In windows
NOTE:
oracle 715am Page 62
NOTE:
In ORACLE SQL
% Replaces 0 or any
_ Replaces 1 char