Useful functions in Oracle 11g Part02

No.of Views956
Bookmarked0 times
Downloads 
Votes0
By  Nimish Garg   On  01 Jul 2010 08:07:21
Tag : Oracle , Database Administrator
In this article, i have given samples to three useful functions and one tips in oracle 11g
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this article, i have given example for another four useful functions and tips to oracle datatbase.

  • Simulating Dense_Rank Analytical Functions (Manual Dense_Rank)
  • Simulating Rank Analytical Functions (Manual Rank)
  • Simulating Analytical Functions KEEP DENSE_RANK OVER PARTITION BY
  • Global Temporary Table

Simulating Dense_Rank Analytical Functions (Manual Dense_Rank)

http://nimishgarg.blogspot.com/2010/06/oracle-simulating-denserank-analytical.html

ORIGINAL QUERY

selectempno,ename,deptno,sal,dense_rank() over(partition by deptno order by sal) drnk
from 
    scott.emp

SIMULATED QUERY

selectempno,ename,deptno,sal,(select count(distinct sal) from scott.emp a where a.deptno=b.deptno and a.sal <= b.sal) drnk
from 
    scott.emp b
order by 
    deptno, sal

 Output 

Image Loading

Simulating Rank Analytical Functions (Manual Rank)

http://nimishgarg.blogspot.com/2010/06/oracle-simulating-rank-analytical.html

ORIGINAL QUERY

selectempno,ename,deptno,sal,rank() over(partition by deptno order by sal) rnk
from 
    scott.emp

 SIMULATED QUERY

select empno,ename,deptno,sal,(select count(sal)+1 from scott.emp b where b.deptno=a.deptno and b.sal < a.sal) rnk
from 
    scott.emp aorder by 
    deptno, sal

 Output 

Image Loading

Simulating Analytical Functions KEEP DENSE_RANK OVER PARTITION BY

Original Query

select    empno,     deptno, to_char(hiredate,'yyyy') hire_yr, sal,sum(sal) keep (dense_rank first order by to_char(hiredate,'yyyy') ) over (partition by deptno) avg_sal_yr1_hire
from     scott.emp
where deptno in (20, 10)order by deptno,  empno, hire_yr;

 Simulated Query

select    empno, deptno, to_char(hiredate,'yyyy') hire_yr, sal,(select sum(sal) from scott.emp a where a.deptno = b.deptno and a.to_char(hiredate,'yyyy') = (select to_char(min(hiredate),'yyyy') from scott.emp c where a.deptno=c.deptno)) avg_sal_yr1_hire
from scott.emp b
where deptno in (20, 10)order by deptno, empno, hire_yr;

 Output 

Image Loading

Global Temporary Table

http://nimishgarg.blogspot.com/2010/06/oracle-global-temporary-table.html

Global temporary table exists solely for your session or whose data persists for the duration of your transaction.

When you create a temporary table, you can specify whether

  • it should last for the duration of your session (on commit preserve rows)
  • or whether its rows should be deleted when the transaction completes (on commit delete rows)

Unlike a permanent table, a temporary table does not automatically allocate space when it is created. Space will be dynamically allocated for the table as rows are inserted:

create global temporary table YEAR_ROLLUP 
(EMPNO NUMBER(4),ENAME VARCHAR2(9),SALARY NUMBER)

 on commit preserve rows;

That's all, i hope these tips and functions help to you. i will post some more functions soon.

 
Sign Up to vote for this article
 
About Author
 
Nimish Garg
Occupation-Software Engineer
Company-Indiamart Intermesh Limited
Member Type-Junior
Location-India
Joined date-04 Jun 2010
Home Page-http://nimishgarg.blogspot.com/
Blog Page-http://nimishgarg.blogspot.com/
Oracle DBA (Performance Tuning and Query Optimization) IndiaMART InterMESH Limited, Noida
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top