Вы находитесь на странице: 1из 42

Important Questions in Oracle, SQL--Oracle

1) What are the Back ground processes in Oracle and what are they?
This is one of the most frequently asked questions. There are basically 9 Processes
but in
a general system we need to mention the first five background processes. They do
the
house keeping activities for the Oracle and are common in any system.

The various background processes in oracle are

Data Base Writer (DBWR): Data Base Writer Writes Modified blocks from Database
buffer cache to Data Files. This is required since the data is not written whenever a
transaction is committed.
Log Writer (LGWR): Log writer writes the redo log entries to disk. Redo Log data is
generated in redo log buffer of SGA. As transaction commits and logs buffer fills,
LGWR writes log entries into an online redo log file.
System Monitor (SMON): The System Monitor performs instance recovery at
instance startup. This is useful for recovery from system failure
Process Monitor (PMON): The Process Monitor performs process recovery when
user Process fails. PMON Clears and Frees resources that process was using.
Check Point (CKPT): At Specified times, all modified database buffers in SGA are
written to data files by DBWR at Checkpoints and Updating all data files and control
files of database to indicate the most recent checkpoint
Achieves (ARCH): The Archiver copies online redo log files to archival storal when
they are busy.
Recover or (RECO): The Recovered is used to resolve the distributed transaction in
network
Dispatcher (Dnnn): The Dispatcher is useful in Multi Threaded Architecture
Lckn: We can have up to 10 lock processes for interred instance locking in parallel
SQL.

2) What is a Transaction in Oracle


A transaction is a Logical unit of work that compromises one or more SQL
Statements executed by a single User. According to ANSI, a transaction begins with
first executable statement and ends when it is explicitly committed or rolled back.

3) What are Procedure, functions and Packages?


Procedures and functions consist of set of PL/SQL statements that are grouped
together as a unit to solve a specific problem or perform set of related tasks.
Procedures do not return values while Functions return one Value

Packages: Packages provide a method of encapsulating and storing related


procedures, functions, variables and other Package Contents

4) How many types of SQL Statements are there in Oracle


5)
There are basically 6 types of SQL statements. They are

Data Definition Language (DDL): The DDL statements define and maintain
objects and drop objects.
Data Manipulation Language (DML): The DML statements manipulate database
data.
Transaction Control Statements: Manage change by DML
Session Control: Used to control the properties of current session enabling and
disabling roles and changing. E.g. Alter Statements, Set Role
System Control Statements: Change Properties of Oracle Instance. E.g.: Alter
1
System
Embedded SQL: Incorporate DDL, DML and T.C.S in Programming Language.
E.g. Using the SQL Statements in languages such as 'C', Open, Fetch, execute and
close

6) Key Words Used in Oracle


The Key words that are used in Oracle are
Committing: A transaction is said to be committed when the transaction makes
permanent changes resulting from the SQL statements.
Rollback: A transaction that retracts any of the changes resulting from SQL
statements in Transaction.
Save Point: For long transactions that contain many SQL statements, intermediate
markers or save points are declared. Save points can be used to divide a
transaction into smaller points.
Rolling Forward: Process of applying redo log during recovery is called rolling
forward.
Cursor: A cursor is a handle (name or a pointer) for the memory associated with a
specific stamen. A cursor is basically an area allocated by Oracle for executing the
SQL Statement. Oracle uses an implicit cursor statement for Single row query and
Uses Explicit cursor for a multi row query.
System Global Area (SGA): The SGA is a shared memory region allocated by the
Oracle that contains Data and control information for one Oracle Instance. It
consists of Database Buffer Cache and Redo log Buffer.
Program Global Area (PGA): The PGA is a memory buffer that contains data and
control information for server process.
Database Buffer Cache: Database Buffer of SGA stores the most recently used
blocks of database data. The set of database buffers in an instance is called
Database Buffer Cache.
Redo log Buffer: Redo log Buffer of SGA stores all the redo log entries.
Redo Log Files: Redo log files are set of files that protect altered database data in
memory that has not been written to Data Files. They are basically used for backup
when a database crashes.
Process: A Process is a 'thread of control' or mechanism in Operating System that
executes series of steps.

7) What are Database Triggers and Stored Procedures?


Database Triggers: Database Triggers are Procedures that are automatically
executed as a result of insert in, update to, or delete from table.

Database triggers have the values old and new to denote the old value in the table
before it is deleted and the new indicated the new value that will be used. Database
Triggers are useful for implementing complex business rules, which cannot be
enforced using the integrity rules. We can have the trigger as before trigger or After
Trigger and at Statement or Row level.
E.g.: operations insert, update, and delete 3
Before, after 3*2 A total of 6 combinations
At statement level (once for the trigger) or row level (for every execution) 6 *
2 A
total of 12.

Thus a total of 12 combinations are there and the restriction of usage of 12 triggers
has been lifted from Oracle 7.3 Onwards.

Stored Procedures: Stored Procedures are Procedures that are stored in


Compiled form in the database. The advantage of using the stored procedures is
that many users can use the same procedure in compiled and ready to use format.

2
8) How many Integrity Rules are there and what are they?
There are Three Integrity Rules. They are as follows:
Entity Integrity Rule: The Entity Integrity Rule enforces that the Primary key cannot
be Null
Foreign Key Integrity Rule: The FKIR denotes that the relationship between the
foreign
key and the primary key has to be enforced. When there is data in Child Tables the
Master tables cannot be deleted.
Business Integrity Rules: The Third Integrity rule is about the complex business
processes
which cannot be implemented by the above 2 rules.

9) What are the Various Master and Detail Relation ships?


The various Master and Detail Relationship are
Non Isolated: The Master cannot be deleted when a child is existing
Isolated: The Master can be deleted when the child is existing
Cascading: The child gets deleted when the Master is deleted.

10) What are the Various Block Coordination Properties?


The various Block Coordination Properties are Immediate Default Setting. The Detail
records are shown when the Master Record are shown. Deferred with Auto Query
Oracle Forms defer fetching the detail records until the operator navigates to the
detail block. Deferred with No Auto Query The operator must navigate to the detail
block and explicitly execute a query

11) What are the Different Optimisation Techniques?


The Various Optimization techniques are
Execute Plan: we can see the plan of the query and change it accordingly based on
the indexes
Optimizer hint: set_item_property('DeptBlock',OPTIMIZER_HINT,'FIRST_ROWS');
Select /*+ First_Rows */ Deptno,Dname,Loc,Rowid from dept
where (Deptno > 25)
Optimize_Sql: By setting the Optimize_Sql = No, Oracle Forms assigns a single
cursor for
all SQL statements. This slow downs the processing because for evertime the SQL
must
be parsed whenever they are executed.
F45run module = my_firstform userid = scott/tiger optimize_sql = No
Optimize_Tp: By setting the Optimize_Tp= No, Oracle Forms assigns seperate
cursor only
for each query SELECT statement. All other SQL statements reuse the cursor.
f45run module = my_firstform userid = scott/tiger optimize_Tp = No

12) How do u implement the If statement in the Select Statement?


We can implement the if statement in the select statement by using the Decode
statement.
e.g select DECODE (EMP_CAT,'1','First','2','Second'Null);
Here the Null is the else statement where null is done .

13) How many types of Exceptions are there


There are 2 types of exceptions. They are
System Exceptions: e.g. When no_data_found, When too_many_rows
User Defined Exceptions: e.g. My_exception exception,When My_exception then

14) What are the inline and the precompiler directives?


The inline and precompiler directives detect the values directly

3
15) How do you use the same lov for 2 columns
We can use the same lov for 2 columns by passing the return values in global
values and using the global values in the code

16) How many minimum groups are required for a matrix report
The minimum number of groups in matrix report are 4

17) What is the difference between static and dynamic LOV


The static LOV contains the predetermined values while the dynamic LOV contains
values that come at runtime.

18) What are snap shots and views?


Snapshots are mirror or replicas of tables. Views are built using the columns from
one or more tables. The Single Table View can be updated but the view with multi
table cannot be updated

19) What are the OOPS concepts in Oracle?


Oracle does implement the OOPS concepts. The best example is the Property
Classes. We can categories the properties by setting the visual attributes and then
attach the property classes for the objects. OOPS supports the concepts of objects
and classes and we can consider the property classes as classes and the items as
objects

20) What is the difference between candidate key, unique key and primary
key?
Candidate keys are the columns in the table that could be the primary keys and the
primary key is the key that has been selected to identify the rows. Unique key is also
useful for identifying the distinct rows in the table.

21) What is concurrency?


Concurrency is allowing simultaneous access of same data by different users. Locks
useful for accessing the database are
a) Exclusive: The exclusive lock is useful for locking the row when an insert, update
or delete is being done. This lock should not be applied when we do only select from
the row.
b) Share lock: We can do the table as Share Lock as many share locks can be put on
the same resource.

22) Privileges and Grants


Privileges are the right to execute a particular type of SQL statements.
E.g.: Right to Connect, Right to create, Right to resource
Grants are given to the objects so that the object might be accessed accordingly.
The grant has to be given by the owner of the object.

23) What are the Pct Free and Pct Used?


Pct Free is used to denote the percentage of the free space that is to be left when
creating a table. Similarly Pct Used is used to denote the percentage of the used
space that is to be used when creating a table
eg. Pctfree 20, Pctused 40

24) Table Space, Data Files, Parameter File, Control Files?


Table Space: The table space is useful for storing the data in the database. When a
4
database is created two table spaces are created.

a) System Table space: This data file stores all the tables related to the system
and DBA tables
b) User Table space: This data file stores all the user related tables

