Chetan SQL Learns
Chetan SQL Learns
as one Session.
Instance: All users interact with Instance to retrieve or store
information.
Database: Is like the notebook where Oracle Instance writes the
information and is encrypted.
PL/SQL is the
superset of SQL i.e. we use PL/SQL instead of SQL when our
target/goal requires multiple SQL commands to be executed
based on certain logic, event or condition then we take the
benefit of this language
Self Join
A self join is a join of a table to itself.
Cartesian Product
If in the Join statement you forget to put the WHERE condition
or intentionally don’t write the WHERE clause at all, the result
will be Cartesian product. Such type of output will be very rarel
useful. If one table had five records and other one had six
records; in the output you will get thirty records (5x6=30).
That’s why we use the word product with such type of join.
Constraints also known as Data Integrity Constraints
Comparison Conditions
Operator Meaning
Logical Conditions
NOT
Returns TRUE if the following condition is
false
OR
Returns TRUE if either component condition
is true
AND
Returns TRUE if both component conditions
are true
Character-Manipulation Functions
These functions manipulate character
strings:
REPLACE BLACK and BLUE
('JACK and JUE','J','BL')
LENGTH('HelloWorld') 10
INSTR('HelloWorld', 'W') 6
LPAD(salary,10,'*') *****24000
RPAD(salary, 10, '*') 24000*****
CONCAT('Hello', 'World') HelloWorld
TRIM('H' FROM 'HelloWorld') elloWorld
SUBSTR('HelloWorld',1,5) Hello
Function Result
Pageno 107
NVL Function
Converts a null value to an actual value:
Types of Group Functions
• AVG
• COUNT
• MAX
• MIN
• STDDEV
• SUM
• VARIANCE
Pageno 236
DELETE Statement
You can remove existing rows from a table
by using the
DELETE statement:
Specific rows are deleted if you specify the
WHERE clause
• All rows in the table are deleted if you omit
the WHERE
clause:
TRUNCATE Statement
• Removes all rows from a table, leaving the
table empty
and the table structure intact
• Is a data definition language (DDL)
statement rather than a
DML statement; cannot easily be undone
Database Objects
Table:- Basic unit of storage; composed of rows
Naming Rules
Table names and column names:
• Must begin with a letter
• Must be 1–30 characters long
• Must contain only A–Z, a–z, 0–9, _, $, and
#
• Must not duplicate the name of another
object owned by
the same user
• Must not be an Oracle server–reserved
word
Dropping a Table
• All data and structure in the table are
deleted.
• Any pending transactions are committed.
• All indexes are dropped.
• All constraints are dropped.
• You cannot roll back the DROP TABLE
statement.
Advantages of Views
To restrict data access
To make complex queries easy
To provide data independence
To provide data independence
Indexes
An index:
• Is a schema object
• Can be used by the Oracle server to
speed up the retrieval
of rows by using a pointer
• Can reduce disk I/O by using a rapid path
access method
to locate data quickly
• Is independent of the table that it indexes
• Is used and maintained automatically by
the Oracle server
Pageno 375
Cartesian Products
• A Cartesian product is formed when:
– A join condition is omitted
– A join condition is invalid
– All rows in the first table are joined to all rows
in the second
table
• To avoid a Cartesian product, always
include a valid join
condition in a WHERE clause.
Pageno – 52(2)
Cascading Constraints
• The CASCADE CONSTRAINTS clause is
used along with
the DROP COLUMN clause.
• The CASCADE CONSTRAINTS clause
drops all referential
integrity constraints that refer to the primary
and unique
keys defined on the dropped columns.
• The CASCADE CONSTRAINTS clause also
drops all
multicolumn constraints defined on the
dropped columns.
Pageno 44(2)
^Pageno 85(2) ^}