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

1. what is meant by DML?

DML-Data Manipulation Language


some of the DML operation are (insert,update,delete,merge)

2.Which one of the following pairs of aggregate functions do you use with character fields? 1.
COUNT(field) and MAX(field) 2. AVG(field) and COUNT(field) 3. MIN(field) and SUM(field) 4.
AVG(field) and MAX(field) 5. COUNT(field) and SUM(field).

Answer / Tulsi
1)THE COUNT(field) and MAX(field) CAN BE USED WITH
CHARACTER FIELDS
3. Which clause of an UPDATE statement allows you to affect
only certain rows of a table?

1. The WHERE clause


2. The SET clause
3. The ROWS AFFECTED clause
4. The ORDER BY clause

Answer / Tulsi
1)THE WHERE CLAUSE
4. If you want a column to be part of the result set, after
which SQL keyword does it belong?

1. SELECT
2. FROM
3. WHERE
4. GROUP BY
5. HAVING

Answer / Sumitha
It is Select.

Bcoz
2) from : includes the table name (source and not columns)
3)Where : specifies the condition based on which the rows
are retrived
4) Group by : mentions the column on which the rows are to
be grouped.. note that the column name mentioned should
also be specified in the select clause
5) Having : not sure
5. Types of locks in database ?

Answer / Lakshminarayana Reddy


2 types
1. Implicit locks: oracle automatically locks the rows
whenever user performs DML operations.
2. Explicit locks: provided by user.
2 tpyes a) Row level locks: used to lock selected rows
of table.It is imposed by "for update" clause in select.
b) Table level locks: used to lock compleate
table. 3 models 1) share mode
2) share update
3) exlcusive mode
Or

1) Shared
A shared lock reserves its object for reading only. It
prevents the object from changing while the lock remains.
More than one program can place a shared lock on the same
object. More than one object can read the record while it is
locked in shared mode.

2) Exclusive
An exclusive lock reserves its object for the use of a
single program. This lock is used when the program intends
to change the object.

You cannot place an exclusive lock where any other kind


of lock exists. After you place an exclusive lock, you
cannot place another lock on the same object.

3) Promotable/Update

A promotable (or update) lock establishes the intent to


update. You can only place it where no other promotable or
exclusive lock exists. You can place promotable locks on
records that already have shared locks. When the program is
about to change the locked object, you can promote the
promotable lock to an exclusive lock, but only if no other
locks, including shared locks, are on the record at the time
the lock would change from promotable to exclusive. If a
shared lock was on the record when the promotable lock was
set, you must drop the shared lock before the promotable
lock can be promoted to an exclusive lock.

6. What is normalization ?
Normalization is a rule applied on the database table in
order to remove redundancy of data.

7. What is the use of cursor ? how cursor allocate context area for executing the
sql statement?
Oracle create a memory area called context area to execute sql statements. that context
area keep all information about the statement processed.
cursor is just a pointer to that context area and you can also say a cursor is pointing to
result set of a query.
Types cursor :
1.Implicit cursor : implicit cursor automatically created by oracle when ever there is dml
operation performed inside pl/sql block.(dml operation means insert,update,delete).
2. Explicit Cursor : its a user defined cursor, user need to define it explicitly.
cursor declared in declaration section called explicit cursor.

Cursor Attributes : there is 4 types of cursor attributes used.


1.%notfound.
2.%found.
3.%isopen
4.%rowcount.
disadvantages of cursors are : each time you fetch a row
from the cursor,it results in a network roundtrip,where are
as normal select query makes only one round trip
cursors are costly as they need temparory storage.

8. Can a table have two primary keys?


No,In the entire table,there will be only one primary key.
A primary key is nothing but a collection of one or more
coloumns used to identify a row in a table.

9. what is the boundary line in varrays?


up to 2 gb

10. When we give SELECT * FROM EMP; How does oracle respond?
When the above statment is fired, Oracle checks for
following things,
1.Syntax Correctness.
2.User Priviledges on Emp Table.
If the above two things are correct then, all columns and
all rows from Emp table are selected in an Implicit area
and then are send to User.
Or
It will retrieve all the columns from emp table.

11. Write one update command to update seqno field of a table


on the basis of row number.
update table1 set seq_no =rownum where 1=1;
update EMP set EMPNO =rownum where 1=1;----update empno 1,2,3,4