We should have separate table spaces for storing the tables and indexes so that the
access is fast.
Data Files: Every Oracle Data Base has one or more physical data files. They store
the
data for the database. Every data file is associated with only one database. Once
the
data file is created the size cannot change. To increase the size of the database to
store more data we have to add data file.

Parameter Files: Parameter file is needed to start an instance. A parameter file


contains
the list of instance configuration parameters
E.g. Db_block_buffers = 500
Byname = ORA7
db_domain = u.s.acme lang

Control Files: Control files record the physical structure of the data files and redo log
files
They contain the Db name, name and location of dbs, data files, redo log files and
time
stamp.

25) Physical Storage of the Data


The finest level of granularity of the database are the data blocks.
Data Block: One Data Block correspond to specific number of physical database
space
Extent: Extent is the number of specific number of contigious data blocks.
Segments: Set of Extents allocated for Extents. There are three types of Segments
a) Data Segment: Non Clustered Table has data segment data of every
table is stored in cluster data segment
b) Index Segment: Each Index has index segment that stores data
c) Roll Back Segment: Temporarily store 'undo' information

26) What is Row Chaining


The data of a row in a table may not be able to fit the same data block. Data for row
is stored in a chain of data blocks.

27) What is a 2 Phase Commit


Two Phase commit is used in distributed data base systems. This is useful to
maintain the integrity of the database so that all the users see the same values. It
contains DML statements or Remote Procedural calls that reference a remote object.
There are basically 2 phases in a 2 phase commit.
a) Prepare Phase: Global coordinator asks participants to prepare
b) Commit Phase: Commit all participants to coordinator to Prepared, Read only or
abort Reply

28) What is the difference between deleting and truncating of tables


Deleting a table will not remove the rows from the table but entry is there in the
database dictionary and it can be retrieved But truncating a table deletes it
completely and it cannot be retrieved.
29) What are mutating tables
5
When a table is in state of transition it is said to be mutating.
E.g. If a row has been deleted then the table is said to be mutating and no
operations can be done on the table except select.

30) What are Codd Rules


Codd Rules describe the ideal nature of a RDBMS. No RDBMS satisfies all the 12
codd rules and Oracle Satisfies 11 of the 12 rules and is the only Rdbms to satisfy
the maximum number of rules.

31) What is Normalization?


Normalization is the process of organising the tables to remove the redundancy.
There are mainly 5 Normalisation rules.
a) 1 Normal Form : A table is said to be in 1st Normal Form when the attributes are
atomic
b) 2 Normal Form: A table is said to be in 2nd Normal Form when all the candidate
keys are dependant on the primary key
c) 3rd Normal Form : A table is said to be third Normal form when it is not dependant
transitively

32) What is the Difference between a post query and a pre query?
A post query will fire for every row that is fetched but the pre query will fire only
once.

33) Deleting the Duplicate rows in the table?


We can delete the duplicate rows in the table by using the Rowid

34) Can U disable database trigger? How?


Yes. With respect to table
ALTER TABLE TABLE [DISABLE all_trigger ]

35) What is pseudo columns ? Name them?


A pseudo column behaves like a table column, but is not actually stored in the table. You
can select from pseudocolumns, but you cannot insert, update, or delete their values. This
section describes these pseudocolumns:
*CURRVAL, *NEXTVAL, *LEVEL, *ROWID, * ROWNUM

36) How many columns can table have?


The number of columns in a table can range from 1 to 254.

37) Is space acquired in blocks or extents?


In extents .

38) what is clustered index?


In an indexed cluster, rows are stored together based on their cluster key values .
Can not applied for HASH.

39) what are the datatypes supported By oracle (INTERNAL)?


Varchar2, Number, Char, MLSLABEL.

40) What are attributes of cursor?


%FOUND , %NOTFOUND , %ISOPEN,%ROWCOUNT

41) Can you use select in FROM clause of SQL select? Yes.
42) what is the significance of SQLCODE & SQLERRM in pl/SQL exception
handler?
For internal exceptions, SQLCODE returns the number of the Oracle error. The
number that SQLCODE returns is negative unless the Oracle error is no data
6
found, in which case SQLCODE returns +100.

SQLERRM: returns the corresponding error message. The message begins with the
Oracle error code. For user-defined exceptions, SQLCODE returns +1 and SQLERRM
returns the message

User-Defined Exception: If no exception has been raised, SQLCODE returns zero and
SQLERRM returns the message

42) what are INSTEAD OF triggers?


INSTEAD OF triggers provide a transparent way of modifying views that cannot be
modified directly through SQL DML statements (INSERT, UPDATE, and DELETE).
These
triggers are called INSTEAD OF triggers because, unlike other types of triggers,
Oracle fires the trigger instead of executing the triggering statement. The trigger
performs update, insert, or delete operations directly on the underlying tables.

43) What is a Result Set? when is it created?


The result set can be defined as a logical set of rows that meet the query submitted
to
the server process. The only way to reference this object is through the cursor
handle.
this is created when the Cursor is opened.

44) Can one only retreive rows X to Y from a table?


SELECT *
(SELECT Rownum rn, tab1.*
FROM tab1)
WHERE rn between lower_value and Upper_value;

Tab1 will be the name of the table and lower_value will be the Lower bound and
upper_bound will be the Upper bound value

45) How can I view the dependencies of a PL/SQL block?


Basically there are two types of dependencies a pl/sql block may have. Dependency
on another pl/sql block called as procedural dependency. Dependency on a
database object called as object dependency. For viewing the procedural
dependencies we have the following group of views.

USER_DEPENDECIES, ALL_DEPENDENCIES and DBA_DEPENDENCIES in the data


dictionary

DBA_DEPENDENCIES: Shows both the dependencies. This views primarily has


these following columns OWNER, NAME, TYPE, REFERENCED_OWNER,
REFERENCED_NAME, REFERENCED_TYPE, REFERENCED_LINK_NAME

Another view can be used to find the object dependencies called as DEPTREE and
IDEPTREE for indirect dependencies.

46) What are the two ways to specify a column alias?


Naming the alias after the column specification separated by a space .
Ex: Select empid id, fname first from employee
2. Use of an 'AS' word to specify the alais more clearly
Ex: Select empid as id, fname as first from employee
47) How does one get the value of a sequence into a PL/SQL variable?
Well, oracle doesn’t allow to assign a sequence value to a PL/SQL variable as
i := sq_sequence.NEXTVAL;(for some silly reason).
7
But you can do this:
select my_sequence.NEXTVAL into :i from dual;
and then use the variable in the needed area.

48) What DBMS package should I use to manipulate the long column in Oracle 7
You cannot use PL/SQL. You have to use OCI calls to do this and Oracle has a great
tech note on this. It is located in our PL/SQL development section at

49) Can one read/write files from PL/SQL?


Included in Oracle is an UTL_FILE package that can read and write operating system
files. The directory you intend writing to has to be set in the init.ora by using
UTL_FILE_DIR
parameter. It can be set to * to allow writes to any directory in the file system
before Oracle 7.3 the only means of writing a file was to use DBMS_OUTPUT with the
SQL*Plus SPOOL command.
following is the example to open and write to a file 'file1' and then close.
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('/tmp', 'file1', 'w');
UTL_FILE.PUTF(fileHandler, 'the lines of text\n');
UTL_FILE.FCLOSE(fileHandler);
EXCEPTION
WHEN utl_file.invalid_path THEN
raise_application_error(-20000, 'ERROR: Invalid path for file or path not in
INIT.ORA.');
END;

50) What are the various types of Exceptions?


User defined and Predefined Exceptions.

51) Can we define exceptions twice in same block?


No.

52) What is the difference between a procedure and a function?


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.

53) Can you have two functions with the same name in a PL/SQL block?
Yes.

54) Can you have two stored functions with the same name?
Yes.

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


No.

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


IN, OUTAND INOUT.

57) Can some body give me some example of INSTEAD OF trigger?


Enter Answer here INSTEAD-OF triggers provide a transparent way of modifying
views that cannot be modified directly through SQL DML statements (INSERT,
UPDATE, and DELETE). These triggers are called INSTEAD-OF triggers because,
unlike other types of triggers, Oracle fires the trigger instead of executing the
8
triggering statement.

CREATE TABLE dept (deptno NUMBER PRIMARY KEY,


deptname VARCHAR2(20),
manager_num NUMBER
);

CREATE TABLE emp (empno NUMBER PRIMARY KEY,


empname VARCHAR2(20),
deptno NUMBER REFERENCES dept(deptno),
startdate DATE
);

CREATE VIEW manager_info AS


SELECT d.deptno, d.deptname, e.empno, e.empname
FROM emp e, dept d
WHERE e.empno = d.manager_num;

CREATE TRIGGER manager_info_insert


INSTEAD OF INSERT ON manager_info
REFERENCING NEW AS n -- new manager information
FOR EACH ROW
DECLARE
empCount NUMBER;
BEGIN

/* First check to make sure that the number of employees


in the department is greater than one */
SELECT COUNT(*) INTO empCount
FROM emp e
WHERE e.deptno = :n.deptno;

/* If there are enough employees then make him or her the manager */
IF empCount >= 1 THEN

UPDATE dept d
SET manager_num = :n.empno
WHERE d.deptno = :n.deptno;

END IF;
END;
/

58) How can I get the source code for a function or a procedure or a package from the
database?
Query the view ALL_SOURCE. It has a field called TYPE, which says whether the
object is a FUNCTION or a PACKAGE or a PACKAGE BODY or a PROCEDURE.
The field TEXT gives the actual source code for that object.
Example: SELECT TEXT FROM ALL_SOURCE WHERE NAME='FUNCTION_NAME';

Need SQL script to remove dash ('-') from data.


