Unit - Ii RDBMS
Unit - Ii RDBMS
ORACLE 9i
Introducing Oracle9i
Oracle9i takes business where it needs to be: meeting and exceeding stringent
demands for high-quality service in a service-driven marketplace. Oracle9i is designed to
optimize traditional, internet and intranet applications, and to stimulate the emerging hosted
application market on the internet.
Oracle9i builds on historic strengths to offer the first complete and simple software
infrastructure for the internet's next generation of intelligent, collaborative applications. The
Oracle9i new features expedite delivery of critical performance, scalability, and availability
essential to providing hosted service software for anyone, anywhere, anytime.
1
PERSONAL DATA BASE:
Oracle9i Database
The Oracle9i Database introduces the following advanced and automated design features that
refine Oracle9i Application Server and Oracle9i Developer Suite to optimize performance for
traditional applications and the emerging hosted application market.
Replacing Oracle Parallel Server, Oracle9i Real Application Clusters provides out-of-the-
box, linear scaling transparency, compatibility with all applications without redesign, and the
ability to rapidly add nodes and disks.
Systems Management
Integrated system management products create a complete view of all critical components
that drive e-business processes. From the client and application server to the database and
host, Oracle9i quickly and completely assesses the overall health of an e-business
infrastructure.
High Availability
Setting a new standard for high availability, Oracle9i introduces powerful new functionality
in areas of disaster recovery, system fault recovery, and planned downtime.
High Security
Oracle9i offers the most secure internet platform for protecting company information through
multiple layers of security for data, users, and companies. Included are features for building
internet-scale applications, for providing security for users, and for keeping data from
different hosted user communities separate.
2
Client/Server Database
Oracle 9i is a client/server database management system based on the relational data model.
It handles failures well through transaction logging and allows administrators to manage
users and databases through administrative tools.
A Database Management System (DBMS) lies at the center of most Client/Server systems in
use today.
– Process client data requests at the local server. – Send only the SQL result to the clients
over the network.
In a centralized architecture, all data and processing are handled by a single central
server. This server is responsible for storing, retrieving, and updating data, as well as
executing application programs and user interfaces. Users access the system through
terminals or workstations that connect to the central server. This architecture is also known as
a monolithic architecture1.
Advantages
Simplicity: With only one server to manage, the system is easier to maintain and
administer.
Consistency: All clients access the same data, ensuring data consistency and integrity.
Disadvantages
Scalability Issues: As the number of clients or the amount of data increases, the central
server can become a bottleneck.
Single Point of Failure: If the central server goes down, all clients lose access to the data
3
What is SQL*Plus?
SQL*Plus is an interactive and batch query tool that is installed with every Oracle
Server or Client installation. It has a command-line user interface, and more recently, a web-
based user interface called iSQL*Plus.
On Windows platforms, context menu options accessed through the right mouse
button enable local files to be sent to the iSQL*Plus user interface.
SQL*Plus has its own commands and environment, and it provides access to the Oracle
RDBMS. It allows you to enter and execute SQL, PL/SQL, SQL*Plus and operating system
commands to perform the following:
enter, edit, store, retrieve, and run SQL commands and PL/SQL blocks
format, perform calculations on, store, and print from query results
connect to a database
define variables
capture errors
4
1. Create database objects such as tables, indexes, and constraints
2. Create users and roles
3. Grant or revoke privileges of users and roles
4. Edit and execute queries
5. Adjust output settings to produce simple reports
6. Edit and execute PL/SQL blocks
7. Insert, update, and delete data in tables
8. Spool output to a file
9. Read and write files containing SQL or PL/SQL scripts
SQL*Plus Commands
It is a command-line tool for Oracle Database that allows users to interact with the database
using SQL and PL/SQL commands. Here are some essential SQL*Plus commands:
Connecting to a Database
Selecting Data
Describing a Table
To set the maximum line width for query output, use the SET LINESIZE command.
SET LINESIZE n;
5
Setting Page Size
To set the number of lines per page for query output, use the SET PAGESIZE command.
SET PAGESIZE n;
Editing Commands
To open the default text editor to edit the current command buffer, use the EDIT command.
EDIT;
Exiting SQL*Plus
To disconnect from the database and exit SQL*Plus, use the QUIT or EXIT command.
QUIT;
-- or
EXIT;
An alternative way to edit the SQL*Plus buffer is to use the text editor within your
operating system. The exact editor used depends on which operating system you are using.
For example, if you are using Windows, the editor invoked is Microsoft Notepad or
download Notepad++.
6
In Oracle SQLPlus, the default text editor is typically set to a basic editor like
Notepad on Windows or vi on Unix/Linux systems. However, you can configure alternate
text editors to suit your preferences. Here's how you can define alternate text editors in
SQLPlus:
You can set your preferred editor by using the DEFINE_EDITOR command in SQL*Plus. For
example:
Replace 'notepad' with the name of your preferred editor, such as 'vim', 'nano', or 'gedit'.
On Windows:
o Open the sqlplus command prompt.
The SQLPlus Worksheet in Oracle SQL Developer is a powerful tool that allows users to
execute SQL and SQLPlus commands for querying, managing, and interacting with Oracle
databases. It supports a wide range of commands and functionalities, making it a versatile
environment for database operations.
The SQL Worksheet supports most SQL*Plus commands, except those related to formatting.
Commonly used commands include:
-- Execute a SQL script
@[Link]
DESC employees;
-- Define a variable
7
-- Execute a PL/SQL block
SHOW ALL;
DISCONNECT;
EXIT;
These commands allow users to perform tasks such as defining variables, executing scripts, and managing
database connections.
Data Definition Language (DDL) in Oracle is used to define and manage database structures
like tables, views, and indexes.
Common DDL commands include CREATE, ALTER, DROP, TRUNCATE, and RENAME.
1. CREATE Command
8
2. ALTER Command
3. DROP Command
4. TRUNCATE Command
The TRUNCATE command removes all rows from a table but retains its structure.
TRUNCATE TABLE employees;
This clears all data from the employees table without generating rollback data.
5. RENAME Command
Key Considerations
Underscores separate the distinct terms that define the Table or Column as per the
standard conventions.
Table names must start with the application name. For example, FSI_, REV_, and so on. All
table names must be in plural form. · Table names must have indicators of the functional
area.
9
Here are some key recommendations based on "Oracle PL/SQL Coding Standards" and Best
Practices: Use meaningful, descriptive names that clearly indicate the purpose of the
variable. Avoid reserved words and special characters. Use underscores (_) to separate words
for readability.
DATA TYPES:
In SQL*Plus, which is an Oracle command-line tool, data types are used to define the kind of
data that can be stored in a table's columns. Here’s a concise explanation of the commonly
used SQL data types:
CHAR(size): Fixed-length character data. The size specifies the number of characters
(default is 1, max is 2000).
VARCHAR2(size): Variable-length character data. The size specifies the maximum number
of characters (up to 4000).
INTERVAL DAY TO SECOND: Stores a time interval in days, hours, minutes, seconds,
and fractional seconds.
BLOB: Binary Large Object, used for storing binary data (e.g., images, videos, etc.).
10
5. Other Data Types
RAW(size): Stores binary data in hexadecimal format (max size: 2000 bytes).
LONG: Stores variable-length character data (up to 2GB, but deprecated in favor of CLOB).
CONSTRAINTS:
SQL*Plus, constraints are rules enforced on data in a table to ensure its integrity and
validity. They help maintain accuracy and consistency in the database. Below are the types of
constraints and their definitions:
1. NOT NULL
Example:
2. UNIQUE
Example:
3. PRIMARY KEY
Combines NOT NULL and UNIQUE. It uniquely identifies each record in a table.
Example:
11
4. FOREIGN KEY
Establishes a relationship between two tables by linking a column in one table to the primary
key in another.
Example:
5. CHECK
Example:
6. DEFAULT
Example:
In SQL*Plus, you use the CREATE TABLE statement. Below is an example of how to
define a table:
5. hire_date DATE NOT NULL: Stores date values and ensures it cannot be null.
6. job_id VARCHAR2(10) NOT NULL: Stores job IDs with a maximum length of 10
characters.
7. salary NUMBER(8, 2): Stores salary values with up to 8 digits, including 2 decimal
places.
ALTER TABLE
The ALTER TABLE statement in SQL is used to add, delete, or modify columns in an
existing table. It can also be used to add and drop various constraints on an existing table.
Adding a Column
13
Example:
ALTER TABLE Customers
Modifying a Column
To change the data type of a column in a table, use the following syntax:
ALTER TABLE table_name
Example:
ALTER TABLE Persons
Dropping a Column
Definition: Permanently deletes a table and all its data from the database.
Syntax:
o Cannot be undone.
2. Renaming a Table
Syntax:
RENAME old_table_name TO new_table_name;
14
Key Points:
o Only the table name changes; data and structure remain intact.
3. Truncating a Table
Definition: Removes all rows from a table but retains the table structure for future
use.
Syntax:
TABLE TYPES
1. Permanent Tables
2. Temporary Tables
Data is automatically deleted when the session ends or the transaction is committed/rolled
back.
Two types:
15
3. External Tables
Allow access to data stored outside the database (e.g., in flat files).
Data is not stored in the database but can be queried as if it were in a table.
Example:
Example:
Copy the codeCREATE TABLE iot_table (id NUMBER PRIMARY KEY, name VARCHAR2(50))
ORGANIZATION INDEX;
5. Partitioned Tables
Example:
6. Clustered Tables
Tables that share the same data blocks because they are frequently joined.
Example:
16
SPOOLING
In SQL*Plus, spooling refers to the process of directing the output of SQL queries or
commands to a file, rather than displaying it on the screen. This is particularly useful for
saving query results, logs, or reports for later use or sharing.
2. Syntax:
o To start spooling:
o SPOOL file_name
This creates a file (e.g., file_name.lst or file_name.txt) and writes the output to it.
o To stop spooling:
o SPOOL OFF
3. Example:
4. SPOOL [Link];
5. SELECT * FROM employees;
6. SPOOL OFF;
o This saves the query result of SELECT * FROM employees into a file named [Link].
7. File Location: By default, the file is created in the current working directory unless a
full path is specified.
8. Use Cases:
o Generating reports.
ERROR CODES
In SQLPlus, error codes are typically associated with Oracle Database errors. These error
codes are numeric identifiers that help diagnose and resolve issues encountered during SQL
execution. Below is an overview of how error codes are structured and used in SQLPlus:
17
1. Structure of Oracle Error Codes
Oracle error codes are prefixed with ORA-, followed by a five-digit number.
Check the Error Message: SQL*Plus provides a detailed error message along with the code.
Use this to understand the issue.
Use SHOW ERRORS Command: If you're working with PL/SQL blocks, use SHOW
ERRORS to view compilation errors.
This error indicates that the table non_existent_table is not found in the database.
18