Oracle SQL

Introduction

Welcome to our introductory Oracle SQL web page, designed to lay the groundwork for your journey into the realm of database management. Here, we provide a comprehensive overview of basic Oracle SQL concepts, equipping you with the fundamental knowledge needed to navigate and manipulate data effectively. From understanding essential syntax to executing simple queries, this page serves as your starting point in mastering Oracle SQL. With clear explanations and illustrative examples, we aim to demystify the complexities of database querying, empowering you to confidently interact with Oracle databases. Whether you're a beginner exploring the world of SQL for the first time or seeking a refresher on the basics, our page is here to support your learning endeavours. Let's embark on this enriching educational journey together and unlock the potential of Oracle SQL!

RDBMS Image
RDBMS
- RDBMS stands for Relational Database Management System.
- Edgar F. Codd introduced RDBMS in the year 1970.
- RDBMS is software used to manage databases.
- Manage stands for storing data, retrieving data, updating old data, and deleting unwanted data from the database.
- Using RDBMS software, we can perform CRUD operations on databases.
- To interact with RDBMS software, we use Structured Query Language (SQL).
Edgar F Codd Rules For RDBMS
- By using RDBMS software, we can store data in the form of rows and columns (Tables).
- Using RDBMS software with the help of SQL, we can create multiple tables in the database.
- We can retrieve data from multiple tables with the help of SQL using RDBMS software.
- We have to store data in the table like atomic values (Single values for cell).
- Using Metadata, we can store data details inside the table using RDBMS (Details for data).
SQL
- SQL stands for Structured Query Language.
- IBM researchers Raymond Boycee and Donald Chamberlin, they introduced SQL in the year of 1970.
- SQL it is a language which is used to communicate with database server with the help of RDBMS software.
- SQL it is also known as Sequel Query Language.
- SQL is not a case sensitive language but data present inside the table is case sensitive.
- In SQL each and every query must and should end with a semi colon(;).
DQL(DATA QUERY LANGUAGE)

DQL statements are used to retrieve data from the database.

DUAL TABLE

It is a dummy table and it consist of only one column and one record.

-->Syntax:-
      SELECT 'LITERAL' FROM DUAL;

  EXAMPLES:-
      SELECT 'Surya' FROM DUAL;

ALIASING

It is used to rename column name and table name for temporarily.

      For Column:-
                  SELECT COLUMN_NAME1 ALIASNAME1,
                  COLUMN_NAME2 ALIASNAME2
                  FROM TABLLE_NAME;

      For Table:-
                  SELECT * FROM TABLE_NAME ALIASNAME;

DATA Integrity

It is used to restrict invalid data to enter into the table is known as "DATA Integrity".

-->Types of DATA Integrity

      1. DATA TYPES

      2. CONSTRAINTS / ATTRIBUTES

DATA TYPES

It is used to specify which type of data to be stored in particular column is known as Data type.

CONSTRAINTS

It is used to give additional condition to the column to store the data.

DDL(DATA DEFINITION LANGUAGE)

All the Data Definition Language statements are used to create the structure of the table and it is used to modify the structure of the table.
- All the Data Definition Language statements are permanent changes.

DML(DATA MANUPLATION LANGUAGE)

- All Data Manipulation Statements are used to manage the database.
- Manage stands for storing data, retrieving data, updating data, deleting data.

TCL(TRANSCATION CONTROL LANGUAGE)

- All data manuplation language statements are temporary changes to make them permanent changes we have to use TCL.

DCL(DATA CONTROL LANGUAGE)

- DCL stands for Data Control Language. It comprises a set of commands used to control access to data stored in the database.
- The primary focus of DCL is on permissions, security, and other related aspects of database management.

OPERATORS

- Operators are some special symbols and all are used to perform some operations on operand.

FUNCTIONS

Functions are important features of sql and all functions are used to perform some calculations on data.

1. SINGLE ROW FUNCTIONS (SCALAR)

- Single row function it will take multiple inputs from the user and it will execute multiple value outputs.
- Single row function we can use inside select statement and inside the where condition.
- We can use multiple single row functions inside the one select statement.
  • 1. UPPER()
  • 2. LOWER()
  • 3. INITCAP
  • 4. LENGTH
  • 5. CONCAT
  • 6. SUBSTR
  • 7. REPLACE
  • 8. INSTR
  • 9. CASE
  • 10. LPAD
  • 11. RPAD
  • 12. ASCII
  • 13. GREATER
  • 14. LEAST
2. MULTI ROW FUNCTIONS (AGGREGATE)

- Multi row function it will take multiple inputs from the user and it will execute single value output.
- Multi row functions it is also known as aggregate function.
- Combination of column of multi row function it is not possible, we will get single-group function error, to overcome from that error we have to go for "GROUP BY CONDITION".
- The multi row function can used inside the where condition, if there is an condition for multi row function we have to go for "HAVING CLAUSE".
- We can use multiple multi row function inside select statement.

  • 1. MAX()
  • 2. MIN()
  • 3. AVG()
  • 4. SUM()
  • 5. COUNT()
3. DATE FUNCTIONS

- Date functions are used to perform operations on date and time data types.
- These functions help in manipulating, formatting, and extracting specific components (such as year, month, day, hour, minute, second) from date values.
  • 1. SYSDATE
  • 2. SYSTIMESTAMP
  • 3. TO_CHAR
  • 4. TO_DATE
  • 5. LAST_DAY
  • 6. MONTHS_BETWEEN
4. NVL

- NVL is used to replace NULL values with a specified default value.
- It evaluates an expression and, if the expression is NULL, returns the specified default value otherwise, it returns the evaluated expression.
- NVL is particularly useful when dealing with NULL values in queries or calculations, allowing you to handle such cases gracefully.

SYNTAX:
SELECT NVL (COLUMN_NAME, VALUE_TO_REPLACE_NULL_VALUE) FROM TABLE_NAME;
Sub Query image
SUB QUERY

- Wherever we are having indirect condition we have to go for SUB QUERY(Unknown condition).
- Query inside another query is know as subquery.
- To join inner query and outer query we have to use operators based on the condition.
- In sub query first the inner query will get executed and we will get one output from inner query, that output will become input to the outer query and we will get final output from outer query.
- *** In Sub query whatever column we are using inside the where condition for outer the same column we have to use inside the select statement for inner query.
- If we have indirect condition on multiple table we have to use sub query.
-*** We cant display multiple tables data as an output using sub query.
- In sub query inner query is independent and outer is dependent on output of the inner query.

JOINS

- Joining or merging two or more tables and retrieve data from tables is known as Joins.
- To perform joins on multiple tables Common Columns are mandatory.

NORMALIZATION

- The process of organizing the data in data base is known as NORMALIZATION.
- The process of decomposing large amount of data into small amount data is known as NORMALIZATION.
- Normalization it is used to reduce Data Redundancy.

DATA REDUNDANCY:-

- Similar type if data present in a table multiple times is known as Data Redundancy.
- Using Normalization we can convert inconsistent data into consistent data.
- Inconsistent means Anomalies(Errors).

TYPES OF ANOMALIES:-

1. Inserting Anomaly
2. Updating Anomaly
3. Deleting Anomaly

- To overcome from these anomalies we have to go for normalization forms.
- Normalization forms are introduced by Edgar F. Codd in the year 1970.

TYPES OF NORMALIZATION FORMS:-

- 1NF
- 2NF
- 3NF
- 3.5NF (BCNF)
- 4NF
- 5NF