You are on page 1of 34

First Job…. Dream Job…. Sparshme5.googlepages.

com

Oracle Sample Questions : SQL*Net


1. What is SQL*Net?

Answer: SQL*NET is Oracle's client/server middleware product that offers


transparent connection from client tools to the database or from one database to
another.

2. What is TNS?

Answer: TNS or Transparent Network Substrate is Oracle's networking


architecture.TNS provides a uniform application interface to enable network
applications to access the underlying network protocols transparently.

The TNS architecture consists of three software components: TNS-based


applications, Oracle Protocol Adapters, and networking software like TCP/IP.

3. How does one configure SQL*Net?

Answer: Most people prefer to edit the SQL*Net configuration files by hand.The
only "officially supported" configuration method, however, is via the Oracle Network
Manager utility.

4. How can I produce a trace file?

Answer: Create/edit your SQLNET.ORA file.You will find the SQLNET.ORA file in
one of the following locations (SQL*Net V2 searches for it in this order):

 Directory pointed to by the TNS_ADMIN parameter ($TNS_ADMIN on


Unix)
 /var/opt/oracle (Unix only)
 $ORACLE_HOME\network\admin directory

It should contain the following lines to produce a trace file:

trace_level_client=16

trace_unique_client=yes

5. How can I set up a dedicated server?

Answer: Set the dedicated server option in your database connects string.ie.

SQLPLUS SCOTT/TIGER@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(PORT=1521)

(NODE=yourServerName)) (CONNECT_DATA=(SID=yourSid)
(SERVER=DEDICATED)))

http://sparshme5.googlepages.com
1
First Job…. Dream Job…. Sparshme5.googlepages.com

or edit your TNSNAMES.ORA file and add the (SERVER=DEDICATED) part in


the CONNECT_DATA list.

6. Can I upgrade to SQL*Net V2 if I still have V1 clients?

Answer: SQL*Net V1 cannot talk with SQL*Net V2, and vice versa.The only way to
overcome this problem is to run SQL*Net V1 and V2 simultaneously on the same
database server.You can then install SQL*Net V2 on your clients as time
permits.SQL*Net V1 and V2 can coexist on the same server, or on the same client.
You can also list V1 connect strings in your TNSNAMES.ORA file.
Eg:

ORA1_NET1 = T:machine_name/port:database_name

7. How can I enable dead connection detection?

Answer: Dead database connections can be detected and killed by SQL*Net if you
specify the SQLNET.EXPIRE_TIME=n parameter in your SQLNET.ORA file.This
parameter will instruct SQL*Net to send a probe through the network to the client
every n minutes, if the client doesn't respond, it will be killed.

8. What different protocol drivers are supported?

Answer: These are the main SQL*Net protocol adapters supported by Oracle:

 VTAM
IBM's
 DEC Net
 IBM's LU 6.2
 Named Pipes
 TCP/IP
 Novell's IPX/SPX
 IBM MVS Cross Memory
 NetBEUI
9. Can one get connected to a database regardless of machine failure?

Answer: With SQL*Net V2 you can connect to a database, even if some kind of
physical failover occurred.Look at the following example:

oradb1 = (DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS =

(COMMUNITY = TCP_COMM)

(PROTOCOL = TCP)

(HOST = Machine01))

http://sparshme5.googlepages.com
2
First Job…. Dream Job…. Sparshme5.googlepages.com

(ADDRESS =

(COMMUNITY = TCP_COMM)

(PROTOCOL = TCP)

(HOST = Machine02)))

{CONNECT_DATA=(

(SID=oradb1))))

Suppose Machine01 is down, then every new SQL*NET connection using service
oradb1 will automatically login to Machine02.However, there is one restriction, the
SID must be the same on both machines.This feature can provide guaranteed login
for application servers and the Oracle Parallel Server.

 What is SQL?

Answer: Structured Query Language (SQL) is a language that provides an interface to


relational database systems.
In common usage SQL also encompasses DML (Data Manipulation Language), for
INSERTs, UPDATEs, DELETEs and DDL (Data Definition Language), used for creating and
modifying tables and other database structures.

 What is SELECT statement?

Answer: The SELECT statement lets you select a set of values from a table in a database.The
values selected from the database table would depend on the various conditions that are
specified in the SQL query.

 How can you compare a part of the name rather than the entire name?

Answer: SELECT * FROM people WHERE empname LIKE '%ab%'Would return a


recordset with records consisting empname the sequence 'ab' in empname.

 What is the INSERT statement?

Answer: The INSERT statement lets you insert information into a database.

 How do you delete a record from a database?

Answer: Use the DELETE statement to remove records or any particular column values from
a database.

 How could I get distinct entries from a table?

http://sparshme5.googlepages.com
3
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: The SELECT statement in conjunction with DISTINCT lets you select a set of
distinct values from a table in a database.The values selected from the database table would
of course depend on the various conditions that are specified in the SQL
query.ExampleSELECT DISTINCT empname FROM emptable

 How to get the results of a Query sorted in any order?

Answer: You can sort the results and return the sorted results to your program by using
ORDER BY keyword thus saving you the pain of carrying out the sorting yourself.The
ORDER BY keyword is used for sorting.SELECT empname, age, city FROM emptable
ORDER BY empname

 How can I find the total number of records in a table?

Answer: You could use the COUNT keyword , exampleSELECT COUNT(*) FROM emp
WHERE age>40

 What is GROUP BY?

Answer: The GROUP BY keywords have been added to SQL because aggregate functions
(like SUM) return the aggregate of all column values every time they are called.Without the
GROUP BY functionality, finding the sum for each individual group of column values was
not possible.

 What is the difference among "dropping a table", "truncating a table" and "deleting
all records" from a table.

Answer: Dropping : (Table structure + Data are deleted), Invalidates the dependent objects
,Drops the indexes Truncating: (Data alone deleted), Performs an automatic commit, Faster
than deleteDelete : (Data alone deleted), Doesn't perform automatic commit

 What are the Large object types suported by Oracle?

Answer: Blob and Clob.

 Difference between a "where" clause and a "having" clause.

Answer: Having clause is used only with group functions whereas Where is not used with.

 What's the difference between a primary key and a unique key?

Answer: Both primary key and unique enforce uniqueness of the column on which they are
defined.But by default primary key creates a clustered index on the column, where are unique
creates a nonclustered index by default.Another major difference is that, primary key doesn't
allow NULLs, but unique key allows one NULL only.

 What are cursors? Explain different types of cursors.What are the disadvantages of
cursors? How can you avoid cursors?

http://sparshme5.googlepages.com
4
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: Cursors allow row-by-row prcessing of the resultsets.Types of cursors: Static,


