0% found this document useful (0 votes)
4 views15 pages

Bca 501

The document provides an overview of Oracle Database, its tools, and key concepts such as database types, primary keys, index creation, views, SQL security management, and PL/SQL exception handling. It explains various Oracle database features, data types, and the importance of security management tools for data integrity and access control. Additionally, it includes examples of SQL commands for creating tables, indexes, and views, as well as discussing the differences between stored procedures and functions.

Uploaded by

Luv Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views15 pages

Bca 501

The document provides an overview of Oracle Database, its tools, and key concepts such as database types, primary keys, index creation, views, SQL security management, and PL/SQL exception handling. It explains various Oracle database features, data types, and the importance of security management tools for data integrity and access control. Additionally, it includes examples of SQL commands for creating tables, indexes, and views, as well as discussing the differences between stored procedures and functions.

Uploaded by

Luv Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

BCA (501) 2019-22

1. What is database? Explain Oracle and its tools.


2. Explain database types of oracle and also explain each data type length.
3. Define primary key. How primary key creation is implemented with table? Explain with example (I)
Need of join operation, (ii) Oracle data conversion function.
4. Explain Index creation implementation in oracle database. (b) How can the automatic data
generation be applied in database fields? Give syntax.
5. Explain the concept of view. Explain creating and destroying a view using suitable example.
6. Explain SQL Security management tools.
7. How exception block of PL/SQL works? Explain using example. (b) What are triggers? How are
triggers executed on events? Explain with example.
8. What is the difference between a stored procedure and function?
9. Explain exceptional handling with suitable example.

Answer
1. A database is a structured collection of data that can be easily accessed, managed,
and updated. It allows users to store data in an organized manner, retrieve it
efficiently, and ensure its integrity. Databases are widely used in applications ranging
from banking to e-commerce.

Databases are managed by Database Management Systems (DBMS), which provide


tools and functionality to create, retrieve, update, and manage data effectively.

Oracle Database, developed by Oracle Corporation, is a relational database


management system (RDBMS). It is widely regarded as one of the most robust and
versatile databases for enterprise applications. Oracle Database supports SQL
(Structured Query Language) and PL/SQL (Procedural Language/SQL), allowing
complex data manipulation and business logic implementation.

Key Features of Oracle Database:

1. Scalability: Supports large-scale databases with millions of records.


2. High Performance: Optimized for high-speed transaction processing.
3. Data Security: Provides features like data encryption, user authentication, and role-based
access.
4. High Availability: Supports features like Real Application Clusters (RAC) and Data Guard to
ensure system availability.
5. Multi-Model Support: Supports relational, JSON, XML, and other types of data.
6. Backup and Recovery: Provides tools for data backup and restoration in case of failure.

Oracle Tools

Oracle provides a variety of tools and utilities to simplify database management,


development, and analysis:

1. SQL*Plus

 A command-line tool to interact with the Oracle Database.


 Allows users to execute SQL commands and PL/SQL scripts.

2. Oracle SQL Developer

 A graphical tool for database development.


 Features include writing and debugging SQL queries, managing database objects, and
migrating databases.
 User-friendly interface for managing Oracle and non-Oracle databases.

3. Oracle Enterprise Manager (OEM)

 A web-based tool for database management.


 Features monitoring, performance tuning, and resource management.
 Centralized control over Oracle databases and applications.

4. Data Pump

 Used for fast data import and export operations.


 Allows efficient transfer of large volumes of data between Oracle databases.

5. RMAN (Recovery Manager)

 A robust tool for backup and recovery.


 Supports incremental backups, full backups, and automated recovery processes.

6. Oracle SQL Loader

 A tool to load data from external files into an Oracle database.


 Supports structured and semi-structured data.

7. Oracle GoldenGate

 A data integration tool for real-time data replication.


 Supports heterogeneous database environments.

8. Oracle Forms and Reports

 Used for designing and deploying applications with a graphical user interface.
 Reports are used to generate formatted data outputs.

