GeekInterview.com
Answered Questions

Find base table of the view

Asked By: swathy.r | Asked On: Feb 5th, 2011

Views are created on the basis of base tableswhat is the query to know the base table of the view? How to know the details of base table?

Answered by: Prem_p on: Apr 28th, 2011

Guys, you don't need a dba privilege for this.Run the query:select * from USER_DEPENDENCIES where  type='VIEW' and name=''This will give you the dependent object information (name , type of the obje...

Answered by: Balakrishna12207 on: Feb 7th, 2011

SELECT * FROM dba_views WHERE View_name=;


Text column can contain "The details of view and table"

Records count

Asked By: Subashpanda | Asked On: Dec 19th, 2010

How to count number of records in a table without using count function?

Answered by: Sandipan on: Sep 6th, 2012

select sum(1) from emp;

Code
  1. SELECT sum(1) FROM emp;

Answered by: smily08 on: Aug 30th, 2012

select max(rownum) from
(select ROW_NUMBER() over (order by col_name) as rowNum from table_name)
withRowNum

Index use

Asked By: kumarnavnit31 | Asked On: Sep 26th, 2010

If you have a three columns table with one index on 2nd column. In the select statement you retrived column 1, can index be used or not?

Answered by: amitsrivastava115 on: Aug 2nd, 2011

Use index in the where clause , this way you can use it other wise not ...

Answered by: geetha on: Jul 30th, 2011

index will be used if the retrieval is based on an indexed column .if the where clause uses a column with index then the query will be executed based on that index.

Single row function

Asked By: sunil_bisht | Asked On: Aug 4th, 2008

Display details of employees having same char at the star and end postition of their namelike abishikathis name have last character and first character is same

Answered by: yuvaevergreen on: Jun 8th, 2011

In Teradata,

sel * from employee where substr(name,1,1)=substr(name,length(trim(name)),1)

Answered by: Miao Lin on: May 9th, 2011

SELECT * from employee
where SUBSTR(EmployeeName, 1,1) = SUBSTR(EmployeeName, -1,1);

How do you print the last n rows or the first n rows of a table ?

Asked By: bharaniprasanth | Asked On: Mar 3rd, 2008

Star Read Best Answer

Editorial / Best Answer

Answered by: nirmal1in

View all questions by nirmal1in   View all answers by nirmal1in

Member Since Jan-2010 | Answered On : Jan 16th, 2010

This can be accomplished in following way:

Example: table - emp

For First n rows:

SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename desc) a
FROM emp) x
WHERE x.a < 5 --- say n is 5 display first 5 records

For last n rows:

SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename) a
FROM emp) x
WHERE x.a < 5

FROM )WHERE .a<

This query can be used for finding nth row also say n = 5

SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename desc) a
FROM emp) x
WHERE x.a = 5

Answered by: deepthi on: May 17th, 2012

Code
  1. SELECT rownum,a.*FROM(SELECT rownum,b.*FROM emp b ORDER BY rownum DESC) a WHERE rownum <&n;

Answered by: Vasavi Katakam on: Jul 18th, 2011

For First N Rows:

Code
  1.  
  2. SELECT top 5 * FROM table_name
  3.  

For Last N Rows:

Code
  1.  
  2. SELECT * FROM
  3. (SELECT top 5 * FROM
  4. table_name
  5. ORDER BY Columnname DESC)
  6. ORDER BY Columnname ASC
  7.  

Display the emploee records who joins the department before their manager?

Asked By: kowmudiswarna | Asked On: Sep 25th, 2007

Answered by: ngoudjou albert on: May 22nd, 2012

We use the selfjoin on the table employees to retrieve the job before thier managers

Code
  1. SELECT * FROM employees e , employees m
  2. WHERE e.manager_id=m.employee_id
  3. AND e.hire_date < m.hire_date;

Answered by: janardhan g on: Aug 7th, 2011

select x.ename from emp x,emp y where x.mgr=y.empno and x.hiredate

Dispaly employee records who gets more salary than the average salary in their department?

Asked By: kowmudiswarna | Asked On: Sep 14th, 2007

Answered by: farhan on: Apr 20th, 2012

Code
  1. SELECT * FROM emp  WHERE sal >(SELECT avg(sal) FROM emp)

Answered by: uma on: Mar 5th, 2012

select * from emp a
where salary >(select avg(salary) from emp b where a.dept_no = b.dept_no);

How do you view the last record added to a table?

Asked By: t_ahwaz | Asked On: Aug 25th, 2007

Answered by: leelakrishna302 on: Jun 15th, 2012

select * from EMP where rowid in (select min(rowid) from EMP);

Answered by: nirmal1in on: Dec 28th, 2010

We can accomplish this with rowid, below is an example of the query to get the latest inserted records from the table say emp

select * from emp outer where outer.rowid in (
select max(inner.rowid) b from emp inner);

How many maximum number of columns can be part of primary key in a table in Oracle 9i and 10g?

Asked By: Sachin Talwar | Asked On: Apr 3rd, 2007

Answered by: VENKAT on: Aug 26th, 2011

32