Dynamic, Forward-only, Keyset-driven.See books online for more
information.Disadvantages of cursors: Each time you fetch a row from the cursor, it results in
a network roundtrip, where as a normal SELECT query makes only one rowundtrip, however
large the resultset is.Cursors are also costly because they require more resources and
temporary storage (results in more IO operations).Furthere, there are restrictions on the
SELECT statements that can be used with some types of cursors.Most of the times, set based
operations can be used instead of cursors.

 What are triggers? How to invoke a trigger on demand?

Answer: Triggers are special kind of stored procedures that get executed automatically when an
INSERT, UPDATE or DELETE operation takes place on a table.Triggers can't be invoked on
demand.They get triggered only when an associated action (INSERT, UPDATE, DELETE)
happens on the table on which they are defined.Triggers are generally used to implement
business rules, auditing.Triggers can also be used to extend the referential integrity checks,
but wherever possible, use constraints for this purpose, instead of triggers, as constraints are
much faster.

 What is a join and explain different types of joins.

Answer: Joins are used in queries to explain how different tables are related.Joins also let you
select data from a table depending upon data from another table.Types of joins: INNER JOINs,
OUTER JOINs, CROSS JOINs.OUTER JOINs are further classified as LEFT OUTER
JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.

 What is a self join?

Answer: Self join is just like any other join, except that two instances of the same table will
be joined in the query.

 How can I eliminate duplicates values in a table?

Answer: SQL> DELETE FROM table_name A WHERE ROWID > (SELECT min(rowid)
FROM table_name B WHERE A.key_values = B.key_values);

 How can one examine the exact content of a database column?

Answer: SELECT DUMP(col1)

FROM tab1

WHERE cond1 = val1;

DUMP(COL1)

Typ=96 Len=4: 65,66,67,32

http://sparshme5.googlepages.com
5
First Job…. Dream Job…. Sparshme5.googlepages.com

For this example the type is 96, indicating CHAR, and the last byte in the column is 32,
which is the ASCII code for a space.This tells us that this column is blank-padded.

 How can I change my Oracle password?

Answer: From SQL*Plus type: ALTER USER username IDENTIFIED BY new_password

 What are the most important DDL statements in SQL?

Answer: The most important DDL statements in SQL are:

 create table-creates a new database table


 alter table-alters (changes) a database table
 drop table-deletes a database table
 create index-creates an index (search key)
 drop index-deletes an index

 What are the different SELECT statements?

Answer: The SELECT statements are:

 SELECT column_name(s) FROM table_nameSELECT DISTINCT column_name(s)


FROM table_name
 SELECT column FROM table WHERE column operator value
 SELECT column FROM table WHERE column LIKE pattern
 SELECT column,SUM(column) FROM table GROUP BY column
 SELECT column,SUM(column) FROM table GROUP BY column HAVING
SUM(column) condition value

 What are the INSERT INTO Statements?

Answer: The INSERT INTO statements are:

 INSERT INTO table_name VALUES (value1, value2,....)


 INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)

 Write theUpdate Statement?

Answer: UPDATE table_name SET column_name = new_value WHERE column_name =


some_value

 What are the Delete Statements?

Answer: These are:

 DELETE FROM table_name WHERE column_name = some_value

Delete All Rows:

http://sparshme5.googlepages.com
6
First Job…. Dream Job…. Sparshme5.googlepages.com

 DELETE FROM table_name


 DELETE * FROM table_name

 how we can sort the Rows?

Answer: There are mainly three types:

 SELECT column1, column2,...FROM table_name ORDER BY columnX, columnY,..


 SELECT column1, column2,...FROM table_name ORDER BY columnX DESC
 SELECT column1, column2,...FROM table_name ORDER BY columnX DESC,
columnY ASC

 Explain IN operator.

Answer: The IN operator may be used if you know the exact value you want to return for at
least one of the columns.

SELECT column_name FROM table_name WHERE column_name IN (value1,value2,..)

 Explain BETWEEN...AND

Answer: SELECT column_name FROM table_name WHERE column_name BETWEEN


value1 AND value2 The values can be numbers, text, or dates.

 What is PL/SQL?

Answer: PL/SQL is Oracle's Procedural Language extension to SQL.PL/SQL's language


syntax, structure and data types are similar to that of ADA.

The language includes object oriented programming techniques such as encapsulation,


function overloading, information hiding.

 How can I protect my PL/SQL source code?

Answer: PL/SQL V2.2, available with Oracle7.2, implements a binary wrapper for PL/SQL
programs to protect the source code.

This is done via a standalone utility that transforms the PL/SQL source code into portable
binary object code (somewhat larger than the original).This way you can distribute software
without having to worry about exposing your proprietary algorithms and methods.SQL*Plus
and SQL*DBA will still understand and know how to execute such scripts.Just be careful,
there is no "decode" command available.

The syntax is:

wrap iname=myscript.sql oname=xxxx.plb

 Can one read/write files from PL/SQL?

http://sparshme5.googlepages.com
7
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: Included in Oracle 7.3 is a UTL_FILE package that can read and write files.The
directory you intend writing to has to be in your INIT.ORA file.
Before Oracle 7.3 the only means of writing a file was to use DBMS_OUTPUT with the
SQL*Plus SPOOL command.

DECLARE

fileHandler UTL_FILE.FILE_TYPE;

BEGIN

fileHandler := UTL_FILE.FOPEN('/home/oracle/tmp', 'myoutput', 'W');

UTL_FILE.PUTF(fileHandler, 'Value of func1 is %s\n', func1(1));

UTL_FILE.FCLOSE(fileHandler);

END;

 Can one use dynamic SQL within PL/SQL?

Answer: From PL/SQL V2.1 one can use the DBMS_SQL package to execute dynamic SQL
statements.
Eg:

CREATE OR REPLACE PROCEDURE DYNSQL AS

cur integer;

rc integer;

BEGIN

cur := DBMS_SQL.OPEN_CURSOR;

DBMS_SQL.PARSE(cur, 'CREATE TABLE X (Y DATE)', DBMS_SQL.NATIVE);

rc := DBMS_SQL.EXECUTE(cur);

DBMS_SQL.CLOSE_CURSOR(cur);

END;

 How does one get the value of a sequence into a PL/SQL variable?

Answer: select sq_sequence.NEXTVAL into :i from dual;

 Is there a PL/SQL Engine in SQL*Plus?

http://sparshme5.googlepages.com
8
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: No.All your PL/SQL are send directly to the database engine for execution.

 Is there a limit on the size of a PL/SQL block?

Answer: Currently, the maximum parsed/compiled size of a PL/SQL block is 64K and the
maximum code size is 100K.You can run the following select statement to query the size of
an existing package or procedure.

SQL> select * from dba_object_size where name = 'procedure_name'

 What is SQL*Plus?