9. Oracle APEX (Application Express)

 A low-code development platform.


 Enables users to build web applications quickly using SQL and PL/SQL.

10. Oracle Cloud Services

 Offers a suite of database services in the cloud.


 Includes Autonomous Database, Database as a Service (DBaaS), and Oracle Analytics Cloud.
Advantages of Using Oracle Database

 Reliability: Trusted by enterprises for critical applications.


 Cross-Platform Support: Available for Windows, Linux, UNIX, and other operating systems.
 Enterprise Features: Advanced tools for data management, analytics, and business
intelligence.
 Support for Large Data: Efficiently manages petabytes of data.
 Integration: Works seamlessly with enterprise tools and cloud services.

By leveraging Oracle's tools and capabilities, organizations can ensure high


performance, security, and scalability for their database needs.

2. Database Types in Oracle

Oracle databases are primarily classified based on their purpose and deployment.
These include:

1. Online Transaction Processing (OLTP) Databases:

 Designed for high-performance transaction processing.


 Used in applications requiring frequent read/write operations like banking and e-
commerce.

2. Data Warehousing Databases:

 Optimized for analytical queries and data reporting.


 Stores large amounts of historical data for Business Intelligence (BI) and
analytics.

3. Distributed Databases:

 Data is distributed across multiple physical locations.\


 Supports high availability and redundancy.

4. Multitenant Databases:

 Introduced with Oracle 12c, supports container and plug-gable databases.


 Provides better resource utilization and simplified management.

5. In-Memory Databases:

 Uses memory for data storage instead of disk.


 Offers lightning-fast query performance for analytics.

6. Cloud Databases:

 Hosted on Oracle Cloud Infrastructure.


 Offers Autonomous Database features like self-repairing, self-optimizing, and self-securing.
Oracle Data Types and Lengths

Oracle supports various data types to handle different kinds of data. These data types
determine the kind of operations that can be performed and how data is stored.

1. Character Data Types

Maximum
Data Type Description
Length
Fixed-length character data. Pads with Up to 2000
CHAR(size)
spaces for shorter data. bytes
Variable-length character data. More Up to 4000
VARCHAR2(size)
storage-efficient than CHAR. bytes
Up to 2000
NCHAR(size) Fixed-length Unicode character data.
bytes
Up to 4000
NVARCHAR2(size) Variable-length Unicode character data.
bytes
Character Large Object for large text
CLOB Up to 4 GB
data.
NCLOB Unicode Character Large Object. Up to 4 GB

2. Numeric Data Types

Maximum
Data Type Description
Length
Stores fixed and floating-point numbers.
Up to 21
NUMBER(p,s) Precision (p) is up to 38, and scale (s) is
bytes
from -84 to 127.
Approximate floating-point number. Equivalent Up to 21
FLOAT
to NUMBER with a precision of 38. bytes
32-bit single-precision floating-point
BINARY_FLOAT 5 bytes
number.
64-bit double-precision floating-point
BINARY_DOUBLE 9 bytes
number.

3. Date and Time Data Types

Maximum
Data Type Description
Length
Stores date and time to the second.
DATE 7 bytes
Default format: DD-MON-YYYY.
Maximum
Data Type Description
Length
Stores date and time with fractional
7–11
TIMESTAMP(p) seconds. Precision (p) ranges from 0 to
bytes
9.
TIMESTAMP WITH TIME
Includes time zone information. 13 bytes
ZONE
TIMESTAMP WITH Normalizes time to the database time 7–11
LOCAL TIME ZONE zone. bytes
INTERVAL YEAR TO Represents a period in years and
5 bytes
MONTH months.
INTERVAL DAY TO Represents a period in days, hours,
11 bytes
SECOND minutes, and seconds.

4. Binary Data Types

Data Maximum
Description
Type Length
Stores binary data as a variable-length Up to 2000
RAW(size)
string. bytes
LONG RAW Stores binary data for backward compatibility. Up to 2 GB
Binary Large Object for large binary data
BLOB Up to 4 GB
(e.g., images, videos).
Points to binary data stored in external
BFILE Up to 4 GB
files.

