0% found this document useful (0 votes)
33 views

DAY-1 - Introduction To Oracle DB & Basic SQL

Uploaded by

vvivekg555
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

DAY-1 - Introduction To Oracle DB & Basic SQL

Uploaded by

vvivekg555
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Introduction to Oracle

DB & Basic SQL


DAY - 1
Course Agenda
• Relational Database Concept
• Relating Multiples tables
• Relational Database Properties
• Communicating With a RDBMS Using SQL
• Relational Database Management System
• SQL Statements
• About PL/SQL
Course Agenda
• PL/SQL Environment
• Benefits Of PL/SQL
• Basic SELECT Statement
• Writing SQL Statements
• Selecting All Columns
• Selecting Specific Columns
• Using Arithmetic Operators
• SQL *Plus Interaction
Course Agenda
• SQL Statements Versus SQL *Plus Commands
• Overview of SQL *Plus
• Logging in to SQL *Plus
• Displaying Table Structure
• SQL *Plus Editing Commands
• SQL *Plus File Commands
Relational Database Concept
In relational databases, each data item has a row of attributes, so the database displays a
fundamentally tabular organization. The table goes down a row of items (the records) and
across many columns of attributes or fields. The same data (along with new and different
attributes) can be organized into different tables.

Important columns in any relational database's tables will be a column whose entry (customer
ID, serial number) can uniquely identify any particular item or record (the primary key), and any
column(s) that link to other tables (the foreign key(s)). The size and complexity of relational
databases typically requires stored procedures to support the relationships and provide access
(interfaces) to external programs which, for example, "query" the relational database to
retrieve and present selected data.
Relational Database Concept
ORACLE

It is a very large and multi-user database management system. Oracle is a relational database
management system developed by 'Oracle Corporation'.
Oracle works to efficiently manage its resource, a database of information, among the multiple
clients requesting and sending data in the network.
It is an excellent database server choice for client/server computing. Oracle supports all major
operating systems for both clients and servers, including MSDOS, NetWare, UnixWare, OS/2
and most UNIX flavors.
Relational Database Properties
What is table?
The data in RDBMS is stored in database objects called tables. The table is a collection of
related data entries and it consists of columns and rows.
Remember, a table is the most common and simplest form of data storage in a relational
database.

What is field?
Every table is broken up into smaller entities called fields. The fields in the CUSTOMERS table
consist of ID, NAME, AGE, ADDRESS and SALARY.
A field is a column in a table that is designed to maintain specific information about every
record in the table.
Relational Database Properties
What is record or row?
A record, also called a row of data, is each individual entry that exists in a table. For example
there are 7 records in the above CUSTOMERS table.

What is column?
A column is a vertical entity in a table that contains all information associated with a specific
field in a table.
Relating Multiples tables
The SQL Joins clause is used to combine records from two or more tables in a database. A JOIN is
a means for combining fields from two tables by using values common to each.
Relating Multiples tables
Types of joins available in SQL:
INNER JOIN: returns rows when there is a match in both tables.
LEFT OUTER JOIN: returns all rows from the left table, even if there are no matches in the right table.
RIGHT OUTER JOIN: returns all rows from the right table, even if there are no matches in the left table.
FULL OUTER JOIN: returns rows when there is a match in one of the tables.
SELF JOIN: is used to join a table to itself as if the table were two tables, temporarily renaming at least
one table in the SQL statement.
CARTESIAN JOIN: returns the Cartesian product of the sets of records from the two or more joined
tables.
Communicating With a RDBMS
Using SQL
Relational Database Management
System
What is RDBMS?

