Академический Документы
Профессиональный Документы
Культура Документы
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?
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 ?
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.
3) Promotable/Update
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.
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.
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 exclusive mode :
this acquires lock on entire table.
another user can not have any lock on that table.
if you got with performance varray is more effective and faster than index by table.
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:
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 count(*) from Employees group by name having salary > 10000;
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 * from Employee a where row_id != select max(row_id) for Employee b where
a.Employee_num=b.Employee_num;
Answer:
Select distinct Department_name from Employee;
Answer:
Table does not have 2 primary key .Table can have 2 unique keys but only 1 primary key.
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:
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:
11.
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.
Answer:
Answer:
Answer:
17.Select 20% salary of Amit and 10% salary of Pradnya from Employee Table?
Answer:
Select Name,
case when name=’Pradnya’ then 0.1*salary end as ‘Pradnya Salary’ from Employee;
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.
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.
1. Union
2. Unionall
3. Intersect
4. Minus
20.What is query to calculate second highest salary of the employee using analytical function?
Answer:
select * from (Select Dense_Rank() over ( order by salary desc) as Rnk,E.* from Employee
E) where Rnk=2;
1.11g feture:
Group by
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
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.
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:=
Trigger:=
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.
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.
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.
For Example:
TRANSLATE
-------
Sa What
REPLACE
--------
Say What
REPLACE TRANSLATE
---------- ----------
m12s12ippi m122121pp1
replace function replaces a sequence of characters in a string with another set of characters.
ex.
REPLA
-----
Xdata
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.