5. ROWID and UROWID

Data Maximum
Description
Type Length
ROWID Unique identifier for a row in a table. 10 bytes
Universal ROWID for tables without ROWID (e.g., Up to 4000
UROWID
external or index-organized tables). bytes

6. XML and JSON Data Types

Data Maximum
Description
Type Length
XMLType Used to store XML data. Depends on
Data Maximum
Description
Type Length
storage
Stores JSON data natively in binary format Depends on
JSON
(introduced in Oracle 21c). storage

3. Primary Key: - A primary key is a constraint in a


relational database that uniquely identifies each record in a
table. The primary key ensures:

1. Uniqueness: No duplicate values are allowed.


2. Non-Null: Every primary key value must be non-null.

Each table can have only one primary key, which can consist of one or more columns
(composite primary key).

Creating a Primary Key with a Table

In Oracle, a primary key can be created during table creation or added later using the
ALTER TABLE statement.

1. Create Primary Key During Table Creation:

CREATE TABLE employees (

emp_id NUMBER(5) PRIMARY KEY,

emp_name VARCHAR2(50),

department_id NUMBER(3)

);

In this example: The column emp_id is defined as the primary key.

2. Add Primary Key After Table Creation:

ALTER TABLE employees

ADD CONSTRAINT emp_pk PRIMARY KEY (emp_id);

Here: A constraint emp_pk is added to make emp_id the primary key.

3. Composite Primary Key:

A primary key can span multiple columns.


CREATE TABLE order_details (

order_id NUMBER(5),

product_id NUMBER(5),

quantity NUMBER(3),

PRIMARY KEY (order_id, product_id)

);

This ensures that the combination of order_id and product_id is unique.

3rd ka baki part extra hai toh ye rahne dete hai hehe

4. Index Creation in Oracle Database

An index in Oracle is a database object that improves the speed of data retrieval. It
creates a structure that allows queries to access rows more quickly than scanning the
entire table. However, indexes also occupy space and can slightly impact write
performance because they need to be updated when data changes.

Types of Indexes

1. B-Tree Index: Default index type, optimized for high-cardinality columns (columns with many
unique values).
2. Bitmap Index: Used for low-cardinality columns (columns with few unique values).
3. Unique Index: Ensures that all values in the indexed column are unique.
4. Composite Index: Indexes multiple columns.
5. Function-Based Index: Indexes based on expressions or functions.
6. Invisible Index: Indexes that are not used by default queries but can be enabled explicitly.

Iske aage code example hai toh thoda rahne dete hai ye.

Creating an Index: -

1. Basic index creation: - CREATE INDEX index_name ON table_name(column_name);

Example: - CREATE INDEX emp_dept_idx ON employees(department_id);

2. Unique Index: - CREATE UNIQUE INDEX index_name ON table_name(column_name);

Example: - CREATE UNIQUE INDEX emp_email_idx ON employees(email);


3. Composite Index: - CREATE INDEX index_name ON table_name(column1, column2);

Example: - CREATE INDEX emp_name_dept_idx ON employees(emp_name, department_id);

4. Function - based Index: - CREATE INDEX index_name ON table_name(UPPER(column_name));

Example: - CREATE INDEX emp_name_idx ON employees(UPPER(emp_name));

5. Bitmap Index: - CREATE BITMAP INDEX index_name ON table_name(column_name);

Example: - CREATE BITMAP INDEX emp_gender_idx ON employees(gender);

5. Concept of a View

A view in a database is a virtual table based on the result of an SQL query. Unlike a
physical table, a view does not store data itself but displays data stored in one or more
tables. Views simplify complex queries, enhance security, and provide a logical
structure for data access.

Key Features of a View

1. Virtual Table: Does not store data physically; dynamically retrieves it from the base table(s).
2. Simplification: Makes it easier to query data, especially with complex joins or filters.
3. Security: Restricts user access to specific columns or rows in a table.
4. Reusability: Can be reused in multiple queries or reports.