RDBMS stands for Relational Database Management System. RDBMS is the basis for SQL, and
for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft
Access.
A relational database is a database that has a collection of tables of data items, all of which is
formally described and organized according to the relational model. Data in a single table
represents a relation, from which the name of the database type comes. In typical solutions,
tables may have additionally defined relationships with each other.
SQL Statements
SQL statements are generally considered to be either Data Manipulation Language (DML)
statements or Data Definition Language (DDL) statements.
Data manipulation language (DML)
SELECT
INSERT
UPDATE
DELETE
MERGE
SQL Statements
Data definition language (DDL)
CREATE
ALTER
DROP
RENAME
TRUNCATE
COMMENT
SQL Statements
Data control language (DCL)
GRANT
REVOKE

Transaction control
COMMIT
ROLLBACK
SAVEPOINT
About PL / SQL
PL/SQL (Procedural Language/Structured Query Language) is Oracle Corporation's procedural
language extension for SQL and the Oracle relational database. PL/SQL is available in Oracle
Database (since version 7).Oracle Corporation usually extends PL/SQL functionality with each
successive release of the Oracle Database.
PL/SQL includes procedural language elements such as conditions and loops. You can declare
constants and variables, procedures and functions, types and variables of those types, and
triggers. You can handle exceptions (runtime errors). Arrays are supported involving the use of
PL/SQL collections. Implementations from version 8 of Oracle Database onwards have included
features associated with object-orientation. You can create PL/SQL units—procedures,
functions, packages, types, and triggers —that are stored in the database for reuse by
applications that use any of the Oracle Database programmatic interfaces.
PL/SQL Environment
SQL*Plus is the most basic Oracle Database utility, with a basic command-line interface,
commonly used by users, administrators, and programmers.

Oracle SQL Developer is a free graphical tool for database development. With SQL Developer,
you can browse database objects, run SQL statements and SQL scripts, and edit and debug
PL/SQL statements. You can also run any number of provided reports, as well as create and
save your own. SQL Developer enhances productivity and simplifies your database
development tasks.SQL Developer can connect to any Oracle Database version 10g and later
and runs on Windows, Linux and Mac OSX.
Benefits Of PL/SQL
 Tight Integration with SQL
 High Performance
 High Productivity
 Portability
 Scalability
 Manageability
 Support for Object-Oriented Programming
 Support for Developing Web Applications
 Support for Developing Server Pages
Basic SELECT Statement
SQL SELECT statement is used to fetch the data from a database table which returns data in the
form of result table. These result tables are called result-sets.

Syntax of SELECT statement:

SELECT column1, column2, columnN FROM table_name;

Here, column1, column2...are the fields of a table whose values you want to fetch. If you want
to fetch all the fields available in the field, then you can use the following syntax:

SELECT * FROM table_name;


Writing SQL Statements
Consider the CUSTOMERS table having the following records:
Writing SQL Statements
Selecting All Columns
An example, which would all columns & rows of the customers available in CUSTOMERS table:
SQL> SELECT * FROM CUSTOMERS;
This would produce the following result:
Writing SQL Statements
Selecting Specific Columns
Example:
An example, which would fetch ID, Name and Salary columns of the customers available in
CUSTOMERS table:
SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS;
Operator in SQL
An operator is a reserved word or a character used primarily in an SQL statement's WHERE
clause to perform operation(s), such as comparisons and arithmetic operations.
Operators are used to specify conditions in an SQL statement and to serve as conjunctions for
multiple conditions in a statement.
 Arithmetic operators
 Comparison operators
 Logical operators
Arithmetic Operators
Arithmetic operators manipulate numeric operands
Comparison Operators
Comparison operators are used in conditions that compare one expression with another. The
result of a comparison can be TRUE, FALSE, or UNKNOWN.
Logical operators
Logical operators manipulate the results of conditions
SQL *Plus Interaction
SQL*Plus is a client terminal software allowing users to interact with Oracle server to
manipulate data and data structures. Users type in SQL statements in SQL*Plus that send
statements to Oracle server. Oracle server then validates and executes the statements on its
databases. The query results are returned to SQL*Plus and displayed to the user. Besides
sending SQL statements to the server, SQL*Plus also saves them into a local buffer and allow
users to view and change the statements.
SQL *Plus Commands
SQL*Plus is a command-line tool that provides access to the Oracle RDBMS. SQL*Plus enables
you to:

 Enter SQL*Plus commands to configure the SQL*Plus environment


 Startup and shutdown an Oracle database
 Connect to an Oracle database
 Enter and execute SQL commands and PL/SQL blocks
 Format and print query results