Answer: SQL*Plus is a command line SQL and PL/SQL language interface and reporting
tool that ship with the Oracle Database Server.It can be used interactively or driven from
scripts.

Although SQL*Plus's predecessor was called UFI (User Friendly Interface), its interface is
quite primitive.

 What commands can be executed from SQL*Plus?

Answer: You can enter three kinds of commands from the SQL*Plus command prompt:

 SQL*Plus commands
 SQL commands
 PL/SQL blocks

 What is the basic SQL*Plus commands?

Answer:

DEFINE Declare a variable (short: DEF)


DESCRIBE Lists the attributes of tables and other objects (short: DESC)
EDIT Places you in an editor so you can edit a SQL command (short: ED)
EXIT or
Disconnect from the database and terminate SQL*Plus
QUIT
GET Retrieves a SQL file and places it into the SQL buffer
HOST Issue a operating system command (short: !)
LIST Displays the last command executed/ command in the SQL buffer (short: L)
PROMPT Display a text string on the screen.Eg prompt Hello World!!!
RUN List and Run the command stored in the SQL buffer (short: /)
Saves command in the SQL buffer to a file.Eg "save x" will create a script file
SAVE
called x.sql
SET Modify the SQL*Plus environment eg.SET PAGESIZE 23
Show environment settings (short: SHO).Eg SHOW ALL, SHO PAGESIZE
SHOW
etc.

http://sparshme5.googlepages.com
9
First Job…. Dream Job…. Sparshme5.googlepages.com

SPOOL Send output to a file.Eg "spool x" will save STDOUT to a file called x.lst
START Run a SQL script file (short: @)
 What is AFIEDT.BUF?

Answer: AFIEDT.BUF stands for A FIle EDiting BUFfer.

AFIEDT.BUF is the SQL*Plus default edit save file.When you issue the command "ed" or
"edit" without arguments, the last SQL or PL/SQL command will be saved to a file called
AFIEDT.BUF and opened in the default editor.

 What is the difference between @ and @@?

Answer: The @ (at symbol) is equivalent to the START command and is used to run
SQL*Plus command scripts.
A single @ symbol runs the script relative to the current directory, the double at (@@) runs a
command file relative to the directory of the current script

 What is the difference between & and &&?

Answer: "&" is used to create a temporary substitution variable and will prompt you for a
value every time it is referenced.
"&&" is used to create a permanent substitution variable as with the DEFINE command and
the OLD_VALUE or NEW_VALUE clauses of a COLUMN statement.

 What is the difference between ! and HOST?

Answer: Both "!" and "HOST" will execute operating system commands as child processes of
SQL*Plus.
The difference is that "HOST" will perform variable substitution (& and && symbols),
whereas "!" will not.

 How can I trap errors in SQL*Plus?

Answer: Use the "WHENEVER OSERROR..." to trap operating system errors and the
"WHENEVER SQLERROR..." command to trap SQL and PL/SQL errors.
Eg:

SQL> WENEVER OSERROR EXIT 9


SQL> WHENEVER SQLERROR EXIT SQL.SQLCODE

 Can I prevent users from executing devious commands?

Answer: Yes, command authorization is verified against the


SYSTEM.PRODUCT_USER_PROFILE table.
This table is created by the V7PUP.SQL and PUPBLD.SQL scripts.

Note that this table is not used when someone signs on as user SYSTEM.

http://sparshme5.googlepages.com
10
First Job…. Dream Job…. Sparshme5.googlepages.com

Eg.to disable all users whose names starts with OPS$ from executing the CONNECT
command:

SQL> INSERT INTO SYSTEM.PRODUCT_USER_PROFILE VALUES ('SQL*Plus',


'OPS$%', 'CONNECT', NULL, NULL, 'DISABLED', NULL, NULL);

 How can I disable SQL*Plus formatting?

Answer: SET ECHO OFF


SET NEWPAGE 0
SET SPACE 0
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF

 Differentiate between TRUNCATE and DELETE.

Answer: The Delete command will log the data changes in the log file where as the truncate
will simply remove the data without it.Hence Data removed by Delete command can be
rolled back but not the data removed by TRUNCATE.Truncate is a DDL statement whereas
DELETE is a DML statement.

 What is the maximum buffer size that can be specified using the
DBMS_OUTPUT.ENABLE function?

Answer: 1000000

 Can you use a commit statement within a database trigger?

Answer: Yes, if you are using autonomous transactions in the Database triggers.

 What is an UTL_FILE? What are different procedures and functions associated with
it?

Answer: The UTL_FILE package lets your PL/SQL programs read and write operating system
(OS) text files.It provides a restricted version of standard OS stream file input/output (I/O).
Subprogram -Description
FOPEN function-Opens a file for input or output with the default line size.
IS_OPEN function -Determines if a file handle refers to an open file.
FCLOSE procedure -Closes a file.
FCLOSE_ALL procedure -Closes all open file handles.
GET_LINE procedure -Reads a line of text from an open file.
PUT procedure-Writes a line to a file.This does not append a line terminator.
NEW_LINE procedure-Writes one or more OS-specific line terminators to a file.
PUT_LINE procedure -Writes a line to a file.This appends an OS-specific line terminator.
PUTF procedure -A PUT procedure with formatting.
FFLUSH procedure-Physically writes all pending output to a file.
FOPEN function -Opens a file with the maximum line size specified.

http://sparshme5.googlepages.com
11
First Job…. Dream Job…. Sparshme5.googlepages.com

 Difference between database triggers and form triggers?

Answer: Database triggers are fired whenever any database action like INSERT, UPATE,
DELETE, LOGON LOGOFF etc occurs.Form triggers on the other hand are fired in response
to any event that takes place while working with the forms, say like navigating from one field
to another or one block to another and so on.

 What is OCI.What are its uses?

Answer: OCI is Oracle Call Interface.When applications developers demand the most powerful
interface to the Oracle Database Server, they call upon the Oracle Call Interface (OCI).OCI
provides the most comprehensive access to all of the Oracle Database functionality.The
newest performance, scalability, and security features appear first in the OCI API.If you write
applications for the Oracle Database, you likely already depend on OCI.Some types of
applications that depend upon OCI are:

 PL/SQL applications executing SQL


 C++ applications using OCCI
 Java applications using the OCI-based JDBC driver
 C applications using the ODBC driver
 VB applications using the OLEDB driver
 Pro*C applications
 tributed SQL

 What are ORACLE PRECOMPILERS?

Answer: A precompiler is a tool that allows programmers to embed SQL statements in high-
level source programs like C, C++, COBOL, etc.The precompiler accepts the source program
as input, translates the embedded SQL statements into standard Oracle runtime library calls,
and generates a modified source program that one can compile, link, and execute in the usual
way.Examples are the Pro*C Precompiler for C, Pro*Cobol for Cobol, SQLJ for Java etc.

 What is syntax for dropping a procedure and a function?Are these operations