Creating a View

The CREATE VIEW statement defines a view by specifying a SELECT query.

Syntax: - CREATE OR REPLACE VIEW view_name AS

SELECT column1, column2, ...

FROM table_name

WHERE condition;

Example: Creating a Simple View

CREATE VIEW emp_dept_view AS

SELECT e.emp_id, e.emp_name, d.department_name

FROM employees e

JOIN departments d

ON e.department_id = d.department_id;

emp_view will display employee details for department 101.


Example: Creating a Complex View with Joins

CREATE VIEW emp_dept_view AS

SELECT e.emp_id, e.emp_name, d.department_name

FROM employees e

JOIN departments d

ON e.department_id = d.department_id;

emp_dept_view combines data from employees and departments tables.

Using a View : - SELECT * FROM emp_view;

Modifying a view : - To update an existing view, use the CREATE OR


REPLACE statement:

CREATE OR REPLACE VIEW emp_view AS

SELECT emp_id, emp_name

FROM employees

WHERE department_id = 102;

Destroying a view: - To remove a view, use the Drop View statement.

Syntax: - DROP VIEW view_name;

Ex: - DROP VIEW emp_view;

Advantages of Views

1. Security: Limits access to sensitive data by exposing only specific columns or rows.
2. Simplification: Hides complex joins and calculations from end users.
3. Reusability: Reduces redundancy by encapsulating queries.
4. Data Independence: Provides a consistent interface even if the underlying table structure
changes.

Limitations of Views

1. Performance: Can slow down queries if the view involves complex joins or aggregations.
2. Restrictions on Updates: Some views are read-only, especially if they involve joins,
aggregations, or non-deterministic functions.
9 page tak mei 5 question hogaya

6. SQL Security Management Tools

SQL security management tools in a database system like Oracle are designed to
control access to data, maintain confidentiality, ensure data integrity, and protect
against unauthorized use or breaches. These tools and features provide mechanisms
for authentication, authorization, encryption, auditing, and user management.

Key SQL Security Management Tools

1. Authentication

Authentication ensures that only authorized users can access the database. Oracle
supports multiple authentication methods:

 Database Authentication: Users are authenticated using database-stored credentials.


 Operating System Authentication: Relies on the OS for user verification.
 Network Authentication: Uses protocols like Kerberos or LDAP.
 Enterprise Authentication: Leverages centralized identity management systems like Oracle
Identity Management.

2. Authorization determines what authenticated users are allowed to do. It involves


assigning privileges and roles:

 System Privileges: Allow users to perform administrative tasks, like CREATE TABLE or
ALTER USER.
 Object Privileges: Control access to specific database objects, like SELECT, INSERT, or
DELETE on a table.
 Roles: A collection of privileges that can be granted to users. Example:

CREATE ROLE manager_role;

GRANT SELECT, INSERT, UPDATE ON employees TO manager_role;

GRANT manager_role TO user1;

3. Data Encryption

Encryption protects sensitive data at rest or in transit:

 Transparent Data Encryption (TDE): Automatically encrypts data stored in tablespaces.

ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY 'mykey';


 Network Encryption: Encrypts data transmitted between the database and clients using
Oracle Net Services.
 Column-Level Encryption: Encrypts specific columns in a table.

CREATE TABLE employees (

emp_id NUMBER,

emp_ssn VARCHAR2(11) ENCRYPT

);

4. Virtual Private Database (VPD)

VPD implements row-level security by dynamically adding a WHERE clause to SQL


queries based on user identity.

 Steps:
1. Create a security policy using PL/SQL.
2. Apply the policy to a table. Example:

BEGIN

DBMS_RLS.ADD_POLICY(

object_schema => 'HR',

object_name => 'employees',

policy_name => 'emp_policy',

function_name => 'policy_function'

);

END;

5. Auditing

Auditing tracks and records user activities to detect unauthorized access or actions.
Oracle offers:

 Standard Auditing: Logs specific database activities.

