B Explain Set Operators With Example
B Explain Set Operators With Example
B Explain Set Operators With Example
Set operators combine the results of two component queries into a single result. Queries
containing set operators are called as compound queries. Set operators in SQL are
represented with following special keywords as: Union, Union all, intersection & minus.
Emp Employee
Ename Ename
a c
b e
) Union: The Union of two or more sets contains all elements, which are present in
E.g. select ename from emp union select ename from employee;
Output
Ename
2) Union all: The Union of 2 or more sets contains all elements, which are present in
E.g. select ename from emp union all select ename from employee;
Output
Ename
present in both. E.g. select ename from emp intersect select ename from
employee;
Output
Ename
4) Minus: The minus of two sets includes elements from set1 minus elements of set2.
E.g. select ename from emp minus select ename from employee;
ename
Ans Exception Handling: Exception is nothing but an error. Exception can be raise when
When the system throws a warning or has an error it can lead to an exception. Such
exception needs to be handled and can be defined internally or user defined.
Exception handling is nothing but a code block in memory that will attempt to resolve
Syntax:
DECLARE ;
Declaration section
…executable statement;
EXCEPTION
END;
Types of Exception:
automatically raised whenever related error occurs. The most common errors that can
occur during the execution of PL/SQL. Not declared explicitly i.e. cursor already open,
invalid cursor, no data found, zero divide and too many rows etc. Programs are handled
2) User defined exception: It must be declare by the user in the declaration part of the
block where the exception is used. It is raised explicitly in sequence of statements using:
Raise_application_error(Exception_Number, Error_Message);
Ans Commit:
The COMMIT command saves all transactions to the database since the last COMMIT
or ROLLBACK command
Or
COMMIT WORK;
Example :
SQL>Commit;
Rollback:
The ROLLBACK command is used to undo transactions that have not already been
The ROLLBACK command can only be used to undo transactions since the last
ROLLBACK TO SAVEPOINT_NAME;
OR
ROLLBACK;
OR
ROLLBACK WORK;
Example:
SQL>ROLLBACK;
Database security refers to the collective measures used to protect and secure a database
or database management software from illegal use and malicious threats and attacks.
1. For prevention of data theft such as bank account numbers, credit card
4. To provide integrity which ensures that only authorized individuals should ever
5. To provide availability which ensure that the data or system itself is available for
authorized individual.
7. To provide non-repudiation which deals with the ability to verify that message
1. Atomicity: When one transaction takes place, many operations occur under one
transaction. Atomicity means either all operations will take place property and reflect in
3. Isolation: It is necessary to maintain isolation for the transactions. This means one
transaction should not be aware of another transaction getting executed. Also their
failures.
Employee(emp_id,emp_name,emp_city,emp_addr,emp_dept,join_date)
Ans i) Display the emp_id of employee who live in city ‘Pune’ or ‘Nagpur’
select emp_id
from Employee
update Employee
set emp_name=’Ayan’
where emp_name=’Ayush’
Select count(*)
from Employee
where emp_dept=50;
c Consider the following schema Depositor (ACC_no, Name, PAN, Balance). Create a
100000
as
select ACC_No,PAN
from Depositor
a Create a sequence
i) Sequence name is Seq_1, Start with 1, increment by 1, minimum value 1,
ii) Use a seq_1 to insert the values into table Student( ID Number(10), Name char
(20));
20;
b Write a PL/SQL program which accepts the customer_ID from the user. If the
handling.
Ans DECLARE
c_id numeric(10);
invalid_id_Exception Exception;
BEGIN
c_id:=&c_id;
if(c_id<0) then
raise invalid_id_Exception;
end if;
EXCEPTION
END;