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

How to find second maximum value from a table?

select max(field1) from tname1 where field1=(select max(field1) from tname1 where field1<(select max(field1) from tname1);

select min(column) from (select column from table order by column desc) where rownum <=2

select max(field1) from table_name where field1 < (select max(field1) from table_name)

How to find out the 10th highest salary in SQL query?

select min(int_salary) from Tbl_Test_Salary where int_salary in (select top 10 int_Salary from Tbl_Test_Salary order by
int_salary desc)

what the difference between UNION and UNIONALL?

union will return the distinct rows in two select s, while union all return all rows

Union will filter duplicate values where as union all will not filter duplicate values

What is Materialized View?

A materialized view is a database object that contains the results of a query. They are local copies of data located remotely or
used to create summary tables based on aggregation of a tables data. Materialized views which store data based on the remote
tables are also know as snapshots.

what is the advantage to use trigger in your PL?

Triggers are fired implicitly on the tables/views on which they are created. There are various advantages of using a trigger.
Some of them are:

- Suppose we need to validate a DML statement(insert/Update/Delete) that modifies a table then we can write a trigger on the
table that gets fired implicitly whenever DML statement is executed on that table.

- Another reason of using triggers can be for automatic updation of one or more tables whenever a DML/DDL statement is
executed for the table on which the trigger is created.

- Triggers can be used to enforce constraints. For eg : Any insert/update/ Delete statements should not be allowed on a
particular table after office hours. For enforcing this constraint Triggers should be used.

- Triggers can be used to publish information about database events to subscribers. Database event can be a system event like
Database startup or shutdown or it can be a user even like User loggin in or user logoff.

what is the differnece between materialized view and snapshot

A materialized view is a replica of a target master from a singlepoint in time. The concept was first introduced with Oracle7
termed asSNAPSHOT. In Oracle release 7.1.6 snapshots were enhanced to enableDMLs along with a new terminology,
updatable snapshots. With Oracle8.1.6 snapshots started to be used in data warehouse environments so anew terminology
materialized view was introduced to address bothdistributed and data warehouse materialized views.

what is the difference between structure and union...

The union is a structure.The main difference between structure and union isThe size of the union is equal to the size of the
largest member of the union where as size of the structrue is the sum of the size of al members of the structure.And one more
thing is that we can use one member of the union at a time.

difference between a equijoin and a union

Indeed both equi join and the Union are very different. Equi join is used to establish a condition between two tables to select
data from them.. eg

select a.employeeid, a.employeename, b.dept_name from

employeemaster a , DepartmentMaster b where a.employeeid = b.employeeid;

This is the example of equijoin whereas with a Union allows you to select the similar data based on different conditions eg
select a.employeeid, a.employeename from employeemaster a where a.employeeid >100 b.employeeid

Union

select a.employeeid, a.employeename from employeemaster a where a.employeename like 'B%'

the above is the example of Union where in we select employee name and Id for two different conditions into the same recordset
and is used thereafter.

difference between a equijoin and a union

for equijoin there must be relationship between two tables

but for union no need to have any relation between the two tables

but equijoin & union are used with more than one table

Explain UNION, MINUS, UNION ALL and INTERSECT

UNION - the values of the first query are returned with the values of the second query eliminating duplicates.
MINUS - the values of the first query are returned with duplicates values of the second query removed from the first query.
UNION ALL - the values of both queries are returned including all duplicates
INTERSECT - only the duplicate values are returned from both queries.

Explain UNION, MINUS, UNION ALL and INTERSECT

UNION: Take the common record once( No Duplicate)

UNION ALL : Takes Duplicates also

Exampl : Say there is EMP having 14 reconds then...

select count(1) from (select ename from emp) returns 14

select count(1) from (select ename from emp union select ename from emp e1) returns 14

But

select count(1) from (select ename from emp union All select ename from emp e1)

returns 28.

what is difference between DBMS and RDBMS?

1.RDBMS=DBMS+Refrential Integrity

2. An RDBMS ia one that follows 12 rules of CODD.

DBMS does not support client/server Architecture but RDBMS supports client/server Architecture.

In subqueries, which is efficient ,the IN clause or Exists

EXISTS is efficient bcose,

1.Exists is faster than IN clause.

2.IN check returns values to main query where as EXISTS returns Boolean (T or F).

Exists is preferred and it's more faster than IN clause....

IN check for all the values and where as EXISTS looks for values one by one and it exists when it found the value....
how can i hide a particular table name of our schema

you can hide the table name by creating synonyms.

e.g) you can create a synonym y for table x

create synonym y for x;

If Delete Any Table In Back-End ThenWhat Are...