Answered by: venkat on: Aug 26th, 2011

The maximum number of columns can be part of Primary Key in a table in Oracle 9i and 10g are 32

How to write a SQL query to find n'th largest element in a column???

Asked By: bkkemparaju | Asked On: Jan 8th, 2007

Answered by: sampra on: Mar 6th, 2012

select * from hello h where 1=(select count(discnt amt) from hello where h.amt

Answered by: nirmal1in on: Dec 25th, 2010

Say for example below are data exist on EMP tableEMPNO  EMPNAME                DEPTNO      ...

What is the difference between procedure and function and package, which is the fastest

Asked By: Suyog | Asked On: Apr 28th, 2006

Answered by: Jay on: Sep 9th, 2012

I do not agree with this, Even a function can perform an action.

Answered by: Kiran Shelar on: Dec 29th, 2011

Hi Everybody, I dont see much update on why package is more faster than function or procedure. Of corse package is must faster than procedure or function The reason being whenvever package is called f...

What  are % type and % rowtype ? What are the advantages of using these over datatypes?

Asked By: Interview Candidate | Asked On: Sep 9th, 2004

 %  type  provides  the data type of a variable or a database column to that variable. % rowtype  provides the record type that represents a entire row of a table or view or columns selected in the cursor. the advantages are : i. Need not  know about variable's...

Answered by: PRADEEP on: Oct 16th, 2012

%rowtype is associated entire table(if we want to declare all columns then we need to declare %rowtype).

%type is associated with one column .(if we want to declare entire column then we need to declare %type).

Answered by: Yaseen on: Aug 9th, 2012

if using %type and %rowtype , no need to know the the data type of the table column . and once the development is finished , the type of column is changed it will not effect the coding.

What is a join

Asked By: Interview Candidate | Asked On: Aug 22nd, 2005

Star Read Best Answer

Editorial / Best Answer

Answered by: NK

Answered On : Jun 29th, 2005

A join is a query that combines rows from two or more tables, views, or materialized views. Oracle performs a join whenever multiple tables appear in the query's FROM clause. The query's select list can select any columns from any of these tables. If any two of these tables have a column name in common, then you must qualify all references to these columns throughout the query with table names to avoid ambiguity. 
 
Most join queries contain WHERE clause conditions that compare two columns, each from a different table. Such a condition is called a join condition. To execute a join, Oracle combines pairs of rows, each containing one row from each table, for which the join condition evaluates to TRUE. The columns in the join conditions need not also appear in the select list. 
 
To execute a join of three or more tables, Oracle first joins two of the tables based on the join conditions comparing their columns and then joins the result to another table based on join conditions containing columns of the joined tables and the new table. Oracle continues this process until all tables are joined into the result. The optimizer determines the order in which Oracle joins tables based on the join conditions, indexes on the tables, and, in the case of the cost-based optimization approach, statistics for the tables. 
 

Answered by: csbhaskar on: Apr 7th, 2011

A join is a query that results in combining rows from two or more tables, views, or materialized views. Oracle Database performs a join whenever names of multiple tables, views or materialized views a...

Answered by: nirmal1in on: Jan 3rd, 2010

Join is relation between more than one table. No of minimum join conditions required is equal to n-1 (where n is number of tables joined together)

What is difference between truncate & delete

Asked By: Interview Candidate | Asked On: Sep 7th, 2005

Answer posted by scott on 2005-05-25 18:30:04: truncate is a DDL command and cannot be rolled back. All of the memory space is released back to the server. delete is a dml command and can be rolled back.  both commands accomplish identical tasks (removing all data from a table), but truncate...

Star Read Best Answer

Editorial / Best Answer

Answered by: Prangya Sahu

Answered On : Nov 21st, 2005

1>TRUNCATE is a DDL command whereas DELETE is a DML command.

2>TRUNCATE is much faster than DELETE.

Reason:When you type DELETE.all the data get copied into the Rollback Tablespace first.then delete operation get performed.Thatswhy when you type ROLLBACK after deleting a table ,you can get back the data(The system get it for you from the Rollback Tablespace).All this process take time.But when you type TRUNCATE,it removes data directly without copying it into the Rollback Tablespace.Thatswhy TRUNCATE is faster.Once you Truncate you cann't get back the data.

3>You cann't rollback in TRUNCATE but in DELETE you can rollback.TRUNCATE removes the record permanently.

4>In case of TRUNCATE ,Trigger doesn't get fired.But in DML commands like DELETE .Trigger get fired.

5>You cann't use conditions(WHERE clause) in TRUNCATE.But in DELETE you can write conditions using WHERE clause.

Answered by: saravanan on: Sep 18th, 2012

delete & truncate command will delete entries from a table.. where as we can delete a single entry using delete but incase of truncate it wont be possible..

using truncate will delete the log files,buffer storage in a table permanently but incase of delete it wont

Answered by: ch.v.sambasivarao on: Jul 10th, 2012

TRUNCATE- truncate is a DDl command,it deletes the records permanently AND it cannot delete specific record.

DELETE- delete is DML command,it delete the records temporarily AND get it the record by using command called rollback,it can delete specific record.

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us: