Prime example showing benefits of Analytical Functions

On the topic of analytical functions, I will be the first to say that they are not my strength. However that said, reading one article after another I am increasingly aware of what I am missing.

I stumbled upon an excellent article demonstrating significant performance gains across the board from timing to resource utilization, all due to the use of analytical functions.

I encourage you take some time and review the posting.

Analytic Functions: A Savior by ASIF MOMEN

Virtual Columns in 11g

Link: http://www.oracle-developer.net/display.php?id=510

"Oracle has supported stored expressions for many years, in views and function-based indexes. Most commonly, views enable us to store and modularise computations and expressions based on their underlying tables' columns. In more recent versions (since around the 8i timeframe), we have been able to index expressions using function-based indexes. Now, with the release of 11g, Oracle enables us to store expressions directly in the base tables themselves as virtual columns.

As we will see in this article, virtual columns are more flexible than any of their prior alternatives. We will examine their basic usage and also consider some of the performance aspects of the new feature."

Count number of character occurences in a string

Sourced from := [email protected]

A question was posed on the listserver regarding the 'how' of identifying how many vowels are in a particular string of text. Not certain as to the purpose of same, however intresting nonetheless. For those on 10g+, use of the REGEXP% syntax comes into play.

DECLARE
v_str varchar2(200):='RAJEEV HERE from lucknow' ;
vn_vowel number;
BEGIN
SELECT length(v_str)- length(REGEXP_REPLACE(v_str,'[a,e,i,o,u,A,E,I,O,U]',''))
into vn_vowel FROM DUAL;
dbms_output.put_line(vn_vowel);
END;

For those on versions prior to 10g, this method was proposed that provided the same result.

select length(COLUMN_NAME) - length( translate(lower(COLUMN_NAME),'zaeiou','z')) from TABLE_NAME ;

Using Analytic Functions in Oracle

Provided by Chaitanya Susarla <chaitanyasusarla at yahoo.com>

This article is just to show some quick yet simple examples of how to use analytic functions in ORACLE. Though It doesn't cover all the analytical functions available, I am just focussing on trivial functions we use in daily sql queries and to understand the way analytics work for them.

All the following examples are tested on ORACLE Version 10.2.0.3.0.

What are analytic functions?
Answer:

(From Oracle documentation of 10g Release2(10.2))

(url: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions001.htm#sthref965)

Analytic functions compute an aggregate value based on a group of rows. They differ from aggregate functions in that they return multiple rows for each group. The group of rows is called a window and is defined by the analytic_clause. For each row, a sliding window of rows is defined. The window determines the range of rows used to perform the calculations for the current row. Window sizes can be based on either a physical number of rows or a logical interval such as time.

Analytic functions are the last set of operations performed in a query except for the final ORDER BY clause. All joins and all WHERE, GROUP BY, and HAVING clauses are completed before the analytic functions are processed. Therefore, analytic functions can appear only in the select list or ORDER BY clause.

Analytic functions are commonly used to compute cumulative, moving, centered, and reporting aggregates.

Do not worry If you don't understand the defintion from Oracle documentation. For any first timers, it is tough to grasp it quickly. After going through the following examples, probably you will have idea of what they are, so that you can revisit the definition and/or URL once again to get complete understanding of how they work and what they are meant for.

Now let us start.....

Pages: 1 · 2 · 3 · 4 · 5 · 6 · 7 · 8 · 9

11g : Using the PL/SQL Function Result Cache

Excerpt from Oracle’s documentation regarding Result Caching. I was very excited by this feature initially, but after reading further and its limitations… my excitement dimmed somewhat.

“The PL/SQL function result caching mechanism provides a language-supported and system-managed means for caching the results of PL/SQL functions in a shared global area (SGA), which is available to every session that runs your application. The caching mechanism is both efficient and easy to use, and it relieves you of the burden of designing and developing your own caches and cache-management policies.”

Click here to view complete document.

What exactly lessened my excitement ?

Restrictions on Result-Cached Functions

So is it a cool new feature yes… but with what appears to be several limiting factors. Are these things to be resolved and enhanced in future versions, or are there key technical reasons for the restrictions. At this point I am too new to the concept to answer either way. Hopefully I will gain some insight later, or if I am lucky the PL/SQL Programming (O’Reilly) 5th edition will cover it. NO its not out, but something tells me its around the corner in the near future.

For details on the restrictions read on.

Pages: 1 · 2