data in field = '5110-1' should be '51101'
9
Here is the function that can eliminate any string from the given string.
create or replace function DELETE_CHAR( CHAR_TYPE varchar2, STRING_TYPE
varchar2 )
return varchar2 as
RETURN_STRING varchar2(1000) := STRING_TYPE;
STRING_LENGTH number := 0;
CHAR_LENGTH number := 0;
CHAR_POSITION number := 0;
begin
select length(STRING_TYPE) into STRING_LENGTH from dual;
select length(CHAR_TYPE) into CHAR_LENGTH from dual;
if STRING_LENGTH > 0 and CHAR_LENGTH > 0 then
select instr(STRING_TYPE, CHAR_TYPE) into CHAR_POSITION from dual;
if CHAR_POSITION = 0 then
return RETURN_STRING;
else
RETURN_STRING := substr(STRING_TYPE, 1, CHAR_POSITION-1)||
substr(STRING_TYPE, CHAR_POSITION+CHAR_LENGTH, STRING_LENGTH);
RETURN_STRING := DELETE_CHAR( CHAR_TYPE, RETURN_STRING );
end if;
end if;
return RETURN_STRING;
end;
/
Example:
select delete_char('-', '111-11-1111') from dual;
ANSWER: 111111111

select delete_char('-', SSN) from EMP;

There is an Oracle built in function REPLACE to do the same job.


Ex: Select REPLACE('111-11-1111','-') from dual;
Ans: 111111111

Ex: Select REPLACE('111-11-1111','-', '*') from dual;


Ans: 111*11*1111

59) What is Over Loading and what are its restrictions?


Over loading means an object performing different functions depending
upon the no. of parameters or the data type of the parameters passed to it.

60) Can functions be over loaded? Yes.

61) Can 2 functions have same name & input parameters but differ only by Return data
type
No.

62) Are the constructs of a procedure, function or a package?


The constructs of a procedure, function or a package are:
variables and constants, cursors, exceptions

63) Why create or Replace and not drop and recreate procedures?
So that Grants are not dropped.

64) Can you pass parameters in packages? How?


Yes. You can pass parameters to procedures or functions in a package.
10
65) What are the parts of a database trigger?
The parts of a trigger are:
A triggering event or statement
A trigger restriction
A trigger action

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


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

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

68) Can views be specified in a trigger statement?


No

69) What are the values of :new and :old in Insert/Delete/Update Triggers ?
INSERT: new = new value, old = NULL
DELETE: new = NULL, old = old value
UPDATE: new = new value, old = old value

70) What are cascading triggers? What is the maximum no of cascading triggers at a
time?
When a statement in a trigger body causes another trigger to be fired, the triggers
are said to be cascading. Max = 32.

71) What are mutating triggers?


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

72) What are constraining triggers?


A trigger giving an Insert/Updat e on a table having referential integrity constraint
on the triggering table.

73) Describe Oracle database's physical and logical structure ?


Physical: Data files, Redo Log files, Control file.
Logical: Tables, Views, Table spaces, etc.

74) Can you increase the size of a table space? How?


Yes, by adding data files to it.

75) Can you increase the size of data files? How?


No (for Oracle 7.0). Yes (for Oracle 7.3 by using the Resize clause ----- Confirm!).
8? 8I? 9I?

76) What is the use of Control files?


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

77) What is the use of Data Dictionary?


Used by Oracle to store information about various physical and logical Oracle
structures e.g. Tables, Table spaces, data files, etc

78) What are the advantages of clusters?


Access time reduced for joins.

79) What are the disadvantages of clusters?


11
The time for Insert increases.

80) Can Long/Long RAW be clustered?


No.

81) Can null keys be entered in cluster index, normal index?


Yes.

82) Can Check constraint be used for self referential integrity? How?
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.

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


Two

84) What are the states of a rollback segment? What is the difference between partly
available and needs recovery?
The various states of a rollback segment are:
ONLINE, OFFLINE, PARTLY AVAILABLE, NEEDS RECOVERY and INVALID.

85) What is the difference between unique key and primary key?
Unique key can be null; Primary key cannot be null.

86) An insert statement followed by a create table statement followed by rollback?


Will the rows be inserted?
YES (TESTED WITH 9I)

87) Can you define multiple save points? Yes.

88) Can you Rollback to any save points?Yes.

89) What is the maximum no. of columns a table can have ? 1000.

90) Can you pass a parameter to a cursor?


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;

91) What is the significance of the&, and && operators in PL SQL?


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.

If a transaction is very large, and the rollback segment is not able to hold the
rollback information, then will the transaction span across different rollback
segments or will it terminate? It will terminate (Please check).

91) What are the various types of RollBack Segments?


Public Available to all instances
Private Available to specific instance

92) Can you use %row count as a parameter to a cursor? Yes

93) Is the query below allowed :

Select sal, ename Into x From emp Where ename = 'KING'


12
(Where x is a record of Number(4) and Char(15))
Yes

94) Is the assignment given below allowed :


ABC = PQR (Where ABC and PQR are records)
Yes

95) Is this for loop allowed :For x in &Start..&End Loop Yes

96) How many rows will the following SQL return :


Select * from emp Where rownum < 10;
9 rows

97) How many rows will the following SQL return :


Select * from emp Where rownum = 10;
No rows

98) Which symbol preceeds the path to the table in the remote database?
@

99) Are views automatically updated when base tables are updated? Yes

100) Can a trigger written for a view?


No

101) 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 ?
Last Record

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

103) Is Sysdate a system variable or a system function? System Function

104) 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 ?
3

105) Definition of relational Database by Dr. Codd (IBM)?


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.

106) What is Multi Threaded Server (MTA)?


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.

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


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

108) What is Functional Dependency


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

109) What is Auditing?


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

110) While designing in client/server what are the 2 imp. Things to be considered?
Network Overhead (traffic), Speed and Load of client server

111) What are the disadvantages of SQL?


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.

112) When to create indexes?


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

113) How can you avoid indexes?


To make index access path unavailable
· Use FULL hint to optimizer for full table scan
· Use INDEX or AND-EQUAL hint to optimizer to use one index or set to
indexes instead of another.
· Use an expression in the Where Clause of the SQL.

114) What is the result of the following SQL :


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

115) Can database trigger written on synonym of a table and if it can be then what
would be the effect if original table were accessed.
Yes, database trigger would fire.

116) Can you alter synonym of view or view? No

117) Can you create index on view? No.

118) What is the difference between a view and a synonym?


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.

119) What is the difference between alias and synonym?


Alias is temporary and used with one query. Synonym is permanent and not
used as alias.

120) What is the effect of synonym and table name used in same Select statement?
14
Valid

121) What's the length of SQL integer? bit length

122) What is the difference between foreign key and reference key?
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.

123) Can dual table be deleted, dropped or altered or updated or inserted? Yes

124) If content of dual is updated to some value computation takes place or not? Yes

125) If any other tables same as dual were created would it act similar to dual? Yes

126) For which relational operators in where clause, index is not used?
, like '% ...' is NOT functions, field +constant, field || ''

127) Assume that there are multiple databases running on one machine. How can
you
switch from one to another?
Changing the ORACLE_SID

128) What is a forward declaration? What is its use?


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.

129) What are the advantages of Oracle?


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

130) 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


15
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;

131) What are the types of Notation?


Position, Named, Mixed and Restrictions.

132) What all important parameters of the init.ora are supposed to be increased if
you
want to increase the SGA size?
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}.

133) 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? Yes

134) What are various types of joins?


Equi joins, Non-equi joins, self-join, outer join

135) What is a package cursor?


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.
136) If you insert a row in a table, then create another table and then say Rollback. In
this
case will the row be inserted?
Yes. because create table is a DDL which commits automatically as soon as it is
executed. The DDL commits the transaction even if the creates statement fails
internally (ex. table already exists error) and not syntactically.

137) What are the various types of queries?


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

138) 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.

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

140) What is PL/SQL?


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.

141) Is there a PL/SQL Engine in SQL*Plus?


No. Unlike Oracle Forms, SQL*Plus does not have a PL/SQL engine. Thus, all your
16
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.

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


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'

143) Can one read/write files from PL/SQL?


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 %s\n', func1(1));
UTL_FILE.FCLOSE(fileHandler);
END;

144) What are the advantage and disadvantages of using a select for update in a
cursor
Using the "for update clause" and then using useing "update... for current
cursor" is a good way to make sure that no one else is changing the rows you are
working with.

If you use this then you cannot issue a commit within the loop. A commit will
release all locks and invalidate your cursor.
145) What constraints will cause oracle to create default indexes
When a table is created, an index associated to the primary key of the table is
also created to enforce uniqueness and faster data selection that uses the
primary key in the where clause of the select statement.

146) How can I get the difference between two date columns?
select floor((date1-date2)*24*60*60)/3600)
|| ' HOURS ' ||
floor((((date1-date2)*24*60*60) -
floor(((date1-date2)*24*60*60)/3600)*3600)/60)
|| ' MINUTES ' ||
round((((date1-date2)*24*60*60) -
floor(((date1-date2)*24*60*60)/3600)*3600 -
(floor((((date1-date2)*24*60*60) -
floor(((date1-date2)*24*60*60)/3600)*3600)/60)*60)))
|| ' SECS ' time_difference
from table a

147) How long will a variable remain defined in SQL Plus?


A Variable defined by a user will remain till the end of the session or if the user
un defines the variable.