possible?

Answer: Drop Procedure/Function ; yes, if they are standalone procedures or functions.If they
are a part of a package then one have to remove it from the package definition and body and
recompile the package.

 Can a function take OUT parameters.If not why?

Answer: yes, IN, OUT or IN OUT.

 Can the default values be assigned to actual parameters?

Answer: Yes.In such case you don't need to specify any value and the actual parameter will
take the default value provided in the function definition.

 What is difference between a formal and an actual parameter?

http://sparshme5.googlepages.com
12
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: The formal parameters are the names that are declared in the parameter list of the
header of a module.The actual parameters are the values or expressions placed in the
parameter list of the actual call to the module.

 What are different modes of parameters used in functions and procedures?

Answer: There are three different modes of parameters:

 IN- The IN parameter allows you to pass values in to the module, but will not pass
anything out of the module and back to the calling PL/SQL block.In other words, for
the purposes of the program, its IN parameters function like constants.Just like
constants, the value of the formal IN parameter cannot be changed within the
program.You cannot assign values to the IN parameter or in any other way modify its
value.
IN is the default mode for parameters.IN parameters can be given default values in
the program header.
 OUT - An OUT parameter is the opposite of the IN parameter.Use the OUT
parameter to pass a value back from the program to the calling PL/SQL block.An
OUT parameter is like the return value for a function, but it appears in the parameter
list and you can, of course, have as many OUT parameters as you like.
Inside the program, an OUT parameter acts like a variable that has not been
initialised.In fact, the OUT parameter has no value at all until the program terminates
successfully (without raising an exception, that is).During the execution of the
program, any assignments to an OUT parameter are actually made to an internal copy
of the OUT parameter.When the program terminates successfully and returns control
to the calling block, the value in that local copy is then transferred to the actual OUT
parameter.That value is then available in the calling PL/SQL block.
 IN OUT - With an IN OUT parameter, you can pass values into the program and
return a value back to the calling program (either the original, unchanged value or a
new value set within the program).The IN OUT parameter shares two restrictions
with the OUT parameter: An IN OUT parameter cannot have a default value. An IN
OUT actual parameter or argument must be a variable.It cannot be a constant, literal,
or expression, since these formats do not provide a receptacle in which PL/SQL can
place the outgoing value.

 Difference between procedure and function.

Answer: A function always returns a value, while a procedure does not.When you call a
function you must always assign its value to a variable.

 Can cursor variables be stored in PL/SQL tables.If yes how.If not why?

Answer: Yes.Create a cursor type - REF CURSOR and declare a cursor variable of that type.
DECLARE

br /* Create the cursor type.*/


TYPE company_curtype IS REF CURSOR RETURN company%ROWTYPE;

/* Declare a cursor variable of that type.*/


company_curvar company_curtype;

http://sparshme5.googlepages.com
13
First Job…. Dream Job…. Sparshme5.googlepages.com

/* Declare a record with same structure as cursor variable.*/


company_rec company%ROWTYPE;
BEGIN
/* Open the cursor variable, associating with it a SQL statement.*/
OPEN company_curvar FOR SELECT * FROM company;

/* Fetch from the cursor variable.*/


FETCH company_curvar INTO company_rec;
/* Close the cursor object associated with variable.*/

CLOSE company_curvar;
END;

 How do you pass cursor variables in PL/SQL?

Answer: Pass a cursor variable as an argument to a procedure or function.You can, in


essence, share the results of a cursor by passing the reference to that result set.

 How do you open and close a cursor variable.Why it is required?

Answer: Using OPEN cursor_name and CLOSE cursor_name commands.The cursor must be
opened before using it in order to fetch the result set of the query it is associated with.The
cursor needs to be closed so as to release resources earlier than end of transaction, or to free
up the cursor variable to be opened again.

 What should be the return type for a cursor variable.Can we use a scalar data type as
return type?

Answer: The return type of a cursor variable can be %ROWTYPE or record_name%TYPE or


a record type or a ref cursor type.A scalar data type like number or varchar can't be used but a
record type may evaluate to a scalar value.

 What is use of a cursor variable? How it is defined?

Answer: Cursor variable is used to mark a work area where Oracle stores a multi-row query
output for processing.It is like a pointer in C or Pascal.Because it is a TYPE, it is defined as
TYPE REF CURSOR RETURN ;

 What WHERE CURRENT OF clause does in a cursor?

Answer: The Where Current Of statement allows you to update or delete the record that was
last fetched by the cursor.

 Difference between NO DATA FOUND and %NOTFOUND

Answer: NO DATA FOUND is an exception which is raised when either an implicit query
returns no data, or you attempt to reference a row in the PL/SQL table which is not yet
defined.SQL%NOTFOUND, is a BOOLEAN attribute indicating whether the recent SQL
statement does not match to any row.

http://sparshme5.googlepages.com
14
First Job…. Dream Job…. Sparshme5.googlepages.com

 What is a cursor for loop?

Answer: A cursor FOR loop is a loop that is associated with (actually defined by) an explicit
cursor or a SELECT statement incorporated directly within the loop boundary.Use the cursor
FOR loop whenever (and only if) you need to fetch and process each and every record from a
cursor, which is a high percentage of the time with cursors.

 What are cursor attributes?

Answer: Cursor attributes are used to get the information about the current status of your
cursor.Both explicit and implicit cursors have four attributes, as shown:

Name Description

1. %FOUND : Returns TRUE if record was fetched successfully, FALSE otherwise.


2. %NOTFOUND : Returns TRUE if record was not fetched successfully, FALSE
otherwise.
3. %ROWCOUNT : Returns number of records fetched from cursor at that point in
time.
4. %ISOPEN : Returns TRUE if cursor is open, FALSE otherwise.

 Difference between an implicit & an explicit cursor.

Answer: The implicit cursor is used by Oracle server to test and parse the SQL statements and the
explicit cursors are declared by the programmers.

 What is a cursor?

Answer: A cursor is a mechanism by which you can assign a name to a "select statement" and
manipulate the information within that SQL statement.

 What is the purpose of a cluster?

Answer: A cluster provides an optional method of storing table data.A cluster is comprised of
a group of tables that share the same data blocks, which are grouped together because they
share common columns and are often used together.For example, the EMP and DEPT table
share the DEPTNO column.When you cluster the EMP and DEPT, Oracle physically stores all
rows for each department from both the EMP and DEPT tables in the same data blocks.You
should not use clusters for tables that are frequently accessed individually.

 How do you find the number of rows in a Table ?