update t1 set tid=6 where rownum=1;

12. what is indexing, searching and user interface?


An index is a performance-tuning method of allowing faster retrieval of records. An index
creates an entry for each value that appears in the indexed columns. By default, Oracle
creates B-tree indexes.

13. what are the differences among these table level lock
modes - IN SHARE MODE, IN SHARE UPDATE MODE, IN EXCLUSIVE
MODE ?
in share mode :
this mode is for read only on entire table.
we can not make changes to table.
any user can have a lock in share mode at same time.

in share update mode :


this mode is used to lock the selected rows for update.
this mode acquires lock on selected rows only,not entire table.
other user can have lock on other rows on the same table but
not on the rows you have locked.

in exclusive mode :
this acquires lock on entire table.
another user can not have any lock on that table.

14. what is the difference between varray and table data


type..please expalain with some examples...

under what situation you will go for varray..instead of


index by table...
the major difference you can say here is bounding.
varray is bounded but index by table is not bounded.
means in varray you can mention the limit but in index by table you cannot.

if you got with performance varray is more effective and faster than index by table.

15. what is the correct way of selection statement


a. select/from/table_name/orderby/groupby/having
b. select/from/table_name/groupby/having/orderby
Ans:
b. select/from/table_name/groupby/having/orderby

EG: select deptno,max(sal)


from emp
group by deptno
having max(sal)> 5000
order by deptno

1.What is SQL?How SQL is helpful in your project?

Answer:

SQL Stands for Structured Query Language which is specially desinged to communicate with
databases.SQL pronounced as Sequel is very widely used language in most of the database
management systems like Oracle,Mysql,Postgresql etc.SQL provides us a simple and efficient
way of reading,writing,executing the data from the system.
2.Suppose I want Employee named Rahul.Suppose i want to get position of U in Rahul.Kindly tell
me Queries in MySQL,MSSQL,Oracle?

ANSWER:

For Oracle:(We are using INSTR function in oracle)

Select Instr(name,’u’) as Position from Employee where name=’Rahul’;

3.What is difference between where and having clause?(90% asked HCL Interview Questions)

Answer:

Both Where Clause and Having clause are filters but these two filters are used for two different
purposes.Where clause is used to filter the non aggregated values and Having clause is used for
Aggregated values.Simply Where clause is used in Static non aggregated values and having
clause is used in aggregated values where you are using aggregated functions like
Count,Sum,Avg.etc.Having Clause always come with group by clause,you can not use having
clause directly.

Example:

Select * from Employees where name=’Amit’;

Select count(*) from Employees group by name having salary > 10000;

4.What is difference between joins and union?

Answer:

SQL joins are nothing but fetching the records where 2 or more tables having the similar
condition.

Example:

Suppose we want to fetch Employee name from Employee table and Department name from
department table where common condition is dept_no.

Select E.Employee_name,D.Department_name from Employee E,Department D where


E.dept_no=d.dept_no;

5.How to find duplicate rows from the table?

Answer:Click on Query for detailed explanation.

Select * from Employee a where row_id != select max(row_id) for Employee b where
a.Employee_num=b.Employee_num;

6.How to get unique department from employee table?

Answer:
Select distinct Department_name from Employee;

7.Can table have 2 primary keys?

Answer:

Table does not have 2 primary key .Table can have 2 unique keys but only 1 primary key.

8.What is Self join?Why it is required?

Answer:

Self join is nothing but Act of joining one table with itself.

Self join is useful in converting hierarchical data structure to flat data structure.

Using Self join you may achieve 2 different functionalities at a same time.

9.Write a query to delete Employee data from Employee table who got incentive in which is stored
into incentive table?

Answer:

Delete from Employee where Employee_id In(Select Employee_ID from Incentive);

10.How to select first five records from the table?(Most commonly asked in HCL Interview
Questions)

Answer:

Different DBMS have different ways to select first five records from the table

Oracle:

Select * from Employee where rownum <=5;

11.

Union Union ALL


1.Union Set operator is used to fetch the records 1.Union all Set operator is used to fetch the records
from 2 different tables which eliminates the from 2 different tables which does not eliminates
duplicate records the duplicate records
2.Syntax: 2.Syntax:

Select col1,col2…from table1; Select col1,col2…from table1;

