Professional Documents
Culture Documents
(Time: 60 minutes)
I Oracle Questions
1. What is the DUAL table? How can we determine the date of the system using the DUAL
table?
The Dual table is special one row and one column table. The table has a single
varchar2(1) column
called Dummy.
SELECT sysdate FROM DUAL ;
Oracle
Oracle
Oracle
Oracle
3. Explain difference between UNION and UNION ALL? When is it used? Write an example
using either one.
The union operator returns results from all the participating queries after eliminating duplications
The union all operator returns results from all the participating queries including the duplicate rows.
Note: number of columns and column data type returned by the query must match however the column
name can be different.
For e.g
Select first_name,last_name from emp
union
select first_name, to_char(age) from emp1;
6. What does COMMIT stand for? In which cases this has to be applied? What is ROLLBACK?
COMMIT: You can see any changes you have made during the transaction by querying the modified tables, but
other users cannot see the changes. After you commit the transaction, the changes are visible to other users.
ROLLBACK:
You can roll back (undo) any changes made during the transaction with
II PL/SQL
8. What are the two parts of a package in PL/SQL? Specify the importance of creating
packages in PL/SQL.
PL/SQL packages are schema objects that groups logically related PL/SQL types, variables and subprograms.
A package will have two mandatory parts:
a) Package specification b)Package body or definition
Importance of Packages
1)Packages improve the performance of functions and procedures
2)Packages allow declare global variables
3)All the procedures and functions relating to a specific sub-system are in one program unit. This is good
design practice and easy to manage.
4)Security :Defining private procedures in the package body which can only be used by the package.
5)Hidden Implementation: Packages let you share your interface information in the package specification and
hide the implementation details in the package body.
6)Modularity: Packages encapsulate logically related variables, constants,subprograms,cursors and exceptions
in named PL/sql Modules.
A cursor is a pointer to a private SQL area that stores information about the processing of a SELECT or
data manipulation language (DML) statement (INSERT, UPDATE, DELETE, or MERGE).
Must used Return Keyword.
It required for row wise validation or in other way you can perform operation on each row.
System-defined exceptions
User-defined exceptions
13. Explain what is meant by DYNAMIC SQL in PL/SQL and why it is sometimes required to
use?
III - SQL
EMPLOYEES
Employee_id
Last_name
First_name
Salary
Commission_pct
Department_id
DEPARTMENTS
Department_id
Department_name
Manager_id
Location_id
14. Create a query to display the employee numbers and last names of all employees who
earn more than the average salary. Sort the results in ascending order of salary.
15. Display the last name, department number and department_name of all employees
whose department location id is 1700.
select EMPLOYEES.Last_name,DEPARTMENTS.Department_id,DEPARTMENT.Department_name
from EMPLOYEES,DEPARTMENTS where Location_id=1700.
17. Insert a new department named Support in location ID 2500 using dept_deptid_seq
sequence.
insert into DEPARTMENTS ( Department_id,Department_name,Location_id)
values(dept_deptid_seq.nextval, Support ,2500);
18. Allow all users on the system to query data from Alices DEPARTMENTS table.
20.
21. Show how many employees have a name that ends with an n.
Select * from EMPLOYEES where First_name like %n;
21. Explain and advantage of using %TYPE instead of declare data types on variables in
PL/SQL?
22. Write an example of DECODE in a SELECT statement using three states in a table called
STATES and column named STATECODE as an example OH=Ohio, IN=Indiana,
KY=Kentucky. Make sure to handle if some other state is in the column.
SELECT DECODE() FROM STATES;
25. How many types of cursors exist in PL/SQL? Shortly explain, when each one of them is
used.
6