Answer: select count(*) from table, or from NUM_ROWS column of user_tables if the table
statistics has been collected.

 What is a pseudo column.Give some examples?

Answer: Information such as row numbers and row descriptions are automatically stored by
Oracle and is directly accessible, ie.not through tables.This information is contained within

http://sparshme5.googlepages.com
15
First Job…. Dream Job…. Sparshme5.googlepages.com

pseudo columns.These pseudo columns can be retrieved in queries.These pseudo columns can
be included in queries which select data from tables. Available Pseudo Columns

1. ROWNUM - row number.Order number in which a row value is retrieved.


2. ROWID - physical row (memory or disk address) location, ie.unique row
identification.
3. SYSDATE - system or today's date.
4. UID - user identification number indicating the current user.
5. USER - name of currently logged in user.

 How you will avoid your query from using indexes?

Answer: By changing the order of the columns that are used in the index, in the Where
condition, or by concatenating the columns with some constant values.

 What is a OUTER JOIN?

Answer: An OUTER JOIN returns all rows that satisfy the join condition and also returns
some or all of those rows from one table for which no rows from the other satisfy the join
condition.

 Which is more faster - IN or EXISTS?

Answer: Well, the two are processed very differently.


Select * from T1 where x in ( select y from T2 )
is typically processed as:
select *
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
The sub query is evaluated, distinct'ed, indexed (or hashed or sorted) and then joined to the
original table - typically.As opposed to
select * from t1 where exists ( select null from t2 where y = x )
That is processed more like:
for x in ( select * from t1 )
loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD
end if
end loop
It always results in a full scan of T1 whereas the first query can make use of an index on
T1(x).So, when is where exists appropriate and in appropriate? Lets say the result of the sub
query ( select y from T2 ) is "huge" and takes a long time.But the table T1 is relatively small
and executing ( select null from t2 where y = x.x ) is very fast (nice index on t2(y)).Then the
exists will be faster as the time to full scan T1 and do the index probe into T2 could be less
then the time to simply full scan T2 to build the sub query we need to distinct on. Lets say the
result of the sub query is small - then IN is typically more appropriate.If both the sub query
and the outer table are huge - either might work as well as the other - depends on the indexes
and other factors.

http://sparshme5.googlepages.com
16
First Job…. Dream Job…. Sparshme5.googlepages.com

 When do you use WHERE clause and when do you use HAVING clause?

Answer: The WHERE condition lets you restrict the rows selected to those that satisfy one or
more conditions.Use the HAVING clause to restrict the groups of returned rows to those
groups for which the specified condition is TRUE.

 There is a % sign in one field of a column.What will be the query to find it?

Answer: SELECT column_name FROM table_name WHERE column_name LIKE '%\%%'


ESCAPE '\';

 What is difference between SUBSTR and INSTR?

Answer: INSTR function search string for sub-string and returns an integer indicating the
position of the character in string that is the first character of this occurrence.SUBSTR function
return a portion of string, beginning at character position, substring_length characters
long.SUBSTR calculates lengths using characters as defined by the input character set.

 Which data type is used for storing graphics and images?

Answer: Raw, Long Raw, and BLOB.

 What is difference between SQL and SQL*PLUS?

Answer: SQL is the query language to manipulate the data from the database.SQL*PLUS is
the tool that lets to use SQL to fetch and display the data.

 What is difference between UNIQUE and PRIMARY KEY constraints?

Answer: An UNIQUE key can have NULL whereas PRIMARY key is always not NOT
NULL.Both bears unique values.

 What is difference between Rename and Alias?

Answer: Rename is actually changing the name of an object whereas Alias is giving another
name (additional name) to an existing object.

 How do you switch from an init.ora file to a spfile?

Answer: Issue the create spfile from pfile command.

 Explain the difference between a data block, an extent and a segment.

Answer: A data block is the smallest unit of logical storage for a database object.As objects
grow they take chunks of additional storage that are composed of contiguous data
blocks.These groupings of contiguous data blocks are called extents.All the extents that an
object takes when grouped together are considered the segment of the database object.

http://sparshme5.googlepages.com
17
First Job…. Dream Job…. Sparshme5.googlepages.com

 Give two examples of how you might determine the structure of the table DEPT.

Answer: Use the describe command or use the dbms_metadata.get_ddl package.

 Explain the difference between a hot backup and a cold backup and the benefits
associated with each.

Answer: A hot backup is basically taking a backup of the database while it is still up and
running and it must be in archive log mode.A cold backup is taking a backup of the database
while it is shut down and does not require being in archive log mode.The benefit of taking a
hot backup is that the database is still available for use while the backup is occurring and you
can recover the database to any point in time.The benefit of taking a cold backup is that it is
typically easier to administer the backup and recovery process.In addition, since you are
taking cold backups the database does not require being in archive log mode and thus there
will be a slight performance gain as the database is not cutting archive logs to disk.

 Give two examples of referential integrity constraints.

Answer: A primary key and a foreign key.

 A table is classified as a parent table and you want to drop and re-create it.How
would you do this without affecting the children tables?

Answer: Disable the foreign key constraint to the parent, drop the table, re-create the table,
enable the foreign key constraint.

 Explain the difference between ARCHIVELOG mode and NOARCHIVELOG mode


and the benefits and disadvantages to each.

Answer: ARCHIVELOG mode is a mode that you can put the database in for creating a
backup of all transactions that have occurred in the database so that you can recover to any
point in time.NOARCHIVELOG mode is basically the absence of ARCHIVELOG mode and
has the disadvantage of not being able to recover to any point in time.NOARCHIVELOG
mode does have the advantage of not having to write transactions to an archive log and thus
increases the performance of the database slightly.

 What command would you use to create a backup control file?

Answer: Alter database backup control file to trace.

 Give the stages of instance startup to a usable state where normal users may access it.

Answer: There are three stages like :

 STARTUP NOMOUNT - Instance startup


 STARTUP MOUNT - The database is mounted
 STARTUP OPEN - The database is opened

 What column differentiates the V$ views to the GV$ views and how?

http://sparshme5.googlepages.com
18
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: The INST_ID column which indicates the instance in a RAC environment

 How would you go about generating an EXPLAIN plan?

Answer: Create a plan table with utlxplan.sql.

Use the explain plan set statement_id = 'tst1' into plan_table for a SQL statement

 How would you go about increasing the buffer cache hit ratio?

Answer: Use the buffer cache advisory over a given workload and then query the
v$db_cache_advice table.If a change was necessary then I would use the alter system set
db_cache_size command.

 Explain an ORA-01555

Answer: 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.

 Where would you look for errors from the database engine?

Answer: In the alert log.

 Compare and contrast TRUNCATE and DELETE for a table.

Answer: 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.

 Give the reasoning behind using an index.