AUDIT SELECT ON employees;

 Unified Auditing: Consolidates audit records from different


sources.

CREATE AUDIT POLICY sensitive_data_policy


ACTIONS SELECT ON sensitive_data;

7. ye code hai long skip it.

8. Difference Between a Stored Procedure and a Function

In Oracle PL/SQL, stored procedures and functions are named blocks of PL/SQL
code that can be reused, but they serve different purposes and have distinct
characteristics.

Aspect Stored Procedure Function


A stored procedure performs a A function performs a
Definition specific task but does not task and must return a
necessarily return a value. single value.
Does not return a value Always returns a value
Return Value directly but can pass values using the RETURN
using OUT parameters. statement.
Used for executing business
Used for computations,
logic, often involving
Purpose returning a single
multiple operations like
result based on inputs.
updates and inserts.
Can be directly used in
Cannot be directly used in SQL
Usage in SQL SQL statements like
statements.
SELECT or WHERE.
Called using the EXECUTE or
Called as part of an
Call Syntax CALL statement, or from an
expression.
anonymous PL/SQL block.
Can have IN, OUT, and IN OUT Only IN parameters are
Parameters
parameters. allowed.
More suited for complex logic Suitable for simple
Complexity and operations that do not operations that require
require a direct result. a single return value.
Cannot include
Transaction Can include COMMIT, ROLLBACK,
transaction control
Control and SAVEPOINT statements.
statements.
Calculating a value like
Example Use Modifying or manipulating
total salary, tax, or
Case multiple database records.
interest.

Examples: - Stored Procedure

CREATE OR REPLACE PROCEDURE update_salary(emp_id IN NUMBER,


increment IN NUMBER

IS

BEGIN

UPDATE employees

SET salary = salary + increment

WHERE id = emp_id;

END;

Calling the Procedure

EXEC update_salary(101, 500);

9. Exception Handling in PL/SQL

Exception handling in PL/SQL is a mechanism to handle runtime errors or anomalies


that occur during the execution of a program. It allows developers to gracefully
recover from errors, log issues, or take corrective action instead of abruptly
terminating the program.

Structure of PL/SQL Block with Exception Handling

A PL/SQL block has three sections:

1. Declaration Section: Variables, constants, or exceptions are declared.


2. Execution Section: Contains the main logic and SQL/PLSQL statements.
3. Exception Section: Handles errors raised in the execution section.

General Syntax: -

DECLARE

-- Variable and exception declarations

BEGIN

-- Executable statements

EXCEPTION

WHEN exception_name THEN

-- Handling specific exception


WHEN OTHERS THEN

-- Handling all other exceptions

END;

Types of Exceptions in PL/SQL

1. Predefined Exceptions: These are automatically raised by Oracle when specific


errors occur.

Examples: NO_DATA_FOUND, TOO_MANY_ROWS, ZERO_DIVIDE.

2. User-Defined Exceptions: These are explicitly declared and raised by the


programmer using the RAISE statement.

Example: Predefined Exception

Scenario: Divide a number by zero.

DECLARE

v_num1 NUMBER := 10;

v_num2 NUMBER := 0;

v_result NUMBER;

BEGIN

-- Attempt division

v_result := v_num1 / v_num2;

DBMS_OUTPUT.PUT_LINE('Result: ' || v_result);

EXCEPTION

WHEN ZERO_DIVIDE THEN

DBMS_OUTPUT.PUT_LINE('Error: Division by zero is not allowed.');

END;

Output: Error: Division by zero is not allowed.

Advantages of Exception Handling

1. Error Recovery: Prevents abrupt program termination.


2. Debugging Aid: Helps identify and log runtime issues.
3. Program Continuity: Ensures consistent program execution even when errors occur.
4. Improved Readability: Separates error-handling logic from business logic.

Conclusion

Exception handling in PL/SQL provides a robust way to manage and recover from
errors during execution. Using predefined and user-defined exceptions effectively
allows developers to create reliable and fault-tolerant database programs.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy