Oracle Interview
Oracle Interview
1.
2.
You have just had to restore from backup and do not have
any control files. How would you go about bringing up this
database?
I would create a text based backup control file, stipulating where
on disk all the data files where and then issue the recover
command with the using backup control file clause.
3.
4.
6.
Where would you look for errors from the database engine?
In the alert log.
7.
Compare and contrast TRUNCATE and DELETE for a
table.
Both the truncate and delete command have the desired outcome
of getting rid of all the rows in a table. The difference between
the two is that the truncate command is a DDL operation and
just moves the high water mark and produces a now rollback.
The delete command, on the other hand, is a DML operation,
which will produce a rollback and thus take longer to complete.
8.
9.
10.
11.
Explain an ORA-01555
You get this error when you get a snapshot too old within
rollback. It can usually be solved by increasing the undo
retention or increasing the size of rollbacks. You should also
look at the logic involved in the application getting the error
message.
What is a mutating table error and how can you get around
it?
This happens with triggers. It occurs because the trigger is trying
to update a row it is currently using. The usual fix involves
4.
5.
6.
7.
8.
9.
10.
11.
3.
4.
6.
7.
8.
You use the ALTER TABLE command for both. However, for
the enable clause you must specify the USING INDEX and
TABLESPACE clause for primary keys.
9.
10. (On UNIX) When should more than one DB writer process
be used? How many should be used
If the UNIX system being used is capable of asynchronous IO
then only one is required, if the system is not capable of
asynchronous IO then up to twice the number of disks used by
Oracle number of DB writers should be specified by use of the
db_writers initialization parameter.
11. You are using hot backup without being in archivelog mode,
can you recover in the event of a failure? Why or why not
You can?t use hot backup without being in archivelog mode. So
no, you couldn?t recover.
12. What causes the "snapshot too old" error? How can this be
prevented or mitigated
This is caused by large or long running transactions that have
either wrapped onto their own rollback space or have had
another transaction write on part of their rollback space. This
can be prevented or mitigated by breaking the transaction into a
using and ratio the number of rows in the table to its number of
blocks against the number of expected rows.
16. How can you find out how many users are currently logged
into the database? How can you find their operating system id
There are several ways. One is to look at the v$session or
v$process views. Another way is to check the current_logins
parameter in the v$sysstat view. Another if you are on UNIX is
to do a "ps -ef|grep oracle|wc -l? command, but this only works
against a single instance installation.
17. A user selects from a sequence and gets back two values, his
select is:
SELECT pk_seq.nextval FROM dual;What is the problem
Somehow two values have been inserted into the dual table. This
table is a single row, single column table that should only have
one value in it.
18. How can you determine if an index needs to be dropped and
rebuilt
Run the ANALYZE INDEX command on the index to validate
its structure and then calculate the ratio of
LF_BLK_LEN/LF_BLK_LEN+BR_BLK_LEN and if it isn?t
near 1.0 (i.e. greater than 0.7 or so) then the index should be
rebuilt. Or if the ratio
BR_BLK_LEN/ LF_BLK_LEN+BR_BLK_LEN is nearing 0.3
1.
How can variables be passed to a SQL routine
By use of the & symbol. For passing in variables the numbers 18 can be used (&1, &2,...,&8) to pass the values after the
command into the SQLPLUS session. To be prompted for a
3.
4.
5.
You want to use SQL to build SQL, what is this called and
give an example
This is called dynamic SQL. An example would be:
set lines 90 pages 0 termout off feedback off verify off
spool drop_all.sql
select ?drop user ?||username||? cascade;? from dba_users
where username not in ("SYS?,?SYSTEM?);
spool off
Essentially you are looking to see that they know to include a
command (in this case DROP USER...CASCADE;) and that you
need to concatenate using the ?||? the values selected from the
database.
6.
7.
8.
9.
command. Once the trace file is generated you run the tkprof
tool against the trace file and then look at the output from the
tkprof tool. This can also be used to generate explain plan
output.
13.
1.
2.
3.
4.
5.
6.
7.
8.
9.
If you see contention for library caches how can you fix it
Increase the size of the shared pool.
15. If you see statistics that deal with "undo" what are they
really talking about
Rollback segments and associated structures.
16. If a tablespace has a default pctincrease of zero what will
this cause (in relationship to the smon process)
The SMON process won?t automatically coalesce its free space
fragments.
17. If a tablespace shows excessive fragmentation what are some
methods to defragment the tablespace? (7.1,7.2 and 7.3 only)
In Oracle 7.0 to 7.2 The use of the 'alter session set events
'immediate trace name coalesce level ts#';? command is the
easiest way to defragment contiguous free space fragmentation.
The ts# parameter corresponds to the ts# value found in the ts$
SYS table. In version 7.3 the ?alter tablespace coalesce;? is best.
If the free space isn?t contiguous then export, drop and import of
the tablespace contents may be the only way to reclaim noncontiguous free space.
18.
19.
20. What can cause a high value for recursive calls? How can
this be fixed
A high value for recursive calls is cause by improper cursor
usage, excessive dynamic space management actions, and or
excessive statement re-parses. You need to determine the cause
and correct it By either relinking applications to hold cursors,
use proper space management techniques (proper storage and
sizing) or ensure repeat queries are placed in packages for
proper reuse.
21. If you see a pin hit ratio of less than 0.8 in the estat library
cache report is this a problem? If so, how do you fix it
This indicate that the shared pool may be too small. Increase the
shared pool size.
22. If you see the value for reloads is high in the estat library
cache report is this a matter for concern
Yes, you should strive for zero reloads if possible. If you see
excessive reloads then increase the size of the shared pool.
23. You look at the dba_rollback_segs view and see that there is
a large number of shrinks and they are of relatively small size,
is this a problem? How can it be fixed if it is a problem
A large number of small shrinks indicates a need to increase the
size of the rollback segment extents. Ideally you should have no
shrinks or a small number of large shrinks. To fix this just
increase the size of the extents and adjust optimal accordingly.
24. You look at the dba_rollback_segs view and see that you
have a large number of wraps is this a problem
A large number of wraps indicates that your extent size for your
rollback segments are probably too small. Increase the size of
your extents to reduce the number of wraps. You can look at the
average transaction size in the same view to get the information
on transaction size.
25. In a system with an average of 40 concurrent users you get
the following from a query on rollback extents:
ROLLBACK CUR EXTENTS
--------------------- -------------------------R01 11
R02 8
R03 12
R04 9
SYSTEM 4
26. You have room for each to grow by 20 more extents each. Is
there a problem? Should you take any action
No there is not a problem. You have 40 extents showing and an
average of 40 concurrent users. Since there is plenty of room to
grow no action is needed.
27. You see multiple extents in the temporary tablespace. Is this
a problem
As long as they are all the same size this isn?t a problem. In fact,
it can even improve performance since Oracle won?t have to
create a new extent when a user needs one.
28.
Define OFA.
OFA stands for Optimal Flexible Architecture. It is a method of
placing directories and files in an Oracle system so that you get
the maximum flexibility for future tuning and file placement.
29.
42.
43.
What is an ERD
An ERD is an Entity-Relationship-Diagram. It is used to show
the entities and relationships for a database logical model.
50.
51. Users from the PC clients are getting the following error
stack:
ERROR: ORA-01034: ORACLE not available
ORA-07318: smsget: open error when opening sgadef.dbf
file.
HP-UX Error: 2: No such file or directory
What is the probable cause
The Oracle instance is shutdown that they are trying to access,
restart the instance.
52. How can you determine if the SQLNET process is running
for SQLNET V1? How about V2
For SQLNET V1 check for the existence of the orasrv process.
You can use the command "tcpctl status" to get a full status of
the V1 TCPIP server, other protocols have similar command
formats. For SQLNET V2 check for the presence of the
LISTENER process(s) or you can issue the command "lsnrctl
status".
53. What file will give you Oracle instance status information?
Where is it located
The alert.ora log. It is located in the directory specified by the
background_dump_dest parameter in the v$parameter table.
54. Users aren?t being allowed on the system. The following
message is received:
ORA-00257 archiver is stuck. Connect internal only, until
freed
What is the problem
The archive destination is probably full, backup the archive logs
and remove them and the archiver will re-start.
55. Where would you look to find out if a redo log was
corrupted assuming you are using Oracle mirrored redo logs
There is no message that comes to the SQLDBA or SRVMGR
programs during startup in this situation, you must check the
alert.log file for this information.
56.
57. You look at your fragmentation report and see that smon
hasn?t coalesced any of you tablespaces, even though you know
several have large chunks of contiguous free extents. What is
the problem
Check the dba_tablespaces view for the value of pct_increase for
the tablespaces. If pct_increase is zero, smon will not coalesce
their free space.
58.
59. You get a call from you backup DBA while you are on
vacation. He has corrupted all of the control files while playing
with the ALTER DATABASE BACKUP CONTROLFILE
command. What do you do
As long as all datafiles are safe and he was successful with the
BACKUP controlfile command you can do the following:
CONNECT INTERNAL
STARTUP MOUNT
(Take any read-only tablespaces offline before next step ALTER
DATABASE DATAFILE .... OFFLINE;)
RECOVER DATABASE USING BACKUP CONTROLFILE
ALTER DATABASE OPEN RESETLOGS;
(bring read-only tablespaces back online)
Shutdown and backup the system, then restart
1.
2.
3.
4.
5.
where
field1=X.field1);
6.
7.
8.
9.
11. What are various privileges that a user can grant to another
user
SELECT
CONNECT
RESOURCE
12. What is difference between UNIQUE and PRIMARY KEY
constraints
A table can have only one PRIMARY KEY whereas there can be
any number of UNIQUE keys. The columns that compose PK are
automatically define NOT NULL, whereas a column that compose
a UNIQUE is not automatically defined to be mandatory must also
specify the column is NOT NULL.
13. Can a primary key contain more than one columns
Yes
14. How you will avoid duplicating records in a query
By using DISTINCT
15. What is difference between SQL and SQL*PLUS
SQL*PLUS is a command line tool where as SQL and PL/SQL
language interface and reporting tool. Its a command line tool that
allows user to type SQL commands to be executed directly against
an Oracle database. SQL is a language used to query the relational
database(DML,DCL,DDL). SQL*PLUS commands are used to
format query result, Set options, Edit SQL commands and
PL/SQL.
16. Which datatype is used for storing graphics and images
LONG RAW data type is used for storing BLOB's (binary large
objects).
17. How will you delete duplicating rows from a base table
DELETE FROM table_name A WHERE rowid>(SELECT
min(rowid) from table_name B where B.table_no=A.table_no);
querydoes not match any rows. When the where clause of the
explicit cursor does not match any rows the %NOTFOUND
attribute is set to TRUE instead.
32. What a SELECT FOR UPDATE cursor represent.
SELECT......FROM......FOR......UPDATE[OF column-reference]
[NOWAIT] The processing done in a fetch loop modifies the rows
that have been retrieved by the cursor.
A convenient way of modifying the rows is done by a method with
two parts: the FOR UPDATE clause in the cursor declaration,
WHERE CURRENT OF CLAUSE in an UPDATE or declaration
statement.
33.
34.
LOOP
35.
SELECT num_credits INTO v_numcredit
s FROM classes
36.
37.
UPDATE students
38.
SET
current_credits=current_credits+v_numcredits
39.
WHERE CURRENT OF X;
40.
END LOOP
41.
COMMIT;
END;
time, which can hold different values at run time. Static cursors
can only be associated with one run time query. A cursor variable
is reference type(like a pointer in C).
Declaring a cursor variable: TYPE type_name IS REF CURSOR
RETURN return_type type_name is the name of the reference
type,return_type is a record type indicating the types of the select
list that will eventually be returned by the cursor variable.
43. What should be the return type for a cursor variable.Can
we use a scalar data type as return type.
The return type for a cursor must be a record type.It can be
declared explicitly as a user-defined or %ROWTYPE can be used.
eg TYPE t_studentsref IS REF CURSOR RETURN students
%ROWTYPE
44. How you open and close a cursor variable.Why it is
required.
OPEN cursor variable FOR SELECT...Statement CLOSE cursor
variable In order to associate a cursor variable with a particular
SELECT statement OPEN syntax is used.In order to free the
resources used for the query CLOSE statement is used.
45. How you were passing cursor variables in PL/SQL 2.2.
In PL/SQL 2.2 cursor variables cannot be declared in a
package.This is because the storage for a cursor variable has to be
allocated using Pro*C or OCI with version 2.2,the only means of
passing a cursor variable to a PL/SQL block is via bind variable or
a procedure parameter.
46. Can cursor variables be stored in PL/SQL tables.If yes
how.If not why.
No, a cursor variable points a row which cannot be stored in a twodimensional PL/SQL table.
47. Difference between procedure and function.
Functions are named PL/SQL blocks that return a value and can be
55.
59.
60.
61.
62.
-execute statements
63.
8.
9.