Useful functions in Oracle 11g Part 04

No.of Views2139
Bookmarked0 times
Downloads 
Votes2
By  Nimish Garg   On  24 Jul 2010 22:07:26
Tag : Oracle , Database Administrator
In this article, i have given samples to another few no of function demonstration here 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 another few no of useful functions and alternatives way  demonstration in oracle 11g.

  1. Triangular Series
  2. Rollup Query
  3. Differece between wm_concat and ListAgg

Triangular Series

http://nimishgarg.blogspot.com/2010/07/oracle-sql-triangular-series-1-3-6-10.html

Example Scenario

11+2=3(1+2)+3=6(1+2+3)+4=10(1+2+3+4)+5=15

The general representation of a triangular number is dn= 1 + 2 + 3 + 4 +...+ (n-2) + (n-1) + n,

SQL for generating Triangular Series

select sum(b) from(select level a from dual connect by level < 10) x,(select level b from dual connect by level < 10) y
where b<=agroup by aorder by 1;

 OUTPUT 

Image Loading

Rollup Query

http://nimishgarg.blogspot.com/2010/07/oracle-rollup-query.html

ROLLUP enables a SELECT statement to calculate multiple levels of subtotals across a specified group of dimensions. It also calculates a grand total. ROLLUP is a simple extension to the GROUP BY clause, so its syntax is extremely easy to use. The ROLLUP extension is highly efficient, adding minimal overhead to a query.

selectdeptno,job,sum(sal)fromscott.emp
group byrollup(deptno,job);

Output

Image Loading

Differece between wm_concat and ListAgg

http://nimishgarg.blogspot.com/2010/07/oracle-differece-between-wmconcat-and.html

1. wm_concat is undocumented and unsupported by oracle, thus rendering production systems unsupported. listagg is documented and supported by oracle.

2. wm_concat allows distinct option. listagg does not allows it.

select wm_concat(distinct ename) as enames from emp;

3. listagg allows to decide string concat order. wm_concat does not allows it.

select listagg(ename,',') within group(order by empno desc) as enames from emp;

4. listagg allows to decide delimiter. wm_concat does not allows it.

select listagg(ename,'***') within group(order by empno desc) as enames from emp;

5. wm_concat allows to be used olap function with order by listagg does not allows it. listagg allows only olap function without order by.

select deptno,wm_concat(ename) over(order by deptno) as enames from emp;

6. wm_concat allows to be used keep. listagg does not allows it.

select wm_concat(ename) keep(dense_rank first order by deptno) as enames from emp;

 That's all. enjoy,i will post more functions and useful queries in future.

 
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