Overview of SQL *Plus
SQL*Plus is an interactive and batch query tool that is installed with every Oracle Database
Server or Client installation. It has a command-line user interface, a Windows Graphical User
Interface (GUI) and the iSQL*Plus web-based user interface.
SQL*Plus has its own commands and environment, and it provides access to the Oracle
Database. It enables you to enter and execute SQL, PL/SQL, SQL*Plus and operating system
commands to perform the following:
 Format, perform calculations on, store, and print from query results
 Examine table and object definitions
 Develop and run batch scripts
 Perform database administration
Logging in to SQL *Plus
When you start SQL*Plus, you need a username and password to login to an Oracle Database
schema. Your username and password identify you as an authorized user of the Oracle
Database schema.
The database administrator (DBA) is responsible for creating your database account with the
necessary privileges and giving you the username and password that enables you to access
your account.
Default logins are created and you are prompted for associated passwords during Oracle
Database installation. Some of the default login usernames created are:
 SYS
 SYSTEM
 HR
Logging in to SQL *Plus
you can connect under a different username using the CONNECT command. The username and
password must be valid for the database.
CONNECT TODD;

CONNECT TODD@database_alias
Displaying Table Structure
Describe command
Syntax
DESCRIBE { table-Name | view-Name }
Description
Provides a description of the specified table or view. For a list of tables in the current schema,
use the Show Tables command. For a list of views in the current schema, use the Show Views
command. For a list of available schemas, use the Show Schemas command.
If the table or view is in a particular schema, qualify it with the schema name. If the table or
view name is case-sensitive, enclose it in single quotes. You can display all the columns from all
the tables and views in a single schema in a single display by using the wildcard character '*'.
Displaying Table Structure
Examples
To describe the view EMP_DETAILS_VIEW, enter
DESCRIBE EMP_DETAILS_VIEW
SQL *Plus Editing Commands
Recall that the previously executed commands (in current SQL*Plus session) are stored in the local buffer. One
way to change an SQL statement in the buffer is by using the line editor. The following are a list of line edit
commands.
 LIST or L--Lists the contents of the buffer
 LIST n or L n--Lists the contents of line number n in the buffer and makes the line current
 LIST * or L *--Lists the current line
 LIST m n--Lists the range from m to n line
 Append text or A text--Adds to the end of the current line (e.g., "A ," adds a comma to the end of line
 INPUT or I--Adds one or more lines after the current line so you can begin adding the text.
 CHANGE /text--Deletes text from the current line
 CHANGE /oldtext/newtext--Replaces oldtext with newtext in the current line
 DEL -- Deletes the current line
SQL *Plus File Commands
SQL*Plus file command allow you to execute commands (or programs) stored in an external
file, input or output data from/to a file, and save SQL commands typed during current session.
Some SQL*Plus file commands are:
 SAVE filename. This allows you to save buffer contents into a file.
 START filename. This allows you to execute a batch of SQL statements stored in a file.
 SPOOL filename. This allows you save SQL statements together with their outputs to a file.
 GET filename. This retrieve a file and places it into the buffer.
 @ filename. This allows you to execute a PL/SQL procedure(s) stored in a file.
Practice session
1. Connect schema HR through SQL Plus
2. Connect Schema HR Using SQL Developer
3. Describe the Table EMPLOYESS
4. Retrieve all rows from the Table DEPARTMENTS
5. Retrieve First_Name,Salary from the Table EMPLOYEES
Thank You

You might also like