Oracle has Schema triggers (CREATE OR REPLACE TRIGGER ... ON SCHEMA ... that will file on DDL commands. You can do
things like

CREATE OR REPLACE TRIGGER save_our_db


BEFORE DROP OR TRUNCATE
ON SCHEMA

to stop/log attempts to drop a table

what is cluster.cluster index and non cluster index

The difference is that, Clustered index is unique for any given table and we can have only one clustered index on a table. The
leaf level of a clustered index is the actual data and the data is resorted in case of clustered index, whereas in case of non-
clustered index the leaf level is actually a pointer to the data in rows so we can have 249 non-clustered indexes on a table.

what is cluster.cluster index and non cluster index

Clustered Index:- A Clustered index is a special type of index that reorders the way records in the table are physically stored.
Therefore table may have only one clustered index.Non-Clustered Index:- A Non-Clustered index is a special type of index in
which the logical order of the index does not match the physical stored order of the rows in the disk. The leaf nodes of a non-
clustered index does not consists of the data pages. instead the leaf node contains index rows.

How to write a sql statement to find the first occurrence of a non zero value?

select a from t where nvl(a,0)<> 0 and rownum < 2 where a is col name and t is the table name

select col from tabname where rowid =(select min(rowid) from tabname where col is not null)here col is column name and
tabname is table name.

Why do I get "Invalid Cursor State" errors when I insert/update/delete data with executeQuery()?

IF u get this error, then there is a problem with the Java program, U may open the cursor with the Readonly mode.Change the
Resultset type then you will get it.This is not problem with the Oracle

Difference between VARCHAR and VARCHAR2?

varchar means fixed length character data(size) ie., min size-1 and max-2000

where as varchar2 means variable length character data ie., min-1 to max-4000

Emp_name varchar(10) - if you enter value less than 10 then remaining space can not be deleted. it used total 10 spaces.

Emp_name varchar2(10) - if you enter value less than 10 then remaining space is automatically deleted

How to store directory structure in a database?

We can do it by the following command:create or replace directory as 'c:\tmp'

what is normalazation,types with eg's. _ with que...

There are 5 normal forms. It is necessary for any database to be in the third normal form to maintain referential integrity and
non-redundance.

First Normal Form: Every field of a table (row,col) must contain an atomic value
Second Normal Form: All columns of a table must depend entirely on the primary key column.
Third Normal Form: All columns of a table must depend on all columns of a composite primary key.
Fourth Normal Form: A table must not contain two or more independent multi-valued facts. This normal form is often avoided for
maintenance reasons.
Fifth Normal Form: is about symmetric dependencies.

What is difference between Oracle and MS Access?...

One of the differences is:

Oracle is multi-user where MS-Access is not.

We can't create sequence in Microsoft Access.We craete sequence in Oracle.

There are 2 tables, Employee and Department. There are few records in employee table, for which, the department is
not assigned. The output of the query should contain all th employees names and their corresponding departments, if
the department is assigned otherwise employee names and null value in the place department name. What is the
query?

select e.ename,d.dname from emp e, dept d where e.deptno = d.deptno(+);

SELECT EMP.ENAME,EMP.DEPTNO,DEPT.DEPTNO FROM EMP LEFT JOIN DEPTWHERE EMP.DEPTNO=DEPT.DEPTNO

what is reference cursor

Refereence cursor is dynamic cursor used with SQL statement like For select* from emp;

There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'.
While inserting the data into the table M was misspelled as F and F as M.What is the update statement to replace F with
M and M with F?

CREATE TABLE temp(


eno NUMBER CONSTRAINTS pk_eno PRIMARY KEY,
gender CHAR(1) CHECK (gender IN( 'M','F')));

INSERT INTO temp VALUES ('01','M');


INSERT INTO temp VALUES ('02','M');
INSERT INTO temp VALUES ('03','F');
INSERT INTO temp VALUES ('04','M');
INSERT INTO temp VALUES ('05','M');
INSERT INTO temp VALUES ('06','F');
INSERT INTO temp VALUES ('07','M');
INSERT INTO temp VALUES ('08','F');

COMMIT;

UPDATE temp SET gender =DECODE(gender,'M','F','F','M');


commit;

update <TableName> set gender= case where gender='F' Then 'M' where gender='M' Then 'F'

what is diffrence between Co-related sub query and nested sub query??

Co-related sub query is one in which inner query is evaluated only once and from that result outer query is evaluated.

Nested query is one in which Inner query is evaluated for multiple times for gatting one row of that outer query.

ex. Query used with IN() clause is Co-related query.


Query used with = operator is Nested query
Correlated subquery runs once for each row selected by the outer query. It contains a reference to a value from the row selected
by the outer query.

Nested subquery runs only once for the entire nesting (outer) query. It does not contain any reference to the outer query row.

For example,

Correlated Subquery:

select e1.empname, e1.basicsal, e1.deptno from emp e1 where e1.basicsal = (select max(basicsal) from emp e2 where
e2.deptno = e1.deptno)

Nested Subquery:

select empname, basicsal, deptno from emp where (deptno, basicsal) in (select deptno, max(basicsal) from emp group by
deptno)

what is table space

Data Base is divided into 2 or more logical structure known as table space. Each table space one or more physical data file in
the hard disk.

How to find out the database name from SQL*PLUS command prompt?
SELECT INSTANCE_NAME from V$INSTANCE;

Select * from v$database;

Select * from global_name;

Difference between Store Procedure and Trigger


stored procedure is a pl/sql programming block stored in the database for repeated execution Whereas,Trigger is a pl/sql
programming block that is executed implicitly by a data manipulation statement.

We need to call the stored procedure explictily where as triggers fires when ever an event occurs.

How to copy sql table.

COPY FROM database TO database action -

destination_table (column_name, column_name...) USING query

eg

copy from scott/tiger@ORCL92 -

to scott/tiger@ORCL92-

create new_emp –

using select * from emp;

I have a table with duplicate names in it. Write me a query which returns only duplicate rows with number of times they
are repeated.

select name,count(name) occurences from table1 group by name having count(name)>1

SELECT DISTINCT (column name) from TABLENAME

Which function is used to find the largest integer less than or equal to a specific value
Floor

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