Oracle Interview Questions and Answers

1. What is Oracle?
Oracle is a company. Oracle is also a database server, which manages data in a very structured way. It allows users to store and retrieve related data in a multi user environment so that many users can concurrently access the same data. All this is accomplished while delivering high performance. A database server also prevents unauthorized access and provides efficient solutions for failure recovery. A standby database is a database replica created by taking a backup of a primary database.
2. What is a Oracle Database?
Oracle provides software to create and manage the Oracle database. The database consists of physical and logical structures in which system, user, and control information is stored. The software that manages the database is called the Oracle database server. Collectively, the software that runs oracle and the physical database are called the Oracle database system. A database buffer cache stores the data in memory for quicker access. The redo logs track and store all the changes made to the database. A Data Guard ensures data protection and high availability of data and control file records the physical structure of the database. Click on the above link to read more and to become a Oracle DBA.
3. What are the roles of DBA?

DBA has the authority to create new users, remove existing users or modify any of the environment variables or privileges assigned to other users.

  •  Manage database storage
  • Administer users and security
  •  Manage schema objects
  •  Monitor and manage database performance
  •  Perform backup and recovery
  • Schedule and automate jobs
4. What are different Oracle database objects?
5. Difference between varchar and varchar2 data types?
Varchar can store upto 2000 bytes and varchar2 can store upto 4000 bytes. Varchar will occupy space for NULL values and Varchar2 will not occupy any space. Both are differed with respect to space.
6. In which language Oracle has been developed?
Oracle has been developed using C Language.
7. What is the data type of DUAL table?
The DUAL table is a one-column table present in oracle database. The table has a single VARCHAR2(1) column called DUMMY which has a value of ‘X’.
8. What is difference between Cartesian Join and Cross Join?
There are no differences between the join. Cartesian and Cross joins are same. Cross join gives cartesian product of two tables – Rows from first table is multiplied with another table which is called cartesian product.
Cross join without where clause gives Cartesian product.
9. How to display employee records who gets more salary than the average salary in the department?
This can be done by this query –
Select * from employee where salary>(select avg(salary) from dept, employee where dept.deptno = employee.deptno;
10. What is DML?
Data Manipulation Language (DML) is used to access and manipulate data in the existing objects. DML statements are insert, select, update and delete and it won’t implicitly commit the current transaction.
11. What is the difference between TRANSLATE and REPLACE?
Translate is used for character by character substitution and Replace is used substitute a single character with a word.
12. How do we display rows from the table without duplicates?
Duplicate rows can be removed by using the keyword DISTINCT in the select statement.
13. What is the usage of Merge Statement?
Merge statement is used to select rows from one or more data source for updating and insertion into a table or a view. It is used to combine multiple operations.
14. What is NULL value in oracle?
NULL value represents missing or unknown data. This is used as a place holder or represented it in as default entry to indicate that there is no actual data present.
15. What is USING Clause and give example?
The USING clause is used to specify with the column to test for equality when two tables are joined.
[sql]Select * from employee join salary using employee ID[/sql]
Employee tables join with the Salary tables with the Employee ID.
16. What is key preserved table?
A table is set to be key preserved table if every key of the table can also be the key of the result of the join. It guarantees to return only one copy of each row from the base table.
The WITH CHECK option clause specifies check level to be done in DML statements. It is used to prevent changes to a view that would produce results that are not included in the sub query.
18. What is the use of Aggregate functions in Oracle?
Aggregate function is a function where values of multiple rows or records are joined together to get a single value output. Common aggregate functions are –
  • Average
  • Count
  • Sum
19. What do you mean by GROUP BY Clause?
A GROUP BY clause can be used in select statement where it will collect data across multiple records and group the results by one or more columns.
20. What is a sub query and what are the different types of subqueries?
Sub Query is also called as Nested Query or Inner Query which is used to get data from multiple tables. A sub query is added in the where clause of the main query.
There are two different types of subqueries:
Correlated sub query: A Correlated sub query cannot be as independent query but can reference column in a table listed in the from list of the outer query.
Non-Correlated subquery: This can be evaluated as if it were an independent query. Results of the sub query are submitted to the main query or parent query.
21. What is cross join?
Cross join is defined as the Cartesian product of records from the tables present in the join. Cross join will produce result which combines each row from the first table with the each row from the second table.
22. What is the use of NVL function?
The NVL function is used to replace NULL values with another or given value. Example is – NVL(Value, replace value)
23. Whether any commands are used for Months calculation? If so, What are they?
In Oracle, months_between function is used to find number of months between the given dates. Example is – Months_between(Date 1, Date 2)
24. What are nested tables?
Nested table is a data type in Oracle which is used to support columns containing multi valued attributes. It also hold entire sub table.
25. What is COALESCE function?
COALESCE function is used to return the value which is set to be not null in the list. If all values in the list are null, then the coalesce function will return NULL. Coalesce(value1, value2,value3,…)
27. What is BLOB datatype?
A BLOB data type is a varying length binary string which is used to store two gigabytes memory. Length should be specified in Bytes for BLOB.
28. How do we represent comments in Oracle?
Comments in Oracle can be represented in two ways –
  1. Two dashes(–) before beginning of the line – Single statement
  2. /*—— */ is used to represent it as comments for block of statement
29. What are temporal data types in Oracle?
Oracle provides following temporal data types:
  • Date Data Type – Different formats of Dates
  • TimeStamp Data Type – Different formats of Time Stamp
  • Interval Data Type – Interval between dates and time
30. How do we create privileges in Oracle?
A privilege is nothing but right to execute an SQL query or to access another user object. Privilege can be given as system privilege or user privilege.
[sql]GRANT user1 TO user2 WITH MANAGER OPTION;[/sql]
31. What is VArray?
VArray is an oracle data type used to have columns containing multivalued attributes and it can hold bounded array of values.
32. How do we get field details of a table?
Describe is used to get the field details of a specified table.
33. What is the difference between rename and alias?
Rename is a permanent name given to a table or a column whereas Alias is a temporary name given to a table or column. Rename is nothing but replacement of name and Alias is an alternate name of the table or column.
34. What is a View?
View is a logical table which based on one or more tables or views. The tables upon which the view is based are called Base Tables and it doesn’t contain data.
35. What is a cursor variable?
A cursor variable is associated with different statements which can hold different values at run time. A cursor variable is a kind of reference type.
36. What are cursor attributes?
Each cursor in Oracle has set of attributes which enables an application program to test the state of the cursor. The attributes can be used to check whether cursor is opened or closed, found or not found and also find row count.
37. What are SET operators?
SET operators are used with two or more queries and those operators are Union, Union All, Intersect and Minus.
38. What are the different Oracle Database objects?
There are different data objects in Oracle –
  • Tables – set of elements organized in vertical and horizontal
  • Views  – Virtual table derived from one or more tables
  • Indexes – Performance tuning method for processing the records
  • Synonyms – Alias name for tables
  • Sequences – Multiple users generate unique numbers
  • Tablespaces – Logical storage unit in Oracle
39. What are the differences between LOV and List Item?
LOV is property whereas list items are considered as single item. List of items is set to be a collection of list of items. A list item can have only one column, LOV can have one or more columns.
40. What are privileges and Grants?
Privileges are the rights to execute SQL statements – means Right to connect and connect. Grants are given to the object so that objects can be accessed accordingly. Grants can be provided by the owner or creator of an object.
41. What is the difference between $ORACLE_BASE and $ORACLE_HOME?
Oracle base is the main or root directory of an oracle whereas ORACLE_HOME is located beneath base folder in which all oracle products reside.
42. What is the fastest query method to fetch data from the table?
Row can be fetched from table by using ROWID. Using ROW ID is the fastest query method to fetch data from the table.
43. What is the maximum number of triggers that can be applied to a single table?
12 is the maximum number of triggers that can be applied to a single table.
44. How to display row numbers with the records?
Display row numbers with the records numbers –
Select columnName1,columnName2, columnName3....,columnNamen  from table;
This query will display row numbers and the field values from the given table.
45. How can we view last record added to a table?
Last record can be added to a table and this can be done by –

    Select * from (select * from employees order by rownum desc) where rownum<2;

46. How can we delete duplicate rows in a table?
Duplicate rows in the table can be deleted by using ROWID
47. What are the attributes of Cursor?
Attributes of Cursor are
Returns NULL if cursor is open and fetch has not been executed
Returns TRUE if the fetch of cursor is executed successfully.
Returns False if no rows are returned.
Returns NULL if cursor is open and fetch has not been executed
Returns False if fetch has been executed
Returns True if no row was returned
Returns true if the cursor is open
Returns false if the cursor is closed
Returns the number of rows fetched. It has to be iterated through entire cursor to give exact real count.
48. Can we store pictures in the database and if so, how it can be done?
Yes, we can store pictures in the database by Long Raw Data type. This datatype is used to store binary data for 2 gigabytes of length. But the table can have only on Long Raw data type.
49. What is an integrity constraint?
An integrity constraint is a declaration defined a business rule for a table column. Integrity constraints are used to ensure accuracy and consistency of data in a database. There are types – Domain Integrity, Referential Integrity and Domain Integrity.
50. What is an ALERT?
An alert is a window which appears in the center of the screen overlaying a portion of the current display.
51. What is hash cluster?
Hash Cluster is a technique used to store the table for faster retrieval. Apply hash value on the table to retrieve the rows from the table.
52. What are the various constraints used in Oracle?
Following are constraints used:
  • NULL – It is to indicate that particular column can contain NULL values
  • NOT NULL – It is to indicate that particular column cannot contain NULL values
  • CHECK – Validate that values in the given column to meet the specific criteria
  • DEFAULT – It is to indicate the value is assigned to default value
53. What is difference between SUBSTR and INSTR?
SUBSTR returns specific portion of a string and INSTR provides character position in which a pattern is found in a string. SUBSTR returns string whereas INSTR returns numeric.
54. What is the parameter mode that can be passed to a procedure?
IN, OUT and INOUT are the modes of parameters that can be passed to a procedure.
55. What are snap shots and views
Snapshots are mirror or replicas of tables. Views are built using the columns from one or more tables.
56. What is a package cursor ?
A cursor declare in the package specification without an SQL statement. The SQL statement for the cursor is attached at runtime from calling procedures.
57. What is the difference between foreign key and reference key ?
Foreign key is attribute which refers to another table primary key. Reference key is the primary key of table referred by another table.
58. What is the difference between a view and a synonym ?
Synonym is Schema Object,just a second name of table,.View can be created with many tables, and with virtual columns and with conditions.
59. How can you avoid indexes ?
To make index access path unavailable Use FULL hint to optimizer for full table scan Use INDEX or AND-EQUAL hint to optimizer to use one index or set to indexes instead of another
60. When to create indexes ?
To be created when table is queried for less than 2% or 4% to 25% of the table rows.
61. What are the disadvantages of SQL ?
  • Interfacing an SQL database is more complex than adding a few lines of code.
  • When table is dropped view becomes inactive. It depends on the table objects.
  • Although SQL databases conform to ANSI & ISO standards, some databases go for proprietary extensions to standard SQL to ensure vendor lock-in.
  • It is an object so it occupies space.
  • View updation problem
62. What are the various types of RollBack Segments ?
The types of Rollback sagments are as follows :
Public Available to all instances
Private Available to specific instance
63. Can you pass a parameter to a cursor ?
Explicit cursors can take parameters,User create cursor called Explicit Cursor CURSOR c1 (median IN NUMBER) IS SELECT job, ename FROM emp WHERE sal > median;
64. What is the maximum no.of columns a table can have ?
65. What are the states of a rollback segment ? What is the difference between partly available and needs recovery ?
The various states of a rollback segment are :
66. What is the use of Data Dictionary ?
It Used by Oracle to store information about various physical and logical structures e.g.Tables
67. What is the use of Control files ?
Contains pointers to locations of various data files, redo log files, etc.
68. Can you increase the size of a tablespace ? How ?
Yes, by adding datafiles to it.
69. Describe Oracle database's physical and logical structure ?
Physical : Data files, Redo Log files, Control file.
Logical : Tables, Views, Tablespaces, etc.
70. What are constraining triggers ?
A trigger giving an Insert/Updat e on a table having referential integrity constraint on the triggering table.
71. What are mutating triggers ?
A trigger giving a SELECT on the table on which the trigger is written.
72. What are cascading triggers? What is the maximum no of cascading triggers at a time?
When a statement in a trigger body causes another trigger to be fired, the triggers are said to be cascading.Max = 32.
73. What is the advantage of a stored procedure over a database trigger ?
We have control over the firing of a stored procedure but we have no control over the firing of a trigger.
74. What are the various types of database triggers ?
There are 12 types of triggers Insert, Delete and Update Triggers. Before and After Triggers. Row and Statement Triggers.
75. What are the parts of a database trigger ?
A triggering event or statement
A trigger restriction
A trigger action
76. Can you pass parameters in packages ? How ?
Yes.You can pass parameters to procedures or functions in a package.
77. Why Create or Replace and not Drop and recreate procedures ?
So that Grants are not dropped.
78. To select records from the given row?
                        select * from SIVAEMP where rownum < =(select count(*)-&n from SIVAEMP);
79. To check the leap year
                        select decode(mod(2004,4),0,’leap year’, ‘not a leap year’) from dual
80. To delete duplicate records
                        delete from sivaemp where rowid not in(select max(rowid) from sivaemp group by empno)
81. To keep latest single record
                        delete from sivaemp where rowid not in(select min(rowid) from sivaemp group by empno)//to keep oldest record
82. To select second max salary
                        select * from sivaemp where salary = (select max(salary) from sivaemp where salary not in (select max(salary) from sivaemp))
83. To select nth max salary
                        select * from sivaemp a where &n-1 = (select count(*) from sivaemp b where a.salary < b .salary)
                        select * from sivaemp a where &n = (select count(*) from sivaemp b where a.salary < =b.salary)
84. To select nth min salary
                        select * from sivaemp a where &n-1 = (select count(*) from sivaemp b where a.salary > b.salary)
                        select * from sivaemp a where &n = (select count(*) from sivaemp b where a.salary > =b.salary)
85. To select top(n) max salaries
                        select * from sivaemp a where &n > (select count(*) from sivaemp b where a.salary < b .salary)
86. To select top(n) min salaries
select * from sivaemp a where &n > (select count(*) from sivaemp b where a.salary > b.salary)
87. To select records from particular row(the remaining rows)
                        select * from sivaemp minus select * from sivaemp where rownum < = (select count(*)- &n-1 from sivaemp )
88. To select first n rows
                        select * from sivaemp where rownum < = (select count(*) + &n -count(*) from sivaemp)
89. Explain the difference between trigger and stored procedure.
Trigger in act which is performed automatically before or after a event occur when DML operations are occur Trigger is Fire. Stored procedure is a set of functionality which is executed when it is explicitly invoked.
90. Differences between DATE and TIMESTAMP in Oracle
Date is used to store date and time values including month, day, year, century, hours, minutes and seconds. TimeStamp datatype stores everything that Date stores and additionally stores fractional seconds. Date: 11:06:12 Timestamp:11:06:12:
91. Create a copy of EMP table without any data?
                                             CREATE TABLE EMP1 AS SELECT * FROM EMP ;
92. Delete the 10th record of EMP table?
93. Find all the departments which have more than 3 employees?
94. Display the manager who is having maximum number of employees working under him?
                        SELECT DISTINCT M.ENAME, COUNT (E.ENAME)
                        FROM EMP E, EMP M WHERE E.MGR=M.EMPNO
                        GROUP BY M.ENAME HAVING COUNT (E.ENAME) > =ALL
                        (SELECT COUNT (E.ENAME) FROM EMP E, EMP M
                        WHERE E.MGR=M.EMPNO GROUP BY M.ENAME);