0% found this document useful (0 votes)
14 views9 pages

DBMS UNIT 3.2

The document provides an overview of SQL logical operators, including BETWEEN and LIKE, as well as date and time functions, string functions, and aggregate functions. It also explains views, PL/SQL block structure, exception handling, cursors, and the ACID properties of transactions. Each section includes definitions, examples, and syntax for better understanding of SQL and PL/SQL functionalities.

Uploaded by

ryuk07u
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)
14 views9 pages

DBMS UNIT 3.2

The document provides an overview of SQL logical operators, including BETWEEN and LIKE, as well as date and time functions, string functions, and aggregate functions. It also explains views, PL/SQL block structure, exception handling, cursors, and the ACID properties of transactions. Each section includes definitions, examples, and syntax for better understanding of SQL and PL/SQL functionalities.

Uploaded by

ryuk07u
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/ 9

Logical Operators

1.​ Logical operators in SQL are used to combining conditions.


They find specific data by checking multiple rules at once.
2.​For example, one can find employees who work in a certain
department and were hired this year.
Between operator:
1.​The BETWEEN operator is used to search for values that are
within a set of values, given the minimum value and the
maximum value inclusive of both the limits.
2.​Eg: select * from emp where salary between 40000 and 50000;
3.​This will result in rows from the emp table where salary
falls in the range of 40000 to 50000.

Like operator :
1.​The LIKE operator is used to compare a value to similar
values using wildcard operators.
2.​It uses two wild characters as ‘%’ and ‘_’ where ‘%’
represents all characters of the pattern and ‘_’ represents
one single character from the pattern.
3.​Eg : Select ename from emp where ename like ‘S%’;
4.​This will return all employee names starting with ‘S’.
5.​Select ename from emp where ename like ‘_a%;
6.​This will return all employee names whose second character is
‘a’

Date and time functions:

1.​SQL Date and Time operations are used for operations on date
and time provided by users.
2.​SQL supports various date and time data types and formats.
The specific date format depends on the database system being
used.
String functions:
1.​The string is a collection of characters used to store
multiple characters.
2.​Most of the time we need to modify and access the strings.
SQL has built-in string functions.
3.​The SQL built-in string functions take an input string and
return an output string.
4.​String functions are used to perform various character
manipulation
Aggregate functions:
1.​An aggregate function is a function where the values of
multiple rows are grouped together as input on certain
criteria to form a single value of more significant meaning.

View:
1.​A view is a virtual table based on the result set of the SQL
statement.
2.​The fields in a view are fields from one or more than one
table in the database.
3.​SQL functions, where join statements can be added to a view
and the data in it can be presented as if it were from one
table.
4.​The database engine recreates the data, using the view’s SQL
statement, every time a user queries a view.
5.​A view can be updated using the create or replace view
command. For deleting a view, a drop query can be used.
6.​View has two types:
1. Simple view: The fields in a view are fields from one
table in the database.
2. Complex view: The fields in a view are fields from
more than one table in the database.
7.​Advantages of views:
a.​Complexity: Views help to reduce complexity.
b.​Security: It increases security by excluding the
sensitive information from the view.
c.​Query Simplicity: It helps to simplify commands from the
user.
d.​Consistency: A view can present a consistent, unchanged
image of the structure of the database.
8.​CREATE VIEW Syntax:
CREATE VIEW view_name AS SELECT column1, column2… from
table_name WHERE condition ;
-​ Example: CREATE VIEW vw_student AS SELECT stud_id,
stud_name,ssc_per from student;

9.​DROP VIEW Syntax:


DROP VIEW view_name;
-​ Example: DROP VIEW student;

10.​ Update VIEW syntax:


UPDATE VIEW view_name
SET column1 = value1, column2 = value2,...
WHERE condition;

PL/SQL Block Structure:

Explanation of PL/SQL Block Structure:

1.​Declaration section:
A block begins with a declarative section where variables,
cursors are declared. It is an Optional block.
2.​Execution section:
Executable SQL or PL/SQL Statements are needed to write here
for the execution. It is a mandatory block.
3.​Exception section:
It is used to handle exceptions. It is an Optional block.
4.​End statement:
It is used to indicate termination of a PL/SQL block. It
is mandatory.

Advantages of PL/SQL:

1. PL/SQL is a portable and high transaction processing language.


2. PL/SQL is in fact a procedural language but it also supports
object oriented programming.
3. It allows users to write as well as access the functions and
procedures from outside the programs.
4. It has got built in libraries of packages.

Exception handling in PL/SQL:


1.​An exception is an error condition during a program
execution.
2.​ PL/SQL supports programmers to catch such conditions using
the EXCEPTION block in the program and an appropriate action
is taken against the error condition.
3.​There are two types of exceptions −
System-defined (built in) exceptions: This types of
exceptions are pre defined by the database system, the user
does not need to define this type of exceptions

User-defined exceptions:
1.​The user defined exceptions are the exception defined by
the user, after the Declare part of the PL/SQL
structure.
2.​The word ‘EXCEPTION’ is used to declare these exceptions
3.​They must be raised explicitly by using the RAISE
statement

4.​The general syntax for exception handling is as follows :


​ DECLARE
​ <Declaration Section>
BEGIN
​ <Executable commands>
EXCEPTION
<Exception handling goes here>
WHEN exception1 THEN
exception1-handling-statements
WHEN exception2
THEN exception2-handling-statements
…… ….…. END;

5.​Example:

Example :
declare
age number := 15;
age_too_low exception;
begin
if age < 18 then
raise age_too_low; -- Explicitly raise the
user-defined exception
end if;
dbms_output.put_line('Age is valid: ' || age);
exception
when age_too_low then
dbms_output.put_line('Error: Age is below 18 and not
allowed.');
End;

Cursor:

1.​ A cursor is a set of rows together with a pointer that


identifies a current row.
2.​It is a database object to retrieve data from a result set
one row at a time.
3.​It is useful when we want to manipulate the record of a table
in a singleton method, in other words one row at a time.
4.​In other words, a cursor can hold more than one row, but can
process only one row at a time.
5.​The set of rows the cursor holds is called the active set.
6.​There are 2 types of cursors: 1) implicit cursor, 2)explicit
cursor
7.​Implicit cursor:
1. These types of cursors are generated and used by the
system during the manipulation of a DML query.
2. An implicit cursor is also generated by the system when a
single row is selected by a SELECT command.
8.​Explicit cursor:
1. This type of cursor is created by the user when the select
command returns more than one row, and only one row is to be
processed at a time.
2. An explicit cursor can move from one row to another in a
result set.
3. An explicit cursor uses a pointer that holds the record of
a row.
4. To create an explicit cursor the following steps are used.
1. Declare cursor: this is done in the declaration section of
PL/SQL program.
2. Open: this step is done before the cursor is used to fetch
the records.
3. Fetch: used to retrieve data row by row from the cursor.
4. Close: once the processing of the data is done, the cursor
can be closed.
ACID Properties of Transaction:

1. Atomicity
2. Consistency
3. Isolation
4. Durability

1. Atomicity: Atomicity means all the operations included in the


single transaction gets executed at a time or none.
2. Consistency: Consistency means updating or editing the same
data stored at different locations.
3. Isolation: Isolation means all the transactions get executed
independent of each other.
4. Durability: Durability means data can be saved in the database
permanently until the user changes it.

You might also like