Answer: Faster access to data blocks in a table.

 Give the two types of tables involved in producing a star schema and the type of data
they hold.

Answer: Fact tables and dimension tables.A fact table contains measurements while
dimension tables will contain data that will help describe the fact tables.

 What type of index should you use on a fact table?

Answer: A Bitmap index

 Explain the difference between $ORACLE_HOME and $ORACLE_BASE.

http://sparshme5.googlepages.com
19
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: ORACLE_BASE is the root directory for oracle.ORACLE_HOME located beneath


ORACLE_BASE is where the oracle products reside.

Oracle Sample Questions : Oracle


Interview Questions
http://sparshme5.googlepages.com
20
First Job…. Dream Job…. Sparshme5.googlepages.com

1. What are the various types of queries ?

Answer: The types of queries are:

 Normal Queries
 Sub Queries
 Co-related queries
 Nested queries
 Compound queries
2. What is a transaction ?

Answer: A transaction is a set of SQL statements between any two COMMIT and
ROLLBACK statements.

3. What is implicit cursor and how is it used by Oracle ?

Answer: An implicit cursor is a cursor which is internally created by Oracle.It is


created by Oracle for each individual SQL.

4. Which of the following is not a schema object : Indexes, tables, public synonyms,
triggers and packages ?

Answer: Public synonyms

5. What is PL/SQL?

Answer: PL/SQL is Oracle's Procedural Language extension to SQL.The language


includes object oriented programming techniques such as encapsulation, function
overloading, information hiding (all but inheritance), and so, brings state-of-the-art
programming to the Oracle database server and a variety of Oracle tools.

6. Is there a PL/SQL Engine in SQL*Plus?

Answer: No.Unlike Oracle Forms, SQL*Plus does not have a PL/SQL engine.Thus,
all your PL/SQL are send directly to the database engine for execution.This makes it
much more efficient as SQL statements are not stripped off and send to the database
individually.

7. Is there a limit on the size of a PL/SQL block?

Answer: Currently, the maximum parsed/compiled size of a PL/SQL block is 64K


and the maximum code size is 100K.You can run the following select statement to
query the size of an existing package or procedure. SQL> select * from
dba_object_size where name = 'procedure_name'

8. Can one read/write files from PL/SQL?

Answer: Included in Oracle 7.3 is a UTL_FILE package that can read and write
files.The directory you intend writing to has to be in your INIT.ORA file (see

http://sparshme5.googlepages.com
21
First Job…. Dream Job…. Sparshme5.googlepages.com

UTL_FILE_DIR=...parameter).Before Oracle 7.3 the only means of writing a file


was to use DBMS_OUTPUT with the SQL*Plus SPOOL command.
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('/home/oracle/tmp', 'myoutput','W');
UTL_FILE.PUTF(fileHandler, 'Value of func1 is %sn', func1(1));
UTL_FILE.FCLOSE(fileHandler);
END;

9. How can I protect my PL/SQL source code?

Answer: PL/SQL V2.2, available with Oracle7.2, implements a binary wrapper for
PL/SQL programs to protect the source code.This is done via a standalone utility that
transforms the PL/SQL source code into portable binary object code (somewhat larger
than the original).This way you can distribute software without having to worry about
exposing your proprietary algorithms and methods.SQL*Plus and SQL*DBA will
still understand and know how to execute such scripts.Just be careful, there is no
"decode" command available. The syntax is: wrap iname=myscript.sql
oname=xxxx.yyy

10. Can one use dynamic SQL within PL/SQL? OR Can you use a DDL in a
procedure ? How ?

Answer: From PL/SQL V2.1 one can use the DBMS_SQL package to execute
dynamic SQL statements.
Eg: CREATE OR REPLACE PROCEDURE DYNSQL AS
cur integer;
rc integer;
BEGIN
cur := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cur,'CREATE TABLE X (Y DATE)', DBMS_SQL.NATIVE);
rc := DBMS_SQL.EXECUTE(cur);
DBMS_SQL.CLOSE_CURSOR(cur);
END;

 What are the various types of queries ?

Answer: The types of queries are:

 Normal Queries
 Sub Queries
 Co-related queries
 Nested queries
 Compound queries

 What is a transaction ?

Answer: A transaction is a set of SQL statements between any two COMMIT and
ROLLBACK statements.

http://sparshme5.googlepages.com
22
First Job…. Dream Job…. Sparshme5.googlepages.com

 What is implicit cursor and how is it used by Oracle ?

Answer: An implicit cursor is a cursor which is internally created by Oracle.It is created by


Oracle for each individual SQL.

 Which of the following is not a schema object : Indexes, tables, public synonyms,
triggers and packages ?

Answer: Public synonyms

 What is PL/SQL?

Answer: PL/SQL is Oracle's Procedural Language extension to SQL.The language includes


object oriented programming techniques such as encapsulation, function overloading,
information hiding (all but inheritance), and so, brings state-of-the-art programming to the
Oracle database server and a variety of Oracle tools.

 Is there a PL/SQL Engine in SQL*Plus?

Answer: No.Unlike Oracle Forms, SQL*Plus does not have a PL/SQL engine.Thus, all your
PL/SQL are send directly to the database engine for execution.This makes it much more
efficient as SQL statements are not stripped off and send to the database individually.

 Is there a limit on the size of a PL/SQL block?

Answer: Currently, the maximum parsed/compiled size of a PL/SQL block is 64K and the
maximum code size is 100K.You can run the following select statement to query the size of
an existing package or procedure. SQL> select * from dba_object_size where name =
'procedure_name'

 Can one read/write files from PL/SQL?

Answer: Included in Oracle 7.3 is a UTL_FILE package that can read and write files.The
directory you intend writing to has to be in your INIT.ORA file (see
UTL_FILE_DIR=...parameter).Before Oracle 7.3 the only means of writing a file was to use
DBMS_OUTPUT with the SQL*Plus SPOOL command.
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('/home/oracle/tmp', 'myoutput','W');
UTL_FILE.PUTF(fileHandler, 'Value of func1 is %sn', func1(1));
UTL_FILE.FCLOSE(fileHandler);
END;

 How can I protect my PL/SQL source code?

Answer: PL/SQL V2.2, available with Oracle7.2, implements a binary wrapper for PL/SQL
programs to protect the source code.This is done via a standalone utility that transforms the
PL/SQL source code into portable binary object code (somewhat larger than the

http://sparshme5.googlepages.com
23
First Job…. Dream Job…. Sparshme5.googlepages.com

original).This way you can distribute software without having to worry about exposing your
proprietary algorithms and methods.SQL*Plus and SQL*DBA will still understand and know
how to execute such scripts.Just be careful, there is no "decode" command available. The
syntax is: wrap iname=myscript.sql oname=xxxx.yyy

 Can one use dynamic SQL within PL/SQL? OR Can you use a DDL in a procedure ?
