Professional Documents
Culture Documents
When working in Oracle, you may find that some of your records have duplicates. You
can delete these duplicate rows by identifying them and using its RowID, or row
address. Before you begin, you should create a backup table in case you need to
reference them after you have deleted records.
2-
DELETE
from table_name
WHERE rowed not in
( select max(rowid) from table_name group by column_name);
Or
or
DELETE
from table_name a
WHERE rowed not in
( select max(rowid) from table_name b where a.column_name=b.column_name);
second max
WITH T AS
(
SELECT *
DENSE_RANK() OVER (ORDER BY Salary Desc) AS Rnk
FROM Employees
)
SELECT Name
FROM T
WHERE Rnk=3;
WITH T AS
(
SELECT *
DENSE_RANK() OVER (ORDER BY Salary Desc) AS Rnk
FROM Employees
)
SELECT Name
FROM T
WHERE Rnk=3;
WITH T AS
(
SELECT *
DENSE_RANK() OVER ( PARTITION BY DEPARTMENT_ID ORDER BY Salary
Desc) AS Rnk
FROM Employees
)
SELECT *
FROM T
WHERE Rnk=1;
OR
SRNO ROW_NUMBER
ROW_ID ROW_NUM
Rowid is
3 ROWNUM is temporary ROW_NUMBER is temporary
permanent
CASE is a Statement in SQL / PL SQL DECODE is a function in Oracle that can be used in SQL only
CASE helps in building conditional logic DECODE also helps in building conditional logic
CASE can use comparison operators like ( IF > ) Decode cannot use comparison operators (like > ) but the Decode logic is based on Equality
CASE can be used as constructs in PL SQL blocks DECODE can be part of SQL statements only. Though the SQL can be used in PL SQL
CASE can handle predicates (like IN) and searchable subqueries DECODE Cannot handle Predicates and searches.
You can use Parameter as CASE statements to procedure calls Decode cannot handle parameters as procedure calls
CASE expects datatype consistency, DECODE does not expect datatype consistency
6) SYNONYMS
What are synonyms in Oracle SQL?
A synonym is an alias or friendly name for the database objects (such as tables,
views, stored procedures, functions, and packages).
Oracle View
In Oracle, view is a virtual table that does not physically exist. It is stored in Oracle data
dictionary and do not store any data. It can be executed when called.