148) Why should I not commit after every record when updating a large table
Committing after every record does not hurt but its much efficient to commit
after a batch of records like 5000 - 7000. I would suggest that you set this range
based on the size of your rollback segment.
17
149) I want to use a view to update a table. Is it possible?
Yes and No. A table can be updated through a view only if it matches certain
criteria.
1. Simple Sub Set of Data
2. All Not Null Columns are included
3. Based on a single table
So, you can update a view that is like this
create view v_emp as select * from emp;

but you cannot update a view like


create view v_emp as select emp_id, sum(sal)
from emp
group by emp_id;

150) What is ROWNUM


ROWNUM is a Psuedo-Column that returns the the sequence of the row returned.
You cannot use it to limit rows since rownum is only incremented after a row is
returned in the result set

151) How can i change the password for my username?


You can change you
alter user user_name idenified by new_password;
so, if you are logged in as scott and want to change your password to lion, you
can use
alter user scott identified by lion;

152) How can I retrieve a specified number of highest- or lowest-value columns with a
single query
oracle refers to this as an "TOP-N Query".
Think of this as a two-step process. In the first step, you create a view with an
ORDER BY clause that orders records in ascending or descending values of a
specified column. You then select the top required number of records from this
view using ROWNUM.

You could combine both of these steps in a single query by selecting the
specified number of records from an in-line view whose records are ordered in
ascending or descending order of the required column.

Thus, to retrieve the three employees in the EMP table with the highest salaries,
you could write the following query:

SQL> SELECT ename, sal


FROM (SELECT ename, sal
FROM emp
ORDER BY sal DESC)
WHERE ROWNUM <= 3;
To retrieve the two departments in the EMP/DEPT tables with lowest total salaries
you could write the following query:

SELECT d.dname, e.total_sal


FROM (SELECT deptno, sum(sal) total_sal FROM emp
GROUP BY deptno
ORDER BY sum(sal) ASC) e, dept d WHERE d.deptno = e.deptno
AND ROWNUM <= 2;

153) What is a ROWID and Why do I need that


18
ROWID is the physical address (location) of the row on the disk. This is the
fastest way to access a row in a table
Note :The rowid format in oracle 8 is different from rowid format of oracle7

154) How does Oracle store the DATE datatype internally?


Oracle stores data in a proprietary format. It uses 7 bytes for Data storage and 1
byte is used for the length data.
The following is the mapping of the oracle's date type
Byte 1 -> Century
Byte 2 -> Year
Byte 3 -> Month
Byte 4 -> Day
Byte 5 -> Hour
Byte 6 -> Minute
Byte 7 -> Second

155) what is an oracle precompiler?


An Oracle Precompiler is a programming tool that allows you to embed SQL
statements in a high-level source program. 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 you can
compile, link, and execute in the usual way. examples are
Pro*C Precompiler for C, Pro*Cobol for Cobol and SQLJ for Java etc.
156) What is a dual table and why is it used?
Dual is a table that contains a dummy column with a row 'X'. it is used to satisfy
the requirements of a SQL syntax containing a From clause.

157) What do locks actually do?


Locks are the mechanism that prevent more than one user at a time making
changes to the database. There are several types of locks that define their
scope.
1. tablelevel lock- allows only that user holding the lock to change any piece of
row data in a table. Row share, Row exclusive, share, share row exclusive and
exclusive are the several modes of a table lock.
2. Row-level lock- It allows the user to change one or two rows of data in a table.
Note: Any row in a table that is not held by a row-level lock can be changed by
another user.

158) Why is the query not fetching the records for the date I wanted?
For example, if your query is
SELECT EMP_NAME, SSN FROM EMP WHERE HIER_DATE = TO_DATE('03-NOV-
1999','DD-MON-YYYY');
Oracle assumes the hours, minutes and seconds to 12:00:00, So it tries to fetch
the records matched on that date at 1200 hours 00 minutes and 00 seconds.
If the record is inserted at 11:02:34 hours, it will not be fetched.
If you need all the records for a particular date, use the date conversion
functions, like
SELECT EMP_NAME, SSN FROM EMP WHERE TO_CHAR(HIER_DATE,'DD-MON-
YYYY') = '03-NOV-1999';

Remember that if you have an Index on the date field the query optimizer may
not use it;
How do I drop an unused column ? Any restrictions if so what are they?
As of Oracle 8i, it is possible to drop a column or UNUSED Column from a Table.
This feature drops the column from a table and releases any space back to the
segment. It will also drop any columns that were previously marked as being
unused. This clause also causes any indexes, constraints and statistics on this
19
column to be dropped.

Alter table shippers drop column ( c9 );


Alter table shippers unused columns;

Restrictions. Oracle does not permit combination drop and set unused clauses in
the same statement. Also an error will occur if drop column is attempted from an
object type table or a nested table or a partitioning key column or a parent key
column. Another good restriction is that a column cannot be dropped from any of
the tables owned by SYS.

159) How can I protect my PL/SQL source code?


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 and available. The syntax is: wrap
iname=myscript.sql oname=xxxx.yyy

160) Can one use dynamic SQL within PL/SQL? OR Can you use a DDL in a procedure?
How?
From PL/SQL V2.1 one can use the DBMS_SQL package to execute dynamic SQL
statements.
Ex: 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;

161) What is nls_date_format?


It is an national Language Set date format. It is used to change the date format
and new_time() function to convert a timestamp to a new time zone.

I want to use sub selects give me an example of what is a good case for sub
selects

Use subselects when you want to get detailed information based on group
values.

confusing... look at the example where I want to display all employees with
salary more than the average salary...

select empno, deptno


from emp a
where a.sal > ( select avg(sal) from emp);

162) What are these v$, x$ tables and views.


These are tables that are intented for the dba to manage performance related
information.
20
These are also referred to as dynamic performance views and give the dba's
enough information to see whats happening in the database at a particular point
in time

163) How can I see what tables I have access to and what tables I own
Oracle Data Dictionary provides 3 levels of views user,all and dba views. These
views provide information based on your privileges in the database.
User_tables, User_indexes.. etc., provide information about the objects you own.
All_Tables, All_indexes... etc., provide information about the objects you have
access to.
Dba_tables, dba_indexes.. etc., provide information about all the objects in the
database but are only available to dba's.
Example :
To see what tables I own...
select table_name from user_tables;
To see what tables I have access to and who the owner is...select owner,
table_name from user_tables;

164) How can I use a large rollback segment ( rblarge )to avoid the snapshot too old
error
You can use the following command
set transaction use rollback segment rblarge;
This has to be the first statement of the transaction and you need to reissue this
statement whenever you end the transaction, i.e, most of us forget to re issue
the command after a commit or rollback.

165) which of the following is better to find the number of rows in a table
1. count(1)
2. count(*)
3. count(rowid)

the answer is
1. and 3.

The function count() executes faster when given a criteria/value which is quicker
to resolve in the sql processing mechanism.Thus, an integer or rowid are faster
to resolve than an '*'which is a wild card symbol for all the colums in a table and
hence it is more time consuming.

166) What is a ROWID and Why do I need that


ROWID is the physical address (location) of the row on the disk. This is the
fastest way to access a row in a table
Note :The rowid format in oracle 8 is different from rowid format of oracle7

167) What is a Cartesian product?


A cartesian product is a result from a select statement that returns all the data
from both the tables . The result of a cartesian product is due to the unspecifying
the where clause for the join select statement.

21
Oracle(SQL) Interview Questions and Answers : SQL

1. To see current user name


Sql> show user;

2. Change SQL prompt name


SQL> set sqlprompt “Manimara > “
Manimara >

3. Switch to DOS prompt


SQL> host

4. How do I eliminate the duplicate rows ?


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);

Example.
Table Emp
Empno Ename
101 Scott
102 Jiyo
103 Millor
104 Jiyo
105 Smith
delete ename from emp a
where rowid < ( select min(rowid) from emp b
where a.ename = b.ename);
The output like,
Empno Ename
101 Scott
102 Millor
103 Jiyo
104 Smith

5. How do I display row number with records?


To achive this use rownum pseudocolumn with query, like
22
SQL> SQL> select rownum, ename from emp;
Output:
1 Scott
2 Millor
3 Jiyo
4 Smith

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
Enter value for Start: 7

ROWNUM EMPNO ENAME


--------- --------- ----------
1 7782 CLARK
2 7788 SCOTT
3 7839 KING
4 7844 TURNER