How ?

Answer: From PL/SQL V2.1 one can use the DBMS_SQL package to execute dynamic SQL
statements.
Eg: CREATE OR REPLACE PROCEDURE DYNSQL AS
cur integer;
rc integer;
BEGIN
cur := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cur,'CREATE TABLE X (Y DATE)', DBMS_SQL.NATIVE);
rc := DBMS_SQL.EXECUTE(cur);
DBMS_SQL.CLOSE_CURSOR(cur);
END;

 What are the various types of Exceptions ?

Answer: User defined and Predefined Exceptions.

 Can we define exceptions twice in same block ?

Answer: No.

 What is the difference between a procedure and a function ?

Answer: Functions return a single variable by value whereas procedures do not return any
variable by value.Rather they return multiple variables by passing variables by reference
through their OUT parameter.

 Can you have two functions with the same name in a PL/SQL block ?

Answer: Yes.

 Can you have two stored functions with the same name ?

Answer: Yes.

 Can you call a stored function in the constraint of a table ?

Answer: No.

 What are the various types of parameter modes in a procedure ?

http://sparshme5.googlepages.com
24
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: IN, OUT AND INOUT.

 What is Over Loading and what are its restrictions ?

Answer: OverLoading means an object performing different functions depending upon the
no.of parameters or the data type of the parameters passed to it.

 Can functions be overloaded ?

Answer: Yes.

 Can 2 functions have same name & input parameters but differ only by return
datatype

Answer: No.

 What are the constructs of a procedure, function or a package ?

Answer: The constructs of a procedure, function or a package are :

 variables and constants


 cursors
 exceptions

 Why Create or Replace and not Drop and recreate procedures ?

Answer: So that Grants are not dropped.

 Can you pass parameters in packages ? How ?

Answer: Yes.You can pass parameters to procedures or functions in a package.

 What are the parts of a database trigger ?

Answer: The parts of a trigger are:

 A triggering event or statement


 A trigger restriction
 A trigger action

 What are the various types of database triggers ?

Answer: There are 12 types of triggers, they are combination of :

 Insert, Delete and Update Triggers.


 Before and After Triggers.
 Row and Statement Triggers.

http://sparshme5.googlepages.com
25
First Job…. Dream Job…. Sparshme5.googlepages.com

 What is the advantage of a stored procedure over a database trigger ?

Answer: We have control over the firing of a stored procedure but we have no control over
the firing of a trigger.

 What is the maximum no.of statements that can be specified in a trigger statement ?

Answer: One.

 Can views be specified in a trigger statement ?

Answer: No

 What are the values of :new and :old in Insert/Delete/Update Triggers ?

Answer: INSERT : new = new value, old = NULL


DELETE : new = NULL, old = old value
UPDATE : new = new value, old = old value

 What are cascading triggers? What is the maximum no of cascading triggers at a


time?

Answer: When a statement in a trigger body causes another trigger to be fired, the triggers are
said to be cascading.Max = 32.

 What are mutating triggers ?

Answer: A trigger giving a SELECT on the table on which the trigger is written.

 What are constraining triggers ?

Answer: A trigger giving an Insert/Updat e on a table having referential integrity constraint


on the triggering table.

 Describe Oracle database's physical and logical structure ?

Answer:

 Physical : Data files, Redo Log files, Control file.


 Logical : Tables, Views, Tablespaces, etc.

 Can you increase the size of a tablespace ? How ?

Answer: Yes, by adding datafiles to it.

 Can you increase the size of datafiles ? How ?

http://sparshme5.googlepages.com
26
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: No (for Oracle 7.0)


Yes (for Oracle 7.3 by using the Resize clause )

 What is the use of Control files ?

Answer: Contains pointers to locations of various data files, redo log files, etc.

 What is the use of Data Dictionary ?

Answer: It Used by Oracle to store information about various physical and logical Oracle
structures e.g.Tables, Tablespaces, datafiles, etc

 What are the advantages of clusters ?

Answer: Access time reduced for joins.

 What are the disadvantages of clusters ?

Answer: The time for Insert increases.

 Can Long/Long RAW be clustered ?

Answer: No.

 Can null keys be entered in cluster index, normal index ?

Answer: Yes.

 Can Check constraint be used for self referential integrity ? How ?

Answer: Yes.In the CHECK condition for a column of a table, we can reference some other
column of the same table and thus enforce self referential integrity.

 What are the min.extents allocated to a rollback extent ?

Answer: Two

 What are the states of a rollback segment ? What is the difference between partly
available and needs recovery ?

Answer: The various states of a rollback segment are :

 ONLINE
 OFFLINE
 PARTLY AVAILABLE
 NEEDS RECOVERY
 INVALID.

http://sparshme5.googlepages.com
27
First Job…. Dream Job…. Sparshme5.googlepages.com

 What is the difference between unique key and primary key ?

Answer: Unique key can be null; Primary key cannot be null.

 An insert statement followed by a create table statement followed by rollback ? Will


the rows be inserted ?

Answer: No.

 Can you define multiple savepoints ?

Answer: Yes.

 Can you Rollback to any savepoint ?

Answer: Yes.

 What is the maximum no.of columns a table can have ?

Answer: 254.

 What is the significance of the & and && operators in PL SQL ?

Answer: The & operator means that the PL SQL block requires user input for a variable.
The && operator means that the value of this variable should be the same as inputted by the
user previously for this same variable

 Can you pass a parameter to a cursor ?

Answer: Explicit cursors can take parameters, as the example below shows.A cursor
parameter can appear in a query wherever a constant can appear.

CURSOR c1 (median IN NUMBER) IS


SELECT job, ename FROM emp WHERE sal > median;

 What are the various types of RollBack Segments ?

Answer: The types of Rollback sagments are as follows :

 Public Available to all instances


 Private Available to specific instance

 Can you use %RowCount as a parameter to a cursor ?

Answer: Yes

http://sparshme5.googlepages.com
28
First Job…. Dream Job…. Sparshme5.googlepages.com

 Is the query below allowed :


Select sal, ename Into x From emp Where ename = 'KING' (Where x is a record of
Number(4) and Char(15))

Answer: Yes

 Is the assignment given below allowed :


ABC = PQR (Where ABC and PQR are records)

Answer: Yes

 Is this for loop allowed :


For x in &Start..&End Loop

Answer: Yes

 How many rows will the following SQL return :


Select * from emp Where rownum < 10;

Answer: 9 rows

 How many rows will the following SQL return :


Select * from emp Where rownum = 10;

Answer: No rows

 Which symbol preceeds the path to the table in the remote database ?

Answer: @

 Are views automatically updated when base tables are updated ?

