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?
How to count number of records in a table without using count function?
select sum(1) from emp;
Code
SELECT sum(1) FROM emp;
select max(rownum) from
(select ROW_NUMBER() over (order by col_name) as rowNum from table_name)
withRowNum
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?
Use index in the where clause , this way you can use it other wise not ...
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.
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
In Teradata,
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 ?
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
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
Code
SELECT rownum,a.*FROM(SELECT rownum,b.*FROM emp b ORDER BY rownum DESC) a WHERE rownum <&n;
For First N Rows:
Display the emploee records who joins the department before their manager?
We use the selfjoin on the table employees to retrieve the job before thier managers
Code
SELECT * FROM employees e , employees m WHERE e.manager_id=m.employee_id AND e.hire_date < m.hire_date;
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?
Code
SELECT * FROM emp WHERE sal >(SELECT avg(sal) FROM emp)
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?
select * from EMP where rowid in (select min(rowid) from EMP);
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?
32
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???
What is the difference between procedure and function and package, which is the fastest
I do not agree with this, Even a function can perform an action.
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?
% 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...
%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).
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.
Answered by: NK
Answered On : Jun 29th, 2005A 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.
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...
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
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...
Answered by: Prangya Sahu
Answered On : Nov 21st, 20051>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.
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
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.
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...
SELECT * FROM dba_views WHERE View_name=;
Text column can contain "The details of view and table"