7. I know the nvl function only allows the same data type (i.e. 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, ursor_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


23
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 9th 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

24
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. How would you determine the time zone under which a database was operating?
select DBTIMEZONE from dual;

23. Explain the use of setting GLOBAL_NAMES equal to TRUE.


Setting GLOBAL_NAMES dictates how you might connect to a database. This
variable is either TRUE or FALSE and if it is set to TRUE it enforces database links to
have the same name as the remote database to which they are linking.

24. What command would you use to encrypt a PL/SQL application?


WRAP

25. Explain the difference between a FUNCTION, PROCEDURE and PACKAGE.


A function and procedure are the same in that they are intended to be a collection
of PL/SQL code that carries a single task. While a procedure does not have to return
any values to the calling application, a function will return a single value. A package
on the other hand is a collection of functions and procedures that are grouped
together based on their commonality to a business function or application.

26. Explain the use of table functions.


Table functions are designed to return a set of rows through PL/SQL logic but are
intended to be used as a normal table or view in a SQL statement. They are also
used to pipeline information in an ETL process.

27. Name three advisory statistics you can collect.


Buffer Cache Advice, Segment Level Statistics, & Timed Statistics

28. Where in the Oracle directory tree structure are audit traces placed?
In unix $ORACLE_HOME/rdbms/audit, in Windows the event viewer

25
29. Explain materialized views and how they are used.
Materialized views are objects that are reduced sets of information that have been
summarized, grouped, or aggregated from base tables. They are typically used in
data warehouse or decision support systems.

30. When a user process fails, what background process cleans up after it?
PMON

31. What background process refreshes materialized views?


The Job Queue Processes.

32. How would you determine what sessions are connected and what resources they
are waiting for?
Use of V$SESSION and V$SESSION_WAIT

33. Describe what redo logs are.


Redo logs are logical and physical structures that are designed to hold all the
changes made to a database and are intended to aid in the recovery of a database.

34. How would you force a log switch?


ALTER SYSTEM SWITCH LOGFILE;

35. Give two methods you could use to determine what DDL changes have been
made. You could use Logminer or Streams

36. What does coalescing a tablespace do?


Coalescing is only valid for dictionary-managed tablespaces and de- fragments
space by combining neighboring free extents into large single extents.

37. What is the difference between a TEMPORARY tablespace and a PERMANENT


tablespace?
A temporary table space is used for temporary objects such as sort structures while
permanent tablespaces are used to store those objects meant to be used as the true
objects of the database.

38. Name a tablespace automatically created when you create a database.


The SYSTEM tablespace.

39. When creating a user, what permissions must you grant to allow them to connect to
the database?
Grant the CONNECT to the user.

40. How do you add a data file to a tablespace?


ALTER TABLESPACE <tablespace_name> ADD DATAFILE <datafile_name> SIZE
<size>

41. How do you resize a data file?


ALTER DATABASE DATAFILE <datafile_name> RESIZE <new_size>;

42. What view would you use to look at the size of a data file?
DBA_DATA_FILES

43. What view would you use to determine free space in a tablespace?
DBA_FREE_SPACE

44. How would you determine who has added a row to a table?
26
Turn on fine grain auditing for the table.

45. How can you rebuild an index?


ALTER INDEX <index_name> REBUILD;

46. Explain what partitioning is and what its benefit is.


Partitioning is a method of taking large tables and indexes and splitting them into
smaller, more manageable pieces.

47. You have just compiled a PL/SQL package but got errors, how would you view the
errors?
SHOW ERRORS

48. How can you gather statistics on a table?


The ANALYZE command.

49. How can you enable a trace for a session?


Use the DBMS_SESSION.SET_SQL_TRACE
or
Use ALTER SESSION SET SQL_TRACE = TRUE;

50. What is the difference between the SQL*Loader and IMPORT utilities?
These two Oracle utilities are used for loading data into the database. The
difference is that the import utility relies on the data being produced by another
Oracle utility EXPORT while the SQL*Loader utility allows data to be loaded that has
been produced by other utilities from different data sources just so long as it
conforms to ASCII formatted or delimited files.

51. Name two files used for network connection to a database.


TNSNAMES.ORA and SQLNET.ORA

1. Oracle is n RDBMS (True)


2. Oracle 8 is an implementation of an object-related database whose beginnings
are in relational technology. (True)
3. Oracle 8 can be scaled to support over 10,000 users (True)
4. Oracle does not support client/server technology. (False)
5. Oracle can support only those database less than a terabyte in size (false)
27
6. You can’t add and subtract number constants as well as other dates from dates
(False)
7. A table can’t contain more than one long column. (True)
8. The scale for a number data type column designates the total number of digits
permissible in that column (False)
9. Default size of CHAR data types s 2 types (False)
10. A number can store a maximum of 127 digits of precision (false)
11. To satisfy the Check constraint, each row in the table must make the conditions
either or unknown (due to null) (False)
12. The name of a table can duplicate the name of another object in your account
(True)
13. Column names with in one table must be unique (True)
14. Oracle doesn’t enforce a constraint if the constraint is disabled (True)
15. A primary key made up a combination of columns is called a composite primer
key (True)
16. The DROP clause in an ALTER command is used to drop columns. (False)
17. You can alter a table in another schema (True)
18. You can always increase the size of a character or a row column or the precision
of a numeric column. (True)
19. The number of columns in the column list of the insert statement must be the
same as the number of values in the value clause. (True)
20. The records removed by using a Truncate command can be retrieved by a roll
back. (False)
21. COMM = NULL can be used as a condition (False)
22. The purpose of SELECT command is retrieve data from one or more tables, views
or snapshots. (True)
23. We can use a NULL for represent a value of zero, because they are equivalent.
(False)
24. A column alias used in the SELECT clause can be referenced elsewhere in a
query. (False)
25. A column alias does not affect the actual name of the column. (True)
26. In the ORDER BY clause and the DISTINCT operator both appear in the SELECT
statement the ORDER BY clause can refer to columns that do not appear in the
SELECT LIST (False)
27. An AND logical operator returns true if either component conditions are either
true or unknown otherwise returns false. (False)
28. Character strings and dates in the WHERE clause must be enclosed in double
quotes (“ “). (False)
29. Multiple columns may be specified after the DISTINCT qualifier & the DISTINCT
affects all the select columns. (True)
30. The BETWEEN ……AND…………..operator will operate with all data types. (True)
31. The command SELECT * from emp WHERE ename LIKE ‘%’ would return event
those records where ename is null (Ture)
32. The command ‘SELECT’ FROM emp WHERE NOT deptno = 10’ will return a
syntax error (False)
33. Oracle performs blank padding for comparisons with char columns. (True)
34. A START WITH condition can contain a sub query (True)
35. Issuing a DEL command at the SQL prompt would delete the contents of SQL
buffer (False)
36. The SQL * plus commands should be terminated with a “;” (False)
37. The SQL * plus variable type used to store elements of command text, which is
“edited” into commands before their execution, is a substitution variable. (True)
38. With a single ampersand in the command the user is prompted for the variable
value every time the command is executed. (True)
39. ‘SELECT & the rest’, command can be used to pass the whole command code via
a variable. (True)
40. If you call a function with an argument of a data type other than the data type
28
expected by the function. Oracle implicitly converts the arguments to the
expected data type before performing the function. (True)
41. The parameter ’n’ in LPAD(char 1, n, char 2) signifies thetotal length of the return
value (True)
42. The only date function that return a number is MONTHS-BETWEEN (TRUE)
43. The date function that returns the time in a different time zone is NEXT-DAY.
(FALSE)
44. The GRETEST function can be used to find out the world that appears last in the
dictionary in a given set of words. (True)
45. Most group functions ignore is NULL’s (True)
46. If you omit GROUP BY clause oracle applies group functions in the select list to
all the rows in the query table or view (True)
47. COUNT (*) group function ignore’s NULL’s (false)
48. Other users cannot lock or update a row until you end your end transaction,
when the row is locked using the FOR UPDATE. (Ture)
49. The DISTINCT and ALL options have no effect on the MAX and MIN functions.
(True)
50. Join is a select statement that combines rows from two or tables. (True)
51. The most common type of join the simple join or equi join returns rows from two
tables based on non-equality condition. (False)
52. A cartesion product always generates a large number of rows and its result are
rearely useful. (True)
53. An outer join returns all the rows returned by the simple join as well as those
rows from one table that do not find a match with any row from the other table.
(True)
54. When column names are the same in both tables being joined then the column
name should be preceded by the table name. (True)
55. A sub query can itself contain a sub query (True)
56. The NOT operator can be used with IN ANY or ALL operators. (True)
57. A nested sub query can be very useful when you need to select rows from a
table with a condition that depends on the data in the table itself. (True)
58. A sub query is evaluated once for the entire parent statement. (True)
59. Oracle place s no limit on the level of query nesting. (True)
60. A sub query cannot return multiple rows with multiple values in each row. (False)
61. A single row comparison operator can be used when a subquery returns more
than one tow. (False)
62. Oracle resolves unqualified columns in the subquery by looking in the subquery
then in the tables of the parent statement and so on (True)
63. It is not possible to use nested sub queries and correlated sub queries in the
UPDATE statement. (False)
64. The records in a table which are removed using a DELETE statement can be
rolled back (True)
65. All the privileges on an object can be granted by using ALL option in the GRANT
command. (True)
66. Previleges can be granted to roles (True)
67. A view contains data of its own (False)
68. A view can be based on another view (True)
69. To create a sequence that increments without bound the MAXVAL or MINVAL
parameters are used for ascending and descending sequences respectively.
(True)
70. Oracle imposes no limits on the number of indexes you can create an a single
table. (True)
71. A synonym can be an alternative name for another synonym. (True)
72. SQL * plus command can be obberviated (True)
73. Once a column statement is issued, it remains active throughout the remainder
of the SQL * plus session and it cannot be during a season. (False)
74. The options in the option list of a COLUMN command may appear in any order.
29
(True)
75. You may refer to the value of a system variable by giving it the prefix SQL. (True)
76. Duplication of values in the column is not suppressed, by breaking on the
column. (False)
77. PL/SQL does not forward references i.e. you must declare a variable or constant
before referencing it in statements. (True)
78. By default, variable are initialized to NULL, unless expressly initialized. (True)
79. The NOT NULL constant is allowed with an un initialized variables. (False)
80. The % type attribute is particularly useful when declaring variables that refer to
database columns. (True)
81. The names of local variables and formal parameters take precedence over the
names of database columns. (False)
82. A GOTO statement can be used to branch out of a loop. (True)
83. The control variable in a FOR loop is created by the loop, and may not be written
to by any statement inside the loop. (True)
84. Loop’s can’t be specially identified by using labels. (False)
85. We can simulate a basic loop using a GOTO and a label. (False)
86. Loop’s may be nested to multiple levels. (True)
87. Without exception handling, every time you issue a command, you must check
for execution errors, i.e. we have to code multiple checks. (True)
88. RAISE statements can be used to raise user defined exceptions only. (False)
89. The exception reproduces itself in successive enclosing blocks until a handler is
found. (False)
90. Omitting the exception name in a RAISE statement, in an exception handler, re
raises the current exception. (False)
91. A GOTO statement cannot branch to an exception handler, not can it branch
from an exception handler into the current block. (True)
92. A PL/SQL construct called a cursor lets you name private SQL area and access it
stored information. (True)
93. If a cursor is correctly open then its % IS OPEN evaluates to False. (False)
94. The %ROWCOUNT attribute returns the number of rows in the active set. (False)
95. Each formal parameter in the cursor declaration must have a corresponding
actual parameter is the OPEN statement.
96. To change the active set or the value of variables in the query you must CLOSE
and re OPEN the cursor with input variables set to their new values. (False)
97. Generally a procedure is used to compute a value and a function perform on
action. (False)
98. Procedures that take no parameters are written without parentheses. (True)
99. You can add new formal parameters to a sub program without having to change
every call for it. (True).
100. Atleast one statement must appear in the executable part of a procedure. (True)
101. You can overload the names of standalone subprogram. (False)

102. One or more RETURN statements must appear in the executable part of function.
(True)
103. The return statement immediately completes the execution of a subprogram and
returns control to the caller. (True)
104. A recursive subprogram is one that calls itself. (True)
105. A stored subprogram cannot call another stored subprogram. (False)
106. To recompile a standalone subprogram we have to use the COMPILE keyword.
(True)
107. Like subprograms, packages can be called, passed parameters or nested. (False)
108. The body of a package can be changed without having to recompile calling
programs. (True)
109. A database trigger has to be invoked explicitly. (False)
110. Database triggers fire with the privileges of the owner not the current user. (True)
111. By default a database trigger fires once per table.
30
112. Oracle guarantees the data integrity of BFILE files stored outside the database.
(False).
113. When you delete an external LOB(BFILE), then only the locator value is deleted.
(True).
114. An index-only table allows you to store the entire table’s data in an index. (True)
115. As of Oracle 8, passwords can expire and accounts may be locked due to repeated
failed attempts to connect. (True)
116. If the instead of clause is used the triggers code will be executed instead of the
event that caused the trigger to be executed. (True)
117. Abstract datatypes can be nested. (True)
118. For each record within the main table, the nested table may contain multiple rows.
(True)
119. For each record within the main table, the nested table may contain multiple rows.
(True).
120. You can also query the varying array directly to determine its maximum number of
entries per row called its COUNT. (false)
121. The data for a nested table is not stored “in-line” with the rest of the table’s data.
(True)
122. Referenced objects are not physically separate from the objects that refer to them.
(false)
123. The rows of an object table can’t be referenced by other objects within the
database. (false)
124. OID values are not reused. (True)
125. The REF operator takes a row object as the argument and returns a reference
value.
(True).
126. You need to know the name of the object table in order to DEREF its value. (False)
127. Object views are a means for defining objects used by existing relational tables.
(True)

1. Data Integrity means that the data contained in the database is both accurate and
consistent
2. The CODD rule that says that an application program must remain unimpaired
when any change is mode in storage representation Physical independence rule
3. The rule that states that all vies that are theoretically updatable must be
updatable by the system view updation rule
4. For any DBMS to be considered as on RDBMS it has to satisfy a minimum of 6
CODD rules
5. The rule which states that all information in a relational database must be stored
in the form of table only Information rule
6. Logical data Independence rule states that users and user programmes should be
independent of the logical structure of the database.
7. The principles of the relational model of database were first laid down by Dr E F
CODD
8. RDBMS stands for Relational Database Management system
9. Partitioning is the ability to break tables and indexes into smaller, more
manageable pieces
31
10. Personal Oracle is the Oracle database product for stand alone workstations.
11. SQL is a Non Procedural language and data access language
12. Oracle has precompilers that allow database access within which of the language
C, Cobol, ADA
13. SQL & Pl/SQL are used in which of the following products SQL*plus, Oracle Forms
and Oracle reports
14. The tools that allows direct and interactive use of the SQL language to access the
Oracle server is Oracle reports, Oracle forms and SQL * Plus.
15. The relations operator that displays certain columns form the relation and is
therefore often called a vertical subset is projection
16. With a non-procedural language you only specify what to do? And not how to do?
17. The database option from oracle corporation, which provides very high security
features, is Trusted Oracle
18. The distributed option supports transactions which update data across more than
one database in a distributed database network
19. Oracle’s procedural language for writing application logic and for manipulating
data outside the database is PL/SQL
20. The closely integrated set of the main application development tools are called
the co-operative development.
21. Array and nested tables are new features of Oracle 8
22. Objects are software representations of real world entities
23. Encapsulation means that each object within the database has a well defined
interface with district borders
24. Extensibility is the ability of an object oriented database to add new objects and
their associated behavior without affecting the other objects and application
25. Partitioning is the ability to break tables and indexes into smaller more
manageable pieces Partitioning
26. Inheritance is the ability to create new classes of objects as specialization of
existing classes
27. Polymorphism is the ability of objects to differently to an identical message
28. Classes are templates for objects
29. Oracle loader is the oracle tool to use when you need to move data into your data
warehouse
30. The organization which implement the standards on a language are ANSI &ISO
31. If you insert a value that is shorter than column length for a column of ‘CHAR’
data type then Oracle Blank Pads the value to column length
32. The data type, which enables storage of variable length character strings
containing up to 2GB is Long
33. 7,2 and 10,-2 is a valid precision and scale value
34. The commands, which compose DCL are Grant & Revoke
35. The data types used for storing byte oriented or binary such as graphics images
or digital sound RAW
36. A collection of logical structures of data or schema objects is called Schema
37. The schemas which are used to enhance performance are Indexes and clusters
38. SQL stands for structure query language
39. The default date format is specified by the initialization parameter
NLS_DATE_Format
40. One Primary key can a table have
41. The option that prevents nulls from occurring if a row is inserted without a value
for the column default
42. The definitive key through which rows in the table are individually identified is
Primary Key
43. To define a composite key(Primary & unique) you must use Table constraint
syntax
44. Oracle generates a name of the form sys-cn where ‘n’ is an integer for each
unnamed constraint ‘n’ in the above case is unique
45. Rows that violate the constraint can be placed into another existing table using
32
the Exceptions into option
46. The clause that allows deletion of reference key values in the parent table that
have dependent rows in the child table and causes Oracle to automatically delete
dependent rows from the child table is ON-DELETE-CASCADE.
47. The table containing the foreign key is called the child or detail table and the
table containing the referenced key is called master table
48. Constraints, which reference one or more columns and are defined separately
from the definition of the columns in the table are called table constraint
49. Foreign keys provide referential integrity rules either with in a table or between
tables.
50. The Only type of integrity constraint that you can add to an existing column using
the MODIFY clause is not null
51. In an insert statement if you omit any columns from the column list, oracle
assigns them default value only
52. To end your current transaction and make permanent all changes performed in
the transaction you use commit command
53. You identify the point in a transaction to which you can later roll_back using a
save_point
54. Rollback your entire current transaction, Rollback your current transaction to a
save point and Roll back the entire session will be done by roll back command.
55. The add clause in an alter command is used to ad a column or integrity constraint
56. You can change a column data type or declare a column’s size only if the column
contains a Null in all rows
57. Using the ADD clause of an alter command the types of integrity constraints which
can be added are Unique, Primary Key, Referential Integrity and CHECK constraint
58. To drop all referential integrity constraints that refer to primary key and unique
keys in the dropped table we use the cascade constraint option
59. All DDL commands are auto committed.
60. The Order of the following clauses in a select statement is WHERE clause, GROUP
BY clause, ORDER BY clause and HAVING clause.
61. Using an (*) in the SELECT clause of a SELECT statement having only the SELECT
and FROM clause would retrieve all the data.
62. If ‘a’ is 10 then the condition a IS NOT NULL evaluates to true
63. To lock the selected rows in a SELECT command we can use the following options
FOR UPDATE
64. In which of the following clauses in a SELECT command we can use a condition
WHERE, START WITH, CONNECT BY and HAVING
65. To return only one of each set of duplicate rows selected we use the distinct
parameter
66. The conditions used in the WHERE and HAVING clauses should evaluate to a
Boolean
67. To retrieve data from schema of another user the table name has to be prefixed
by Scheme Name
68. To test for nulls only use the comparison operators IS NULL and IS NOT NULL
69. The list of expressions that appear after the SELECT keyword and before the
FROM clause is called the select list.
70. An expression(s), Column partition(s), table name and column name(s) can be
used by an ORDER BY clause.
71. The default order in which records are retrieved when an ORDER BY clause is used
is ascending
72. The logical operator that returns true if both component conditions are true,
otherwise return false is AND
73. When using the BETWEEN x AND Y in a condition the values of x and y are
inclusive
74. The operator precedence between AND & OR is AND over OR
75. The omission where clause, returns all rows from the tables, views or snapshots in
the FROM clause
33
76. LOGICAL operators are used to combine the results of two component conditions
to produce a single result based on them or to invert the result of a single
condition
77. To check for the column value in a set of values we use the IN operator
78. The IN operator is equivalent to ANY
79. To check for a range of values we use the between operator.
80. In a hierarchical query the children are evaluated with respect to a current parent
row by using CONNECT BY clause
81. In a hierarchical query if the START WITH clause is omitted then Oracle will
display all the rows, uses all, rows in the table as root rows
82. In a hierarchical query if one row is both the parent(or grand parent or direct
ancestor) and a child (or a grand child or a direct decendent of another row then
Oracle return on error.
83. For a root node the pseudo column LEVEL returns the value 1
84. In a hierarchical query with the clause “CONNECT BY prior emp no = mgr.and sal
>comm.; the prior operator applies only to empno
85. The LIKE operator helps in making a wild card search or pattern matching
operation.
86. The search string used to pattern match all strings that have ‘D’ as the second
character is ‘_D%’
87. The tool that can be used to force priority is ()
88. To project a column alias with a space in if we have to enclose the column is “ “
89. In a hierarchical query the root node(s) or row(s) is identified from the Start with
clause.
90. To list a range of lines m to n from the SQL buffer the editing command used is l
mn
91. double ampersand, DEFINE,ACCEPT commands are used to assign a value to a
variable in SQL * plus
92. Data types can be checked, more explanatory prompts, response values can be
hidden are the benefits in using ACCEPT to define substitution variables
93. Values can be supplied to the substitution variables in command files as
parameters using the command
94. The DEFINE command is used to find out if a variable is already defined and to
define a variable.
95. The SQL * plus environment the last SQL command issued is stored in a part of
memory called the SQL Builder
96. The command that displays and runs the current SQL command in the buffer is
run
97. the command used to open the default editor in order to edit contents of a saved
file is ED filter
98. The SQL * plus variable type used to store individual values which may be
assigned and read at run-time is bind variable
99. The option with the ACCEPT command that will help suppress the user response is
hide.
100. The value returned by SIGN(n) when n > 1 is 1
101. The output of LTRIM(‘BILL CLINTON’,’BALL’) is ILL CLINTON
102. The output of SUBSTR(‘CREAE’,3,3) is EAT
103. The conversion function that can be used to store the date in a different format
than one specified by the NLS_DATE_FORMAT is TO_CHAR
104. The written data type of NVL(expr 1, expr 2) is same as expr 1
105. A function is similar to an operator in that it manipulates data items and returns a
result
106. Single row functions are also known as scalar functions
107. A group function returns a single result row for a group of queried rows.
108. The value returned by MOD(M,0) is M
109. Homonyms in the English language can be found out using the soundex function
110. The SELECT statement contains the GROUP By clause, the select list can only
34
contain constants & group functions and GROUP BY clause expressions
111. The sequence in which WHERE, GROUP BY, HAVING
112. DISTINCT OPERATOR, GROUP BY and SET operator clause constants cannot be
used in a SELECT statement with a FOR UPDATE clause.
113. COUNT () and VARIANCE() are group functions.
114. Group clause can contain any columns in the tables regardless of whether the
columns appear in the select list, Multiple expressions and Multiple columns
115. A group function returns a single result row for a group of queried rows.
116. Many group functions accept the options distinct and all
117. The having clause is used to restrict which groups of rows defined by the GROUP
BY clause are returned by the query.
118. The FOR UPDATE clause locks the rows selected by the query.
119. You can substitute a value for a NULL using the NVL function.
120. The number of minimum join conditions tat are required to join ‘n’ tables is ‘n-1’
121. In an outer join (+) sign is placed on the deficient table side
122. In a vertical join, to return all rows retrieved by the first query that are not in the
second. We use minus operator.
123. The select statement used in the vertical join must select some number of
columns with corresponding columns having same data type
124. In a vertical join SELECT statements are executed from Top to bottom
125. The outer join extends the result of a simple or equi
126. If a join query does not contain the WHERE clause then such a join would be a
product or cartisian join
127. If a table containing ‘n’ records is Cartesian joined with a table with ‘m’ records
then the resultant table will have n*m records
128. In a vertical join, column names from the first query appear in the result
129. Temporary labels used in the FROM clause of query are called table aliases.
130. IN and =ANY are multirow comparison operator
131. A sub query can appear WHERE,HAVING & SET operator clauses and operator.
132. In SELECT statement Boolean conditions figures WHERE,HAVING,STARTWITH and
CONNECT BY clauses
133. A sub query is a SELECT statement that is nested with in another SELECT
statement.
134. When a sub query returns only one row, such a sub query is called single row sub
query.
135. The =ANY operator is similar to IN and SOME operators.
136. The all operator compares a value to every value returned by a sub query
137. A nested or sub query is used to answer multiple part question.
138. If WHERE clause is not specified in an UPDATE statement then all rows are
updated
139. Privileges can be granted to user(s), Role and Public
140. A person can grant a privilege on an object if he is the owner of the object, he has
the grant any privilege and he has been granted a privilege with GRANT OPTION.
141. A grantee can also alter a role granted to him with the ADMIN option
142. Granting Alter privilege on an object allows the grantee to change the object.
143. A correlated object is a sub query that is evaluated once for each row processed
by the parent statement.
144. In a correlated sub query if the tables in a sub query and parent query contain a
column with the some name, a reference to the column in the parent query must
be fixed by the table names & table users
145. A sub query is identified by the use of an outer queries column in the inner
queries predicate clause.
146. In an UPDATE statement the set clause determines which columns are updated
and what new values are stored in them
147. The difference between a DELETE and TRUNCATE command is the action of
truncation is auto commited.
148. Joins, SET OPERATORS, GROUP FUNCTIONS, ORDER BY CLAUSE, GROUP BY,
35
CONNECT BY or START WITH clause constructs should not be used in the view
query to enable DML’s on the view
149. The data base object from which multiple users may generate unique integers is
sequence
150. Maximum 16 columns that an index can contain.
151. Cluster columns must correspond to columns in each of the cluster tables in data
type
152. Profiles & rules and roll back segments and table spaces objects are stored in the
database, but are not in contained in a schema.
153. A view is also called a virtual or logical table
154. The tables upon which a view is based are called base table
155. To ensure that inserts and updates performed through the view must result in
rows that the view query can select we use the with check option
156. The first reference to the NEXT VAL of a sequence returns the start with value.
157. Tables can be added to an existing cluster by issuing a CREATE table statement
with the cluster clause.
158. The display of the number of records selected in a query can be set by using
FEEDBACK.
159. To make SQL * plus wait for you to press(return) before displaying a new page of
output, you have to set PAUSE
160. The option used with the COLUMN command that sets and nulls in the column to a
specified string is NULL
161. The breaks in reports can be active on COLUMNS, ROWS/PAGES and REPORT
162. The clause in COMPUTE COMMAND THAT HELPS IN COMPUTING COUNT OF ROWS
NUMBER
163. The SQL * plus command which displays any database table structure is describe
164. The SET command can be made the default for every session, by including them
in a file called login sql
165. To find out the value of a SET variable use the show command
166. The clear option with the COLUMN command removes the previous column
formatting command for that column.
167. The title and btitle command are used to produce titles on a page.
168. If a global identifier is re declared in sub-block, then in the sub-block the local
declaration prevails.
169. The assignment of a NUMBER value to a CHAR variable will result in Implicit data
type conversion
170. The reserved word which can be used instead of the assignment operator to
initialize variable and constants Default
171. The SQL function which are not available in procedural statements are GROUP
functions, GREATEST and LEAST
172. To distinguish non-PL/SQL variables, they are predefined by a colon and **
173. PL/SQL variables and constants have attributes, which are properties that let you
reference the data type and structure of an object without repeating its definition.
174. Identifiers declared in a PL/SQL block are considered local to that and global to all
its blocks, out blocks
175. The order in which operations are performed, operator precedence can be
controlled through the usage of paranthesis
176. The two functions provided by Pl/SQL in addition to the functions available in SQL
for error reporting are SQL CODE and SQL ERROR
177. A constant must be initialized in its declaration, other wise you get a compilation
error.
178. The IF-THEN-ELSE is a conditional control construct
179. The control construct that helps in conditional iteration is WHILE loop
180. The FOR loop control variable may be decremented, starting at the hight value by
using REVERSE in the loop
181. GOTO’s may pass control to labeled points with in the current block and an
enclosing block.
36
182. The bounds of a FOR loop range can be literals, variables or expressions but must
evaluate to INTGER
183. The flow of control through a program, is handled by using control structure
184. PL/SQL lets you process the data using conditional, interactive and sequential
control constructs.
185. In a IF-THEN-ELSE construct if all conditions evaluate to FALSE or NULL, the
statement in the else clause are executed
186. The lack of an exist or an exit-when statement in a basic loop will result in an
endless or infinite loop.
187. The FOR loop counter cannot be assign values, but can be referenced like a
constant.
188. The exception handler that catches all exceptions that the block does not name
specially is others
189. The predefined exception which is raised in SQL statement if the conversion of a
character string to number fails is Invalid Number
190. The procedure which lets you issue user-defined error messages from a stored
subprogram or database trigger is Raise-Application-Error
191. A SELECT INTO statement that calls a GROUP function will raise NO-DATA-FOUND.
192. The complier directive which tells the compile to associate a name with an oracle
error number is Exception_init.
193. The PL/SQL mechanism which lets you bullet proof, your program so that it can
continue operating in the presence of error is exception handling
194. Internal or predefined exception are raised implicitly(automatically) by the
runtime system.
195. The two main types of exceptions are predefined and user defined
196. PL/SQL declares predefined exceptions globally in a package called STANDARD
197. To declare an exception by introducing its name, the key word exception is used.
198. Data can be retrieved into variables using which of the following options INSERT
INTO and FETCH
199. The formal parameters of a cursor must be IN parameter
200. Actual parameters in an open statement can be associated with formal
parameters in a cursor declaration using positional notation and named notation
201. which of the following does a cursor FOR loop do open cursor, fetch rows of values
from active set and close cursor.
202. We can test whether a FETCH was successful or not by checking the FOUND and
NOT FOUND attribute.
203. A PL/SQL construct called a cursor lets you name a private SQL area and access its
stored information
204. Oracle used work areas called private SQL area to execute SQL statements and
stored processing information.
205. There are two kinds of cursor Explicit and implicit.
206. The set of rows returned by a multi row query is called as an active set
207. Updates or deletes can be applied on the single row currently being addressed in
a explicit cursor by using the where current of clause.
208. The advantages of a sub program are Modularity, reusability, maintainability,
abstraction and Extensibility.
209. You can use the same name for several different sub programs as long as their
formal parameters differ in number, order or data type family. The feature is also
called overloading.
210. The parameter which acts like an uninitialized variable inside the subprogram is
INOUT parameter
211. You cannot overload two subprograms if their formal parameters differ only in
Name and parameter mode and data types in the same family.
212. PL/SQL has two types of subprogram called procedures and functions.
213. PL/SQL programs have two parts the specification and the functions.
214. The behavior of formal parameters can be defined using parameter nodes
215. Inside the subprogram, an IN parameter acts like a constant.
37
216. You can pass different number of actual parameters to a sub program if the
default values are defined for the IN and INOUT parameters
217. In a function specification the RETURN clause specifies data type of the RETURN
value.
218. Calls to user defined function can appear in procedural statement.
219. The variables declared in a subprogram specification and referenced in the
subprogram body are Formal parameters.
220. Higher productivity, Better Performance, Memory savings and Tighter Security are
offered by Stored subprograms.
221. A subprogram is valid if, since its last compilation.
222. Functions and procedures are structured alike, except that function has the return
clause.
223. A function subprogram is called as part of an expression.
224. The problem of defining mutually recursive subprograms is solved by using
Forward declaration.
225. Recursive programs are more elegant and efficient less when compared to an
interactive version.
226. PL/SQL declares built-in functions globally in Standard package.
227. A package can contain Subprogram, Cursors, Types and Exceptions.
228. A package need not have a body if it contains only constraints and variables,
exceptions and types.
229. SQL statements and subprogram calls can appear in a trigger body.
230. The correlation names :new and :old can be replaced by using REFERENCING
CLAUSE.
231. Database triggers are used to maintain Business integrity.
232. A package is a database object that groups logically related PL/SQL types, objects
and subprograms.
233. A subprogram defined in a package body may not be accessible outside its
specification is included in the package specifications.
234. To reference the types, objects and subprograms declared within a package
specification we have to prefix their names with the Package name.
235. The package which contains the subprograms PUT, PUT_LINE, GET and GET_LINE
is DBMS_OUTPUT.
236. The LOB that supports a multi byte character set it NCLOB
237. DBMS_LOB package, API’s(Application Programming Interface) and OCI(Oracle Call
Interface) are the valid methods for manipulating LOB data.
238. SUBSTR and INSTR are available in the DBMS_LOB package.
239. You can use the alter table command to perform exchange, drop, split and
truncate on a partition.
240. DBA is a role.
241. For each of the LOB columns, Oracle will store a locate value that tell It where to
find any out-of-line data stored for the record.
242. If an internally stored LOB column’s value is NULL, then you will have to set it to
an empty locater value before updating it to a non-null value.
243. To create an index-only table, you use the Organisation index clause of the create
table command.
244. Oracle uses the partitions check constraints to determine which partition the
record should be inserted into.
245. A role is set of privileges.
246. A varying array is a column object, collection.
247. Polymorphism object oriented concepts are not supported by Oracle 8
248. ‘THE’ key word can be used to flatten a nested table
249. The ability of the same instruction to be interpreted in different ways by different
objects is called Polymorphism
250. The information about the attributes of a user’s abstract data types is available
with which of the following data dictionary tables USER_TYPE_ATTRS and
ALL_TYPE_ATTRS
38
251. Abstract data types are data types that consist of one or more sub types.
252. An object has a name, a standard representation, and a standard collection of
operations that affect it.
253. To create you own methods use the create type body command.
254. Oracle creates methods, called constructor methods, for data management when
you create an abstract data type.
255. The operations that affect the object are called methods.
256. A nested table is an example of Embedded object and column object
257. The difference between nested tables, LOB’s and Varying arrays are they are
stored out of line.
258. You create a method to an abstract data type by using create type body
command.
259. Drop cannot performed on a type that is in use by a table.
260. To show the full structure of the abstract data types used by an object table on a
querying you have to use value.
261. An embedded object is one that is completely contained within abother.
262. Each row within the object table has an OID, Object Interface value
263. The DEREF operator takes a reference value as input and returns the value of the
row objects.
264. If you delete the object to which a reference points we have a dangling REF in the
record of the referencing table.
265. To use an abstract data type owned by another user you ought to have the
execute privilege on that type.

39
Oracle Notes:

Oracle 8i

It is a database of Internet computing, It changes the of information managed and


accessed to meet the demand of Internet age.
Significant new feature for OLTP(Online trans Processing) and data
ware housing Application.
To mange all types of detain web site.
iFS (Internet file System)
inter Media to manage and access multimedia data, audio, video
Support to java (to install JVM on server)
--Security enhancement (authentication and authorization, centralizing user
management)

Oracle 8(ORDBMS)
-Parallel enhancement, faster connection
-Table partitioning, Connection increased to 30000, Table column unto 1000
-database size increased from few tera byte to 10 tera. , Data file inc 65,533
-Support MTS, provides LOB

Oracle Start
Oracle instance start -Allocates SGA and start Background processes.
Mount Oracle DB-Method of Associating DB with previous started instance
Opening DB-To make available.

Normalization

It's a technique through. which we can design the database. During normalization
dependencies can be identified which can cause pbs during deletion & updation. It
is used in simplifying the structure of table.

1st Normal Form - Un normalized data transfer to normalized form.


2ndNormal Form - Functional dependencies can be findout & decompose the table
without loss of data.
3rd Normal Form - Transits dependencies, every non-key attribute is functionally
dependant on just Primary Key.
4th Normal Form(BCNF)-The relation, who has multiple candidate keys, then we have
to go for BCNF.

De-normalization
At the same time when information is required from more than one table at faster
rate then it is wiser to add some sort of dependencies.

40
Rolling Forward
To reapply to Data file to all changes that are recorded in Redo log file due to which
data file contains committed & uncommitted data.

Forward Declaration
To declares variable and procedures before using it.
2- Tier Arch. dis advantages-When Business Rule changes.

PL/SQL Record: To represents more than one row at time.

PL/SQL Table: To define single variable comprises several data element.


To delete define one more empty table and assign it.

Table space : Profile-To control system resources, memory, disk space and CPU
time.
We can find rows affected by %row count.

Data Binding: Dividing the cursor in apple as per select stat.

Truncate : Faster than delete, doesn’t fire ny DB trigger, Allocate space, No


roolback.

Deferred Integrity constraints: When we refer PK in the same table where we


defined.

Cascading trigger: Temporary Table-Delete operation table.

Log Table-to store information about error.

Err Trap -To trap error: use SQLERRM,SQLCODE

Modularity: PL/SQL allows to create program module to improve software reliability


and to hide complexity

Positional and Named Notation : The actual arguments are associaed with formal
arguments by position k/s Positional Notation. It’s commonly used.
A Trigger doesn't accept argument & have same name as table or procedure as it
exist in separate namespace.

SQL Language Extension: Oracle * provide new built-in datatype, object datatypes,
nested tables, and a no of other features that require new DDL extension.
VARRAY
REF
LOBS
Create table AA(a N (10)
B date,
C varchar2 (10));

Create type aa1 as varray (5) of number (5);

The UTLBSTAT and UTLESTAT script to get general overview of database 's
performance over a certain period of time.
UTLBSTAT creates table and views containing cumulative database performance
summary information at the time when the script runs .All the objects create by
UTLBSTAT contain word login.

41
Utlbstat.sql

UTLESTAT creates table and views containing cumulative database performance


summary information at the time when the script runs .All the objects create by
UTLESTAT contain word end.
UTLESTAT spools the results of these SQL statements to a file called REPORT.TXT
Utlestat.sql

Determine the shared Pool Performance.

The shared pool is one of the memory structures in SGA. It is comprised of the data
dictionary and the library cache. Check v$sgastat. The data dictionary cache buffers
data dictionary objects that contain data about tables, indexes, users and all other
objects. The Library Cache/SQL Cache buffers previously executed queries, so that
they need not be reloaded and reparsed if user calls them again. Otherwise if the
information is not in the buffer then oracle must get it from disk. The V$LIBRAY
CACHE View stores performance data for library cache and V$rowCACHE view stores
performance data for the data dictionary cache. Sometime we may have to increase
the value of initialization parameter SHARED_POOL_SIZE.
To improve the performance .

Redo Log --

Oracle 8 stores all changes to the database, even uncommitted changes, in the redo
log files. LGWR writes .

Alter database archievelog

Edit the parameter initialization file.


Log_archieve_start =true -turn it on
Log_archieve_dest=c:/oracle/ora81/archieve -location
log_archieve_format="ARCH%S.LOG" - name format for archieve file .
%S for log sequence number .

By querying the V$SESSION view , we can determine who is logged on ,as well as
information such as the time of logon .

Kill a session - ALTER system kill session '&sid,&serial'


Select Sid,serial#,status from V$session where username='name';

Unbalanced Index –
if we do have lot on index on a table and we are doing I/U/D frequently then there is
a problem of disk contention . To check this problem sees the BLEVEL value in
DBA_INDEXES and if it is 1,2,3,4 then it’s ok else rebuild the index .

Alter index satish.a_satish rebuild unrecoverable ;

Comments on table and columns

--For documentation purpose .


Comment table a is ‘table a’ ; Retrieve comment from user_tab_comment
Comment column a. a is ‘column a’; user_col_comments

42

Вам также может понравиться