Union Union all

Select col1,col2…from table2; Select col1,col2…from table2;


3.For Performance tuning Union operator is not 3.Union all is preferable operator in Performance
preferable as it takes time to eliminate duplicate tuning.
records

12. 13.What is Optimizer?

Answer:

Optimizer is nothing but the execution of query in optimum manner.Optimizer is most efficient
way of processing the query.SQL parser ,SQL Optimizer and source code generator compiles
the SQL statement.

14.How to insert name with single Quote in Employee table?

Answer:

We need to use another single Quote before special character.

Insert into Employee (Name) values(‘Amit”’);

15.Fetch the employees who has joined in January month?

Answer:

Select * from Employee where To_Char(Joining_Date,’MM’)=’01’;

Select * from Employee where To_Char(Joining_Date,’MON’)=’JAN’;

16.How to set NLS_Date_Format in SQL?

Answer:

Alter session NLS_DATE_FORMAT=’HH24:MI:SS’;

17.Select 20% salary of Amit and 10% salary of Pradnya from Employee Table?

Answer:

Select Name,

Case when name=’Amit’ then 0.2*salary end as ‘Amit Salary’,

case when name=’Pradnya’ then 0.1*salary end as ‘Pradnya Salary’ from Employee;

18.What is unique index?

Answer:
To create unique index you must have CREATE ANY INDEX privilege.Here the concept is bit
different.User needs to check the values of the table to create unique index.If table contains
uniquely identified values in specified column then you should use unique index.Especially while
creating the table if we specify the primary key then unique index is automatically created on
that column.But for Unique key constraint columns you separately need to do indexing.Kindly
make sure that Unique key indexes created on the columns which has unique values only.

19.What are Set operators in SQL?

Answer:

Set operators are nothing but the operators which are used to connect two tables and fetch the
records from the two tables.We need to follow one condition that the table set 1 columns and
table set 2 columns are same and its datatype must be same.SQL Set Operators combines the
result of 2 queries or components on to the single result.

Following are Set Operators in SQL:

1. Union
2. Unionall
3. Intersect
4. Minus

Click Here to get more information about Set operators…

20.What is query to calculate second highest salary of the employee using analytical function?

Answer:

We need to use Dense_Rank function to calculate second highest salary:

select * from (Select Dense_Rank() over ( order by salary desc) as Rnk,E.* from Employee
E) where Rnk=2;

1.11g feture:

 Adaptive Cursor Sharing.


 ADDM Enhancements (for RAC)
 Automatic Diagnostic Repository (ADR)
 Automated Maintenance Tasks.
 Automatic Memory Management.
 Automatic SQL Tuning.
 Automatic Storage Manager (ASM) Enhancements.
 AWR Baseline Enhancements.
 Case Sensitive Passwords in Oracle Database
 DDL With the WAIT Option (DDL_LOCK_TIMEOUT) - Avoid unnecessary "ORA-00054:
resource busy" errors in 11g.
 Partitioning Enhancements in Oracle Database
 Query Result Cache in Oracle Database
 Read-Only Tables in Oracle Database
 Scheduler Enhancements in Oracle Database
 SQL Performance Analyzer in Oracle Database
 SQL Plan Management in Oracle Database

2. difference between group by and partition by in oracle:

Group by

1. Reduces the no. of records


2. In select we need to use only columns which are used in group by. but we can
use aggregate functions.
3. In filter condition we need to use having clause instead of where clause.

A group by normally reduces the number of rows returned by rolling them up and
calculating averages or sums for each row. partition by does not affect the number of
rows returned, but it changes how a window function's result is calculated.

Partition By

1. No. of records will not be reduced. Instead of that it will add one extra column.
2. In select we can use N no. of columns. No restrictions.
3. We can use where clause in filter condition apart from partition column

partition by will not reduce the number of rows returned

Rank function will skip the sequence while assigning the rank for the group of partition and
assigns same rank for equals.
As we observe in the above output it skipped 2 for the group of partition (123,789,345).
Again it re-started new rank sequence for new partition group.

Dense_rank function will not skip the sequence while assigning the rank for the group of
partition and assigns same rank for equals.

Row_number function will just assigns a sequence for the group of partition.

Now we will see with a example how row_number function is useful in eliminating
duplicates rows.

4. How exception is different from error.