Answer: Yes

 Can a trigger written for a view ?

Answer: No

 If all the values from a cursor have been fetched and another fetch is issued, the
output will be : error, last record or first record ?

Answer: Last Record

 A table has the following data : [[5, Null, 10]].What will the average function return ?

Answer: 7.5

 Is Sysdate a system variable or a system function?

http://sparshme5.googlepages.com
29
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: System Function

 Consider a sequence whose currval is 1 and gets incremented by 1 by using the


nextval reference we get the next number 2.Suppose at this point we issue an rollback
and again issue a nextval.What will the output be ?

Answer: 3

 Definition of relational DataBase by Dr.Codd (IBM)?

Answer: A Relational Database is a database where all data visible to the user is organized
strictly as tables of data values and where all database operations work on these tables.

 What is Multi Threaded Server (MTA) ?

Answer: In a Single Threaded Architecture (or a dedicated server configuration) the database
manager creates a separate process for each database user.But in MTA the database manager
can assign multiple users (multiple user processes) to a single dispatcher (server process), a
controlling process that queues request for work thus reducing the databases memory
requirement and resources.

 Which are initial RDBMS, Hierarchical & N/w database ?

Answer:

 RDBMS - R system
 Hierarchical - IMS
 N/W - DBTG

 Difference between Oracle 6 and Oracle 7

Answer:

ORACLE 7 ORACLE 6
Cost based optimizer Rule based optimizer
Shared SQL Area SQL area allocated for each user
Multi Threaded Server Single Threaded Server
Hash Clusters Only B-Tree indexing
Roll back Size Adjustment No provision
Truncate command No provision
Distributed Database Distributed Query
Table replication & snapshots No provision
Client/Server Tech No provision
 What is Functional Dependency

http://sparshme5.googlepages.com
30
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: Given a relation R, attribute Y of R is functionally dependent on attribute X of R if


and only if each X-value has associated with it precisely one -Y value in R

 What is Auditing ?

Answer: The database has the ability to audit all actions that take place within it. a) Login
attempts, b) Object Accesss, c) Database Action Result of Greatest(1,NULL) or
Least(1,NULL) NULL

 While designing in client/server what are the 2 imp.things to be considered ?

Answer: Network Overhead (traffic), Speed and Load of client server

 What are the disadvantages of SQL ?

Answer: Disadvantages of SQL are :

 Cannot drop a field


 Cannot rename a field
 Cannot manage memory
 Procedural Language option not provided
 Index on view or index on index not provided
 View updation problem

 When to create indexes ?

Answer: To be created when table is queried for less than 2% or 4% to 25% of the table rows.

 How can you avoid indexes ?

Answer: 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.
 Use an expression in the Where Clause of the SQL.

 What is the result of the following SQL :


Select 1 from dual UNION Select 'A' from dual;

Answer: Error

 Can database trigger written on synonym of a table and if it can be then what would
be the effect if original table is accessed.

Answer: Yes, database trigger would fire.

 Can you alter synonym of view or view ?

http://sparshme5.googlepages.com
31
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: No

 Can you create index on view

Answer: No.

 What is the difference between a view and a synonym ?

Answer: Synonym is just a second name of table used for multiple link of database.View can
be created with many tables, and with virtual columns and with conditions.But synonym can
be on view.

 What's the length of SQL integer ?

Answer: 32 bit length

 What is the difference between foreign key and reference key ?

Answer: Foreign key is the key i.e.attribute which refers to another table primary key.
Reference key is the primary key of table referred by another table.

 Can dual table be deleted, dropped or altered or updated or inserted ?

Answer: Yes

 If content of dual is updated to some value computation takes place or not ?

Answer: Yes

 If any other table same as dual is created would it act similar to dual?

Answer: Yes

 For which relational operators in where clause, index is not used ?

Answer: <> , like '%...' is NOT functions, field +constant, field||''

 .Assume that there are multiple databases running on one machine.How can you
switch from one to another ?

Answer: Changing the ORACLE_SID

 What are the advantages of Oracle ?

Answer: Portability : Oracle is ported to more platforms than any of its competitors, running
on more than 100 hardware platforms and 20 networking protocols. Market Presence : Oracle
is by far the largest RDBMS vendor and spends more on R & D than most of its competitors
earn in total revenue.This market clout means that you are unlikely to be left in the lurch by

http://sparshme5.googlepages.com
32
First Job…. Dream Job…. Sparshme5.googlepages.com

Oracle and there are always lots of third party interfaces available. Backup and Recovery :
Oracle provides industrial strength support for on-line backup and recovery and good
software fault tolerence to disk failure.You can also do point-in-time recovery. Performance :
Speed of a 'tuned' Oracle Database and application is quite good, even with large
databases.Oracle can manage > 100GB databases. Multiple database support : Oracle has a
superior ability to manage multiple databases within the same transaction using a two-phase
commit protocol.

 What is a forward declaration ? What is its use ?

Answer: PL/SQL requires that you declare an identifier before using it.Therefore, you must
declare a subprogram before calling it.This declaration at the start of a subprogram is called
forward declaration.A forward declaration consists of a subprogram specification terminated
by a semicolon.

 What are actual and formal parameters ?

Answer: 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;

 What are the types of Notation ?

Answer: Position, Named, Mixed and Restrictions.

 What all important parameters of the init.ora are supposed to be increased if you
want to increase the SGA size ?

Answer: In our case, db_block_buffers was changed from 60 to 1000 (std values are 60, 550
& 3500) shared_pool_size was changed from 3.5MB to 9MB (std values are 3.5, 5 & 9MB)
open_cursors was changed from 200 to 300 (std values are 200 & 300) db_block_size was
changed from 2048 (2K) to 4096 (4K) {at the time of database creation}. The initial SGA
was around 4MB when the server RAM was 32MB and The new SGA was around 13MB
when the server RAM was increased to 128MB.

 .If I have an execute privilege on a procedure in another users schema, can I execute
his procedure even though I do not have privileges on the tables within the procedure ?

Answer: Yes

 What are various types of joins ?

http://sparshme5.googlepages.com
33
First Job…. Dream Job…. Sparshme5.googlepages.com

Answer: Types of joins are:

 Equijoins
 Non-equijoins
 self join
 outer join

 What is a package cursor ?

Answer: A package cursor is a cursor which you declare in the package specification without
an SQL statement.The SQL statement for the cursor is attached dynamically at runtime from
calling procedures.

 If you insert a row in a table, then create another table and then say Rollback.In this
case will the row be inserted ?

Answer: Yes.Because Create table is a DDL which commits automatically as soon as it is


executed.The DDL commits the transaction even if the create statement fails internally (eg
table already exists error) and not syntactically.

http://sparshme5.googlepages.com
34

You might also like