Oracle Interview Questions & Answers:-
1.
What is the command to To see
current user name
Sql> show user;
2. How to Change the SQL
prompt name
SQL>
set sqlprompt “Manimara > “
Manimara
>
Manimara
>
3. Command
Switch to DOS prompt
SQL> host
4. How
do I eliminate the duplicate rows in a table ?
SQL> delete from table_name where rowid not in
(select max(rowid) from table group by duplicate_values_field_name);
or
SQL>
delete duplicate_values_field_name dv from table_name ta where rowid
<(select min(rowid) from table_name
tb where ta.dv=tb.dv);
5. How do I
display row number with records?
To achive this use rownum pseudocolumn with
query, like SQL> SQL> select
rownum, ename from emp;
6. Display
the records between two range
select
rownum, empno, ename from emp where
rowid in
(select rowid from emp where rownum
<=&upto
minus
select rowid from emp where
rownum<&Start);
Enter value for upto: 10
7. I know the nvl function
only allows the same data type(ie. number or char or date Nvl(comm, 0)), if
commission is null then the text “Not Applicable” want to display, instead of blank space. How
do I write the query?
SQL> select nvl(to_char(comm.),'NA') from
emp;
Output
:
NVL(TO_CHAR(COMM),'NA')
-----------------------
NA
300
500
NA
1400
NA
NA
8. Oracle cursor : Implicit
& Explicit cursors
Oracle
uses work areas called private SQL areas to create SQL statements.
PL/SQL
construct to identify each and every work are used, is called as Cursor.
For
SQL queries returning a single row, PL/SQL declares all implicit cursors.
For
queries that returning more than one row, the cursor needs to be explicitly
declared.
9. Explicit Cursor attributes
There are four cursor attributes used in
Oracle
cursor_name%Found,
cursor_name%NOTFOUND, cursor_name%ROWCOUNT, cursor_name%ISOPEN
10. Implicit
Cursor attributes
Same as explicit cursor but prefixed by the
word SQL
SQL%Found,
SQL%NOTFOUND, SQL%ROWCOUNT, SQL%ISOPEN
Tips
: 1. Here SQL%ISOPEN is false, because oracle automatically closed the implicit
cursor after executing SQL statements.
2.
All are Boolean attributes.
11. Find
out nth highest salary from emp table
SELECT DISTINCT (a.sal) FROM EMP A WHERE &N =
(SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
Enter value for n: 2
SAL
---------
3700
12. To
view installed Oracle version information
SQL> select banner from v$version;
13.
Display the number value in Words
SQL>
select sal, (to_char(to_date(sal,'j'), 'jsp'))
from
emp;
the
output like,
SAL (TO_CHAR(TO_DATE(SAL,'J'),'JSP'))
---------
-----------------------------------------------------
800 eight hundred
1600 one thousand six hundred
1250 one thousand two hundred fifty
If
you want to add some text like,
Rs. Three Thousand only.
SQL> select sal
"Salary ",
(' Rs. '||
(to_char(to_date(sal,'j'), 'Jsp'))|| ' only.'))
"Sal
in Words" from emp
/
Salary Sal in Words
-------
------------------------------------------------------
800 Rs.
Eight Hundred only.
1600 Rs. One Thousand Six Hundred only.
1250 Rs. One Thousand Two Hundred Fifty only.
14. Display
Odd/ Even number of records
Odd
number of records:
select
* from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp);
1
3
5
Even
number of records:
select
* from emp where (rowid,0) in (select rowid, mod(rownum,2) from emp)
2
4
6
15. Which
date function returns number value?
months_between
16. Any
three PL/SQL Exceptions?
Too_many_rows, No_Data_Found, Value_Error,
Zero_Error, Others
17. What are PL/SQL Cursor
Exceptions?
Cursor_Already_Open,
Invalid_Cursor
18. Other way to replace query
result null value with a text
SQL> Set NULL ‘N/A’
to
reset SQL> Set NULL ‘’
19. What
are the more common pseudo-columns?
SYSDATE, USER , UID, CURVAL, NEXTVAL, ROWID,
ROWNUM
20. What
is the output of SIGN function?
1
for positive value,
0
for Zero,
-1
for Negative value.
21. What is the maximum number of
triggers, can apply to a single table?
12 triggers.
22) What
is a relational database management system?
When
answering these types of questions you need to answer them in a very detailed
manner because everyone in your group can answer them without any difficulty.
There should be difference between your approach and the other candidates.
Interview candidate should try to present all the information he has in a very
detailed and step by step manner. A professional approach should be present.
23) What
do you know about normalization? Explain in detail?
24) Explain
the difference between a procedure and a function? What do you understand by
those terms?
25) Explain
about functional dependency and its relation with table design?
26) Explain
the different normalization forms?
Remember
how you answer shortens your technical interview you are trying to convince the
interviewer that you are a suitable candidate for the job.
27) What
is a cursor and what are the steps need to be taken?
If
possible while answering this question try to explain him the various steps in
an order.
28)
What are the various types of
queries in Oracle ?
The types of queries
are:
·
Normal Queries
·
Sub Queries
·
Co-related
queries
·
Nested queries
·
Compound queries
29) What
are the components of physical database structure of Oracle database?
Oracle database is comprised of three types of files. One or more datafiles, two are more redo log files, and one or more control files.
Oracle database is comprised of three types of files. One or more datafiles, two are more redo log files, and one or more control files.
30) What
are actual and formal parameters ?
Actual Parameters : Subprograms pass information using parameters.The variables or expressions referenced in the parameter list of a subprogram call are actual parameters.For example, the following procedure call lists two actual parameters named emp_num and amount:
Eg.raise_salary(emp_num, amount);
Formal Parameters : The variables declared in a subprogram specification and referenced in the subprogram body are formal parameters.For example, the following procedure declares two formal parameters named emp_id and increase:
Eg.PROCEDURE raise_salary (emp_id INTEGER, increase REAL) IS current_salary REAL;
Actual Parameters : Subprograms pass information using parameters.The variables or expressions referenced in the parameter list of a subprogram call are actual parameters.For example, the following procedure call lists two actual parameters named emp_num and amount:
Eg.raise_salary(emp_num, amount);
Formal Parameters : The variables declared in a subprogram specification and referenced in the subprogram body are formal parameters.For example, the following procedure declares two formal parameters named emp_id and increase:
Eg.PROCEDURE raise_salary (emp_id INTEGER, increase REAL) IS current_salary REAL;
31) What
are various types of joins in Oracle ?
Types of joins are:
Types of joins are:
·
Equijoins
·
Non-equijoins
·
self join
·
outer join
31) What
are the components of logical database structure of Oracle database?
There are tablespaces and database’s schema objects.
There are tablespaces and database’s schema objects.
32) What’s
the length of SQL integer?
32 bit
32 bit
33) What
is a tablespace?
A database is divided into Logical Storage Unit called tablespaces. A tablespace is used to grouped related logical structures together.
A database is divided into Logical Storage Unit called tablespaces. A tablespace is used to grouped related logical structures together.
34) What is an oracle instance?
35) What is an Archiver in Oracle?
36) What is a partition of table in Oracle?
35) What is an Archiver in Oracle?
36) What is a partition of table in Oracle?
37) What
is a transaction in Oracle ?
A transaction is a set of SQL statements between any two COMMIT and ROLLBACK statements.
A transaction is a set of SQL statements between any two COMMIT and ROLLBACK statements.
38) What
is SYSTEM tablespace and when is it created?
Every Oracle database contains a tablespace named SYSTEM, which is automatically created when the database is created. The SYSTEM tablespace always contains the data dictionary tables for the entire database.
Every Oracle database contains a tablespace named SYSTEM, which is automatically created when the database is created. The SYSTEM tablespace always contains the data dictionary tables for the entire database.
39) Explain
the relationship among database, tablespace and data file ?
Each databases logically divided into one or more tablespaces one or more data files are explicitly created for each tablespace.
Each databases logically divided into one or more tablespaces one or more data files are explicitly created for each tablespace.
40) What
are the various types of Exceptions in Oracle ?
User defined Exceptions
Predefined Exceptions
User defined Exceptions
Predefined Exceptions
41) What
is implicit cursor and how is it used by Oracle ?
An implicit cursor is a cursor which is internally created by Oracle.It is created by Oracle for each individual SQL
An implicit cursor is a cursor which is internally created by Oracle.It is created by Oracle for each individual SQL
42) What
is schema?
A schema is collection of database objects of a user.
A schema is collection of database objects of a user.
43) What
are the types of Notation in Oracle ?
Position, Named, Mixed and Restrictions.
Position, Named, Mixed and Restrictions.
44) What is an exception in Oracle?
45) What is a synonym in Oracle?
46) What is a join, and what are the different types of joins in Oracle?
45) What is a synonym in Oracle?
46) What is a join, and what are the different types of joins in Oracle?
47) What
are Schema Objects?
Schema objects are the logical structures that directly refer to the database’s data. Schema objects include tables, views, sequences, synonyms, indexes, clusters, database triggers, procedures, functions packages and database links.
Schema objects are the logical structures that directly refer to the database’s data. Schema objects include tables, views, sequences, synonyms, indexes, clusters, database triggers, procedures, functions packages and database links.
48) Can
objects of the same schema reside in different tablespaces?
Yes.
Yes.
49) Can
a tablespace hold objects from different schemes?
Yes.
Yes.
50) What
is Oracle table?
A table is the basic unit of data storage in an Oracle database. The tables of a database hold all of the user accessible data. Table data is stored in rows and columns.
A table is the basic unit of data storage in an Oracle database. The tables of a database hold all of the user accessible data. Table data is stored in rows and columns.
51) What
is an Oracle view?
A view is a virtual table. Every view has a query attached to it. (The query is a SELECT statement that identifies the columns and rows of the table(s) the view uses.)
A view is a virtual table. Every view has a query attached to it. (The query is a SELECT statement that identifies the columns and rows of the table(s) the view uses.)
52) What
is Partial Backup ?
A Partial Backup is any operating system backup short of a full backup, taken while the database is open or shut down.
A Partial Backup is any operating system backup short of a full backup, taken while the database is open or shut down.
53) What is Mirrored on-line Redo Log ?
A mirrored on-line redo log consists of
copies of on-line redo log files physically located on separate disks, changes
made to one member of the group are made to all members.
54) What are the various types of parameter
modes in a procedure in Oracle ?
·
IN
·
OUT
·
INOUT
55) What
is Full Backup ?
A full backup is an operating system backup of all data files, on-line redo log files and control file that constitute ORACLE database and the parameter.
A full backup is an operating system backup of all data files, on-line redo log files and control file that constitute ORACLE database and the parameter.
56) Can
a View based on another View ?
Yes.
Yes.
57) What is the use of
Control File ?
When an instance of an ORACLE database is started, its control file is used to identify the database and redo log files that must be opened for database operation to proceed. It is also used in database recovery.
When an instance of an ORACLE database is started, its control file is used to identify the database and redo log files that must be opened for database operation to proceed. It is also used in database recovery.
58) ODBC stands for?
59) What is mean by de-normalization?
59) What is mean by de-normalization?
60) Do
View contain Data ?
Views do not contain or store data.
Views do not contain or store data.
61) What
are the Referential actions supported by FOREIGN KEY integrity constraint ?
UPDATE and DELETE Restrict - A referential integrity rule that disallows the update or deletion of referenced data. DELETE Cascade - When a referenced row is deleted all associated dependent rows are deleted.
UPDATE and DELETE Restrict - A referential integrity rule that disallows the update or deletion of referenced data. DELETE Cascade - When a referenced row is deleted all associated dependent rows are deleted.
62) What
are the type of Synonyms?
There are two types of Synonyms Private and Public.
There are two types of Synonyms Private and Public.
63) What
is a Redo Log ?
The set of Redo Log files YSDATE,UID,USER or USERENV SQL functions, or the pseudo columns LEVEL or ROWNUM.
The set of Redo Log files YSDATE,UID,USER or USERENV SQL functions, or the pseudo columns LEVEL or ROWNUM.
64) What
is an Index Segment ?
Each Index has an Index segment that stores all of its data.
Each Index has an Index segment that stores all of its data.
65) What is a cursor?
66) Advantages of redo log files?
67) What is referential integrity?
66) Advantages of redo log files?
67) What is referential integrity?
68) What
are the different type of Segments ?
Data Segment, Index Segment, Rollback Segment and Temporary Segment.
Data Segment, Index Segment, Rollback Segment and Temporary Segment.
69) What
are Clusters ?
Clusters are groups of one or more tables physically stores together to share common columns and are often used together.
Clusters are groups of one or more tables physically stores together to share common columns and are often used together.
70) What
is an Index ?
An Index is an optional structure associated with a table to have direct access to rows, which can be created to increase the performance of data retrieval. Index can be created on one or more columns of a table.
An Index is an optional structure associated with a table to have direct access to rows, which can be created to increase the performance of data retrieval. Index can be created on one or more columns of a table.
71) What is an Extent ?
An Extent is a specific number of contiguous data blocks, obtained in a single allocation, and
An Extent is a specific number of contiguous data blocks, obtained in a single allocation, and
used to store a specific type of information.
72) What
is Table ?
A table is the basic unit of data storage in an ORACLE database. The tables of a database hold all of the user accessible data. Table data is stored in rows and columns.
A table is the basic unit of data storage in an ORACLE database. The tables of a database hold all of the user accessible data. Table data is stored in rows and columns.
73) What
are the advantages of views?
- Provide an additional level of table security, by restricting access to a predetermined set of rows and columns of a table.
- Hide data complexity.
- Simplify commands for the user.
- Present the data in a different perspective from that of the base table.
- Store complex queries.
- Provide an additional level of table security, by restricting access to a predetermined set of rows and columns of a table.
- Hide data complexity.
- Simplify commands for the user.
- Present the data in a different perspective from that of the base table.
- Store complex queries.
74) What
is an Oracle sequence?
A sequence generates a serial list of unique numbers for numerical columns of a database’s tables.
A sequence generates a serial list of unique numbers for numerical columns of a database’s tables.
75) What
is a synonym?
A synonym is an alias for a table, view, sequence or program unit.
A synonym is an alias for a table, view, sequence or program unit.
76) What
is a private synonym?
Only its owner can access a private synonym.
Only its owner can access a private synonym.
77) What
is a public synonym?
Any database user can access a public synonym.
Any database user can access a public synonym.
78) What
are synonyms used for?
- Mask the real name and owner of an object.
- Provide public access to an object
- Provide location transparency for tables, views or program units of a remote database.
- Simplify the SQL statements for database users.
- Provide public access to an object
- Provide location transparency for tables, views or program units of a remote database.
- Simplify the SQL statements for database users.
79) How
are the index updates?
Indexes are automatically maintained and used by Oracle. Changes to table data are automatically incorporated into all relevant indexes.
Indexes are automatically maintained and used by Oracle. Changes to table data are automatically incorporated into all relevant indexes.
80) Describe
the Normalization principles?
81) What
is Rollback Segment ?
A Database contains one or more Rollback Segments to temporarily store “undo” information.
A Database contains one or more Rollback Segments to temporarily store “undo” information.
82) What
are the Characteristics of Data Files ?
A data file can be associated with only one database. Once created a data file can’t change size. One or more data files form a logical unit of database storage called a tablespace.
A data file can be associated with only one database. Once created a data file can’t change size. One or more data files form a logical unit of database storage called a tablespace.
83) How
to define Data Block size ?
A data block size is specified for each ORACLE database when the database is created. A database users and allocated free database space in ORACLE data blocks. Block size is specified in INIT.ORA file and can’t be changed latter.
A data block size is specified for each ORACLE database when the database is created. A database users and allocated free database space in ORACLE data blocks. Block size is specified in INIT.ORA file and can’t be changed latter.
84) What
does a Control file Contain ?
A Control file records the physical structure of the database. It contains the following information.
Database Name
Names and locations of a database’s files and redolog files.
Time stamp of database creation.
A Control file records the physical structure of the database. It contains the following information.
Database Name
Names and locations of a database’s files and redolog files.
Time stamp of database creation.
85) What is difference between UNIQUE
constraint and PRIMARY KEY constraint ?
A column defined as UNIQUE can contain
Nulls while a column defined as PRIMARY KEY can’t contain Nulls.
86) When
does a Transaction end ?
When it is committed or Rollbacked.
When it is committed or Rollbacked.
87) How
does one create a new database? (for DBA)
One can create and modify Oracle databases using the Oracle “dbca” (Database Configuration Assistant) utility. The dbca utility is located in the $ORACLE_HOME/bin directory. The Oracle Universal Installer (oui) normally starts it after installing the database server software.
One can also create databases manually using scripts. This option, however, is falling out of fashion, as it is quite involved and error prone
One can create and modify Oracle databases using the Oracle “dbca” (Database Configuration Assistant) utility. The dbca utility is located in the $ORACLE_HOME/bin directory. The Oracle Universal Installer (oui) normally starts it after installing the database server software.
One can also create databases manually using scripts. This option, however, is falling out of fashion, as it is quite involved and error prone
88) What is a database buffer cache in Oracle?
Use the same extent size for all the
segments in a given tablespace. Locally Managed tablespaces (available from 8i
onwards) with uniform extent sizes virtually eliminates any tablespace
fragmentation. Note that the number of extents per segment does not cause any
performance issue anymore, unless they run into thousands and thousands where
additional I/O may be required to fetch the additional blocks where extent maps
of the segment are stored.
89) What
does COMMIT do ?
COMMIT makes permanent the changes resulting from all SQL statements in the transaction. The changes made by the SQL statements of a transaction become visible to other user sessions transactions that start only after transaction is committed.
COMMIT makes permanent the changes resulting from all SQL statements in the transaction. The changes made by the SQL statements of a transaction become visible to other user sessions transactions that start only after transaction is committed.
90) Define
Transaction ?
A Transaction is a logical unit of work that comprises one or more SQL statements executed by a single user.
A Transaction is a logical unit of work that comprises one or more SQL statements executed by a single user.
91) What is Read-Only Transaction ?
A Read-Only transaction ensures that the results of each query executed in the transaction are
A Read-Only transaction ensures that the results of each query executed in the transaction are
consistant with respect to the same point in time.
92) What is a deadlock ? Explain .
Two processes wating to update the rows of a table which are locked by the other process then deadlock arises. In a database environment this will often happen because of not issuing proper row lock commands. Poor design of front-end application may cause this situation and the performance of server will reduce drastically.These locks will be released automatically when a commit/rollback operation performed or any one of this processes being
killed externally.
Two processes wating to update the rows of a table which are locked by the other process then deadlock arises. In a database environment this will often happen because of not issuing proper row lock commands. Poor design of front-end application may cause this situation and the performance of server will reduce drastically.These locks will be released automatically when a commit/rollback operation performed or any one of this processes being
killed externally.
No comments:
Post a Comment