Error: Any departure from the expected behavior of the system or program, which stops the
working of the system is an error. In general error is which nobody can control or guess when
it occurs.

Exception: Any error or problem which one can handle and continue to work normally.
Exception can be guessed and can be handled.

In Java Exception and Error are sub class of Throwable. It is differentiated based on the
program control. Error such as OutOfMemoryError which no programmer can guess and can
handle it. It depends on dynamically based on architectire, OS and server configuration.
Where as Exception programmer can handle it and can avoid application's misbehavior. For
example if your code is looking for a file which is not available then IOException is
thrown.Such instances programmer can guess and can handle it.

5. A deadlock occurs when two or more sessions are waiting for data locked by each
other, resulting in all the sessions being blocked. Oracle automatically detects and
resolves deadlocks by rolling back the statement associated with the transaction
that detects the deadlock.
6. difference between trigger and constraint in oracle:

Constraints are used to maintain the integrity and atomicity of database .in other words it can
be said they are used to prevent invalid data entry . the main 5 constraints are
NOT NULL,PRIMARY KEY,FOREIGN KEY,UNIQUE KEY and CHECK

Triggers are bascically stored procedures which automaticallly fired when any insert,update or
delete is issued on table.
Another most imp. deff. is that trigger effected only those row after which trigger applied but
constraint effected all row of table .

CONSTRAINTS:=

1.it will check the existing data and feature data.


2.we cant change the constraint behavior these are predefined.
3.constraint are not support the object tables.
4.constraints can create on table,view and define on variables also(default,not null).

Trigger:=

1.It evaluates feature data.


2.we can change the trigger behavior
3.Trigger supports the object tables.
4.trigger are created only on table,view

7. cascade : A foreign key with cascade delete means that if a record in the parent
table is deleted, then the corresponding records in the child table will automatically
be deleted. This is called a cascade delete in Oracle.

8. What is the use of CASCADE CONSTRAINTS?


When this clause is used with the DROP command, a parent table can be dropped even
when a child table exists.
The CASCADE CONSTRAINTS clause drops all referencial integrity constraints that refer to
the primary and unique keys defined on the dropped columns.

A package is a schema object that groups logically related PL/SQL types, variables,
constants, subprograms, cursors, and exceptions. A package is compiled and stored in the
database, where many applications can share its contents. You can think of a package as
an application.

packages are good because of:

 modularity
 easier application design
 information hiding
 added functionality
 better performance

Both Replace and Translate are single row functions in Oracle 9i.
The Replace Function replaces single character with multiple characters.
But in Translate Function replaces sinlge character with sinlge character only.

replace chages the record in database.


but translate won't change it the database content is not changed
Replace used for String and Translate used for Character

For Example:

SQL> SELECT translate('So What', 'o', 'ay')


2 FROM dual;

TRANSLATE
-------
Sa What

SQL> SELECT REPLACE('So What', 'o', 'ay')


2 FROM dual;

REPLACE
--------
Say What

SQL> select replace('missisippi','is','12') replace, translate('missisippi','is','12') translate from dual;

REPLACE TRANSLATE
---------- ----------
m12s12ippi m122121pp1
replace function replaces a sequence of characters in a string with another set of characters.
ex.

select replace('123data',123,'X') from dual;

REPLA
-----
Xdata

here 123 replaces by X

translate function replaces a sequence of characters in a string with another set of characters.
However, it replaces a single character at a time.
ex1.
select translate('1data23base',123,'XYZ') from dual

TRANSLATE('
-----------
XdataYZbase

Replace function searches for a string and replaces with the given
string.
Translate function searches for a character and it replaces in
occurrence of the character.

What is the difference between REF Cursor & Normal Cursor


in oracle?
Normal cursors fall under the category of static cursors while REF cursors are dynamic. This
means that normal cursors can only be used again not defined. Ref cursors on the other
hand can be changed. A Ref cursor can be passed from one procedure to another. A normal
cursor cannot.

What is Global temporary table in oracle? and what are the


benefits of it?
GLOBAL TEMPORARY TABLE is used to store temporary data in scenarios where complex
calculation is involved. The data in this table is session specific. This means that the data in
temporary table cannot be shared with other sessions and is valid only until session is
active. It is most useful when the table structure of an application is not known or the data in
the temporary table is needed only while using the application.

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