Bca 501
Bca 501
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.
Oracle Tools
1. SQL*Plus
4. Data Pump
7. Oracle GoldenGate
Used for designing and deploying applications with a graphical user interface.
Reports are used to generate formatted data outputs.
Oracle databases are primarily classified based on their purpose and deployment.
These include:
3. Distributed Databases:
4. Multitenant Databases:
5. In-Memory Databases:
6. Cloud Databases:
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.
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
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.
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.
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.
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
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
Each table can have only one primary key, which can consist of one or more columns
(composite primary key).
In Oracle, a primary key can be created during table creation or added later using the
ALTER TABLE statement.
emp_name VARCHAR2(50),
department_id NUMBER(3)
);
order_id NUMBER(5),
product_id NUMBER(5),
quantity NUMBER(3),
);
3rd ka baki part extra hai toh ye rahne dete hai hehe
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: -
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.
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
FROM table_name
WHERE condition;
FROM employees e
JOIN departments d
ON e.department_id = d.department_id;
FROM employees e
JOIN departments d
ON e.department_id = d.department_id;
FROM employees
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
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.
1. Authentication
Authentication ensures that only authorized users can access the database. Oracle
supports multiple authentication methods:
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:
3. Data Encryption
emp_id NUMBER,
);
Steps:
1. Create a security policy using PL/SQL.
2. Apply the policy to a table. Example:
BEGIN
DBMS_RLS.ADD_POLICY(
);
END;
5. Auditing
Auditing tracks and records user activities to detect unauthorized access or actions.
Oracle offers:
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.
IS
BEGIN
UPDATE employees
WHERE id = emp_id;
END;
General Syntax: -
DECLARE
BEGIN
-- Executable statements
EXCEPTION
END;
DECLARE
v_num2 NUMBER := 0;
v_result NUMBER;
BEGIN
-- Attempt division
EXCEPTION
END;
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.