You are on page 1of 1304

OracleBlog: February 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I think
data, I think Oracle. I also enjoy writing, so I use this format to organise my thoughts. Please
feel free to discuss any thoughts you may have on the same topics, even old ones (I will see and
respond to such comments). You may want to start with "LIST ALL ARTICLES" under Archives.

Friday, February 24, 2006


About Me
The Oracle Effect Name: Robert
You thought the Tom Kyte Effect was the most Vollman
powerful force in the Oracle Blogging Universe. But Location: Calgary,
we were all mistaken! For today, I got a much higher Alberta, Canada
spike than ever. The source? Oracle itself!
I was born and raised in Ottawa,
and have lived in Calgary since
1991. I like playing sports
(hockey, soccer, ultimate,
basketball, you name it) and
military board games. I also
I am especially grateful that Gary Myers caught my enjoy reading, walking, and
sloppy error before a bunch of people read it. My playing with my 2 cats Lilly and
only regret is that I didn't really have anything Brutus. I'm a database
particular intelligent to say, and even if I did, it was application specialist, whatever
said so much better by (among other people) that is.
Howard Rogers.
View my complete profile
Since the link will change soon, here is a JPG to
mark my 15 minutes of nerd fame.
Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald

http://thinkoracle.blogspot.com/2006_02_01_archive.html (1 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

The Oak Table


● Cary Millsap and Hotsos


● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
// posted by Robert Vollman @ Friday, February 24, 2006 3 ❍ Oracle Base Aggregator

comments Top Blogs


❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
Wednesday, February 22, 2006
Blogger of the Year Eddie Awad
Never noticed this before

Data Warehouser David Aldridge


So I was searching through the latest Oracle 10g

Oracle Geek Lewis Cunningham


SQL Reference,

❍ Database Expert James Koopmann


check out what I found on page 5-175: ❍ Dizwell's Howard Rogers
SELECT manager_id, last_name, salary, SUM(salary) ❍ Oracle Master Laurent Schneider
OVER (PARTITION BY manager_id ORDER BY salary ❍ Security Expert Pete Finnigan
RANGE UNBOUNDED PRECEDING) l_csum ❍ Oracle Award Winner Mark
FROM employees; Rittman
❍ Doug Burns
MANAGER_ID LAST_NAME SALARY L_CSUM ❍ Oracle ACE of the Year Dr. Tim
---------- --------- ------ ------ Hall
100 Mourgos 5800 5800 ❍ UKOUG's Andrew (Arfur C.) Clarke
100 Vollman 6500 12300 ❍ Newbie DBA Lisa Dobson
...
❍ Coffee-Drinking DBA Jon Emmons
I'm in the Oracle default HR schema! I'm employee ❍ Chris Foot
123 and I report directly to KING, the President! Of ❍ The Pythian DBA Team Blog
course, I'm one of the lowest paid managers, but ❍ DBA Don Seiler
still. ❍ DBA Coskan Gundogar
❍ Oracle WTF
Of course, the first name is Shonta. But I can dream,
right? I can pretend that I'm one of Lex de Haan's
fictional colleagues, right?
ARCHIVES
❍ LIST ALL ARTICLES
I also saw this in the latest version of Oracle 9i ❍ May 2005

http://thinkoracle.blogspot.com/2006_02_01_archive.html (2 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

documentation: ❍ June 2005


SQL Reference: ❍ July 2005
Page 365, 6-155 for the example of SUM. ❍ August 2005
Page 1532, 18-42 on using LEVEL Pseudo-Column. ❍ September 2005
❍ October 2005
and Sample Schemas: ❍ November 2005
Page 68, section 4-28 on Oracle's sample HR ❍ December 2005
Schema ❍ January 2006
So it must have been around for awhile. I think ❍ February 2006
that's so cool! I'm going to write Oracle and ask ❍ March 2006
them to fix my first name. I urge you to do the ❍ April 2006
same in your implementations: ❍ May 2006
❍ June 2006
UPDATE employees SET first_name = 'Robert' where ❍ July 2006
last_name = 'Vollman'; ❍ August 2006
❍ September 2006
// posted by Robert Vollman @ Wednesday, February 22, 2006 1
❍ October 2006
comments ❍ November 2006
❍ December 2006
❍ January 2007
Oracle Sequences ❍ February 2007
Proactively maintaining your database ... something ❍ March 2007
some people do only AFTER a problem of some kind. ❍ April 2007
❍ May 2007
Case in point, a customer recently asked us what
June 2007
sequences are being used as primary keys, what are

October 2007
their maximum values, and are any in danger of

running out. Guess what motivated that


Current Posts
investigation?

Most of this is rather trivial using only the


ALL_SEQUENCES table.

1. What sequences are being used, and do they roll


over or run out?

SELECT cycle_flag, sequence_name FROM


ALL_SEQUENCES;

2. Which sequences are being used as primary keys?

That's trickier. See, even if you're using a sequence


as a primary key, there's no way to tell by just
looking at a table somewhere. The INSERT
commands could be calling that sequence directly.
Edit Or, it could be inserted by a trigger. I'm not

http://thinkoracle.blogspot.com/2006_02_01_archive.html (3 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

aware of any easy, reliable way to determine if


sequences are being used as primary keys without
looking table by table.

However, generally that is what people like to use


sequences for, so there's a good chance that all the
sequences are being used as keys somewhere.

3. Which sequences are in danger of running out?

SELECT sequence_name, (max_value - last_number)/


increment_by sequences_left
FROM ALL_SEQUENCES
ORDER BY sequences_left;

4. What happens when a sequence runs out?

Well that depends if its a roll-over or not.

CREATE SEQUENCE rollover_seq MINVALUE 1 START


WITH 1 INCREMENT BY 1 MAXVALUE 3 CYCLE
NOCACHE;
CREATE SEQUENCE runout_seq MINVALUE 1 START
WITH 1 INCREMENT BY 1 MAXVALUE 3 NOCYCLE
NOCACHE;

CREATE TABLE sequence_table (roll NUMBER(1),


runout NUMBER(1));

Run this three times:


INSERT INTO sequence_table (roll, runout) VALUES
(rollover_seq.NEXTVAL, runout_seq.NEXTVAL);

On the fourth time:


ORA-08004: sequence RUNOUT_SEQ.NEXTVAL
exceeds MAXVALUE and cannot be instantiated

But the other one rolls over:


INSERT INTO sequence_table (roll, runout) VALUES
(rollover_seq.NEXTVAL, 4);

scott@Robert> SELECT * FROM sequence_table;


ROLL RUNOUT
---------- ----------
1 1
2 2
3 3
2 4

http://thinkoracle.blogspot.com/2006_02_01_archive.html (4 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

Why is it 2,4 instead of 1,4? Well we "used up" the 1


on the misfire, so now we have a "gap." Every time
NEXTVAL is "called", the sequence increments.
CURRVAL doesn't. Of course, CURRVAL gives you
last_number, which is one that's presumably already
in use.

By the way, as usual, you can get some better


examples, and a better reference, from Dan
Morgan's library.

Those looking for an equivalent to AUTONUMBER in


other RDBMS may find that using an Oracle
sequence is close to the same functionality. Edit Just
use the sequence's NEXTVAL as your insert for your
key, or in a trigger, like so:

-- Won't work:
CREATE TABLE MyTable (seq_id NUMBER(1) DEFAULT
rollover_seq.NEXTVAL);
ORA-00984: column not allowed here

-- Will work:
CREATE TABLE MyTable (seq_id NUMBER(1));

CREATE OR REPLACE TRIGGER trig_seq BEFORE


INSERT ON MyTable
FOR EACH ROW
BEGIN
SELECT rollover_seq.NEXTVAL into :new.seq_id
FROM dual;
END;

To prevent this post from getting longer than it


needs to be, I'll just send you to AskTom to read a
discussion about the performance of using Oracle
sequences as primary keys.

One final word, about the NOCACHE command I


used up there. The default CACHE value is 20, so I
had to use NOCACHE because it would try to CACHE
more values than the sequence had. CACHE actually
CACHEs the next few values for quicker access. But
if ever there is a system failure, those previously-
retrieved sequence numbers are gone. You'll be left

http://thinkoracle.blogspot.com/2006_02_01_archive.html (5 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

with a "gap."

Of course, gaps may not be the end of the world for


you. If they are, you'll need to use ALTER SEQUENCE
to fix them. I've already mentioned two ways to get
gaps with sequences, here's one more. If you do a
transaction with NEXTVAL and then rollback, the
sequence doesn't roll back to where you started.
That'll create a gap, too.

// posted by Robert Vollman @ Wednesday, February 22,

2006 17 comments

Tuesday, February 21, 2006


Oracle Interview Questions
"We're interviewing an Oracle guy tomorrow, can
you give me a few questions to ask him?"

Not an uncommon request. The problem is, there


are literally thousands of potential Oracle questions,
but it all depends on what are you trying to achieve.
So I pushed back:

"What kind of Oracle-related skills would the


candidate need that you want to ask for?"
"You tell us. We just want to know if he knows
Oracle. Whatever an Oracle guy would need to
know."

Pretty soon thereafter I figured out that it was a


pointless conversation to continue, although I did
love the way he summarized dozens of very
different positions into that one term: "Oracle Guy."

Nevertheless, it got me thinking. What makes for a


good technical question? I have conducted, or been
invited to, several interviews, so it got me to
thinking about which questions were most effective
at getting to the heart of the matter: "Will this
candidate succeed technically in this role?"

Elements of a Good Technical Interview Question.

1. Must require knowledge of the area, including


domain and philosophy, to solve.

http://thinkoracle.blogspot.com/2006_02_01_archive.html (6 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

I don't think it's enough that a candidate


demonstrates proficiency with the technology. I like
to see if they understand the overall philosophy of
the product (Oracle, in this case): What needs was it
meant to provide, what kind of problems was it
designed to solve, how does it accomplish those
tasks.

2. Must require overall technical skill/experience/


understanding to solve.

I mean to say that a good question shows if the


candidate understands (for example) relational
databases themselves, not just a particular
relational database. Carrying this example, does
your C++ developer understand algorithms and
software design?

3. Does not require knowledge of precise syntax

In my mind, anyone can look something up in a


manual. You don't need to walk into an empty
boardroom and know exactly how something is
called. I don't think knowledge of syntax is a
reliable indicator of the suitability of a candidate.

For example, you could have a good candidate


"blank out" on the syntactic details, and you could
also have a bad candidate who swallowed a
reference manual the night before the interview.

Now, I would be worried if the candidate didn't


know BASIC syntax. But I don't want to waste
precious time asking basic questions, and if he is
truly is that inexperienced, I should be able to
figure it out in other ways.

4. Can be answered quickly.

Time is precious in an interview, and you shouldn't


need long, convoluted questions to determine
whether or not a candidate "gets it." A good
question demonstrates quickly if the candidate is on
the right path, or wouldn't get it regardless of how
much time he had.

5. Is not a "gotcha"

http://thinkoracle.blogspot.com/2006_02_01_archive.html (7 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

I've met some interviewers that seem to use the


opportunity not to evaluate the candidate, but to
prove how clever they are (either to the candidate or
the manager). They do this by asking really obscure
tricks, sometimes referred to as "gotchas."

The problem with asking questions in the obscure


corners is that even very experienced candidates
may not have worked in that area and, if they have,
may not have stumbled across that particular gem.

Just remember, the purpose of the interview isn't to


make YOU look clever, and asking silly questions
might make a great candidate think "what kind of
clown show am I getting myself into?"

6. Has many possible solutions and approaches

The most effective questions I have ever asked, or


been asked, were the ones that triggered lively
technical discussions between the interviewer and
the candidate. Why? You get to catch a glimpse not
only of the candidates thinking process, but also
how he communicates. I also like the added benefit
of not punishing (in fact, rewarding) those that
approach problems differently than the interviewer.

7. Requires asking for more information (or make


assumptions).

Personally, I believe one of the keys to success in IT


is to define a problem before approaching it. That's
why I lean towards these types of questions. Did the
candidate come back, or just try to solve it? If he
came back, what kind of questions did he ask? In
the face of an incompletely-defined problem, did he
get stuck, or did he make some assumptions and
continue? If so, what assumptions did he make?

8. Is relevant to the business/job being considered

Would you hire a cleaning service with award-


winning carpet cleaning if you had hardwood floors?
Would you hire a running back who excels in bad
weather if you played in a dome? Would you hire an
accomplished science-fiction writer to author your
biography? No? Then why probe for technical skills
that don't directly apply to the position you're

http://thinkoracle.blogspot.com/2006_02_01_archive.html (8 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

attempting to fill?

Closing Thoughts

Incidentally, in the end I referred the manager in


question to a couple of links which have hundreds
of Oracle-interview questions. You can pick your
favourites but, more likely, you can read them until
you come up with good ideas that suit your needs.

http://www.orafaq.com/forum/t/9760/2/
http://www.databasejournal.com/features/oracle/
article.php/3085171

As an aside, that last article was written by one of


my preferred columnists, James Koopmann. He
hasn't written much recently, but check out his
archives, he's got some great articles there. For
instance, check out his series on Oracle Session
Tracing.

// posted by Robert Vollman @ Tuesday, February 21, 2006 3

comments

Tuesday, February 14, 2006


BPEL
BPEL (Business Process Execution Language) is an
xml-based language for use with the Service-
Oriented Architecture (SOA) to software
development.

Simply put, BPEL is an XML-based standard used to


define business processes, generally by
demonstrating how relevant Web Services connect
and communicate. You would use BPEL to layout the
general business flow and how the Web Services are
used. In the end, you have a particularly-formatted
XML file running on a BPEL Server.

To do this, Oracle provides the BPEL Process


Manager. This is a BPEL IDE that will generate your
BPEL XML file, and then run it on a BPEL Engine
running on top of the Oracle Application Server.
There are lots of other engines out there, BPEL and

http://thinkoracle.blogspot.com/2006_02_01_archive.html (9 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

SOA is by no means unique to Oracle. In fact, here


is an Open Source BPEL Server, ActiveBPEL.

BPEL has its roots in IBM and Microsoft's WSFL and


XLANG. It was originally called BPEL4WS (BPEL for
Web Services), but was renamed WS-BPEL. BPEL was
meant to replace WSCI ("Whiskey"), which Oracle put
forward with Sun and SAP a few years ago for the
same purpose (designing the coordination of Web
Services). And if that is not enough acronyms for
you, I'll just note that BPEL uses WSDL to determine
the format of the messages to be sent among the
various Web Services.

For those wanting a quick hands-on "taste" of BPEL,


here is what I did.

1. Start BPEL Server


2. Start the BPEL Designer, which is part of
JDeveloper
3. Connected to the BPEL Console through a web
browser
4. Create a new "BPEL Process Project" in JDeveloper
5. Made a few minor changes to the default project
6. Toggled to Source and saw my changes in the
XML
7. Validated the changes using the "BPEL Validation
Browser."
8. Generated a nice JPG of my BPEL business process

9. Deployed the project to the default BPEL Server I

http://thinkoracle.blogspot.com/2006_02_01_archive.html (10 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

had started
10. Found the deployed service in the BPEL Console
11. From the BPEL Console, entered a parameter
and initiated my BPEL process
12. Still from the BPEL Console, audited the flow
and examined the XML messages that went back
and forth

Thus concludes my introductory post on BPEL. Next


I'm going to find some Web Services out there and
build a more significant business process. When I
do, I'll be sure to post an article with my JPG and
what I thought of some of the bells and whistles.

// posted by Robert Vollman @ Tuesday, February 14, 2006 1

comments

Tuesday, February 07, 2006


TRANSLATE
TRANSLATE is a useful little function that can
replace given characters in the first string with
other given characters. TRANSLATE will go through
the provided string looking for any instance of
characters in the first list and, when found, replace
them with the corresponding character in the
second list. Any characters in the given string that
don't show up in the first list are left alone.

If the first list is longer than the second list, that


means that some characters have no corresponding
character. In that case, such characters are simply
replaced with nothing (ie. deleted). So if you want to
remove a character, put them at the end of your
first list. It clearly doesn't make sense for the
second list to be longer than the first list, nor does
it make sense to have duplicates in the first list
(although it certainly makes sense in the second
list). If you do have inconsistent duplicates in your
first list, Oracle seems to choose the character in
the second list corresponding to its first occurence
in the first list.

By the way, the two lists are actually passed as


strings, but it makes more sense to picture them as
lists. C programmers will be most comfortable,

http://thinkoracle.blogspot.com/2006_02_01_archive.html (11 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

because they are used to interpreting strings as


arrays of characters, and that's what we're dealing
with here.

TRANSLATE is under chapter 6 (Functions) of


Oracle's SQL Reference.

Let's look at a first, simple example to remove the


dashes in a phone number and replace them with
dots to form some kind of standard syntax.

scott@Robert> SELECT TRANSLATE


('(619)455-1998', ')-(', '..') PHONE_NO
FROM DUAL;

PHONE_NO
------------
619.455.1998

Complex constraints are a particularly good use for


TRANSLATE. Let's presume you have a column that
represents a special code in your company where
the 4th character must be a digit, and the first digit.
Well, you may know that INSTR can tell you where
the first occurence of a particular character is, but
you're looking for 10 characters, how can that be
done? Quite easily, because with TRANSLATE you
can change all characters to a single one.

CREATE TABLE MyTable (special_code


VARCHAR2(32) CHECK (INSTR
(TRANSLATE(special_code, '123456789',
'000000000'), '0') = 4));

scott@Robert> INSERT INTO MyTable


(special_code) VALUES ('abc123');

1 row created.

scott@Robert> INSERT INTO MyTable


(special_code) VALUES ('abcd1234');
INSERT INTO MyTable (special_code)
VALUES ('abcd1234')
*
ERROR at line 1:

http://thinkoracle.blogspot.com/2006_02_01_archive.html (12 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

ORA-02290: check constraint (SCOTT.


SYS_C008454) violated

That is an excellent technique of how TRANSLATE


can be applied to a problem. As a side note, we can
use RPAD to generate that second list for us if it is
very long.

CREATE TABLE MyTable (special_code


VARCHAR2(32) CHECK (INSTR
(TRANSLATE(special_code, '123456789',
RPAD('0', 9, '0')), '0') = 4));

Let's say you have a special column that should


ONLY have numbers. How can you do that? Well
how about you delete them all, and then see if you
have an empty string? That would look something
like this:

CREATE TABLE MyTable (numeric_only


VARCHAR2(32) CHECK (TRANSLATE
(numeric_only, '0123456789', '') IS
NULL));

scott@Robert> INSERT INTO MyTable


(numeric_only) VALUES ('abc123');

1 row created.

Oops? What happened? I'll show you this little


feature of TRANSLATE:

scott@Robert> SELECT TRANSLATE


('abc123', '0123456789', '') FROM DUAL;

T
-

The truth is, if the second list is empty, it seems to

http://thinkoracle.blogspot.com/2006_02_01_archive.html (13 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

wipe out the entire string. Fortunately there is a


pretty easy way around this. Just make sure the
second string isn't empty. Map some non-important
character to the same character, like so:

scott@Robert> SELECT TRANSLATE


('abc123', '$0123456789', '$') FROM
DUAL;

TRA
---
abc

Let's try this new constraint:

CREATE TABLE MyTable (numeric_only


VARCHAR2(32) CHECK (TRANSLATE
(numeric_only, '$0123456789', '$') IS
NULL));

scott@Robert> INSERT INTO MyTable


(numeric_only) VALUES ('1234');

1 row created.

scott@Robert> INSERT INTO MyTable


(numeric_only) VALUES ('abc123');
INSERT INTO MyTable (numeric_only)
VALUES ('abc123')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.
SYS_C008456) violated

Much better! You know, if we wanted to allow some


non-numeric characters, but no more than 2, we
could use LENGTH to do that.

CREATE TABLE MyTable (max_2


VARCHAR2(32) CHECK (LENGTH
(TRANSLATE(max_2, '$0123456789',
'$')) <= 2));

http://thinkoracle.blogspot.com/2006_02_01_archive.html (14 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

scott@Robert> INSERT INTO MyTable


(max_2) VALUES ('abc123');
INSERT INTO MyTable (max_2) VALUES
('abc123')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.
SYS_C008459) violated

scott@Robert> INSERT INTO MyTable


(max_2) VALUES ('ab123');

1 row created.

As a quick aside, you'll notice that I specify my


column names when I'm doing an insert. Why, you
may ask, do I do that? Well don't you think what I'm
doing is clearer to you, the reader, when I specify
which values I'm inserting? Furthermore, if the
schema of a table changes, my INSERT command
will still work, assuming the schema change doesn't
affect the columns I'm using, and that there are no
new parameters that require a value.

You can do so much with TRANSLATE when


combined with other functions, such as (to name
just a few):

INSTR: gets the position of the first matching


character
TRIM: take away spaces, or specific, single
characters (also see LTRIM, RTRIM)
UPPER: converts all characters to upper case (also
see LOWER)
RPAD: creates a string of the same character (also
see LPAD)
LENGTH: calculates the length of a string

Despite the simplicity of the function, it comes in


useful in complex constraints and transformations,
both by itself and in concert with other Oracle
functions.

As a final note, for those of you needing something


other than the 1-to-1 switch that TRANSLATE
allows, and instead needing to replace one

http://thinkoracle.blogspot.com/2006_02_01_archive.html (15 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

substring with another, you want to use REPLACE.


Doubtlessly that will be the topic of a later post.

Dan Morgan's Reference on TRANSLATE:


http://www.psoug.org/reference/translate_replace.
html

// posted by Robert Vollman @ Tuesday, February 07, 2006 5

comments

Thursday, February 02, 2006


Oracle and SOA
I went to a seminar yesterday in downtown Calgary
where Oracle was unveiling its SOA Solution to all
the big Canadian oil and gas giants. SOA is the
latest buzz-acronym for "Service-Oriented
Architecture."

What is SOA?

SOA is not a technology or something you install. It


is a concept, or rather an approach to modelling
your system, and one that is different from the
standard client/server model you may be used to.
As opposed to large, proprietary applications that
do everything, SOA is a design meant to try to
integrate numerous and diverse software
applications with common interfaces, in the name
of code reuse/maintainability, and adaptibility. The
notion of using a group of independent applications
to accomplish a shared task is also sometimes
referred to as grid computing.

Everyone knows that "Web Services" are one of the


hottest things lately. An SOA is essentially a
collection of such services, communicating with one
another, generally through XML. (Of course I am
over-simplifying things: SOA can involve any kind
of self-contained service communicating in any
way.)

SOA is not specific to any technology, indeed every


"family" of technologies has its own SOA solution,
and usually you can mix-and-match your own.
However, open-source XML-based technologies

http://thinkoracle.blogspot.com/2006_02_01_archive.html (16 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

such as BPEL, SOAP and WSDL are very commonly


used.

For more information about SOA in general, visit


OASIS's web site:
OASIS Open Standard for SOA

What is Oracle's SOA Solution?

It was inevitable that Oracle would join in the fray


and devise SOA-based solutions. At the very least
as part of its "Oracle Fusion" project to integrate
PeopleSoft and JD Edwards. Notice the recent
acquisitions of Kurian, Collaxa and Oblix were all
steps along the SOA path.

Oracle's SOA solution leans heavily towards J2EE,


their preferred language in which to develop your
Web Services. They want you to use the perhaps
poorly-named JDeveloper as your IDE for
developing your Web Services with Oracle
Containers (OC4J). JDeveloper includes the toolset
Oracle Application Development Framework (ADF)
which also includes Oracle TopLink for object-
relational mapping. Of course they suggest you use
the Oracle Application Server for these Web
Services. Get more information on this from Oracle's
whitepaper:
Oracle's JDeveloper White Paper

One of the new components is the BPEL Process


Manager, acquired with Collaxa, which is an
application that includes several tools to develop
BPEL models and the underlying Web Services. This
is where you define which services are called, and
when. Grab this whitepaper for more on that:
Oracle's BPEL White Paper

For those who want more details, I am preparing a


future post on BPEL, followed by some of these
other acronyms I've mentioned. Note to Eddie: Half
the presenters pronounced it "bipple" and the other
half pronounced it "b-pull."

That summarizes my introductory post on Oracle


and SOA. I will be writing articles with more meat
and technical details over the next couple of weeks,

http://thinkoracle.blogspot.com/2006_02_01_archive.html (17 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

but for those who are intrigued and just can't wait,
here are some Oracle white papers on SOA:
Oracle E-Business and SOA
IDC: Oracle's SOA Platform

For more information about Oracle's SOA Solution,


visit their web site:
Oracle's Main SOA Site

// posted by Robert Vollman @ Thursday, February 02, 2006 3

comments

SourceForge
Have you been overlooking the wealth of handy
tools and code on SourceForge?

SourceForge.net is a web site that hosts literally


hundreds of thousands of projects. Its an excellent
source of open source development projects. You
can download software and source code and
collaborate with others on projects.

Having trouble designing your software? Search


SourceForge for similar projects and see what they
did.

Want to avoid re-inventing a wheel? Find something


suitable to your purposes at SourceForge.

Let's look at a quick example. The simplest example


I could find is a little PL/SQL script that generates a
package based on a table. I'm not promoting this
particular script, I'm just using it as an example.

You can fetch the simple example here:


http://sourceforge.net/projects/plsqlgenpkg/

Download it, and inside the zip file you'll find some
PL/SQL. Go ahead and run it: it will ask for a table
name, and a package name. It will then generate
some PL/SQL that you can use to generate a
package for your table. Easy as that.

That is pretty typical of SourceForge. Hunt around


and find some useful applications. There are PL/SQL

http://thinkoracle.blogspot.com/2006_02_01_archive.html (18 of 19)1/9/2008 2:49:06 AM


OracleBlog: February 2006

Editors and PL/SQL Plug-Ins to various IDEs (like


Eclipse). I've seen Java programs that can monitor
your database. All sorts of things.

Might be a good place to share your open source


tools, no? Especially the ones on which you're
looking for feedback.

I recommend rooting through SourceForge from


time to time if you don't already.

// posted by Robert Vollman @ Thursday, February 02, 2006 1

comments

http://thinkoracle.blogspot.com/2006_02_01_archive.html (19 of 19)1/9/2008 2:49:06 AM


OracleBlog: The Thomas Kyte Effect

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, December 20, 2005


About Me
The Thomas Kyte Name: Robert Vollman
Effect Location: Calgary, Alberta,
Good grief! Canada

I saw a spike in my statcounter and I was born and raised in


I checked it out to see if I got Ottawa, and have lived in Calgary since
spammed. Instead I am the newest 1991. I like playing sports (hockey, soccer,
beneficiary of the "Thomas Kyte ultimate, basketball, you name it) and
Effect." military board games. I also enjoy reading,
walking, and playing with my 2 cats Lilly
Well, strictly speaking, the Thomas and Brutus. I'm a database application
Kyte Effect is when your blog is specialist, whatever that is.
referenced in a blog article of his,
but in my case I was simply added
View my complete profile
to his list of links. And then bam -
several hundred hits today.

With all due respect to Doug, Lisa


and Eddie, in one day I've got more
Best Links
● Ask Tom Kyte
referrals from his blog than Oracle Docs
everyone else put together.

● Dan Morgan and PSOUG


I told Tom we could "cash in" on the ● Steven Feuerstein
"Thomas Kyte Effect" with a few ● Jonathan Lewis
well-chosen ads, but sadly he ● FAQ
wouldn't go for it. ● Connor McDonald

http://thinkoracle.blogspot.com/2005/12/thomas-kyte-effect.html (1 of 3)1/9/2008 2:49:10 AM


OracleBlog: The Thomas Kyte Effect

The Oak Table


Well, as long as you're all here, I ● Cary Millsap and Hotsos


would like to say two things: ● Steve Adams and Ixora
1. Welcome to my blog! ● Anjo Kolk and OraPerf
2. Please look through my archives,
Dizwell Oracle Wiki
some of my more interesting reads

My Personal Blog
are in July/August.

Comments are very welcome, even


on older posts (I get auto-emailed
when someone posts something). Aggregators
Brian Duff's OraBlogs

Also, I like to provide something Eddie Awad's OracleNA
useful in every post, so here it is: a

Pete Finnigan's Aggregator


link to an article by Steven

Oracle's Bloglist
Feuerstein about how to hide your

Oracle Base Aggregator


code: ❍

http://htmldb.oracle.com/pls/otn/
f? Top Blogs
p=2853:4:6669219410898182474:: ❍ Oracle's Ask Tom Kyte
NO::P4_QA_ID:4102 ❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
// posted by Robert Vollman @ Tuesday, ❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
December 20, 2005 ❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
Oracle Master Laurent Schneider
Comments: ❍

i feel that too, being listed on tom ❍ Security Expert Pete Finnigan
kyte blog generates much more ❍ Oracle Award Winner Mark Rittman
traffic than orablogs and google ❍ Doug Burns
together ;-) ❍ Oracle ACE of the Year Dr. Tim Hall
# posted by Laurent Schneider : ❍ UKOUG's Andrew (Arfur C.) Clarke
Wednesday, 21 December, 2005 ❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
Post a Comment ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
<< Home ❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/12/thomas-kyte-effect.html (2 of 3)1/9/2008 2:49:10 AM


OracleBlog: The Thomas Kyte Effect

❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/12/thomas-kyte-effect.html (3 of 3)1/9/2008 2:49:10 AM


OracleBlog: The Oracle Effect

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, February 24, 2006


About Me
The Oracle Effect Name: Robert
You thought the Tom Kyte Effect was the Vollman
most powerful force in the Oracle Blogging Location: Calgary,
Universe. But we were all mistaken! For today, Alberta, Canada
I got a much higher spike than ever. The
source? Oracle itself! I was born and raised in Ottawa,
and have lived in Calgary since
1991. I like playing sports
(hockey, soccer, ultimate,
basketball, you name it) and
military board games. I also
enjoy reading, walking, and
I am especially grateful that Gary Myers playing with my 2 cats Lilly and
caught my sloppy error before a bunch of Brutus. I'm a database
people read it. My only regret is that I didn't application specialist, whatever
really have anything particular intelligent to that is.
say, and even if I did, it was said so much
better by (among other people) Howard View my complete profile
Rogers.

Since the link will change soon, here is a JPG


to mark my 15 minutes of nerd fame.
Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG

http://thinkoracle.blogspot.com/2006/02/oracle-effect.html (1 of 3)1/9/2008 2:49:14 AM


OracleBlog: The Oracle Effect

● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
// posted by Robert Vollman @ Friday, February 24, 2006 Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
Comments: ❍ Oracle Base Aggregator
> got a much higher spike than ever
Nice to read, i'd be interested about how Top Blogs
many accesses you are talking in more ❍ Oracle's Ask Tom Kyte
concrete numbers. ❍ Oracle Guru Jonathan Lewis
Blogger of the Year Eddie Awad
BR,

Data Warehouser David Aldridge


Martin

❍ Oracle Geek Lewis Cunningham


# posted by Anonymous : Friday, 24 February, 2006
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
Martin, ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
Very roughly speaking, it looks like I've gotten ❍ Oracle Award Winner Mark
about 300 unique visitors in the last 2 days Rittman
from Oracle's web site. ❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim
Robert Hall
# posted by Robert Vollman : Friday, 24 February, ❍ UKOUG's Andrew (Arfur C.) Clarke
2006 ❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
Chris Foot
FYI, your link remains to be on the http://

❍ The Pythian DBA Team Blog

http://thinkoracle.blogspot.com/2006/02/oracle-effect.html (2 of 3)1/9/2008 2:49:14 AM


OracleBlog: The Oracle Effect

www.oracle.com/technology/index.html site, DBA Don Seiler


as of 2:09 P.M. EST on 20060226. ❍ DBA Coskan Gundogar


# posted by Hae-Kwang : Sunday, 26 February, 2006 ❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
Post a Comment ❍ May 2005
June 2005
<< Home

❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2006/02/oracle-effect.html (3 of 3)1/9/2008 2:49:14 AM


OracleBlog: Bookmark This Page

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday,
About Me
March 28, 2006
Name: Robert Vollman
Bookmark Location: Calgary, Alberta, Canada
This Page
To ease the I was born and raised in Ottawa, and have lived in
task of Calgary since 1991. I like playing sports (hockey,
browsing my soccer, ultimate, basketball, you name it) and military board games.
archives, I've I also enjoy reading, walking, and playing with my 2 cats Lilly and
put together Brutus. I'm a database application specialist, whatever that is.
an organised
list of my View my complete profile
previous posts.
Bookmark this,
because I will
keep it up to
Best Links
date. I will also ● Ask Tom Kyte
include a link ● Oracle Docs
to this post ● Dan Morgan and PSOUG
under Archives. ● Steven Feuerstein
● Jonathan Lewis
Note: If you FAQ
comment on

Connor McDonald
an older

The Oak Table


article, I will

Cary Millsap and Hotsos


get an ●

automatic ● Steve Adams and Ixora


email. So I will ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (1 of 21)1/9/2008 2:49:16 AM


OracleBlog: Bookmark This Page

see it and I will ● Dizwell Oracle Wiki


respond to it, ● My Personal Blog
so please feel
free to do so!

For Newbies: Aggregators


Tuesday, Brian Duff's OraBlogs

December 20, ❍ Eddie Awad's OracleNA


2005 ❍ Pete Finnigan's Aggregator
20 Beginner ❍ Oracle's Bloglist
Oracle ❍ Oracle Base Aggregator
Questions
Top Blogs
Friday, June ❍ Oracle's Ask Tom Kyte
17, 2005 Oracle Guru Jonathan Lewis
Asking For

❍ Blogger of the Year Eddie Awad


Help - Tips on ❍ Data Warehouser David Aldridge
where to go Oracle Geek Lewis Cunningham
and how to do

Database Expert James Koopmann


it.

❍ Dizwell's Howard Rogers


Wednesday, ❍ Oracle Master Laurent Schneider
July 19, 2006 ❍ Security Expert Pete Finnigan
Finding ❍ Oracle Award Winner Mark Rittman
Information - ❍ Doug Burns
How do you ❍ Oracle ACE of the Year Dr. Tim Hall
find answers to ❍ UKOUG's Andrew (Arfur C.) Clarke
other ❍ Newbie DBA Lisa Dobson
questions? ❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
Thursday, July
The Pythian DBA Team Blog
14, 2005

DBA Don Seiler


Oracle Docs -

DBA Coskan Gundogar


For when

Oracle WTF
people tell you

to RTFM!
ARCHIVES
Best Practises: ❍ LIST ALL ARTICLES
May 2005
Thursday,

June 2005
October 19,

July 2005
2006

❍ August 2005

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (2 of 21)1/9/2008 2:49:16 AM


OracleBlog: Bookmark This Page

3 Easy Ways to ❍ September 2005


Improve Your ❍ October 2005
PL/SQL - ❍ November 2005
Improving your ❍ December 2005
code through ❍ January 2006
instrumentation ❍ February 2006
and bulk ❍ March 2006
processing. ❍ April 2006
May 2006
Friday, March

09, 2007 ❍ June 2006


40 Tips From ❍ July 2006
Tom (Kyte) ❍ August 2006
❍ September 2006
Tuesday, June ❍ October 2006
14, 2005 ❍ November 2006
Bind Variables ❍ December 2006
in PL/SQL - ❍ January 2007
Short answer: ❍ February 2007
PL/SQL binds ❍ March 2007
all variables ❍ April 2007
(with some ❍ May 2007
exceptions like ❍ June 2007
dynamic SQL) ❍ October 2007
Tuesday,
January 24,
2006
Gathering
Requirements

Wednesday,
March 01, 2006
Handling
exceptions - A
how-to guide.

Friday, March
10, 2006
Handling
Performance
Issues

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (3 of 21)1/9/2008 2:49:16 AM


OracleBlog: Bookmark This Page

Wednesday,
August 17,
2005
Keeping Tables
Small - In
terms of
number of
rows, not
columns.
Improve
performance.

Monday,
October 31,
2005
Oracle
Packages -
And why/how
you should use
them.

Monday, July
11, 2005
Specifying
INSERT
Columns - Why
it's a good
habit.

Wednesday,
May 18, 2005
Steven
Feuerstein on
Refactoring

Tuesday, July
26, 2005
Use
Constraints - A
how-to guide
for people to
whom I BEG to

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (4 of 21)1/9/2008 2:49:16 AM


OracleBlog: Bookmark This Page

let the
database
handle the
data's integrity.

Monday, July
25, 2005
Use Views -
Why they're
handy.

Tuesday,
September 12,
2006
Using
Numerical
Fields - Don't
use them for
fields that
aren't real
numbers.

Oracle
Packages:

Wednesday,
October 12,
2005
DBMS_OUTPUT.
PUT_LINE

Thursday,
November 24,
2005
DBMS_PIPE -
For
communication
between
sessions

Sunday,
August 14,
2005

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (5 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

UTL_HTTP -
Including an
example of
how to get a
stock quote
from the
Internet.

Top 20 Lists:

Sunday,
January 15,
2006
Oracle DO
NOTs - From
AskTom

Tuesday,
December 20,
2005
20 Beginner
Oracle
Questions

Monday,
September 12,
2005
20 Oracle
Lessons - After
my first few
months of
blogging.

Monday,
December 19,
2005
20 PL/SQL
Coding Tips -
Inspired by an
AskTom thread

Tuesday,
October 17,

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (6 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

2006
Software
Vendor
Customer
Support - How
to improve
your luck when
dealing with
support (ok
there are only
14)

Book Reviews:

Wednesday,
June 22, 2005
Expert One-on-
One - A couple
of mistakes
from my
favourite
Oracle book.

Monday, May
16, 2005
Optimizing
Oracle
Performance
(Millsap, Holt)

Wednesday,
November 02,
2005
Oracle
Insights: Tales
of the Oak
Table

Thursday, June
23, 2005
PL/SQL Books
- A list of my

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (7 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

three favourite
PL/SQL books

Templates:

Thursday, June
30, 2005
OOP in PL/
SQL? Yep

Wednesday,
July 13, 2005
Stored
Procedure
template

Great Debates:

Tuesday, June
21, 2005
Natural vs
Synthetic keys
- Choosing
primary keys.

Wednesday,
March 29, 2006
Optimizer -
Should we be
overriding it in
our application?

Monday,
September 19,
2005
PL/SQL Code
Storage: Files
vs In-DB
Packages

Wednesday,
January 18,
2006

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (8 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

PL/SQL vs J2EE
- Where should
you put the
business logic?

NULLs:

Friday,
September 09,
2005
NULLs in
COUNT - Why
counting on a
column might
get you a
different total.

Friday, June
10, 2005
NULLs in Oracle

Tuesday, May
17, 2005
NULL vs
Nothing - ANSI
SQL is unlike
programming
languages
because NULL
is not nothing.

Gotchas!

Monday, June
13, 2005
Blank Lines
and SQLPlus

Friday, May 20,


2005
Multiple
Foreign Keys
on the Same ID

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (9 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

Monday, July
04, 2005
SQLCODE and
SQLERRM in
INSERTs

How-To
Guides:

Wednesday,
September 14,
2005
Analyzing
Query
Performance -
using
SQLTRACE and
TKPROF

Friday, May 04,


2007
ANSI Joins - Or
do you want to
stick with the
old school
style?

Tuesday,
February 14,
2006
BPEL - For SOA

Tuesday,
January 17,
2006
Bulk Binding:
FORALL -
Improve
performance of
bulk updates.

Thursday,

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (10 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

September 22,
2005
Column Name
as a Variable

Thursday, June
16, 2005
Common Table
Column Types
- Two tables
with columns
on the same
type, but not
actually related.

Wednesday,
August 24,
2005
COMPUTE -
How to
emulate a
feature found
in other
languages

Saturday, June
18, 2005
Connect By -
Heirarchical
queries,
something you
need to know.

Monday, June
20, 2005
Decode -
CASE's
precursor.

Thursday,
November 10,
2005
DUAL Table -

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (11 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

You've seen it,


what is it?

Thursday, May
19, 2005
Dynamically
assigning size
of varchar2 -
You do it in
other
languages, can
you do it in PL/
SQL (and how)?

Wednesday,
May 25, 2005
ENUM in Oracle
- Emulating a
common
programming
feature in PL/
SQL.

Friday, July 01,


2005
Extra Columns
in a GROUP BY

Tuesday, May
09, 2006
Finding Nearby
Rows. Three
methods of
solving similar
requirements.

Monday,
August 01,
2005
Import Export

Monday, May
28, 2007

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (12 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

Multirow
Inserts - Does
Oracle support
the ANSI SQL
standard of
inserting
multiple rows?
No. But here's
how you can
fake it.

Thursday, May
26, 2005
NOCOPY Hint -
Improve
performance
by changing
how variables
are passed to
PL/SQL
procedures.

Saturday, July
23, 2005
Oracle
BOOLEAN - PL/
SQL has
BOOLEAN,
here's how to
emulate it in
Oracle's SQL

Friday, July 29,


2005
Oracle By
Example -
Bringing
several
concepts
together to
solve a
problem.

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (13 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

Friday, June
24, 2005
Oracle Client -
How to install

Tuesday, July
04, 2006
Oracle and Java

Monday,
October 30,
2006
Oracle
Passwords -
Answering
your common
questions

Thursday,
December 15,
2005
Oracle and Perl

Thursday,
February 02,
2006
Oracle and
SOA - Covers
Oracle's
Service-
Oriented
Architecture at
a high level

Wednesday,
February 22,
2006
Oracle
Sequences -
This is the one
Oracle carried
on its main
page

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (14 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

Thursday,
September 01,
2005
Pivot and
Crosstab
Queries - A
very useful
technique for
turning rows
into columns,
and vice versa

Monday, April
03, 2006
Pivot Queries
Using Variable
Number of
Columns - Part
2 on pivot
queries, when
you don't know
how many
columns you
need in
advance.

Friday,
September 30,
2005
PL/SQL
Procedure Call
Overhead - Is
there one?

Friday, August
11, 2006
PL/SQL
Procedure Call
Overhead Re-
visited - By
Zsolt Lajosfalvi

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (15 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

Saturday,
September 02,
2006
Protecting PL/
SQL Code -
Using wrap.

Tuesday, May
24, 2005
Random
Numbers -
How to
generate them.

Monday,
November 21,
2005
RAW Datatype

Tuesday, June
27, 2006
Recursion vs
Iteration -
What are they,
what are the
advantages of
each one?

Tuesday, June
13, 2006
Refreshing
Data - A High-
level picture of
the flow and
what to keep in
mind when
designing your
data import
strategy

Thursday,
October 06,

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (16 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

2005
ROWNUM and
ROWID - And
how they're
used to solve
various issues,
and improve
retrieval times.

Tuesday,
February 07,
2006
TRANSLATE -
What it is, how
to use it.

Wednesday,
August 10,
2005
UNION ALL -
How and when
to avoid
performance
hits

Monday, April
17, 2006
Updating Views
- Can you do
it, and if so,
when.

Monday, June
27, 2005
Using Bad
Names in
Oracle

Tuesday,
October 04,
2005
Using DECODE
to exploit

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (17 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

COUNT/NULL
feature -
Applying
DECODE and
our knowledge
of COUNT/
NULL together
in a little trick
to speed up a
query.

Wednesday,
June 15, 2005
Variable
Constraints -
Can you use
variables in
constraints?
How?

Friday,
November 10,
2006
View
Constraints -
Can you
manage
integrity using
views?

Monday, July
18, 2005
Which instance
am I in?

Tuesday, May
30, 2006
Windowing
Clauses - How
they are used
to empower
your analytic
functions.

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (18 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

Other:

Monday,
February 26,
2007
Fun With Tom
Kyte - Get a
laugh out of
Oracle's king
of wit

Thursday, April
05, 2007
Oracle Beefs -
Here are mine.
What are yours?

Tuesday,
October 31,
2006
Oracle Gurus -
What makes an
Oracle guru?

Tuesday,
February 21,
2006
Oracle
Interview
Questions -
How to come
up with useful
ones.

Sunday, June
03, 2007
SQL Interview
Questions -
Here's what I
ask. Prepare
for your
interviews.

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (19 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

Friday, May 25,


2007
What Makes a
Great Oracle
Blog?

// posted by
Robert
Vollman @ Tuesday,
March 28, 2006

Comments:
Fear not, I've
got two posts
coming up

That's good.
For a moment I
thought you're
experiencing
the blogger
burnout effect.
Good luck in
your new job.

I've put
together an
organised list
of my previous
posts

Unlike other
blogging
platforms (like
WordPress for
example), one
of the
disadvantages
of Google's
Blogger is its

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (20 of 21)1/9/2008 2:49:17 AM


OracleBlog: Bookmark This Page

inability to
categorize
posts so that
you can easily
and
automatically
view an
archives page
just like the
one you just
posted (nicely
organized BTH).
# posted by
Eddie Awad :
Tuesday, 28
March, 2006

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/03/bookmark-this-page.html (21 of 21)1/9/2008 2:49:17 AM


OracleBlog: May 2005

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, May 26, 2005


About Me
On Vacation Name: Robert Vollman
I am taking a much needed vacation Location: Calgary, Alberta,
to Italy for my brother's wedding. Canada
I'll post new material on June 13th, so
please check back then. I was born and raised in
Ottawa, and have lived in Calgary since
In the mean time, here is how you 1991. I like playing sports (hockey,
can pass your break time, apart from soccer, ultimate, basketball, you name it)
reading my recent posts (including and military board games. I also enjoy
one today) or visiting the links on the reading, walking, and playing with my 2
right: cats Lilly and Brutus. I'm a database
application specialist, whatever that is.
1. The Dizwell Forum has some great
Oracle discussions on many topics. View my complete profile

http://www.phpbbserver.com/phpbb/
index.php?mforum=dizwellforum
Best Links
2. Oracle magazine has great articles, ● Ask Tom Kyte
especially Ask Tom and Steven ● Oracle Docs
Feuerstein's PL/SQL Best Practises: ● Dan Morgan and PSOUG
● Steven Feuerstein
http://www.oracle.com/technology/ ● Jonathan Lewis
index.html ● FAQ
Connor McDonald
3. Lots of other Oracle professionals

http://thinkoracle.blogspot.com/2005_05_01_archive.html (1 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

have blogs. I enjoy many of them, but The Oak Table


based on frequency of updates and ● Cary Millsap and Hotsos


number of Oracle-related posts, my ● Steve Adams and Ixora
favourites are David Aldridge and ● Anjo Kolk and OraPerf
Niall Litchfield: ● Dizwell Oracle Wiki
My Personal Blog
http://oraclesponge.blogspot.com/

http://www.niall.litchfield.dial.pipex.
com/

Please look under "Comments" for


Aggregators
more ideas, and of course contribute Brian Duff's OraBlogs

your own. ❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
Arrivederci! ❍ Oracle's Bloglist
❍ Oracle Base Aggregator
// posted by Robert Vollman @ Thursday, May

26, 2005 1 comments Top Blogs


❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
NOCOPY Hint ❍ Blogger of the Year Eddie Awad
What is NOCOPY? ❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
'NOCOPY' is an optional 'hint' to tell Database Expert James Koopmann
the PL/SQL 'compiler' not to go

Dizwell's Howard Rogers


through the overhead of making a

Oracle Master Laurent Schneider


copy of the variable, instead just send

Security Expert Pete Finnigan


a reference. This is generally because ❍

we don't plan on modifying it within ❍ Oracle Award Winner Mark Rittman


the procedure. ❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
My first surprise was that you ❍ UKOUG's Andrew (Arfur C.) Clarke
couldn't use "IN NOCOPY." Isn't ❍ Newbie DBA Lisa Dobson
NOCOPY your way of telling Oracle ❍ Coffee-Drinking DBA Jon Emmons
you don't plan on messing around Chris Foot
with the parameter? Yes, but you

The Pythian DBA Team Blog


CAN'T mess with IN parameters, try it!

❍ DBA Don Seiler


CREATE OR REPLACE PROCEDURE ❍ DBA Coskan Gundogar
MyProc (in_value IN number) ❍ Oracle WTF

ARCHIVES
AS
BEGIN
in_value := 3; ❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005_05_01_archive.html (2 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

END; ❍ May 2005


June 2005
PLS-00363: expression 'IN_VALUE'

July 2005
cannot be used as an assignment

August 2005
target

❍ September 2005
Therefore, it is always safe to send IN ❍ October 2005
parameters by reference, making ❍ November 2005
NOCOPY redundant. ❍ December 2005
❍ January 2006
My second surprise was that you had ❍ February 2006
to specify NOCOPY for an OUT
March 2006
parameter. Because by definition isn't

April 2006
an OUT parameter stating that you

May 2006
plan on modifying the variable? Why ❍

would it be an OUT variable if you ❍ June 2006


weren't touching it? So why would ❍ July 2006
you NOT want NOCOPY? The answer ❍ August 2006
(like so many) comes from Ask Tom: ❍ September 2006
❍ October 2006
http://asktom.oracle.com/pls/ask/f? ❍ November 2006
p=4950:8::::: ❍ December 2006
F4950_P8_DISPLAYID:2047154868085 ❍ January 2007
❍ February 2007
Tom explains one situation where March 2007
you want a copy rather than a

April 2007
reference for an OUT or IN OUT

May 2007
parameter. When you change a

June 2007
NOCOPY parameter, it changes right ❍

away, instead of upon successful ❍ October 2007


completion of the stored procedure.
❍ Current Posts
Imagine you modified the parameter,
but threw an exception before
successful completion. But that
parameter has been changed and the
calling procedure could be stuck with
a bogus value.

Despite how much I trust Tom,


everybody knows that I don't believe
things until I see for myself. And
neither should you! Besides, things
change. Here's my example.

http://thinkoracle.blogspot.com/2005_05_01_archive.html (3 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

CREATE OR REPLACE PROCEDURE


NoCopyProc (in_value IN OUT
NOCOPY number)
AS
x number;
BEGIN
DBMS_OUTPUT.PUT_LINE(in_value || '
NoCopyProc');
in_value := 2;
x := 1/0;
END;

CREATE OR REPLACE PROCEDURE


CopyProc (in_value IN OUT number)
AS
x number;
BEGIN
DBMS_OUTPUT.PUT_LINE(in_value || '
CopyProc');
in_value := 4;
x := 1/0;
END;

CREATE OR REPLACE PROCEDURE


InterProc (in_value IN OUT NOCOPY
number)
AS
BEGIN
IF (in_value = 1) THEN NoCopyProc
(in_value);
ELSE CopyProc(in_value);
END IF;
EXCEPTION
WHEN OTHERS THEN NULL;
END;

CREATE OR REPLACE PROCEDURE


MyProc
AS
the_value NUMBER(1);
BEGIN
the_value := 1;
InterProc(the_value);

http://thinkoracle.blogspot.com/2005_05_01_archive.html (4 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

DBMS_OUTPUT.PUT_LINE(the_value);

the_value := 3;
InterProc(the_value);
DBMS_OUTPUT.PUT_LINE(the_value);
END;

BEGIN MyProc; END;

1 NoCopyProc
2
3 CopyProc
3

For an excellent and more detailed


overview of NOCOPY, complete with
examples, restrictions and
performance analysis, I once again
refer you to Steven Feuerstein's
writings. Although I encourage you to
add his books to your collection, this
chapter happens to be on-line for
free:

Oracle PL/SQL Programming Guide to


Oracle8i Features
http://www.unix.org.ua/orelly/oracle/
guide8i/ch10_01.htm

So what is a guy to do?

Well, first of all, it was suggested to


me that I should find a more gender-
neutral way of summing up an article.
Allow me to rephrase.

So what should we do?

1. Understand what NOCOPY means


and its uses and restrictions (by
following those links)
2. Take advantage of NOCOPY when
you want the performance advantage
of avoiding the cost of the temporary

http://thinkoracle.blogspot.com/2005_05_01_archive.html (5 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

storage for OUT or IN OUT


parameters.
3. Avoid NOCOPY when you don't
want the side effects if the procedure
fails early.

Remember, in the end, that NOCOPY


is just a "hint" and Oracle will do
whatever it wants anyway. Like all
hints, you have to ask yourself what
makes it necessary, and what makes
you think Oracle is going to choose
incorrectly.

// posted by Robert Vollman @ Thursday, May

26, 2005 2 comments

Wednesday, May 25, 2005


ENUM in Oracle
What is ENUM?

ENUM is short for enumeration. Its a


useful programming type that
contains an ordered list of string
values. The programmer can define
the valid values depending on their
application.

Some good examples of ENUMs


would be days and months, or
something like directions ('North',
'South', 'East', 'West').

Is there an Oracle 'ENUM' type?

No, not really. But there are other


ways of accomplishing the same
thing.

For tables, just set it to a string and


add a constraint that it is within a
certain set.

http://thinkoracle.blogspot.com/2005_05_01_archive.html (6 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

CREATE TABLE atable (


col1 varchar2(10),
CONSTRAINT cons_atable_col1
CHECK (col1 IN ('Monday', 'Tuesday',
'Wednesday', 'Thursday',
'Friday', 'Saturday', 'Sunday'))
);

SQL> INSERT INTO atable (col1)


VALUES ('Monday');

1 row created.

SQL> INSERT INTO atable (col1)


VALUES ('Blingday');
insert into atable (col1) values
('Blingday')
*
ERROR at line 1:
ORA-02290: check constraint
(ROBERT.CONS_ATABLE_COL1)
violated

What happens if you use this type in


a procedure? Will the constraint be
checked? No.

CREATE OR REPLACE PROCEDURE


MyProc (in_col IN atable.col1%TYPE)
AS
BEGIN
DBMS_OUTPUT.PUT_LINE(in_col);
END;

SET SERVEROUTPUT ON;

EXEC MyProc('Monday');
EXEC MyProc('Blingday');

So can you create a package subtype


for this? That would be more elegant
anyway.

But according to Oracle PL/SQL

http://thinkoracle.blogspot.com/2005_05_01_archive.html (7 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

Programming by Steven Feuerstein


Chapter 4, I don't think you can
(check comments for any refutations
to this).

http://www.amazon.com/exec/
obidos/ASIN/0596003811/
qid=1117039808/sr=2-1/
ref=pd_bbs_b_2_1/102-9543590-
3979349

I think the best thing to do in this


case is to create a procedure to
validate your input.

CREATE OR REPLACE PROCEDURE


MyCheck (in_col IN atable.col1%TYPE)
AS
BEGIN
IF (in_col NOT IN ('Monday', 'Tuesday',
'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday')) THEN
-- Throw Exception here, be sure to
catch it in MyProc!!
NULL;
END IF;
END;

This approach is consistent with


Steven Feuerstein's approach to
programming. He suggests
separating these things into separate
procedures. Then when a future
release of Oracle supports a concept,
or when you figure out how to do it,
you can make the change in a single
place.

So what is a guy to do?


1. If you want to use enum in a table,
use a check constraint.
2. If you want to use enum in a
stored procedure, write a separate

http://thinkoracle.blogspot.com/2005_05_01_archive.html (8 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

procedure to validate the input.

// posted by Robert Vollman @ Wednesday,

May 25, 2005 1 comments

Tuesday, May 24, 2005


Random Numbers
Let me get your advice on this one.

Here's the situation, you need an


evenly distributed sequence of
random integers from 1 to 20. You
decided to use the Oracle random
number package 'dbmsrand'.

Incidentally, I decided to do it this


way after searching Ask Tom.

http://asktom.oracle.com/~tkyte/
Misc/Random.html
http://asktom.oracle.com/pls/ask/f?
p=4950:8:::::
F4950_P8_DISPLAYID:831827028200

There is a link to his web site to the


right. Bookmark it.

While you're at it, bookmark Dan


Morgan's page (link on the right).

http://www.psoug.org/reference/
dbms_random.html

Ok, back to the story.

After you read the instructions on


using it, you probably write
something like this in your PL/SQL
stored procedure:

AS

http://thinkoracle.blogspot.com/2005_05_01_archive.html (9 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

random_value number(2,0);
BEGIN
random_value := dbms_random.value
(0,20);

Now you notice whoops, you're


getting some 0s. You don't want 0.
Plus you're not getting very many
20s. So you do this instead

random_value := dbms_random.value
(1,21);

Much better! But whoops - you're


getting the occasional 21! So you
scratch your brain and do this:

random_value := dbms_random.value
(1,21);
random_value := MOD(random_value,
20) + 1;

That should pour the 21s into the 1


pile, which you noticed is very, very
slightly lower than the others.

Now you think you're getting the


values you want. So here are my
questions:

1. Will this truly generate an even


sample of numbers from 1 to 20? Will
there be the right number of 1s and
20s?
2. Is there a better way?
3. Say you're generating a very large
sequence, thinking about
performance, do you see any
problems with this approach I should
consider?

Here is the complete solution:

--------------------
@utlraw

http://thinkoracle.blogspot.com/2005_05_01_archive.html (10 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

@prvtrawb.plb
@dbmsoctk
@prvtoctk.plb
@dbmsrand

create table value_holder as (f_value


NUMBER(2,0));

create or replace procedure


ValuePlacer (number_to_generate IN
number)
AS
random_value number(2,0);
BEGIN
for x in 1..number_to_generate
LOOP
random_value := dbms_random.value
(1,21);
random_value := MOD(random_value,
20) + 1;
insert into value_holder values
(random_value);
END LOOP;
END;

exec ValuePlacer(1000);

select f_value, count (f_value) from


value_holder group by f_value;
-----------------

Thanks!

// posted by Robert Vollman @ Tuesday, May

24, 2005 1 comments

Friday, May 20, 2005


Multiple Foreign Keys
on the Same ID
You can't set the same foreign key for
two different columns with the same
constraint:

http://thinkoracle.blogspot.com/2005_05_01_archive.html (11 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

create table atable (


id varchar2(65) primary key);

create table btable (


a_id1 varchar2(65),
a_id2 varchar2(65));

ALTER TABLE btable


ADD CONSTRAINT btable_fkey_both
FOREIGN KEY (a_id1, a_id2)
REFERENCES atable(id, id)
ON DELETE SET NULL;

ERROR at line 1:
ORA-00957: duplicate column name

ALTER TABLE btable


ADD CONSTRAINT btable_fkey_both
FOREIGN KEY (a_id1, a_id2)
REFERENCES atable(id)
ON DELETE SET NULL;

ERROR at line 1:
ORA-02256: number of referencing
columns must match referenced
columns

But you can do it if you break it up


into separate constraints:

ALTER TABLE btable


ADD CONSTRAINT btable_fkey1
FOREIGN KEY (a_id1)
REFERENCES atable (id)
ON DELETE SET NULL;

Table altered.

ALTER TABLE btable


ADD CONSTRAINT btable_fkey2
FOREIGN KEY (a_id2)
REFERENCES atable (id)
ON DELETE SET NULL;

http://thinkoracle.blogspot.com/2005_05_01_archive.html (12 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

Table altered.

Note: Monday is a holiday in Canada,


no update until Tuesday.

// posted by Robert Vollman @ Friday, May 20,

2005 0 comments

Thursday, May 19, 2005


Dynamically assigning
size of varchar2
I thought I would declare my variable-
lengthed variables with a pre-defined
constant. Why?

1. I'd be sure they matched up


everywhere.
2. I could change them all in a single
place if required.

But I don't think you can do that in PL/


SQL.

CREATE OR REPLACE PACKAGE


test_constants IS
MAX_LEN CONSTANT NUMBER := 32;
END test_constants;

Package created.

SET SERVEROUTPUT ON

-- Anonymous block
DECLARE
x VARCHAR2(test_constants.
MAX_LEN); -- Can't do this
BEGIN
x := 'Test ' || test_constants.MAX_LEN;
dbms_output.put_line(x);
END;

ERROR at line 2:

http://thinkoracle.blogspot.com/2005_05_01_archive.html (13 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

ORA-06550: line 2, column 31:


PLS-00491: numeric literal required

But what about other types?

Substitute NVARCHAR2, VARCHAR,


CHAR, NCHAR, or STRING if you like,
same result. Incidentally the "N" just
means you are specifying the length
in bytes instead of characters.

So what is a guy to do?

1. Just put a comment before every


number, and make it a practise to
make sure they all match.

DECLARE
x VARCHAR2(32); -- test_constants.
MAX_LEN = 32

But here is another option.

2. Create a table with the types you


want, and then use those types.

CREATE TABLE TEST_CONSTANTS (


MAX_LEN VARCHAR2(32)
);

Table created.

DECLARE
x TEST_CONSTANTS.MAX_LEN%TYPE;
BEGIN
x := 'Test';
dbms_output.put_line(x);
END;

// posted by Robert Vollman @ Thursday, May

19, 2005 4 comments

Wednesday, May 18, 2005

http://thinkoracle.blogspot.com/2005_05_01_archive.html (14 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

Steven Feuerstein on
Refactoring
Refactoring for PL/SQL Developers
By Steven Feuerstein

From Oracle Magazine January/


February 2005

http://www.oracle.com/technology/
oramag/oracle/05-jan/o15plsql.html

Steven Feuerstein is one of my


favourite PL/SQL authors, especially
when he lays off the socio-political
tangents.

I especially enjoyed his article on


refactoring PL/SQL code. I had a few
thoughts to add to it.

My additional thoughts on
Refactoring:

1. One of the advantages that also


bears note is that re-factoring your
code can encourage code re-use.
Clean, modular, well-written code is
easy to re-use, reducing future
programming efforts.

2. However, one of the disadvantages


of code re-factoring is that you can
introduce unknown factors to a
(presumably) working, trusted
procedure. There is an expense to re-
testing and re-validating the
modified code. Even if you FIXED
errors, some other procedures might
have been written in such a way that
they depend on them, and they will
now fail.

My additional imperfections in the

http://thinkoracle.blogspot.com/2005_05_01_archive.html (15 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

unfactored code sample:

1. Inline documentation

I think Steven failed to point out the


most egregious transgression: lack of
inline documentation! I believe
almost every procedure needs it, at
LEAST a 'header' but preferrably also
some comments that explain in plain
language what was intended by the
code. Steven did go ahead and add
some in-line documentation, but
didn't draw any attention to that.

* Note: Perhaps due to his friendly


nature, I am referring to him in this
post in the familiar. Certainly no
disrespect is intended.

2. Bad variable names

If this article was to be re-written, I


would change the initial code sample
to use very bad variable names and
then re-name them as part of the
"refactored" version. I think that's a
very common problem.

My comments on the refactored


version:

1. utl_file_constants

Rather than define my own file


utl_file_constants, I would use
something that was already defined
and possibly tied in. I mean, there's a
REASON that 32767 was used. You
are bound by a particular (probably
OS-level, or DB-level) limitation that
is probably defined in some package
or some configuration value, or right
in UTL_FILE.

http://thinkoracle.blogspot.com/2005_05_01_archive.html (16 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

If you define your own and then all of


a sudden the 32767 limitation is
changed at the OS or DB level, you
STILL have to go change all your
private constant packages. I mean
that's a bit better than having to
change magic numbers in your code,
but we can do a little better, I think.

get_next_line_from_file isn't even


aware of that limitation. How would
this program fail if you set the value
to, say, '4' instead of '32767' in
utl_file_constants?

It appears like Steven didn't even use


his utl_file_constant for 32767 in the
final version (Code Listing 7). Why
not? The answer is probably that you
can not dynamically define the length
of a string. That is, of course, a PL/
SQL restriction. I suppose we should
be happy with whatever magic
numbers we can remove.

2. compare_latest_read

I'm really not sure I would have


created "compare_latest_read". That
seems like we are overdoing it. I
mean this is not a big procedure and
its entire point is to do what is in that
procedure anyway. Why introduce the
overhead of another procedure
(assuming there is any overhead)?

Think of it this way, you are passing


in the lines. Instead of that, you could
pass in the files and
compare_latest_read can call
get_next_line_from_file to get the
lines. That would be reasonable. But
now, all of a sudden, the main

http://thinkoracle.blogspot.com/2005_05_01_archive.html (17 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

procedure is doing nothing but


initialising and calling a procedure.
So basically "compare_latest_read" is
one reasonable change away from
already doing all the work.

So why is it even necessary? It is only


done once ... How is the purpose of
this internal procedure significantly
different from the purpose of the
overall procedure? I suppose this is
just an opinion, and a matter of taste,
but I really think the extra procedure
is unnecessary.

Other comments and questions:

1. VARCHAR2 length

In the procedure Steven uses


VARCHAR2 as a variable-lengthed
string even though we know the
maximum size (32767). Is there any
value in specifying VARCHAR2
(32767) instead of VARCHAR2 in the
final version (as the IN or OUT
parameters)? Is there any advantage
to that? Is it even possible?

2. Procedures vs Functions

Any reason why Steven uses


procedures instead of functions?

3. Cleanup: closing an unopened file

In "cleanup", will there be a problem


if you UTL_FILE.fclose a file that
hasn't been opened? Because that will
happen if there is an exception while
opening the first file when cleanup
closes both.

4. Handling "WHEN OTHERS"

http://thinkoracle.blogspot.com/2005_05_01_archive.html (18 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

WHEN OTHERS - cleanup .... without


any error message written to screen
or log?? For shame! Steven said
earlier in the article you would re-
raise the exception, but in the end he
didn't.

Plus the problem with re-raising an


exception is you are actually getting a
NEW exception. If it is checked later,
the error messages will say the error
was created at this new line number
instead of the original spot. Might as
well fully handle the exception right
here when we catch it.

Conclusion:

A sure sign of a good article is that it


gets you thinking. Steven Feuerstein
rarely fails to achieve that. I have
shared these thoughts with him, and
I'll follow-up with any answers or
clarification he provides.

I noticed Harm Vershuren had some


thoughts in his blog as well:
http://technology.amis.nl/blog/index.
php?p=317

// posted by Robert Vollman @ Wednesday,

May 18, 2005 1 comments

Tuesday, May 17, 2005


NULL vs Nothing
In Oracle, there is a difference
between 'null' and nothing at all. Here
is my story.

I discovered this when playing with


default values. First, I created a table
that had a default value for one

http://thinkoracle.blogspot.com/2005_05_01_archive.html (19 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

column. Then I tried to insert a row


that had nothing at all, and it
wouldn't use the default value. So I
tried inserting a row with null, and it
didn't assign the default value.
Observe.

SQL> create table atable (


2 last_name varchar2(32) not null,
3 first_name varchar2(32) not null,
4 rating smallint default 0);

Table created.

SQL> insert into atable values


('Smith', 'John', null);

1 row created.

SQL> select * from atable;

LAST_NAME FIRST_NAME RATING


--------------------------------
--------------------------------
----------
Smith John

Notice it inserted NULL, and not the


default value.

SQL> insert into atable values


('Smith', 'John');
insert into atable values ('Smith',
'John')
*
ERROR at line 1:
ORA-00947: not enough values

Why doesn't this work? You may


know this already, but in the words of
Dan Morgan: "By not specifying
column names you are signifying that
you are providing values for ALL
columns. This is why it is a very bad
practice as doing an ALTER TABLE

http://thinkoracle.blogspot.com/2005_05_01_archive.html (20 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

ADD immediately invalidates all SQL


statements."

So let's do it the proper way and see


if there is a difference.

SQL> insert into atable (last_name,


first_name) values ('Smith', 'John');

1 row created.

SQL> select * from atable;

LAST_NAME FIRST_NAME RATING


--------------------------------
--------------------------------
----------
Smith John
Smith John 0

And there is a difference. Excellent.


Out of curiousity between the two
ways of inserting rows, I tried this:

SQL> insert into atable (last_name,


first_name, rating) values ('Smith',
'John', null);

1 row created.

SQL> select * from atable;

LAST_NAME FIRST_NAME RATING


--------------------------------
--------------------------------
----------
Smith John
Smith John 0
Smith John

So I was thinking, why isn't this null


being replaced with the default value?
Isn't the default value there for
instances to replace null? If you're as
skeptical as I am, it will make sense

http://thinkoracle.blogspot.com/2005_05_01_archive.html (21 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

after this second test, where I add the


"NOT NULL" constraint.

drop table atable;

create table atable (


last_name varchar2(32) not null,
first_name varchar2(32) not null,
rating smallint default 0 NOT NULL);

SQL> insert into atable (last_name,


first_name, rating) values ('Smith',
'John', null)
*
ERROR at line 1:
ORA-01400: cannot insert NULL into
("ROBERT"."ATABLE"."RATING")

That's when I figured out where I was


confused. There are 3 things you can
assign to a column when doing an
insert:
1. a value (eg: 0)
2. null
3. nothing at all

See, there is a difference between #2


(null) and #3 (nothing at all). To wit:
1. Using null (#2) is 'ok' if you are
inserting without specifying columns.
Nothing at all (#3) is not.
2. Null (#2) will not be replaced by a
default value when inserting, whereas
nothing at all (#3) will.

When I started looking at stored


procedures, I found even more
difference between NULL and
nothing. My second story starts off as
an investigation of passing NULL to
stored procedures.

There is no such thing as "NOT NULL"


for stored procedure parameters.

http://thinkoracle.blogspot.com/2005_05_01_archive.html (22 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

I noticed that the "NOT NULL"


keyword can't be used in procedure
parameters (nor can NULL).
Apparently that is for creating tables
only. You can not force input
parameters to a procedure to be non-
null. All you can do is start your
procedure by verifying the input
parameters.

SQL> create or replace procedure


MyProc1 (some_value IN number NOT
NULL)
2 AS
3 BEGIN
4 NULL;
5 END;
6/

Warning: Procedure created with


compilation errors.

Nor can you allow it to be NULL.

SQL> create or replace procedure


MyProc2 (some_value IN number
NULL)
2 AS
3 BEGIN
4 NULL;
5 END;
6/

Warning: Procedure created with


compilation errors.

You can, however, assign default


values. However, note the difference
between assigning "NULL" and
assigning nothing at all.

SQL> create or replace procedure


MyProc3 (some_value IN number := 0)

http://thinkoracle.blogspot.com/2005_05_01_archive.html (23 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

2 AS
3 BEGIN
4 DBMS_OUTPUT.PUT_LINE
(some_value);
5 NULL;
6 END;
7/

Procedure created.

SQL> exec MyProc3();


0

PL/SQL procedure successfully


completed.

SQL> exec MyProc3(NULL);

PL/SQL procedure successfully


completed.

SQL> exec MyProc3(1);


1

PL/SQL procedure successfully


completed.

Bottom line, there is a difference


NULL and nothing at all for both
tables and stored procedures. So
what is a guy to do?
1. Understand there is a difference
between NULL and nothing
2. For tables, use "NOT NULL" and for
stored procedures, verify the input
manually
3. Use default values for both tables
and stored procedures when passing
nothing at all.

// posted by Robert Vollman @ Tuesday, May

17, 2005 3 comments

http://thinkoracle.blogspot.com/2005_05_01_archive.html (24 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

Monday, May 16, 2005


Optimizing Oracle
Performance (Millsap,
Holt)
There are certain "camps" in the
worldwide Oracle community. For
example, there is the "Oak Table
Network" of "Oracle scientists" who
seek thorough understandings of
issues backed up by details, tests and
proofs. Contrasting is the "Silver
Bullet" family of field-tested generals
who prefer rules of thumb and quick
fixes even it means some false
understandings and occasionally
being wrong. Cary Millsap (of the Oak
Table Network) stands as someone
respected by both sides.

Cary Millsap worked at Oracle for 10


years on system performance before
co-founding Hotsos in 1999 (http://
www.hotsos.com - register for free).
He is one of the most trusted sources
on matters of Oracle system
performance, and "Optimizing Oracle
Performance" is considered his finest
work (4.5 out of 5 stars on Amazon).
The best way to learn more about
him is to see for yourself. Here are
some of his most popular articles:

"Diagnosing Performance Problems"


from Oracle Magazine. A brief
summary of what is covered in this
book:http://www.oracle.com/
technology/oramag/oracle/04-jan/
o14tech_perf.html

"Introduction", the first chapter from


"Optimizing Oracle
Performance."Chapter 1: http://www.

http://thinkoracle.blogspot.com/2005_05_01_archive.html (25 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

oreilly.com/catalog/optoraclep/
chapter/ch01.pdf

"Case Study", the 12th chapter from


"Optimizing Oracle
Performance."Chapter 12 (Case
Study): http://www.oreillynet.com/
pub/a/network/excerpt/
optimizing_oracle_chap12/index.html

"Performance Management: Myths


and Facts." One of his most popular
articles.https://secure.hotsos.com/
downloads/visitor/00000024.pdf

"Why a 99%+ Database Buffer Cache


Hit Ratio is Not Ok." Another of his
more popular articles.http://www.
oradream.com/pdf/Why%20a%2099%
20Cahe%20Hit%20Ratio%20is%20Not%
20OK.pdf

While everyone will have their own


favourite parts of the book, I think
most readers would agree that
getting a good taste of the author's
performance tuning philosophy is
one of the highlights. "Method R", not
to be confused with "System R" (ie.
SQL), is not about looking at
STATSPACK, cache hit ratios, or V$
tables and guessing. The author
wanted to devise a system to identify
and resolve the top performance
concerns of an organisation with
reliable, predictable results. The first
few chapters put this method in
writing in perhaps the best way since
the introduction of "YAPP" (Anjo Kolk).

"The performance enhancement


possible with a given improvement is
limited by the fraction of the

http://thinkoracle.blogspot.com/2005_05_01_archive.html (26 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

execution time that the improved


feature is used." - Amdahl's Law

After several years of research, the


author discovered that Extended SQL
Trace Data was at the centre of
"Method R". Some of the articles
should give you a good taste of what
Extended SQL Trace data is, if you
didn't know already. By the time you
finish reading this book you will
know exactly how to collect and
interpret all the little "ela=17101
p1=10 p2=2213 p3=1 ..." within into
something meaningful. For some,
that justifies the price tag right there.

So in essence I would have re-named


this book "Method R: Optimizing
Oracle Performance Using Extended
SQL Trace Data," because that is
basically what this book is about.
There are some reasonably "stand-
alone" chapters on other topics, for
instance on the Oracle Fixed View
tables (Chapter 8) and on Queueing
Theory (Chapter 9), but that is not
the primary focus of the book.

Those that are expecting a more


broad treatment of the subject of
performance tuning may be
justifiably disappointed that it
basically covers only this narrow
aspect. However, it is covered very
well, and it isn't really covered
anywhere else. The author makes no
apologies for this, claiming that
extended SQL trace data is the only
resource you will ever need for
diagnosing and solving performance
problems.

"You cannot extrapolate detail from

http://thinkoracle.blogspot.com/2005_05_01_archive.html (27 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

an aggregate." - Cary Millsap's


preference of SQL extended trace
data over fixed views (system-wide
average performance characteristics)

Indeed, some people might contend


that the author spends a little too
much time stating his beliefs,
defending them, and patting himself
on the back. But I think it adds a
certain flavour to the book, and I
respect an author who backs up his
statements.

"Proving that V$ data are superior to


extended SQL trace data because of
the 'missing time' issue is analagous
to proving that its safer to be in a
room with a hungry bear if you'll just
close your eyes." - Cary Millsap

The book can be a tough read in the


sense that the author goes very deep
into the material, and generally each
subject is treated thoroughly.
Chapter 9 on Queueing Theory can
be a particularly overwhelming
chapter. But the material is served in
bite-size pieces, and broken up with
tips, tricks, stories, diagrams and
code (sometimes 3+ pages worth at a
time, embedded directly in the
middle of a chapter). There are even
worthwhile exercises at the end of
each chapter.

In the end, I enjoyed this book and


I'm glad I got it. I don't consider it a
"must have" for your Oracle
collection, but I definitely feel it is
quite worthwhile. I recommend it
especially to those who read his
articles and were very comfortable
with his writing style and philosophy,

http://thinkoracle.blogspot.com/2005_05_01_archive.html (28 of 29)1/9/2008 2:49:22 AM


OracleBlog: May 2005

and also to those that need a book on


extended SQL trace data (because
this is basically the only one). But
even those in the "Silver Bullet" camp
will be glad to add another tool to
their belt.

Thumbs up.

http://www.coug.ab.ca/Resources/
BookReviews/MillsapsOOPByRVollman.
htm

// posted by Robert Vollman @ Monday, May

16, 2005 0 comments

http://thinkoracle.blogspot.com/2005_05_01_archive.html (29 of 29)1/9/2008 2:49:22 AM


OracleBlog: Never noticed this before

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday,
About Me
February 22, 2006
Name: Robert Vollman
Never Location: Calgary, Alberta, Canada
noticed
this before I was born and raised in Ottawa, and have lived in
So I was Calgary since 1991. I like playing sports (hockey,
searching soccer, ultimate, basketball, you name it) and military board
through the games. I also enjoy reading, walking, and playing with my 2 cats
latest Oracle 10g Lilly and Brutus. I'm a database application specialist, whatever
that is.
SQL Reference,
check out what I
View my complete profile
found on page 5-
175:

SELECT
manager_id,
Best Links
● Ask Tom Kyte
last_name, Oracle Docs
salary, SUM

Dan Morgan and PSOUG


(salary)

Steven Feuerstein
OVER (PARTITION

BY manager_id ● Jonathan Lewis


ORDER BY salary ● FAQ
RANGE ● Connor McDonald
UNBOUNDED ● The Oak Table
PRECEDING) ● Cary Millsap and Hotsos
l_csum ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/02/never-noticed-this-before.html (1 of 4)1/9/2008 2:49:25 AM


OracleBlog: Never noticed this before

FROM employees; ● Anjo Kolk and OraPerf


● Dizwell Oracle Wiki
MANAGER_ID ● My Personal Blog
LAST_NAME
SALARY L_CSUM
----------
---------
------ ------
Aggregators
100 Mourgos Brian Duff's OraBlogs

5800 5800 ❍ Eddie Awad's OracleNA


100 Vollman ❍ Pete Finnigan's Aggregator
6500 12300 ❍ Oracle's Bloglist
... ❍ Oracle Base Aggregator

I'm in the Oracle


default HR
Top Blogs
Oracle's Ask Tom Kyte
schema! I'm ❍

employee 123 ❍ Oracle Guru Jonathan Lewis


and I report ❍ Blogger of the Year Eddie Awad
directly to KING, ❍ Data Warehouser David Aldridge
the President! Of ❍ Oracle Geek Lewis Cunningham
course, I'm one ❍ Database Expert James Koopmann
of the lowest ❍ Dizwell's Howard Rogers
paid managers, ❍ Oracle Master Laurent Schneider
but still. ❍ Security Expert Pete Finnigan
Oracle Award Winner Mark Rittman
Of course, the

Doug Burns
first name is ❍

Shonta. But I can ❍ Oracle ACE of the Year Dr. Tim Hall
dream, right? I ❍ UKOUG's Andrew (Arfur C.) Clarke
can pretend that ❍ Newbie DBA Lisa Dobson
I'm one of Lex de ❍ Coffee-Drinking DBA Jon Emmons
Haan's fictional ❍ Chris Foot
colleagues, right? ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
I also saw this in DBA Coskan Gundogar
the latest version

Oracle WTF
of Oracle 9i

documentation:
SQL Reference: ARCHIVES
Page 365, 6-155 ❍ LIST ALL ARTICLES
for the example ❍ May 2005
of SUM. ❍ June 2005
Page 1532, 18- ❍ July 2005

http://thinkoracle.blogspot.com/2006/02/never-noticed-this-before.html (2 of 4)1/9/2008 2:49:25 AM


OracleBlog: Never noticed this before

42 on using ❍ August 2005


LEVEL Pseudo- ❍ September 2005
Column. ❍ October 2005
November 2005
and Sample

December 2005
Schemas:

January 2006
Page 68, section

February 2006
4-28 on Oracle's

March 2006
sample HR ❍

Schema ❍ April 2006


❍ May 2006
So it must have ❍ June 2006
been around for ❍ July 2006
awhile. I think ❍ August 2006
that's so cool! I'm ❍ September 2006
going to write ❍ October 2006
Oracle and ask
November 2006
them to fix my

December 2006
first name. I urge

January 2007
you to do the ❍

same in your ❍ February 2007


implementations: ❍ March 2007
❍ April 2007
UPDATE ❍ May 2007
employees SET ❍ June 2007
first_name = ❍ October 2007
'Robert' where
last_name =
'Vollman';

// posted by Robert
Vollman @ Wednesday,
February 22, 2006

Comments:
Oracle: Sure we
can..but are you
sure you dont
want salary
column updated ?
# posted by

http://thinkoracle.blogspot.com/2006/02/never-noticed-this-before.html (3 of 4)1/9/2008 2:49:25 AM


OracleBlog: Never noticed this before

Anonymous :
Thursday, 23
February, 2006

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/02/never-noticed-this-before.html (4 of 4)1/9/2008 2:49:25 AM


OracleBlog: June 2005

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I think data,
I think Oracle. I also enjoy writing, so I use this format to organise my thoughts. Please feel free
to discuss any thoughts you may have on the same topics, even old ones (I will see and respond
to such comments). You may want to start with "LIST ALL ARTICLES" under Archives.

Thursday, June 30, 2005


OOP in PL/SQL? Yep
I was recently speaking with someone who was stunned to find out that object-
oriented programming is available in PL/SQL (as of version 9, basically).

I guess I was stunned he didn't know this, but then again, I guess there isn't much
fanfare about it.

Inheritance? Yep.
Polymorphism? Yep.
Encapsulation? Yep.

I gave him this basic, bare-bones template. It isn't much, but it can get someone
started.

CREATE OR REPLACE TYPE some_object AS OBJECT (

some_variable NUMBER(10),

MEMBER FUNCTION member_function RETURN NUMBER,


MEMBER FUNCTION member_function (l_overloading IN NUMBER) RETURN NUMBER,
MEMBER PROCEDURE member_procedure,

-- Static functions can be used with an instance of the object


-- They can NOT reference any other non-static member functions or variables
STATIC FUNCTION static_function (l_value IN NUMBER DEFAULT 1) RETURN
NUMBER,

-- Constructors must return self. Constructors are optional


CONSTRUCTOR FUNCTION some_object (some_variable NUMBER) RETURN SELF AS
RESULT,

-- Used for comparison purposes: GROUP BY, ORDER BY, DISTINCT

http://thinkoracle.blogspot.com/2005_06_01_archive.html (1 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

-- No parameters allowed, returns NUMBER, DATE, VARCHAR2, CHAR or REAL


MAP MEMBER FUNCTION map_member_function RETURN NUMBER

-- ORDER takes one parameter of same type, and returns NUMBER


-- You may only have EITHER MAP OR ORDER
-- ORDER MEMBER FUNCTION order_member_function (some_other_object IN
some_object) RETURN NUMBER

)
INSTANTIABLE -- Or "NOT INSTANTIABLE" if this is a base class only
NOT FINAL -- Or "FINAL" if this class will NOT have a sub-class
;

CREATE OR REPLACE TYPE composition_object AS OBJECT (

composed_object some_object

);

CREATE OR REPLACE TYPE derived_object


UNDER some_object (

OVERRIDING MEMBER PROCEDURE member_procedure

);

CREATE OR REPLACE TYPE BODY some_object AS

MEMBER FUNCTION member_function RETURN NUMBER


IS
BEGIN
-- The "SELF" isn't necessary, but is always available by default in member
functions
RETURN SELF.some_variable;
END member_function;

MEMBER FUNCTION member_function (l_overloading IN NUMBER) RETURN NUMBER


IS
BEGIN
RETURN l_overloading;
END member_function;

MEMBER PROCEDURE member_procedure


IS
BEGIN
NULL;
END member_procedure;

-- Note: Unlike with packages, no private functions or declarations are allowed.

http://thinkoracle.blogspot.com/2005_06_01_archive.html (2 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

-- MEMBER FUNCTION hidden_proc RETURN NUMBER ...

-- Remember, static functions can't access SELF variables


STATIC FUNCTION static_function (l_value IN NUMBER DEFAULT 1) RETURN NUMBER
IS
BEGIN
RETURN l_value;
END static_function;

CONSTRUCTOR FUNCTION some_object (some_variable NUMBER) RETURN SELF AS


RESULT
AS
BEGIN
SELF.some_variable := some_variable;

-- It will automatically return self, don't even try to return anything else
RETURN;

END some_object;

MAP MEMBER FUNCTION map_member_function RETURN NUMBER IS


BEGIN
RETURN SELF.some_variable;
END map_member_function;

-- ORDER MEMBER FUNCTION order_member_function (some_other_object IN


some_object) RETURN NUMBER IS
-- BEGIN
-- IF some_other_object.some_variable < SELF.some_variable THEN RETURN 1;
-- ELSIF some_other_object.some_variable > SELF.some_variable THEN RETURN -1;
-- ELSE RETURN 0;
-- END IF;
-- END order_member_function;

END;

CREATE OR REPLACE TYPE BODY derived_object AS

OVERRIDING MEMBER PROCEDURE member_procedure


IS
BEGIN
NULL;
END member_procedure;

END;

-- Test!
DECLARE

http://thinkoracle.blogspot.com/2005_06_01_archive.html (3 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

-- You MUST instantiate it to use it. A NULL object is hard to use.


my_some_object some_object := some_object(0);
my_composition_object composition_object := composition_object
(my_some_object);
my_number NUMBER;
BEGIN
my_number := my_composition_object.composed_object.member_function;
my_number := some_object.static_function(my_number);
END;

// posted by Robert Vollman @ Thursday, June 30, 2005 2 comments

Constraints
No blog from me. But here is an excellent one from Jeff Hunter that I wish I'd
written.

http://marist89.blogspot.com/2005/06/deferrable-constraints_29.html

Also, check his Comments to see Doug Burns' link to an article by Chris Date.

// posted by Robert Vollman @ Thursday, June 30, 2005 1 comments

Monday, June 27, 2005


Using Bad Names in Oracle
In Oracle, you can't start a table, procedure or variable name with a number.

SQL> CREATE TABLE 123Table (aval NUMBER);


CREATE TABLE 123Table (aval NUMBER)
*
ERROR at line 1:
ORA-00903: invalid table name

You can get around this simply using quotes.

SQL> CREATE TABLE "123Table" (aval NUMBER);

Table created.

This will take the name very literally. So literally, in fact, that you can no longer rely
on Oracle's typical case-insensitivity.

SQL> drop table "123TABLE";


drop table "123TABLE"
*
ERROR at line 1:

http://thinkoracle.blogspot.com/2005_06_01_archive.html (4 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

ORA-00942: table or view does not exist

You can also use quotes to use reserved words.

SQL> CREATE TABLE "TABLE" ("NUMBER" NUMBER);

Table created.

// posted by Robert Vollman @ Monday, June 27, 2005 0 comments

Friday, June 24, 2005


Oracle Client
Here are the simple steps required for setting up an Oracle Client on a PC.

You will need:


- A working Oracle Server :)
- A compatible Oracle Client
- The service name, domain name, host name and port

1. Install Oracle SQL*Plus client on your PC

This should be quick and easy, accept all defaults.

2. Modify %ORACLE_HOME%\network\admin\tnsnames.ora

SRV_NAME.WHATEVER.COM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = host_name)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = srv_name)
)
)

3. Check %ORACLE_HOME%\network\admin\sqlnet.ora

NAMES.DEFAULT_DOMAIN = whatever.com
NAMES.DIRECTORY_PATH= (TNSNAMES, HOSTNAME)

4. Modify %ORACLE_HOME%\network\admin\listener.ora

http://thinkoracle.blogspot.com/2005_06_01_archive.html (5 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = C:\oracle\ora92)
(SID_NAME = srv_name)
)

5. Test connection

sqlplus username/password@srv_name

// posted by Robert Vollman @ Friday, June 24, 2005 0 comments

Thursday, June 23, 2005


PL/SQL Books
There are 3 PL/SQL books considered above the pack.

I settled on Scott Urman's book, but that's only because I got a deal on it when
Nexus Computer Books in Calgary went out of business. I like it, and it is ranked
#1 among PL/SQL books on Amazon.com.

Oracle9i PL/SQL Programming


Scott Urman
32.99
664 Pages
4 on 7 reviews
Rank in sales: #5460

I really like Steven Feuerstein's work, most of which can be found on the web. He's
got Q&A, Puzzlers, and regular articles on Oracle's site. You can find sample
chapters on-line. Despite the fact that I already have a good PL/SQL book, I might
get this one, too. He also has a "Best Practises" book.

Oracle PL/SQL Programming, Third Edition


Steven Feuerstein
34.62
1018 Pages
4 on 66 reviews
Rank in sales: #17659

Connor McDonald of the Oak Table Network has a highly rated PL/SQL book as
well. He also has an Internet presense. His site is awesome, he's got some great
stuff, so his book ought to be great, too. I wouldn't mind picking this up.

Mastering Oracle PL/SQL: Practical Solutions

http://thinkoracle.blogspot.com/2005_06_01_archive.html (6 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

Connor McDonald
32.99
648 Pages
4.5 on 5 reviews
Rank in sales: #106559

There are other PL/SQL books out there, but any of these 3 is probably your best
bet. Leave some comments if you have a preference for the 3, or know of any other
really great PL/SQL books to consider.

// posted by Robert Vollman @ Thursday, June 23, 2005 0 comments

Wednesday, June 22, 2005


Expert One-on-One
The general consensus is that Tom Kyte's "Expert One-on-One Oracle" is the best
Oracle book available, and most Oracle professionals have a copy on their shelves.

In Chapter 1 of the first edition, you'll see a scheduling algorithm that is supposed
to avoid double-bookings. Here is an example of how to double-book a room:

CREATE TABLE resources (resource_name VARCHAR2(25) primary key);


CREATE TABLE schedules (resource_name VARCHAR2(25) references resources,
start_time DATE, end_time DATE);

INSERT INTO resources (resource_name) VALUES ('Room A');


INSERT INTO schedules (resource_name, start_time, end_time) VALUES ('Room A',
'01-Jan-04', '04-Jan-04');

VARIABLE new_start_time VARCHAR2(32)


EXEC :new_start_time := '02-Jan-04'

VARIABLE new_end_time VARCHAR2(32)


EXEC :new_end_time := '03-Jan-04'

VARIABLE room_name VARCHAR2(25)


EXEC :room_name := 'Room A'

-- If the count comes back 0, the room is yours


SELECT COUNT (*) FROM schedules WHERE resource_name = :room_name
AND (start_time BETWEEN :new_start_time AND :new_end_time
OR
end_time BETWEEN :new_start_time AND :new_end_time);

This returns 0, which means the room is double-booked!!

Here is the fixed version from the 2nd edition:

http://thinkoracle.blogspot.com/2005_06_01_archive.html (7 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

ops$tkyte@ORA10GR1> select count(*)


2 from schedules
3 where resource_name = :room_name
4 and (start_time <= :new_end_time)
5 and (end_time >= :new_start_time);

According to Tom, "the only [other] notable fix is with regards to function based
indexes where I said erroneously that the to_date() function was "broken" with
respect to the YYYY format - it is not (can you see why :)"

Here it is:

CREATE TABLE t (y VARCHAR2(32));

CREATE INDEX t2 ON t(to_date(y,'yyyy'));


ORA-01743: only pure functions can be indexed.

As a workaround in the book, Tom created his own "to_date" function. But there is
a far simpler reason why this doesn't work (and a far simpler solution). Even
though it was staring us all in the very same pages, not very many people could
figure out why this function-based index was disallowed:

"My conclusion in the book is wrong because to_date with the 'yyyy' format is not
deterministic."

That means that for the same input, you can get a different output. But how can
that be?

ops$tkyte@ORA10GR1> select to_date( '2005', 'yyyy' ) from dual;

TO_DATE('
---------
01-JUN-05

"Today, in june, to_date(2005) returns 01-jun, last month, same function, same
inputs - would return 01-may"

Wow. Never would have guessed to_date(year) would be non-deterministic.

Tom also clarified that the following function would be deterministic and therefore
eligible for a function-based index:

create index t2 on t( to_date( '01'||y, 'mmyyyy') );

That, of course, would force it to choose January no matter what time of year you
called the function.

To me, it is very funny that to_date:


1. IS deterministic if you leave out the day (it will always choose the 1st day)
2. IS NOT deterministic if you leave out the month (it will not choose the 1st

http://thinkoracle.blogspot.com/2005_06_01_archive.html (8 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

month, but rather the current month).

Often in Oracle there is method behind the madness, but I do now know why there
is this difference.

So I guess this issue is just another interesting footnote in some nerd's blog...

// posted by Robert Vollman @ Wednesday, June 22, 2005 2 comments

Tuesday, June 21, 2005


Natural vs Synthetic keys
Primary keys should be:
1. Unique
2. Never changed (or very infrequently)

This is because they are used in other tables to reference a single row.

(Definitions from www.orafaq.com)


Natural Key: A key made from existing attributes.
Surrogate Key: A system generated key with no business value. Usually
implemented with database generated sequences.

This topic has been discussed at great length many times. We recently re-hashed it
on the Dizwell Forum.

Disadvantages:

EDIT: Please note: There are some potentially important corrections and
clarifications to the below. Please see Howard's comments and follow the links to
his blog or the forum discussion.

Natural keys:
- May require the concatentation of many columns, so it gets very long
- Sometimes a natural key can be hard to find (in example: names can change)
- In a sense, you are duplicating data
- Can lead to future conflicts when the database expands beyond original
requirements
- Care must be taken to avoid block-splitting
- Care must be taken to avoid index range scans
- Tend to change, albeit infrequently

"You nearly always end up having to append a number to guarantee both


uniqueness and existence. If I always have to append a guaranteed unique existing
number to ensure I meet my requirements, why not make it the key itself."
- Niall Litchfield

Synthetic/Surrogate keys:

http://thinkoracle.blogspot.com/2005_06_01_archive.html (9 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

- Meaningless by itself (ie. no relationship to the data to which it is assigned)


- Implementation is database-dependent
- Care must be taken to avoid contention (monotically increasing and smaller
indexes)
- Similar rows would not have similar keys

Gauss suggested considering using a GUID for the surrogate key. No trigger is
required, uniqueness is guaranteed over space and time, but it is 16 bytes.

SQL> CREATE TABLE atable (pk RAW(16) DEFAULT SYS_GUID() PRIMARY KEY,
2 a_str VARCHAR2(32));
Table created.
SQL> INSERT INTO atable (a_str) VALUES ('One');
1 row created.
SQL> INSERT INTO atable (a_str) VALUES ('Two');
1 row created.
SQL> SELECT * FROM atable;
PK A_STR
-------------------------------- --------------------------------
5C3BCF77D55B41E78DE4016DFBE25FFA One
D3B959F3010745D3854F8FC2B09A18F3 Two

// posted by Robert Vollman @ Tuesday, June 21, 2005 9 comments

Monday, June 20, 2005


Decode
Here is another handy Oracle-only SQL tool: DECODE.

Decode allows you to do if/elseif/else logic within an SQL query, similar to a CASE
WHEN statement in a PL/SQL procedure.

DECODE (expression, if_equal_to_this_1, give_me_this_1, else_if_equal_to_this_2,


give_me_this_2, ..., default)

Dan Morgan's Reference on DECODE:


http://www.psoug.org/reference/decode_case.html

The default value is optional, if it is left out, it defaults to NULL. And the maximum
number of comparisons is 255.

It works very much like a CASE WHEN statement, so you can already think of uses,
especially if you nest your DECODEs.

Remember the article I wrote on NULL vs Nothing and on NULLs in general?

http://thinkoracle.blogspot.com/2005_06_01_archive.html (10 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html
http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html

Well, you can actually use DECODE like NVL. Don't believe me? I don't blame you,
because I told you that NULL is not equal to NULL. But here is a quote right from
the Oracle 9i SQL Reference:

"In a DECODE function, Oracle considers two nulls to be equivalent. If expr is null,
then Oracle returns the result of the first search that is also null."

And here is the example because like me you don't believe anything without proof:

SQL> CREATE TABLE atable (avalue VARCHAR2(32));

Table created.

SQL> INSERT INTO atable (avalue) VALUES (NULL);

1 row created.

SQL> INSERT INTO atable (avalue) VALUES ('This is not NULL');

1 row created.

SQL> SELECT DECODE(avalue, NULL, 'This is NULL', avalue) avalue


2 FROM atable;

AVALUE
--------------------------------
This is NULL
This is not NULL

If you don't believe how useful it can be, here is a FAQ that shows how to use
DECODE for (among other things) avoiding divide-by-zero errors:

http://www.db.cs.ucdavis.edu/public/oracle/faq/decode.html

In practise, I have seen DECODE used for the ORDER BY clause.

If you are still not convinced, you can "Ask Tom" how DECODE can be used to have
a conditional foreign key. That is, a foreign key that only applies to certain rows!

http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:1249800833250

// posted by Robert Vollman @ Monday, June 20, 2005 4 comments

Saturday, June 18, 2005

http://thinkoracle.blogspot.com/2005_06_01_archive.html (11 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

Connect By
I couldn't resist sharing this one, which I found on DBA-Support recently:

http://www.dbasupport.com/forums/showthread.php?t=47760

The question was how to create a column as the concatentation of many rows into
one, without using PL/SQL: just a single query.

Here is the example given:

CREATE TABLE t1 (col1 VARCHAR2(1));


INSERT INTO t1 VALUES ('a');
INSERT INTO t1 VALUES ('b');
INSERT INTO t1 VALUES ('c');
INSERT INTO t1 VALUES ('d');
INSERT INTO t1 VALUES ('e');

Desired result of an SQL statement on test:

abcde

The answer came from Tamil Selvan:

1 SELECT REPLACE(col1, ' ')


2 FROM (SELECT SYS_CONNECT_BY_PATH(col1,' ') col1, level
3 FROM t1
4 START WITH col1 = (select min(col1) from t1) -- 'a'
5 CONNECT BY PRIOR col1 < col1
6 ORDER BY level DESC)
7* WHERE rownum = 1
SQL> /

REPLACE(COL1,'')
----------------------------------------
abcde

Here are the things that may be new to someone new to Oracle (especially Oracle 9
or 10):
- SYS_CONNECT_BY_PATH
- CONNECT BY

This is an interesting example, but it is just one use of these features.

Here is a link to Dan Morgan's reference on CONNECT BY


http://www.psoug.org/reference/connectby.html

And here is an Ask Tom article.


http://www.oracle.com/technology/oramag/oracle/05-may/o35asktom.html

http://thinkoracle.blogspot.com/2005_06_01_archive.html (12 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

// posted by Robert Vollman @ Saturday, June 18, 2005 5 comments

Friday, June 17, 2005


Asking For Help
There are a lot of people who know Oracle. It makes sense to leverage their
abilities when you're stuck. Why re-invent the wheel?

First of all, often answers are easy to come by yourself. For example, here is Jeff
Hunter's suggestions on where to find answers:

http://marist89.blogspot.com/2005/06/where-can-i-find-help.html

If you want to reach a large body of Oracle professionals, the best approach is to
post it to a popular newsgroup or forum. Here are a few of my favourites.

Oracle Technology Network:


http://forums.oracle.com/forums/forum.jsp?forum=75

comp.databases.oracle.server:
http://groups-beta.google.com/group/comp.databases.oracle.server

DBA-Support:
http://www.dbasupport.com/forums/

Dizwell Forum:
http://www.phpbbserver.com/phpbb/viewforum.php?f=2&mforum=dizwellforum

It is tempting to contact certain professionals directly. After all, there are several of
them that spend seemingly hours answering questions in these forums, and
putting together web pages to assist fellow Oracle professionals.

But be aware that some of them do not have the time (or sometimes the interest)
in answering questions, like Mark Rittman or Duncan Mills.

http://www.rittman.net/archives/001276.html
http://www.groundside.com/blog/content/DuncanMills/
2005/06/16/Questions_Questions.html

And be aware that those that do like to receive questions may have a specific
method of submitting them, such as Tom Kyte and Steven Feuerstein:

http://asktom.oracle.com
http://www.oracle.com/technology/pub/columns/plsql/index.html

If you do ask someone a question, it sounds like these are the ground rules to
follow:

http://thinkoracle.blogspot.com/2005_06_01_archive.html (13 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

1. Don't even bother submitting urgent questions with time deadlines.


2. Even if English isn't your first language, try to make the question as clear as
possible.
3. Try to keep the question brief, but ...
4. Try to provide all necessary information, including examples and error messages
5. Don't ask questions that are obviously school assignments
6. Include "why" you are doing something.

http://tkyte.blogspot.com/2005/05/why.html

But the most important thing is:

Always try to find the answer yourself first!

Loosely Related:
http://vollman.blogspot.com/2005/04/roberts-tips-on-asking-for-help-1.html

// posted by Robert Vollman @ Friday, June 17, 2005 4 comments

Thursday, June 16, 2005


Common Table Column Types
I have two tables which are created in an SQL file, and I want to have a column in
common in both.

CREATE TABLE atable (atable_id VARCHAR2(32), atable_value NUMBER);


CREATE TABLE btable (btable_id VARCHAR2(32), btable_name VARCHAR2(32));

However, I don't want to have to rely on manual verification to make sure they are
the same type. And if I want to change them for a future version, I'd rather only
change it in one place.

I can't do this (abbreviated example):

CREATE TABLE atable (atable_id VARCHAR2(32));


SQL> CREATE TABLE btable (btable_id atable.atable_id%TYPE);
CREATE TABLE btable (btable_id atable.atable_id%TYPE)
*
ERROR at line 1:
ORA-00911: invalid character

And I can't do this:

CREATE OR REPLACE PACKAGE table_types


AS
SUBTYPE table_id IS VARCHAR2(32);
END;

http://thinkoracle.blogspot.com/2005_06_01_archive.html (14 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

SQL> CREATE TABLE atable (atable_id table_types.table_id);


CREATE TABLE atable (atable_id table_types.table_id)
*
ERROR at line 1:
ORA-00902: invalid datatype

So what should we do?

If there is a logical link between these two fields, we can use referential integrity
constraints (thanks "hsheehan"):

SQL>CREATE TABLE atable(atable_id VARCHAR2(32), atable_value NUMBER);

Table created.

SQL>ALTER TABLE atable ADD UNIQUE(atable_id);

Table altered.

SQL>CREATE TABLE btable(btable_id REFERENCES atable(atable_id), btable_name


VARCHAR2(32));

Table created.

However, this will require that every atable.atable_id be unique (ORA-02270), and
it will also require that every btable.btable_id exists in atable.atable_id (ORA-
02291)

This may not always be appropriate, because sometimes there is no such


relationships between columns. You may simply want all columns in a database
that are somehow similar (example: people's names) to be the same type. You may
be doing this for convenience or because you have common functions on these
columns.

In that case, you may need to resort to a 3rd-party schema modeller. After all,
that's what they're for.

Otherwise, you can create a file of tags, use these tags in a "pre-SQL" file, then
write a Perl script to do text substitutions to generate the SQL file. For example:

Tags.txt:
ID_TYPE VARCHAR2(32)
CreateTable.pre:
CREATE TABLE ATABLE (atable_id ID_TYPE, atable_value NUMBER);
CREATE TABLE BTABLE (btable_id ID_TYPE, btable_name VARCHAR2(32));
Execute your Perl script here
CreateTable.sql:
CREATE TABLE ATABLE (atable_id VARCHAR2(32), atable_value NUMBER);
CREATE TABLE BTABLE (btable_id VARCHAR2(32), atable_name VARCHAR2(32));

http://thinkoracle.blogspot.com/2005_06_01_archive.html (15 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

Thanks to the folks at the Dizwell Forum for helping me think this one through.
http://www.phpbbserver.com/phpbb/viewtopic.php?
t=179&mforum=dizwellforum&sid=6802

Here are some loosely related previous blogs on this:


http://thinkoracle.blogspot.com/2005/05/dynamically-assigning-size-of-
varchar2.html
http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html

// posted by Robert Vollman @ Thursday, June 16, 2005 0 comments

Wednesday, June 15, 2005


Variable Constraints
You can't use variables in constraints.

CREATE OR REPLACE PACKAGE test_constants IS


test_val CONSTANT NUMBER := 20;
END test_constants;

CREATE TABLE atable (


a_id NUMBER,
CONSTRAINT atable_test CHECK (a_id > test_constants.test_val)
);

ORA-00904: "TEST_CONSTANTS"."TEST_VAL": invalid identifier

Check Constraints can NOT contain subqueries, so forget about doing it that way.

It is basically only for comparisons and simple operations.

How about this convoluted way of achieving the goal. Create a trigger that will
check the value upon insert or update, and then trigger a special constraint.

SQL> CREATE TABLE atable (


2 a_id NUMBER,
3 a_error NUMBER,
4 CONSTRAINT id_too_high CHECK (a_error <> 1)
5 );

Table created.

SQL> CREATE OR REPLACE TRIGGER atable_trig


2 BEFORE INSERT OR UPDATE OF a_id ON atable FOR EACH ROW
3 BEGIN
4 IF :new.a_id > test_constants.test_val THEN :new.a_error := 1;
5 END IF;

http://thinkoracle.blogspot.com/2005_06_01_archive.html (16 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

6 END;
7/

Trigger created.

SQL> INSERT INTO atable (a_id) VALUES (1);

1 row created.

SQL> INSERT INTO atable (a_id) VALUES (21);


INSERT INTO atable (a_id) VALUES (21)
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.ID_TOO_HIGH) violated

Check the comments to see if someone has a better way.

Related links:
http://thinkoracle.blogspot.com/2005/05/enum-in-oracle.html

// posted by Robert Vollman @ Wednesday, June 15, 2005 1 comments

Tuesday, June 14, 2005


Bind Variables in PL/SQL
If you learn nothing else from the Oracle experts out there but want to improve
your Oracle application development knowledge, then read up on bind variables.

Bind variables are already very well explained, here are my favourite links on the
subject:

Mark Rittman's Bind Variables Explained


http://www.rittman.net/archives/000832.html

Tom Kyte is one of the champions of using Bind Variables. Links to his articles and
books can be found at the bottom of Mark's article.

After reading these articles, I understood that PL/SQL automatically binds


variables, so you really don't have to worry. But I was still concerned that I might
be missing something.

Tom has a query that you can run to determine if you are currently using bind
variables or not. Find it here (Hint: select sql_test from v$sqlarea):
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:1163635055580.

I posted the following question to the Dizwell forum, which is an excellent place to
tap the minds of Oracle gurus directly.

http://thinkoracle.blogspot.com/2005_06_01_archive.html (17 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

http://www.phpbbserver.com/phpbb/viewtopic.php?t=169&mforum=dizwellforum

Is there any possible way to NOT use bind variables in a PL/SQL stored procedure
WITHOUT using 'execute immediate' or DBMS_SQL package?

I just want to make sure that there are only 2 situations I have to look out for in
my PL/SQL code with regards to bind variables.

A developer from Australia going by "gamyers" responded with ref cursors:

DECLARE
v_cur sys_refcursor;
BEGIN
OPEN v_cur FOR 'select 1 from dual where 1=2';
CLOSE v_cur;
END;

Also, you could code


IF v_value =1 then
select ... where col_a = 1;
ELSIF v_value = 2 then
select ... where col_a = 2;
....

But with that sort of code you are probably dealing with a very small set of SQL
statements and are specifically wanting different plans etc.

And the champion himself, Tom Kyte, had this reply and defined some new terms:
"Overbind" and "Underbind." Using these terms I was asking whether it was
possible to "Underbind" using PL/SQL.

The only way to improperly bind in PL/SQL is when you use dynamic sql.

Else, you can "overbind" -- bind when you didn't need to, but you cannot
"underbind", not binding when you should!

eg:

for x in ( select * from all_objects where object_type = 'TABLE' )


loop

is perfectly ok, you do NOT need to:

declare
l_otype varchar2(25) := 'TABLE';
begin
for x in ( select * from all_objects where object_type = l_otype )
loop

http://thinkoracle.blogspot.com/2005_06_01_archive.html (18 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

You do not need to bind 'TABLE' in that query since no matter how many times you
run that query, it'll be 'TABLE' over and over.

But with static SQL, it's not possible to "underbind"

As an aside, visit Jeff Hunter's Oracle blog, which is fast becoming one of my
favourites. Here is his recent post on where Oracle DBAs can get help:
http://marist89.blogspot.com/2005/06/where-can-i-find-help.html

// posted by Robert Vollman @ Tuesday, June 14, 2005 0 comments

Monday, June 13, 2005


Blank Lines and SQLPlus
Try creating the following table using SQLPlus Worksheet.

create table atable (

aint integer

);

You will get this error:

SP2-0734: unknown command beginning "aint integ..." - rest of line ignored.

It thinks "aint integer" is a new command. What is the problem? Repeat this test
using SQLPlus at a prompt:

SQL> create table atable


2(
3
SQL>

The blank line stops the statement.

This doesn't apply to all statements, but it does apply to select/insert/update/


delete queries. It doesn't apply to creating procedures:

SQL> CREATE OR REPLACE PROCEDURE MyProc


2
3 AS
4
5 BEGIN
6
7 NULL;
8
9 END;

http://thinkoracle.blogspot.com/2005_06_01_archive.html (19 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

10 /

Procedure created.

At first I just made the blank lines a comment:

create table atable (


--
aint integer
--
);

Table created.

But eventually I took a closer look and arrived at the correct solution. Here it is.

set sqlblanklines on;

SQL> create table atable


2(
3
4 aint integer
5
6 );

Table created.

Its just a little SQLPlus foible.

If you see something similar and you aren't using blank lines, see if you're using
any special symbols and look at "set sqlprefix" instead.

So what should we do?


1. Put in comments to avoid the blank lines.
2. Use something other than sqlplus.
3. Explicitly set blanklines on at the top of your statement.

// posted by Robert Vollman @ Monday, June 13, 2005 1 comments

Friday, June 10, 2005


NULLs in Oracle
If you read only one sentence per posting, read this:

NULLs may not behave as you'd expect in Oracle, and as a result, NULLs are the
cause of many application errors.

I got a fair bit of private feedback on my recent article on the differences between

http://thinkoracle.blogspot.com/2005_06_01_archive.html (20 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

"NULL" and nothing. Here is the link to the original article, and check out Howard
Rogers' comments.

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html

Let's start with an example to demonstrate a simple property of NULL: that NULL is
not equal to anything, including NULL itself.

SELECT * FROM dual WHERE NULL = NULL;

No rows selected.

SELECT * FROM dual WHERE NULL <> NULL;

No rows selected.

What happened here? How can something be both not equal and not not equal to
something else at the same time? That probably doesn't make much sense, does it?

Essentially NULL means you don't know the value. Basically, you can't say whether
its equal or not equal to anything else. You need to abandon the binary logic you
learned in first-year math and embrace tri-value logic.

That was also a clear demonstration of how you should be careful using equals or
not equals when dealing with NULLs. Instead, use "IS". Observe:

SELECT * FROM dual WHERE NULL IS NULL;

D
-
X

As an aside, you may be wondering what the heck "dual" is. And what do we do
when we have a question? We ask Tom!

http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:1562813956388

In my mind, dual is simply a table with a single row that is guaranteed to be there.
And when you use it, it makes you look clever because that's what the experts
use. :)

While I'm blowing your mind with the behaviour of NULL, check out this other case,
kindly provided by Tom Kyte:

IF (x = 'A') THEN something


ELSE something else
END IF;

IF NOT(x = 'A') THEN something else

http://thinkoracle.blogspot.com/2005_06_01_archive.html (21 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

ELSE something
END IF;

Do these two pieces of pseudo-code look the same to you? In many languages,
yes. But not in PL/SQL. Why?

Consider the case that x is NULL. In the first case it will do "something else"
because it is not equal to 'A'. In the second case it will do "something" because it is
also not not equal to 'A'.

Tom knows I never believe anything without proof, so he provided me with one:

ops$tkyte@ORA9IR2> declare
2 x varchar2(1);
3 begin
4 if ( x = 'A' )
5 then
6 dbms_output.put_line( 'X=A' );
7 else
8 dbms_output.put_line( 'NOT X=A' );
9 end if;
10
11 if NOT( x = 'A' )
12 then
13 dbms_output.put_line( 'NOT X=A' );
14 else
15 dbms_output.put_line( 'X=A' );
16 end if;
17 end;
18 /
NOT X=A
X=A

PL/SQL procedure successfully completed.

Pretty bizarre, eh? Starting to understand the behaviour of NULL? Starting to see
why misunderstanding NULL can lead to application errors?

While we are discussing NULLs, here a few more useful things.

First, you can use the "set null" command to change how NULL will appear in
SQLPLUS. This will not change anything in the database, or equality, it will just
change the appearance.

create table atable (last_name varchar(12));


insert into atable (last_name) values ('Smith');
insert into atable (last_name) values (NULL);

select * from atable;

http://thinkoracle.blogspot.com/2005_06_01_archive.html (22 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

LAST_NAME
------------
Smith

2 rows selected.

set null [NULL];

select * from atable;

LAST_NAME
------------
Smith
[NULL]

2 rows selected.

Also, you can use these two functions, nvl and nvl2:

nvl(expr_1, expr_2)
Returns expr_2 if expr_1 is null and expr_1 otherwise.

nvl2(expr_1, expr_2, expr_3)


Returns expr_3 if expr_1 is null and expr_2 otherwise.

select nvl(last_name, '[NONE]') as last_name from atable;


LAST_NAME
------------
Smith
[NONE]

2 rows selected.

select nvl2(last_name, 'Y: ' || last_name,'N') as last_name from atable;

LAST_NAME
---------------
Y: Smith
N

2 rows selected.

Those of you who, like me, work on many different databases have hopefully seen
by now that NULLs are handled differently in Oracle. As a final demonstration,
consider how NULLs are handled in Sybase ASE.

In Sybase ASE (and MS SQL), there is a configuration parameter that tells the
database whether to treat NULLs as they are defined in the ANSI SQL standard, or

http://thinkoracle.blogspot.com/2005_06_01_archive.html (23 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

whether to "bend the rules" a bit, and allow "NULL = NULL" to be true.
Furthermore, the behaviour changes depending on whether you're in a join clause
or a search clause.

http://sybasease.blogspot.com/2005/05/nulls-in-sybase-ase.html

That is not the case in Oracle. As confusing as NULLs may be at first, they are
consistent. They will behave the same logically everywhere no matter how and
where you use them.

So what should we do?


1. Understand that "NULL = NULL" and "NULL <> NULL" are both false because
NULL means "I don't know"
2. Use "IS NULL" instead of "= NULL" if you are checking for NULLness.
3. Use "nvl" and "nvl2" if you want to eliminate the possibility of a NULL in a
statement by assigning it a (temporary) value.

For future reference, consult Dan Morgan's page on NULL:


http://www.psoug.org/reference/null.html

This is definitely not the last article you'll see on NULL given how often it is
misunderstood. I encourage you to include your own experiences of your favourite
NULLisms in the "comments" section. And, naturally, I appreciate corrections and
clarifications.

And as a final thanks to Tom, here are some pictures from when he visited us in
Calgary this past March.
http://www.coug.ab.ca/events/05-mar.htm

// posted by Robert Vollman @ Friday, June 10, 2005 9 comments

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I like
playing sports (hockey, soccer, ultimate, basketball, you name it) and military
board games. I also enjoy reading, walking, and playing with my 2 cats Lilly and Brutus. I'm a
database application specialist, whatever that is.

View my complete profile

http://thinkoracle.blogspot.com/2005_06_01_archive.html (24 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot

http://thinkoracle.blogspot.com/2005_06_01_archive.html (25 of 26)1/9/2008 2:49:31 AM


OracleBlog: June 2005

❍ The Pythian DBA Team Blog


❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

❍ Current Posts

http://thinkoracle.blogspot.com/2005_06_01_archive.html (26 of 26)1/9/2008 2:49:31 AM


OracleBlog: July 2005

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, July 29, 2005


Oracle By Example
I would like to elaborate on one point from my recent blog on Using
Views:

http://thinkoracle.blogspot.com/2005/07/use-views.html

The example in question is a recent case where I used Views to very


easily perform a complex query.

Let's set it up. We have a simple company with expenses and


revenues broken up by type and department. I'm ignoring many
columns/constraints and the expensetype table for simplicity.

CREATE TABLE department (


dept_name VARCHAR2(32) PRIMARY KEY,
dept_description VARCHAR2(64)
);
CREATE TABLE expenses (
dept_name REFERENCES department(dept_name),
expense_type VARCHAR2(32),
expense_description VARCHAR2(64),
expense_amount NUMBER(10,2)
);
CREATE TABLE revenues (
dept_name REFERENCES department(dept_name),
revenue_type VARCHAR2(32),

http://thinkoracle.blogspot.com/2005_07_01_archive.html (1 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

revenue_description VARCHAR2(64),
revenue_amount NUMBER(10,2)
);

Okay now I'd like to insert a little sample data so we can test some
queries

INSERT INTO department VALUES ('DEPT_A', 'Expenses Only');


INSERT INTO department VALUES ('DEPT_B', 'Revenues Only');
INSERT INTO department VALUES ('DEPT_C', 'Expenses and
Revenues');
INSERT INTO department VALUES ('DEPT_D', 'No Expenses Nor
Revenues');

INSERT INTO expenses VALUES ('DEPT_A', 'TYPE_1', 'Expense 1',


10.00);
INSERT INTO expenses VALUES ('DEPT_A', 'TYPE_2', 'Expense 2',
12.50);
INSERT INTO expenses VALUES ('DEPT_C', 'TYPE_1', 'Expense 3',
44.90);
INSERT INTO expenses VALUES ('DEPT_C', 'TYPE_3', 'Expense 4',
92.75);

INSERT INTO revenues VALUES ('DEPT_B', 'TYPE_1', 'Revenue 1',


14.60);
INSERT INTO revenues VALUES ('DEPT_B', 'TYPE_1', 'Revenue 2',
15.80);
INSERT INTO revenues VALUES ('DEPT_C', 'TYPE_4', 'Revenue 3',
47.75);
INSERT INTO revenues VALUES ('DEPT_C', 'TYPE_5', 'Revenue 4',
6.15);

We want a query that will show us every department, and its total
expenses and revenues. We want dept_name, sum(expenses), sum
(revenues), regardless of type.

Doing a single sum would be easy, we could just "GROUP BY" a


particular column. Even if we wanted to add dept_description, we
could just use Connor McDonald's trick:

http://thinkoracle.blogspot.com/2005/07/extra-columns-in-
group-by.html

http://thinkoracle.blogspot.com/2005_07_01_archive.html (2 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

For simplicity, by the way, we won't include dept_description - we


know we can using that technique.

Go ahead and write the query. I'm sure its possible! But not
everyone can figure it out, you might wind up with something really
complex.

So how will views help us? Well, we can create views that give us the
sum for expenses and values:

CREATE VIEW expensesview AS


SELECT dept_name, sum(expense_amount) expense_sum
FROM expenses
GROUP BY dept_name;
CREATE VIEW revenuesview AS
SELECT dept_name, sum(revenue_amount) revenue_sum
FROM revenues
GROUP BY dept_name;

Nothing could be easier. That is also some pretty handy views to


have. As you recall, a view can be thought of as a "virtual table" or
as a stored query. A stored query we are about to put to use.

SELECT d.dept_name, e.expense_sum, r.revenue_sum


FROM department d, expensesview e, revenuesview r
WHERE d.dept_name = e.dept_name
AND d.dept_name = r.dept_name;

Here are the results ... oops!

DEPT_NAME EXPENSE_SUM REVENUE_SUM


-------------------------------- ----------- -----------
DEPT_C 137.65 53.9

Why did we only get DEPT_C? Because, of course, either


expense_sum or revenue_sum was NULL in the other 3
departments. I'm only showing this mistake so I can show the

http://thinkoracle.blogspot.com/2005_07_01_archive.html (3 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

application of an outer join. An outer join will give you all possible
rows. Just add a (+) next to the column you're joining on.
Symbolically that means you want to add (+) rows where none exist.

SELECT d.dept_name, e.expense_sum, r.revenue_sum


FROM department d, expensesview e, revenuesview r
WHERE d.dept_name = e.dept_name(+)
AND d.dept_name = r.dept_name(+);
DEPT_NAME EXPENSE_SUM REVENUE_SUM
-------------------------------- ----------- -----------
DEPT_A 22.5
DEPT_B 30.4
DEPT_C 137.65 53.9
DEPT_D

Perfect.

We could have done this without views. Indeed, we could have


embedded the simple queries we used to make the views directly
into this final query. Maybe in an example as simple as this that
would be ok. But these kinds of things can get complex. Plus, now
other queries can take advantage of those views.

As a final note, how do you figure we can replace the NULLs up


there with zeros? The answer is something like DECODE or NVL.

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html

SELECT d.dept_name,
NVL(e.expense_sum,0) tot_expense,
NVL(r.revenue_sum,0) tot_revenue
FROM department d, expensesview e, revenuesview r
WHERE d.dept_name = e.dept_name(+)
AND d.dept_name = r.dept_name(+);
DEPT_NAME TOT_EXPENSE TOT_REVENUE
-------------------------------- ----------- -----------
DEPT_A 22.5 0
DEPT_B 0 30.4
DEPT_C 137.65 53.9
DEPT_D 0 0

http://thinkoracle.blogspot.com/2005_07_01_archive.html (4 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

// posted by Robert Vollman @ Friday, July 29, 2005 0 comments

Tuesday, July 26, 2005


Use Constraints
I was ready to explain to you why you should take advantage of
Oracle's ability to manage the integrity of your data rather than rely
on your applications, but I found a much better explanation in the
Oracle Data Warehousing Guide. Read the section "Why Integrity
Constraints are Useful in a Data Warehouse" in Chapter 7 on
"Integrity Constraints."

So instead, let me give you a just a really quick primer from my own
experience, and a couple of treats.

There are many types of constraints, including primary key, unique,


referential (foreign key) and check constraints. I'll talk about check
constraints.

There are basically three ways to set up your table constraint. Check
a reference (like Dan Morgan's http://www.psoug.org/reference/
constraints.html) for more detail, but I will review them here.

1. On the Same Line

CREATE TABLE ConstraintTable (


MyNumber NUMBER(1) CHECK (MyNumber < 5)
);

Using this method (only), you can't reference other columns in the
table in your check constraint. Try it:

CREATE TABLE ConstraintTable (


MyNumber1 NUMBER(1),
MyNumber2 NUMBER(1) CHECK (MyNumber2 > MyNumber1)
);

ORA-02438: Column check constraint cannot reference other


columns

It is also not obvious what name the constraint takes so it's more
difficult to alter it later. But here is how:

http://thinkoracle.blogspot.com/2005_07_01_archive.html (5 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

SQL> SELECT constraint_name


2 FROM user_constraints
3 WHERE table_name = 'CONSTRAINTTABLE';

CONSTRAINT_NAME
------------------------------
SYS_C007536

2. During table creation

Example:

CREATE TABLE ConstraintTable (


MyNumber NUMBER(1)
CONSTRAINT c_my_number CHECK (MyNumber < 5)
);

Doing it this way allows you to reference other columns in the table:

SQL> CREATE TABLE ConstraintTable (


2 MyNumber1 NUMBER(1),
3 MyNumber2 NUMBER(1),
4 CONSTRAINT c_my_number CHECK (MyNumber2 > MyNumber1)
5 );

3. Alter table

You can create your table as normal, and then add your constraints
separately. I don't think there is any actual difference to Oracle
between method #2 and #3.

CREATE TABLE ConstraintTable (MyNumber Number(1));

ALTER TABLE ConstraintTable ADD CONSTRAINT c_my_number


check (MyNumber < 5);

There is actually a 4th way, kind of. See, CHECK constraints can not
include sub-queries, and you can't reference other tables in them.
You also can't use package-defined constants or variables. All you
can basically do is simple things, like <>=, and [not] between/in/
like/equals

I get around all of this by using triggers. I add a simple constraint to


the table (possibly a "NOT NULL", if applicable) and then write a
trigger which will do my check - referencing other tables, writing

http://thinkoracle.blogspot.com/2005_07_01_archive.html (6 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

subqueries and using package-defined constants as I please - and


then deliberately set off the simple constraint.

Of course, this may look silly to a user, who gets an error on


inserting a row with a NULL value when it clearly isn't NULL. So I
usually write something to a log, or name my simple constraint, and
I certainly document the source code. But that's a topic for another
day.

Here is an article where I describe the concept in more detail,


picking especially on using variables in constraints. But apply the
same logic for complex integrity constraints when you want to
reference other tables.

http://thinkoracle.blogspot.com/2005/06/variable-constraints.html

Ok, let me wrap it up by saying that one of the other advantages of


constraints is that you can disable them when you need to:

SQL> INSERT INTO ConstraintTable (MyNumber) VALUES (6);

ORA-02290: check constraint (SYS.SYS_C007536) violated

(By the way, that's the other way to find out the name of your
constraint: violate it!)

SQL> ALTER TABLE ConstraintTable DISABLE CONSTRAINT


SYS_C007536;

SQL> INSERT INTO ConstraintTable (MyNumber) VALUES (6);

And you're ok! Of course, you better make sure the data is ok by the
time you turn it back on, or you'll get this error:

SQL> ALTER TABLE ConstraintTable ENABLE CONSTRAINT


SYS_C007536;

ORA-02293: cannot validate (SYS.SYS_C007536) - check constraint


violated

Which is a great segue into my closing, which includes two of my


favourite discussions on disabling and deferring constraints. Check
them out:

Jeff Hunter

http://thinkoracle.blogspot.com/2005_07_01_archive.html (7 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

http://marist89.blogspot.com/2005/06/deferrable-constraints_29.
html

Doug Burns
http://doug.burns.tripod.com/oracle/index.blog?entry_id=1170846

// posted by Robert Vollman @ Tuesday, July 26, 2005 2 comments

Monday, July 25, 2005


Use Views
Very often the solution to a problem involves using a view. Use
Views!

What is a View?

Most people think of a view either as a stored, named query, or as a


"virtual table."

Here are two definitions from Oracle, along with references to the
key documents on Views to review.

"A logical representation of a table or combination of tables."


- Oracle Application Developer's Guide, Section 2.11 (Views)

"A view takes the output of a query and presents it as a table."


- Oracle Concepts Guide, Section 10.16 (Views)

How do you create a View?

Nothing could be easier. Here:

CREATE OR REPLACE VIEW MyView AS


(Insert Query Here!)

For more, you can always reference Dan Morgan's library:


http://www.psoug.org/reference/views.html

How do I use Views?

Treat it just like a table. You can query them, as well as insert,
update and delete*. Bear in mind that these actions will update the
base table(s). Likewise, any changes to the base table(s) will
automatically update the View*.

http://thinkoracle.blogspot.com/2005_07_01_archive.html (8 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

*This is true in general. Some Views can't be updated, and you can
make a View READONLY.

Here is how to tell what Views exist:

SELECT view_name FROM user_views;

Here is how to tell what the View is:

SELECT text FROM user_views WHERE view_name = 'MyView';

Why are they useful?

I use them for many reasons, here are the most common situations
where I will advocate their use:

1. Denormalizing the database

Sometimes its nice to pull related data from several tables into a
single table. Using views allows you to satisfy both the Fabian
Pascalesque relational database purist, and the pragmatic user.

2. Making things look better

For example, you can use a view to substitute a generic ID number


with the name of the individual. You can leave out columns that are
rarely interesting. You can use a view to add information that is
derived from other data, for example figure out everyone's salary in
Canadian dollars in an international organisation.

3. Complex queries/query simplification

You might have several queries that have to perform similar logic.
You can just create a view for that logic, and make the queries far
simpler. Also, when I can't figure out how to write a really complex
query, sometimes I just create views as intermediate steps.

For example, say you have a table of expenses, with "department",


"type" and "total", a revenue table with the same columns, and a
department table. Now you have to put together a query that shows
each department, and their total expenses and revenues, regardless
of type.

Rather than write a really complex query, just write a view (or two)
that contains the sum of the expenses and revenues, by

http://thinkoracle.blogspot.com/2005_07_01_archive.html (9 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

department. Then you can create a query to put them all into a
single row by (outer) joining on those views. Simple!

4. Restrict access to a column or row

Say you want a user to have access to only part of a table (either by
row or column). Here's what you do: restrict his access to the table
completely, then create a view that contains the information the
user is allowed to access, and then grant that user access to the
view.

5. Rename a column

Create a view which is exactly like the table, but with the column
renamed. That is really easy, and it will save you from having to
possibly update lots of other tables or applications because you left
the base table alone. No, you can't write indexes on views, but
queries get optimized as normal, and it will use the base table's
indexes at that time.

6. Change schema, but still support an old version

Just like renaming a column. You can completely re-design your


database schema, but create views to support legacy applications
who still rely on the structure and naming of the original. That will
save a lot of hassle.

I will close with a really interesting aspect of Views.

SQL> CREATE TABLE BaseTable (MyNumber NUMBER(1));

Table created.

SQL> INSERT INTO BaseTable (MyNumber) VALUES (1);

1 row created.

SQL> CREATE VIEW MyView AS SELECT * FROM BaseTable;

View created.

SQL> ALTER TABLE BaseTable ADD (MyString VARCHAR2(32));

Table altered.

SQL> INSERT INTO BaseTable (MyNumber, MyString) VALUES (2,

http://thinkoracle.blogspot.com/2005_07_01_archive.html (10 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

'Hello');

1 row created.

SQL> SELECT * FROM MyView;

MYNUMBER
----------
1
2

SQL> SELECT * FROM BaseTable;

MYNUMBER MYSTRING
---------- --------------------------------
1
2 Hello

The View is NOT updated when the BaseTable is, even when you
SELECT *. When you write SELECT * the view chooses its columns
then and there.

// posted by Robert Vollman @ Monday, July 25, 2005 7 comments

Saturday, July 23, 2005


Oracle BOOLEAN
There is no BOOLEAN datatype in Oracle, as far as tables are
concerned.

CREATE TABLE BooleanTable (MyBool BOOLEAN);

ORA-00902: invalid datatype

But there is a BOOLEAN datatype in PL/SQL.

CREATE OR REPLACE PROCEDURE BoolProc (in_bool IN BOOLEAN)


AS
my_bool BOOLEAN := TRUE;
BEGIN
IF (in_bool = my_bool) THEN
DBMS_OUTPUT.PUT_LINE('True');
ELSE
DBMS_OUTPUT.PUT_LINE('False or NULL');

http://thinkoracle.blogspot.com/2005_07_01_archive.html (11 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

END IF;

EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE('SQLCODE: ' || SQLCODE);
END BoolProc;

Why is there no Boolean in Oracle for tables? What should we do


instead? This:

CREATE TABLE BoolTable (MyBool CHAR(1) CHECK (MyBool IN ( 'Y',


'N' )));

As for the first question, as usual, let's Ask Tom:

http://asktom.oracle.com/pls/ask/f?
p=4950:8:2109566621053828525::NO::F4950_P8_DISPLAYID,
F4950_P8_CRITERIA:6263249199595

// posted by Robert Vollman @ Saturday, July 23, 2005 7 comments

Thursday, July 21, 2005


Oracle Blogs
If you enjoy this blog, there may be other Oracle-related blogs you
will also enjoy reading. You may be surprised to learn just how
many good Oracle blogs are out there. I follow quite a few on a daily
or casual basis. Here are my favourites.

Brian Duff hosts OraBlogs, which picks up several of the below


Oracle blogs, so it can be a one-stop blog.
http://www.orablogs.com/orablogs/

Tom Kyte, respected author of "Ask Tom." Covers a pretty wide


spectrum of Oracle-related topics, including new things and "best
practises." This is on practically everyone's favourite blog list, and
every post gets dozens of comments.
http://tkyte.blogspot.com/

Niall Litchfield has one of the first Oracle blogs I read. He has
interesting posts on a variety of topics including htmldb, and Oracle

http://thinkoracle.blogspot.com/2005_07_01_archive.html (12 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

10g.
http://www.niall.litchfield.dial.pipex.com/

Howard Rogers is the master of the Dizwell Forum. The discussions


therein are generally the inspiration for his posts. His passionate
Oracle rants give his blog a lot of flavour.
http://www.dizwell.com/blogindex.html

David Aldridge, is an all-purpose Oracle warehouse specialist. I love


his posts on warehouse design and maintenance. He also posts
regularly about Oracle 10g and its features.
http://oraclesponge.blogspot.com/

Mark Rittman is a database warehouse developer and covers a lot of


stuff, like modelling. He has a link to all the Oracle blogs that are
out there (good or bad), so you can go through there and pick your
favourites.
http://www.rittman.net/

Jeff Hunter is an Oracle DBA with a relatively new blog. He posts a


wide variety of topics, and he is on a lot of people's favourites list.
http://marist89.blogspot.com/

Tim Hall is an Oracle DBA, designer and developer. Posts on a


variety of topics and is not shy about sharing his opinions. Despite
the fact that he doesn't use IDEs, he's one of the few people who
mention them.
http://oracle-base.blogspot.com/

Doug Burns, another Oracle DBA, reads and writes papers and
books. I count on him to post about the latest news and papers/
books of interest.
http://doug.burns.tripod.com/oracle/

Pete Finnigan, an Oracle security expert, provides the latest news of


bugs and security flaws. Even though I'm not into security that
much, I still enjoy his posts.
http://www.petefinnigan.com/weblog/entries

Eddie Awad, an Oracle application developer who posts interesting


things about Oracle as he finds them. Also talks about ColdFusion
and Biztalk occasionally. Has me in his blogroll! :)
http://awads.net/wp/

http://thinkoracle.blogspot.com/2005_07_01_archive.html (13 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

Peter Scott is a manager (!) in charge of an Oracle data warehouse.


As a result his posts are generally about the situation of the day,
which is usually of significance to everyone.
http://pjs-random.blogspot.com/

Lisa Dobson, an Oracle DBA whose brand new blog focuses on the
Newbie perspective.
http://newbiedba.blogspot.com/

Amis Technology Corner has a number of Oracle professionals from


various backgrounds that post on a variety of topics, including
Oracle-related events and publications, and various designs and
features.
http://technology.amis.nl/blog/

Mike Ault, a Burleson consultant and published author, posts on a


variety of Oracle-related topics related to his interesting adventures
while consulting. No comments allowed, ostensibly for legal reasons
but people posted a lot of corrections when they were allowed.
http://mikerault.blogspot.com/

Robert Freeman, another Burleson consultant and a 15-year Oracle


DBA, posts on a variety of Oracle-related topics of interest to DBAs,
including the types of problems he sees and solves and things he
finds in the latest releases.
http://robertgfreeman.blogspot.com/

If you know of any other Oracle-related blogs that you enjoy, please
add a Comment so I can check it out. Please spread the word of
these great blogs!

// posted by Robert Vollman @ Thursday, July 21, 2005 4 comments

Monday, July 18, 2005


Which instance am I in?
Here's an easy one a colleague asked me.

You are logged into your default session (example: sqlplus scott/
tiger with no @instance)

You want to know which instance you are logged into.

http://thinkoracle.blogspot.com/2005_07_01_archive.html (14 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

You can't query V$ tables directly, because you're not logged in as


SYS.

So while looking around at similar questions on Jonathan Lewis'


cooperative FAQ:
http://www.jlcomp.demon.co.uk/faq/MySessID.html

I saw SYS_CONTEXT. That looked like it would do the trick. So I


looked it up in my favourite reference, Dan Morgan's:
http://www.psoug.org/reference/sys_context.html

And came up with this:

SELECT SYS_CONTEXT(‘USERENV’,’DB_NAME’) FROM DUAL;

You can also get the 'INSTANCE' using this, but that doesn't do you
any good if you can't query the V$INSTANCE table.

That solves the problem, but I'm sure that's just one of many ways
to do it:

1. Some other queries on some system tables, and/or


2. Some command-line command, and/or
3. Some environment file somewhere.

Also, I know some people who put this directly into their sqlplus
prompt.

// posted by Robert Vollman @ Monday, July 18, 2005 1 comments

Thursday, July 14, 2005


Oracle Docs
We have seen articles on where to go for help, and how to ask for
help:

http://thinkoracle.blogspot.com/2005/06/asking-for-help.html

Recently Tom Kyte wrote an article on Reading the F'n Manual:

http://tkyte.blogspot.com/2005/07/rtfm.html

Which begs the F'n question. Where are the F'n manuals? Which

http://thinkoracle.blogspot.com/2005_07_01_archive.html (15 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

manuals should you F'n read?

The first question is easy, it's all here:

http://www.oracle.com/technology/documentation/index.html

Personally, I use Oracle9, so I have this page bookmarked:

http://www.oracle.com/technology/documentation/oracle9i.html

For the novice, you want to go to View Library and Getting Started

There you will find links for the Installer, the Administrator, and the
Developer. These links give you recommendations for which F'n
manuals to read.

Being an application developer the key F'n manual for me, without
dispute, is:

Oracle9i Application Developer's Guide - Fundamentals


http://download-west.oracle.com/docs/cd/B10501_01/
appdev.920/a96590.pdf

I won't include all the links, because a list of all F'n manuals for
Oracle9i can be found here:

http://www.oracle.com/pls/db92/db92.docindex?
remark=homepage

Here are the F'n manuals that are recommended for Application
Developers:

Oracle9i Database Concepts Guide


Oracle9i SQL Reference
Oracle9i Data Warehousing Guide
PL/SQL User's Guide and Reference
Oracle9i Supplied PL/SQL Packages and Types Reference
Oracle9i Database Performance Tuning Guide and Reference
Oracle9i Database Error Messages

Beyond that, there are also F'n manuals for more advanced
programming (Java, C++, XML, Object-Related).

Please feel free to leave me some F'n comments with other F'n good
manuals and books.

http://thinkoracle.blogspot.com/2005_07_01_archive.html (16 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

// posted by Robert Vollman @ Thursday, July 14, 2005 4 comments

Wednesday, July 13, 2005


Stored Procedure template
Since there was some interest in the "object" template,

http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html

and since I've been dry on ideas lately because I haven't been
working on non-Oracle things the last week or two, I decided to
share another one of my templates. This time: stored procedures.
Enjoy!

SET SERVEROUTPUT ON;

-- 'NOCOPY' makes it a pointer (pass by reference) - faster.


-- 'DETERMINISTIC' means the output is the same for every input -
allows caching (for return type tables)
-- CREATE OR REPLACE FUNCTION MyFunc (p_something IN OUT
NOCOPY Transactions.number%TYPE)
-- RETURN BOOLEAN DETERMINISTIC
-- 'DEFAULT' is the same as ':=' for both here and DECLARE
CREATE OR REPLACE PROCEDURE MyProc (p_something IN
Transactions.number%TYPE DEFAULT 1)
-- The following says it is independent of anything calling it (eg:
rollbacks, etc)
-- IS PRAGMA AUTONOMOUS_TRANSACTION
AS
[[BlockName]]
-- If its an anonymous block:
-- DECLARE
v_datetime TIMESTAMP;
v_transaction Transactions.number%TYPE := 0;
v_the_date_is CONSTANT VARCHAR2(12) := 'The date is ';

-- Create an exception, the pragma is optional


v_my_exception EXCEPTION;
PRAGMA EXCEPTION_INIT(v_my_exception, 100);

-- subprograms (functions) MUST be declared last


PROCEDURE NothingReally IS BEGIN NULL; END NothingReally;

http://thinkoracle.blogspot.com/2005_07_01_archive.html (17 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

BEGIN
-- SET TRANSACTION READ ONLY; -- Use consistent snapshot of
the database
-- SET TRANSACTION READ WRITE; -- The default. Turns "off" the
Read Only
-- SET TRANSACTION ISOLATION LEVEL READ COMMITTED
-- SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
-- SET TRANSACTION USE ROLLBACK SEGMENT

-- This is a comment
SELECT systime INTO BlockName.v_datetime FROM dual;
DBMS_OUTPUT.PUT_LINE(v_the_date_is || v_datetime);

[[LoopName]]
IF 1=1
THEN NULL;
ELSIF 1=2
THEN RAISE NO_DATA_FOUND;
ELSE
THEN NothingReally;
END IF;

CASE
WHEN 1=1 THEN NULL;
-- Application Errors have to be -20000 to -20999 inclusive and
can't be caught specifically
WHEN 1=2 THEN RAISE_APPLICATION_ERROR(-20000, 'Error: '||
v_the_date_is||' BAH');
ELSE NULL;
END CASE;

LOOP
EXIT WHEN 1=1;
END LOOP;

FOR v_transaction IN 0 .. 10
LOOP
NULL;
END LOOP;

WHILE 1=2
LOOP
RAISE v_my_exception;
END LOOP;

http://thinkoracle.blogspot.com/2005_07_01_archive.html (18 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

COMMIT;
EXCEPTION
-- This only covers errors raised after BEGIN (but NOT in 'DECLARE'!)
-- You can "OR" exceptions.
-- An exception can't be in more than 1 block
WHEN v_my_exception
THEN NULL;
-- This is optional but good practice.
-- Unhandled exceptions fall through to the next block or statement
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE('SQLCODE: ' || SQLCODE);
END MyProc;
/

// posted by Robert Vollman @ Wednesday, July 13, 2005 0 comments

Monday, July 11, 2005


Specifying INSERT Columns
Here is a quick one that I touched on briefly in one of my first blogs:

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html

It can be important to specify which columns you plan on providing


values for in an INSERT statement. Repeating Dan Morgan's quote:

"By not specifying column names you are signifying that you are
providing values for ALL columns. This is why it is a very bad
practice as doing an ALTER TABLE ADD immediately invalidates all
SQL statements."

Here is an example. I created a table, and then wrote a procedure


that will insert a row WITHOUT specifying the values. Works fine if
the table doesn't change:

SET SERVEROUTPUT ON;

CREATE TABLE MyTable (MyInt NUMBER);

CREATE OR REPLACE PROCEDURE InsertIntoMyTable (InValue IN

http://thinkoracle.blogspot.com/2005_07_01_archive.html (19 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

NUMBER)
AS
BEGIN
DBMS_OUTPUT.PUT_LINE('Inserting ' || InValue || ' into MyTable');
INSERT INTO MyTable VALUES (InValue);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE('SQLCODE: ' || SQLCODE);

END InsertIntoMyTable;
/

EXEC InsertIntoMyTable(1);
Inserting 1 into MyTable

PL/SQL procedure successfully completed.

So let's try modifying the table, and try again.

ALTER TABLE MyTable ADD (MyString VARCHAR2(32));

EXEC InsertIntoMyTable(2);
BEGIN InsertIntoMyTable(2); END;

*
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00905: object SCOTT.INSERTINTOMYTABLE is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

The procedure fails, and can't recompile. Perhaps you want that
behaviour, because you want to require all your procedures to be
checked every time a related table has changed. But, then again,
maybe you don't.

In that case, modify the stored procedure to specify which value you
are inserting, and then you're good to go. Let's repeat this test that
way:

CREATE OR REPLACE PROCEDURE InsertIntoMyTable (InValue IN


NUMBER)
AS

http://thinkoracle.blogspot.com/2005_07_01_archive.html (20 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

BEGIN
DBMS_OUTPUT.PUT_LINE('Inserting ' || InValue || ' into MyTable');
INSERT INTO MyTable (MyInt) VALUES (InValue);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE('SQLCODE: ' || SQLCODE);

END InsertIntoMyTable;
/

SQL> EXEC InsertIntoMyTable(2);


Inserting 2 into MyTable

PL/SQL procedure successfully completed.

SQL> ALTER TABLE MyTable ADD (MyOtherInt NUMBER);

Table altered.

SQL> EXEC InsertIntoMyTable(3);


Inserting 3 into MyTable

PL/SQL procedure successfully completed.

// posted by Robert Vollman @ Monday, July 11, 2005 0 comments

Tuesday, July 05, 2005


Regular Expressions in Oracle
I was recently asked to do a blog about Regular Expressions in
Oracle 10, because they were cool.

They are cool.

Except to people that get spooked by a bunch of [:whatever:] in


their code, and feel their lunch come up when they see '[^:]+,\?.{3}
(tip: if that is you, don't ever read Perl code).

Anyway I can not do a blog on Regular Expressions in Oracle 10 for


two reasons:

1. I only blog about what I'm currently working on and studying, and

http://thinkoracle.blogspot.com/2005_07_01_archive.html (21 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

2. I use Oracle 9.

But no worries. There is a great article on Oracle Regular


Expressions:

http://www.oracle.com/technology/oramag/webcolumns/
2003/techarticles/rischert_regexp_pt1.html

Hmph, looks like I blogged about Oracle Regular Expressions after


all.

Oh yes, and here is your Regular Expression reference, courtesy of


(who else) Dan Morgan:

http://www.psoug.org/reference/regexp.html

He covers REGEXP_INSTR, REGEXP_LIKE, REGEXP_REPLACE,


REGEXP_SUBSTR.

// posted by Robert Vollman @ Tuesday, July 05, 2005 3 comments

Monday, July 04, 2005


SQLCODE and SQLERRM in INSERTs
Here is an interesting foible. Normally you can build strings on the
fly from functions and insert them into a table. Like so:

CREATE TABLE LogTable (logString VARCHAR2(128));

CREATE OR REPLACE FUNCTION MyFunc RETURN VARCHAR2


AS
BEGIN
RETURN 'Hello';
END;

CREATE OR REPLACE PROCEDURE MyProc


AS
BEGIN
NULL;
EXCEPTION
WHEN OTHERS
THEN
INSERT INTO LogTable (logString) VALUES (MyFunc || ' ' || MyFunc);

http://thinkoracle.blogspot.com/2005_07_01_archive.html (22 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

END;

But you can't do this with SQLCODE and SQLERRM.

CREATE OR REPLACE PROCEDURE MyProc


AS
BEGIN
NULL;
EXCEPTION
WHEN OTHERS
THEN
INSERT INTO LogTable (logString) VALUES (SQLCODE || ' ' ||
SQLERRM);
END;

PL/SQL: ORA-00984: column not allowed here

You can always put the values in a string for a workaround.

CREATE OR REPLACE PROCEDURE MyProc


AS
errString LogTable.logString%TYPE;
BEGIN
NULL;
EXCEPTION
WHEN OTHERS
THEN
errString := SQLCODE || ' ' || SQLERRM;
INSERT INTO LogTable (logString) VALUES (errString);
END;

Procedure created.

For reference, look up SQLCODE and SQLERRM in the PL/SQL User's


Guide and Reference.

Bonus. I found the following blog while reviewing OraBlogs:


http://blog.niftypaint.nl/

Which pointed me to Eddie Awad's great blog:


http://awads.net/wp/

Enjoy!

http://thinkoracle.blogspot.com/2005_07_01_archive.html (23 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

// posted by Robert Vollman @ Monday, July 04, 2005 5 comments

Friday, July 01, 2005


Extra Columns in a GROUP BY
Happy Canada Day. I have a really good one today.

My problem:

I have a table 'ASSIGNMENTS' that keeps track of each assignment,


who holds which assignment, and as of which date they have held it.

It would be very handy to have a view that shows all assignments,


and who is currently on that assignment.

CREATE TABLE ASSIGNMENTS(ASSIGNMENT VARCHAR2(32),


EMPLOYEE VARCHAR2(32), EFFECTIVE DATE);

INSERT INTO ASSIGNMENTS(ASSIGNMENT, EMPLOYEE, EFFECTIVE)


VALUES ('Prime Minister', 'Jean Chretien', '04-Nov-93');
INSERT INTO ASSIGNMENTS(ASSIGNMENT, EMPLOYEE, EFFECTIVE)
VALUES ('Governor General', 'Adrienne Clarkson', '07-Oct-99');
INSERT INTO ASSIGNMENTS(ASSIGNMENT, EMPLOYEE, EFFECTIVE)
VALUES ('Prime Minister', 'Paul Martin', '12-Dec-03');

You must be familiar with GROUP BY.

SELECT ASSIGNMENT, MAX(EFFECTIVE) AS_OF FROM ASSIGNMENTS


GROUP BY ASSIGNMENT;

ASSIGNMENT AS_OF
-------------------------------- ---------
Governor General 07-OCT-99
Prime Minister 12-DEC-03

2 rows selected.

Ok, now we would like to add in the name of the person. But
whoops, doesn't work as you'd expect.

SELECT ASSIGNMENT, EMPLOYEE, MAX(EFFECTIVE) AS_OF FROM


ASSIGNMENTS GROUP BY ASSIGNMENT;

ORA-00979: not a GROUP BY expression

http://thinkoracle.blogspot.com/2005_07_01_archive.html (24 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

You see, we can't include any columns that aren't part of the GROUP
BY. And, we can't include it in the group by, because then we'd get a
result no different from assignments.

There is an answer. Connor McDonald has it:

http://www.oracledba.co.uk/tips/9i_first_last.htm

Alright, what is Connor talking about? Basically he is grouping the


"extra" column (empno), and making it a secondary grouping to the
main grouping (sal).

But, really, MIN(EMPNO)? Why are we including an aggregate


function on empno? Well, Connor is doing it because he wants to
break ties.

Even though we don't need to break ties, we still need to use an


aggregate function, otherwise it becomes part of the group by. Any
aggregate function will do since we shouldn't have duplicates.

DENSE_RANK , FIRST, ORDER BY

- ORDER BY will sort a set of rows by a particular column. In


Connor's case it is salary, in our case, it will be 'effective'.
- DENSE_RANK provides the positioning of a particular row within
an ordered list of rows.
- FIRST goes hand-in-hand with DENSE_RANK and will naturally
provide us with the first, ranked row in a ordered list of rows.

Note that the ORDER BY defaults to ascending order, and so in our


case we either want to choose LAST or put the ORDER BY in
descending order instead.

Essentially he is creating an ordered list of all salaries, and choosing


the empno that shows up first on that list. Sounds like what we
want!

Here is Dan Morgan's reference on numeric functions like these:


http://www.psoug.org/reference/number_func.html

KEEP is just a clever Oracle trick to keep the work we're doing in the
shared pool because we're using it twice in the same query.

So applying Connor's teachings to our situation, we get:

http://thinkoracle.blogspot.com/2005_07_01_archive.html (25 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

CREATE OR REPLACE VIEW CURRENT_ASSIGNMENTS AS


SELECT ASSIGNMENT,
MAX(EMPLOYEE) KEEP (DENSE_RANK LAST ORDER BY EFFECTIVE)
EMPLOYEE,
MAX(EFFECTIVE) AS_OF
FROM ASSIGNMENTS
GROUP BY ASSIGNMENT;

SELECT * FROM CURRENT_ASSIGNMENTS;

ASSIGNMENT EMPLOYEE AS_OF


--------------------------------
-------------------------------- ---------
Governor General Adrienne Clarkson 07-OCT-99
Prime Minister Paul Martin 12-DEC-03

2 rows selected.

Coming up in some future blog, Tom Kyte mentioned the awesome


"MEMBER OF" feature that is in Oracle 10g. It will tell you easily
whether a value is contained in a particular set/table. I'm looking
for a way to do this in Oracle 9.

http://thinkoracle.blogspot.com/2005/05/enum-in-oracle.html

// posted by Robert Vollman @ Friday, July 01, 2005 1 comments

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

http://thinkoracle.blogspot.com/2005_07_01_archive.html (26 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns

http://thinkoracle.blogspot.com/2005_07_01_archive.html (27 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

❍ Oracle ACE of the Year Dr. Tim Hall


❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005_07_01_archive.html (28 of 29)1/9/2008 2:49:36 AM


OracleBlog: July 2005

❍ Current Posts

http://thinkoracle.blogspot.com/2005_07_01_archive.html (29 of 29)1/9/2008 2:49:36 AM


OracleBlog: August 2005

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated, but it
is the most powerful tool when it comes to data. That's why when I think data, I think Oracle. I also enjoy
writing, so I use this format to organise my thoughts. Please feel free to discuss any thoughts you may
have on the same topics, even old ones (I will see and respond to such comments). You may want to
start with "LIST ALL ARTICLES" under Archives.

Monday, August 29, 2005


About Me
New Blogs Name: Robert
Not long ago, I wrote a blog on all the Oracle Blogs out Vollman
there: Location: Calgary,
Alberta, Canada
http://thinkoracle.blogspot.com/2005/07/oracle-blogs.
html
I was born and raised in Ottawa,
and have lived in Calgary since
Not long after that, I included a list of links to all the blogs
1991. I like playing sports
I follow (see the side, below links).
(hockey, soccer, ultimate,
Well there have been a couple of changes and new basketball, you name it) and
additions. The most exciting of which is I found a blog by military board games. I also
Laurent Schneider. He is one of my favourite posters from enjoy reading, walking, and
the Oracle Forum: playing with my 2 cats Lilly and
Brutus. I'm a database
http://forums.oracle.com/forums/forum.jspa?forumID=75 application specialist, whatever
that is.
His posts usually involve how to use Oracle to solve
someone's problems. Over the months I've been reading View my complete profile
this forum, I've seen him cover a wide spectrum.

Here is a link to one of of his most recent articles:


Best Links
http://laurentschneider.blogspot.com/2005/08/pivot- ● Ask Tom Kyte
table.html ● Oracle Docs
● Dan Morgan and PSOUG
There are a few other changes: ● Steven Feuerstein
Jonathan Lewis
Doug Burns changed his blog's location:

FAQ
http://oracledoug.blogspot.com/

● Connor McDonald
Radoslav Rusinov has a new blog, which he has kicked off ● The Oak Table
with a discussion of the latest Burleson Boondoggle on PGA: ● Cary Millsap and Hotsos
http://dba-blog.blogspot.com/ ● Steve Adams and Ixora
● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2005_08_01_archive.html (1 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

Hopefully these blogs will make up for my lack of content ● Dizwell Oracle Wiki
recently! ● My Personal Blog

// posted by Robert Vollman @ Monday, August 29, 2005 2 comments

Aggregators
Brian Duff's OraBlogs

Wednesday, August 24, 2005 ❍ Eddie Awad's OracleNA


Pete Finnigan's Aggregator
COMPUTE ❍

Oracle's Bloglist
Let's say you wanted to write a query that contained an

Oracle Base Aggregator


aggregate (eg: sum, min, max, count). No problem, you can ❍

use 'GROUP BY'.


Top Blogs
But suppose you wanted to write a query that was a report ❍ Oracle's Ask Tom Kyte
containing both the aggregate and the detail. That makes it ❍ Oracle Guru Jonathan Lewis
trickier. ❍ Blogger of the Year Eddie Awad
Data Warehouser David Aldridge
You may even know how to do it in other databases: ❍

❍ Oracle Geek Lewis Cunningham


http://sybasease.blogspot.com/2005/08/compute.html ❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
There is a simple way of accomplishing this in SQL*Plus. ❍ Oracle Master Laurent Schneider
SQL*Plus includes a function of the same name (COMPUTE) ❍ Security Expert Pete Finnigan
that will do the formatting for you. ❍ Oracle Award Winner Mark
Rittman
In order to use it, you also have to use 'BREAK'. Let's take a
Doug Burns
very brief look at it. BREAK, like COMPUTE, is an SQL*Plus

command that you would issue at any time prior to your ❍ Oracle ACE of the Year Dr. Tim
query. For example, the following BREAK command will Hall
remove all values in DEPTNO if they are the same as the ❍ UKOUG's Andrew (Arfur C.) Clarke
preceding value, and skip 1 line after each grouping. ❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
scott@Robert> BREAK ON deptno SKIP 1 NODUPLICATES ❍ Chris Foot
scott@Robert> SELECT ename, sal, deptno ❍ The Pythian DBA Team Blog
2 FROM emp ❍ DBA Don Seiler
3 ORDER BY deptno; ❍ DBA Coskan Gundogar
ENAME SAL DEPTNO ❍ Oracle WTF

ARCHIVES
---------- ---------- ----------
CLARK 2450 10
VOLLMAN 5000
❍ LIST ALL ARTICLES
MILLER 1300
SMITH 800 20 ❍ May 2005
ADAMS 1100 ❍ June 2005
FORD 3000 ❍ July 2005
SCOTT 3000 ❍ August 2005
JONES 2975 ❍ September 2005
ALLEN 1600 30 ❍ October 2005
BLAKE 2850 ❍ November 2005
MARTIN 1250 ❍ December 2005
JAMES 950 ❍ January 2006

http://thinkoracle.blogspot.com/2005_08_01_archive.html (2 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

TURNER 1500 ❍ February 2006


WARD 1250 ❍ March 2006
❍ April 2006
❍ May 2006
June 2006
Now let's add our COMPUTE command. This one will ❍

calculate the subtotal of salary, just like it would using ❍ July 2006
GROUP BY. The advantage here is that its in the same table. ❍ August 2006
❍ September 2006
scott@Robert> COMPUTE SUM LABEL subtotal OF sal ON ❍ October 2006
deptno ❍ November 2006
scott@Robert> SELECT ename, sal, deptno FROM emp ❍ December 2006
ORDER BY deptno; ❍ January 2007
❍ February 2007
ENAME SAL DEPTNO ❍ March 2007
---------- ---------- ----------
❍ April 2007
CLARK 2450 10
❍ May 2007
VOLLMAN 5000
❍ June 2007
MILLER 1300
---------- ********** ❍ October 2007
8750 subtotal
❍ Current Posts
SMITH 800 20
ADAMS 1100
FORD 3000
SCOTT 3000
JONES 2975
---------- **********
10875 subtotal
ALLEN 1600 30
BLAKE 2850
MARTIN 1250
JAMES 950
TURNER 1500
WARD 1250
---------- **********
9400 subtotal

Naturally, this also works with other aggregate functions


like SUM, MIN, MAX, AVG, STD, VARIANCE, COUNT,
NUMBER.

For reference, check out the SQL*Plus User's Guide:


http://download-west.oracle.com/docs/cd/B10501_01/
server.920/a90842.pdf

You want chapters 7 and 13:


7 Formatting SQL*Plus Reports
13 SQL*Plus Command Reference

http://thinkoracle.blogspot.com/2005_08_01_archive.html (3 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

UPDATE: Actually there's a simple way without SQL*Plus, by


using GROUPING, see Tom Kyte's Comment. Here is his
example of my Oracle9 environment.

scott@Robert> SELECT DECODE(GROUPING_ID(ename), 1,


'Subtotal' ) tag
2 ename, deptno, SUM(sal)
3 FROM emp
4 GROUP BY GROUPING SETS( (ename,deptno), (deptno) );

TAG ENAME DEPTNO SUM(SAL)


-------- ---------- ---------- ----------
CLARK 10 2450
MILLER 10 1300
VOLLMAN 10 5000
Subtotal 10 8750
FORD 20 3000
ADAMS 20 1100
JONES 20 2975
SCOTT 20 3000
SMITH 20 800
Subtotal 20 10875
WARD 30 1250
ALLEN 30 1600
BLAKE 30 2850
JAMES 30 950
MARTIN 30 1250
TURNER 30 1500
Subtotal 30 9400

Read about GROUPING, GROUPING_ID and GROUPING SETS


in SQL Reference:
http://download-west.oracle.com/docs/cd/B10501_01/
server.920/a96540.pdf

// posted by Robert Vollman @ Wednesday, August 24, 2005 6 comments

Wednesday, August 17, 2005


Keeping Tables Small
David Aldridge recently put together a list of ways to make
table scans faster:

http://oraclesponge.blogspot.com/2005/08/list-ways-to-
scan-table-faster.html

There is one really simple, effective but often overlooked

http://thinkoracle.blogspot.com/2005_08_01_archive.html (4 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

way of decreasing the time it takes to scan a table that I


want to elaborate on. It's based on this simple premise:

Fewer Rows = Faster Scans.

The time it takes to scan a table can be roughly calculated


like so:
Number of Rows TIMES Time to Process One Row

Many people focus on the second part of the question (the


time it takes to process a single row), when sometimes it is
far more simple to decrease the number of rows.

What that means is, look at the table and determine if some
of the data is used infrequently enough that it can be
moved aside to an archived version of this table.

You may need to modify your existing applications to


account for cases where you truly do need to look at all
that data. In that case, you might keep a view of all data.

That is basically my point, so you can stop reading there if


you wish. I have put together an example, where I elaborate
on this a little further. It is meant only as a demonstration
of what I mean, not any kind of compelling argument or
proof.

First off, here is an easy way to create a nice, big test table.

CREATE TABLE ReallyBigTable AS SELECT * FROM


ALL_OBJECTS;

SELECT COUNT (*) FROM ReallyBigTable;

40763

Now I'm going to create a query that ought to really suffer,


performance-wise, the larger the table is:

SELECT SUM(object_id) FROM ReallyBigTable


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable);

Time Elapsed: 00:11:42.09

Alright, now let's create an archive and active version of


this table. For argument's sake, let's say that anything with
an object_id below 40000 is used infrequently enough that
it is safe to push aside for our business-specific purposes:

CREATE TABLE ReallyBigTable_Archive AS SELECT * FROM


ReallyBigTable
WHERE object_id < 40000;

http://thinkoracle.blogspot.com/2005_08_01_archive.html (5 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

SELECT COUNT (*) FROM ReallyBigTable_Archive;

38000

CREATE TABLE ReallyBigTable_Active AS SELECT * FROM


ReallyBigTable
WHERE object_id >= 40000;

SELECT COUNT (*) FROM ReallyBigTable_Active;

2763

I'm in a single-user environment doing a test, so I really


don't have to worry right now about updates taking place.
Otherwise we'd have to more clever about the creation of
our archive and active tables. But I will say that creating
these tables can be lightning-fast!

Ok, now let's try our query on our little table:

SELECT SUM(object_id) FROM ReallyBigTable_Active


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable_Active);

Time Elapsed: 00:00:02.08

So it completed in 0.3% of the time. Awesome!

"OK," you say, "but you're cheating!" So what if I am?


Sometimes in the real world we CAN cheat. Sometimes we
don't have to go through all the data, every time, every
case. Don't get mad at Oracle or your DBA or your
application when it's not fast enough, just get creative. You
don't always have to apply painful Kolkian techniques or
Millsapian analysis to get results.

Moving on, there may still be some applications that want


to query on the whole dataset. No problem, that is still
possible using UNION. But what kind of price will we pay?
Let's see, in this one example:

DROP TABLE ReallyBigTable;

CREATE VIEW ReallyBigTable AS


SELECT * FROM ReallyBigTable_Archive
UNION ALL
SELECT * FROM ReallyBigTable_Active;

Remember, a view is just like a stored query, but we can


use it like a table. Which means our applications don't have
to change their queries.

http://thinkoracle.blogspot.com/2005_08_01_archive.html (6 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

http://thinkoracle.blogspot.com/2005/07/use-views.html

One limitation of this kind of view is that we won't be able


to insert from our legacy applications anymore:

INSERT INTO ReallyBigTable (object_id) VALUES (NULL);

ORA-01732: data manipulation operation not legal on this


view

Let's see how much of a performance penalty we have in


this case by using a view instead of the original base table:

SELECT SUM(object_id) FROM ReallyBigTable


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable);

Time Elapsed: 00:08:18.02

What??? The use of a view on two smaller sub-tables took


less time than the original table? It only took 70% as much
time. Probably something to do with having the data in
memory, or statistics, or something like that. I'll get back
to you in another blog. The main thing I wanted to
demonstrate was that the performance would be in the
same "order" as the original query. That is, you're not
taking a huge performance hit by using a view.

Out of curiousity, let's take a mixed sub-example, where


we are using our new, smaller table against that big view.

SELECT SUM (object_id) FROM ReallyBigTable_Active


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable);

Time Elapsed: 00:00:43.05

Nice.

One final point, if I may. Notice I used "UNION ALL" instead


of "UNION." I did this because UNION rearranges the order
of the table, and removes duplicates.

http://thinkoracle.blogspot.com/2005/08/union-all.html

I don't care about duplicates and order, and I didn't want


the performance hit, so I used UNION ALL. Of course, I am
curious to know how significant the performance hit is in
this case. Let's see.

CREATE OR REPLACE VIEW ReallyBigTable AS


SELECT * FROM ReallyBigTable_Archive
UNION

http://thinkoracle.blogspot.com/2005_08_01_archive.html (7 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

SELECT * FROM ReallyBigTable_Active;

SELECT SUM(object_id) FROM ReallyBigTable


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable);

Time Elapsed: 00:13:20.02

So it took about 60% longer than with UNION ALL.

SELECT SUM (object_id) FROM ReallyBigTable_Active


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable);

Time Elapsed: 00:00:54.05

And this one about 25% longer. So in this case it was


definitely noticeable.

Wrap-up:
1. David Aldridge has a great article on how to make your
table scans go faster.
2. In addition to his techniques, I recommend "being
creative" (aka "cheating") and trying to split your data.
3. Use Views to maintain applications that SELECT from the
big, original table so you don't have to change code and
can still query the whole set.
4. Using Views will not have a big performance hit. In fact,
in this demonstration it was faster (a topic for another
day's blog).
5. Use UNION ALL instead of UNION in this view to avoid
the noticeable performance hit.

// posted by Robert Vollman @ Wednesday, August 17, 2005 4 comments

Sunday, August 14, 2005


UTL_HTTP
Let's say you want to pull some real-time information off
the Internet and put it in your database. For example:
- Stock Market Quotes
- Temperature
- Sports scores

No need to write a separate application in Java or whatever,


you can do it all directly in Oracle.

Your solution will involve using one of the many handy


Oracle built-in utilities: UTL_HTTP.

For reference, flip open Chapter 78 of the 'Supplied PL/SQL

http://thinkoracle.blogspot.com/2005_08_01_archive.html (8 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

Packages and Types Reference'.

Tom Kyte also had a discussion in the Appendix of "Expert


One-on-One Oracle", and also on Ask Tom:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:285215954607

Let's look at a simple example, grabbing a market


quotation.

You can get the latest quotes from Yahoo Finance. Using
UTL_HTTP.REQUEST, you can get the content of that page,
and then search within for the data you want.

SELECT UTL_HTTP.REQUEST('http://finance.yahoo.com/q?
s=KMP') FROM DUAL;

If you're behind a firewall, include the IP or name of your


proxy server as the second parameter.

For simplicity, I'm not including the output here, but you
can see that we don't have our quote in there. That's
because we only got the first 2000 bytes of the web page.
If we want more, we need to use REQUEST_PIECES.

Down below I have included a working example. It's


roughly thrown together, but it does illustrate the point:
you can use UTL_HTTP to retrieve information from the
Internet that you can put in the database.

As an aside, talk to some lawyers to make sure the data


you are mining is not violating any copyrights.

After you write stored procedures to retrieve web pages,


and to extract information from within and insert them into
the database, you can automate the updates by calling the
stored procedures using DBMS_JOB (a topic for another
day!).

SET SERVEROUTPUT ON

DECLARE
l_pieces UTL_HTTP.HTML_PIECES;
-- We'll look at two 2000-byte pages at a time
l_two_pages VARCHAR2(4000);
l_start_read NUMBER;
l_end_read NUMBER;
l_quote VARCHAR2(12);
BEGIN
-- Grab up to a maxium of 32 2000-byte pages, and then
go through them,
-- looking at 2 pages at a time in case the data we are

http://thinkoracle.blogspot.com/2005_08_01_archive.html (9 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

looking for
-- overlaps a page boundary
l_pieces := UTL_HTTP.REQUEST_PIECES('http://finance.
yahoo.com/q?s=KMP', 32);
FOR i IN 1 .. l_pieces.COUNT LOOP
l_two_pages := l_two_pages || l_pieces(i);
-- Look for a string preceding the information we want
-- If we find it, add 52 (magic, Yahoo-specific number)
-- to find the point where the quote will begin
SELECT INSTR(l_two_pages, 'Last Trade', 1, 1) INTO
l_start_read FROM dual;
IF (l_start_read > 0) THEN
l_start_read := l_start_read + 52;
IF (l_start_read < 3950) THEN
SELECT INSTR(l_two_pages, '<', l_start_read, 1) INTO
l_end_read FROM dual;
IF (l_end_read > 0) THEN
IF ((l_end_read - l_start_read) < 12) THEN
SELECT SUBSTR(l_two_pages, l_start_read, l_end_read -
l_start_read) INTO l_quote FROM dual;
DBMS_OUTPUT.PUT_LINE(l_quote);
ELSE
DBMS_OUTPUT.PUT_LINE('Error (Quote more than 12
chars)');
END IF;
EXIT;
END IF;
END IF;
END IF;
l_two_pages := l_pieces(i);
END LOOP;
END;

// posted by Robert Vollman @ Sunday, August 14, 2005 4 comments

Wednesday, August 10, 2005


UNION ALL
You want to write a query that contains the rows from 2 or
more tables. What you want to use is one of Oracle's set
operators: UNION, INTERSECT, or MINUS. (Note: in the ANSI
SQL standard, MINUS is referred to as EXCEPT). My example
will deal with UNION.

You may have tables containing your employees,


contractors and clients, each with their own unique and
appropriate columns. For illustrative purposes, however,
let's consider only their names and phone numbers.

http://thinkoracle.blogspot.com/2005_08_01_archive.html (10 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

CREATE TABLE Employee (e_name VARCHAR2(32),


e_phonenumber VARCHAR2(16));
CREATE TABLE Contractor (c_name VARCHAR2(32),
c_phonenumber VARCHAR2(16), c_startcontract DATE,
c_endcontract DATE);
CREATE TABLE Client (c_name VARCHAR2(32),
c_phonenumber VARCHAR2(16));

Let's get some sample data:

INSERT INTO Employee VALUES ('Joe Smith', '555-555-


1234');
INSERT INTO Contractor VALUES ('Adam Johnson', '555-
555-8888', '01-Jan-04', '01-Mar-04');
INSERT INTO Contractor VALUES ('Bob Jackson', '555-555-
1111', '01-Jan-04', NULL);
INSERT INTO Contractor VALUES ('Adam Johnson', '555-
555-8888', '01-Jan-05', '01-Mar-05');
INSERT INTO Client VALUES ('Bill Taylor', '555-555-6767');
INSERT INTO Client VALUES ('Adam Johnson', '555-555-
8888');

What you would like to do is create a view to contain all the


phone numbers. You can use the UNION operator, which is
very easy. Write your queries however you wish, just make
sure that they all have the same number of columns and
similar data types.

SELECT e_name, e_phonenumber FROM Employee


UNION
SELECT c_name, c_phonenumber FROM Contractor
UNION
SELECT c_name, c_phonenumber FROM Client;

E_NAME E_PHONENUMBER
-------------------------------- ----------------
Adam Johnson 555-555-8888
Bill Taylor 555-555-6767
Bob Jackson 555-555-1111
Joe Smith 555-555-1234

Excellent!

But observe two things:


1. The order of the results have been re-arranged
2. There are no duplicates.

Actually, 1 and 2 are tied closely together. Oracle re-


arranges the results in order to put identical rows next to
each other and remove duplicates. On large tables, you

http://thinkoracle.blogspot.com/2005_08_01_archive.html (11 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

may get a bit of a performance hit.

If you don't care about removing duplicates, or especially if


you want the duplicates, use UNION ALL instead:

SELECT e_name, e_phonenumber FROM Employee


UNION ALL
SELECT c_name, c_phonenumber FROM Contractor
UNION ALL
SELECT c_name, c_phonenumber FROM Client;

E_NAME E_PHONENUMBER
-------------------------------- ----------------
Joe Smith 555-555-1234
Adam Johnson 555-555-8888
Bob Jackson 555-555-1111
Adam Johnson 555-555-8888
Bill Taylor 555-555-6767
Adam Johnson 555-555-8888

If you want them sorted, but don't want duplicates


removed, you can include an ORDER BY clause. Use UNION
with ORDER BY if you want duplicates removed and you
want a guaranteed order.

SELECT e_name, e_phonenumber FROM Employee


UNION ALL
SELECT c_name, c_phonenumber FROM Contractor
UNION ALL
SELECT c_name, c_phonenumber FROM Client
ORDER BY 1;

E_NAME E_PHONENUMBER
-------------------------------- ----------------
Adam Johnson 555-555-8888
Adam Johnson 555-555-8888
Adam Johnson 555-555-8888
Bill Taylor 555-555-6767
Bob Jackson 555-555-1111
Joe Smith 555-555-1234

If you just want to remove duplicates within tables, but not


in the merged set, try the DISTINCT clause.

SELECT DISTINCT e_name, e_phonenumber FROM Employee


UNION ALL
SELECT DISTINCT c_name, c_phonenumber FROM

http://thinkoracle.blogspot.com/2005_08_01_archive.html (12 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

Contractor
UNION ALL
SELECT DISTINCT c_name, c_phonenumber FROM Client;

E_NAME E_PHONENUMBER
-------------------------------- ----------------
Joe Smith 555-555-1234
Adam Johnson 555-555-8888
Bob Jackson 555-555-1111
Adam Johnson 555-555-8888
Bill Taylor 555-555-6767

I guess it all depends what you want.

Here is Dan Morgan's reference on Built-In Operators:


http://www.psoug.org/reference/ora_operators.html

But you also want to check out the Oracle SQL Reference,
Chapter 8: SQL Queries and Subqueries.

For your reading pleasure, check out this article by


Jonathan Gennick on set operators, including UNION:
http://five.pairlist.net/pipermail/oracle-
article/2003/000003.html

Administrative note: I've added a new section to include the


links to all the Oracle blogs I regularly visit, to save you
from going here:
http://thinkoracle.blogspot.com/2005/07/oracle-blogs.
html

// posted by Robert Vollman @ Wednesday, August 10, 2005 3 comments

Tuesday, August 09, 2005


OraBlogs!
Brian Duff maintains a blog that brings together all the
feeds from the various Oracle blogs that are out there.

http://www.orablogs.com/orablogs/

There are some fine blogs that are not included because
they do not support RSS 2.0 feed. Mine was one such case,
I used atom. Peter Scott and Doug Burns then pointed me
to Feedburner. It converts your feed from one format into
another.

http://thinkoracle.blogspot.com/2005_08_01_archive.html (13 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

http://www.feedburner.com/

Just go to their web site, type in the URL to your feed, and
then accept all the defaults. Just be sure that you have
these three settings (courtesy of Doug):

1) Do NOT select Smartfeed


2) Select Convert Format Burner
3) Select RSS 2.0 from the list of options.

If all goes well, this should be my first post on OraBlogs. It


would be great to kick things off with a great post but,
alas, I have nothing to post about today. Instead, just like a
bad 80s sitcom, I will do a "flashback highlight episode.
Here are my 5 favourite posts from my 3 months of
existence:

May 17th: NULL is not nothing


http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.
html

June 10th: NULLs in Oracle (kind of a "Part 2")


http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.
html

July 1st (Canada Day): Extra Columns in a Group By


http://thinkoracle.blogspot.com/2005/07/extra-columns-
in-group-by.html

July 26th: Use Constraints!


http://thinkoracle.blogspot.com/2005/07/use-constraints.
html

July 29th: Using Views and other techniques to solve a


particular problem
http://thinkoracle.blogspot.com/2005/07/oracle-by-
example.html

// posted by Robert Vollman @ Tuesday, August 09, 2005 0 comments

Monday, August 01, 2005


Import Export
I recently installed a new Oracle instance on my laptop. I
wanted to migrate my small development database
(complete with structure and data) from my main
workstation to my laptop.

It was very easy using the import (IMP) and export (EXP)

http://thinkoracle.blogspot.com/2005_08_01_archive.html (14 of 15)1/9/2008 2:49:41 AM


OracleBlog: August 2005

tools. They are described in Chapter 1 (Export) and Chapter


2 (Import) of the Oracle Utilities Guide, available here:

http://www.oracle.com/technology/documentation/index.
html

Everything you should need to know is in there. For good


measure, I read Chapter 8 of Tom Kyte's "Expert One-on-
One Oracle" on Import and Export.

Word of caution: Think twice before using IMP/EXP as your


back-up strategy on large, complex databases.

Both utilities are located in $ORACLE_HOME/bin directory.


You need to run the $ORACLE_HOME/rdbms/admin/catexp.
sql file. You can see the commands you need by using the
HELP=Y option at your command prompt

C:\> EXP HELP=Y

So for me, the process was as easy as this:

1. Export the data

C:\> EXP USERID=scott/tiger OWNER=scott FILE=scott.dmp

2. Copy the DMP file to the target machine

3. Import the data

C:\> IMP USERID=scott/tiger FILE=scott.dmp FULL=Y

Done! All the tables, triggers, procedures, view and


constraints, as well as all the data. While I was at it, I just
created a BAT file out of this and added it to the Task
Manager to back-up my data regularly. (Unix: SH file and
CRON).

As a final note, here is a good FQ, by Frank Naude:


http://www.orafaq.com/faqiexp.htm

// posted by Robert Vollman @ Monday, August 01, 2005 2 comments

http://thinkoracle.blogspot.com/2005_08_01_archive.html (15 of 15)1/9/2008 2:49:41 AM


OracleBlog: September 2005

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, September 30, 2005


PL/SQL Procedure Call Overhead
Is there much overhead in calling PL/SQL procedures?

I assume that if the answer is "yes," you'll want to avoid procedure calls,
which would likely mean making your procedures bigger (by combining
several into one). That makes me shudder because clean, modular code
is easier to read and maintain, not to mention making it easier to
develop new code if its based on reliable, tested code.

I assume there is at least some overhead to calling PL/SQL procedures. I


mean, if the procedure is not in the cache, you'll obviously have to go
the disk to fetch it.

If it's already in memory, there could still be some overhead in the


passing of parameters. UNLESS you can use the "NOCOPY" hint, that is.

http://thinkoracle.blogspot.com/2005/05/nocopy-hint.html

But to be honest, I don't know how much overhead any particular


procedure call will have. Sorry to those that read the title and hoped that
the content would contain the definitive answer. I might have something
more conclusive after doing some research. In the meantime, here is
what I do every time I have a question: I test it.

Even if I showed you a quote in a book that shows you how to calculate
the overhead, I would STILL advise testing it. Documents can be out-of-
date, misunderstood and just plain wrong. You need to test it.

http://thinkoracle.blogspot.com/2005_09_01_archive.html (1 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

Here is how to test it.

1. Write (or identify) a stored procedure that reflects your business


requirements.

CREATE OR REPLACE PROCEDURE DoIt


IS
BEGIN
NULL;
-- Do some stuff in here!
END DoIt;

2. Now split that stored procedure into two (or more) parts, and a master
proc

CREATE OR REPLACE PROCEDURE DoItPartOne


IS
BEGIN
NULL;
-- Do part of the stuff here...
END DoItPartOne;

...etc!

CREATE OR REPLACE PROCEDURE DoItInParts


IS
BEGIN
DoItPartOne;
-- DoItPartTwo;
-- etc...
END DoItInParts;

3. With stats on, call that first stored procedure that does everything,
and then run TKPROF to analyse it.

ALTER SESSION SET SQL_TRACE = TRUE;


EXEC DoIt;
ALTER SESSION SET SQL_TRACE = FALSE;

TKPROF robert_ora_3028.trc robert_ora_3028.prf explain='sys/********


as sysdba'

More on gathering and analysing simple performance statistics:


http://thinkoracle.blogspot.com/2005/09/analyzing-query-

http://thinkoracle.blogspot.com/2005_09_01_archive.html (2 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

performance.html

4. With stats on, call that second stored procedure.

ALTER SESSION SET SQL_TRACE = TRUE;


EXEC DoItInParts;
ALTER SESSION SET SQL_TRACE = FALSE;

You may find, as I did, that it is very hard to set up a test that reveals any
kind of noticeable performance overhead. But if the procedures were
spread out over the disk and not in the cache, or if there were lots and
lots of parameters, I bet we could see some overhead. But if your
procedure is called often enough for it to be important to you, the
procedures would probably be in the cache at any given time.

But don't spend too much time in conjecture, and even when I do
produce some facts, set up your tests anyway.

// posted by Robert Vollman @ Friday, September 30, 2005 4 comments

Thursday, September 22, 2005


Column Name as a Variable
Consider the situation where you are writing a stored procedure that
takes a column name as a variable, and then does some work based on a
query that uses that column name. How would you do it?

Let's consider a hypothetical situation. Say you have a table with all your
employees. Some of the columns are responsible for their pay.
Employees can get paid in different ways, for example: base salary,
hourly wage, bonus, dividend, etc. You have made each one of these a
separate column in the table. (Note: all these columns are of the same
type).

You have a number of stored procedures that access these tables. They
all share some things in common, so you have decided to make some
common "helper" procedures for all the "master" procedures to use.

Your "helper" procedure would have to take the column name from the
"master" procedure, and then perform the common queries and data
manipulations for that given column.

1. Dynamic SQL

http://thinkoracle.blogspot.com/2005_09_01_archive.html (3 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

One way of doing that is with dynamic SQL. Observe:

CREATE OR REPLACE PROCEDURE HelperProc (


in_col_name IN VARCHAR2,
out_val OUT NUMBER)
IS
BEGIN
EXECUTE IMMEDIATE 'SELECT MAX(' || in_col_name || ') FROM EMP' INTO
out_val;
END;

SET SERVEROUTPUT ON;

DECLARE
out_val NUMBER;
BEGIN
HelperProc('EMPNO', out_val);
DBMS_OUTPUT.PUT_LINE(out_val);
END;

It works very well:


- It's a single line, no matter how many possible columns are used
- You don't need to know the column names in advance
- You don't need to change it after a DDL change

However, there are drawbacks to Dynamic SQL. Among others, there is


extra parsing and (most seriously) vulnerabilities to SQL injection. I won't
go into more detail on Dynamic SQL, but I promise to blog on it soon.

2. Static SQL

The obvious recourse is to use something like IF or CASE or (my


favourite) DECODE.

CREATE OR REPLACE PROCEDURE HelperProc (


in_col_name IN VARCHAR2,
out_val OUT NUMBER)
IS
BEGIN
SELECT MAX(DECODE(in_col_name, 'EMPNO', EMPNO, 'MGR', MGR, 'SAL',
SAL, 'COMM', COMM, 'DEPTNO', DEPTNO, NULL))
INTO out_val
FROM EMP;
END;

http://thinkoracle.blogspot.com/2005_09_01_archive.html (4 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

Essentially this is like looking at the column name, and doing something
different depending on what it is. That's practically all you can do with
static SQL, by definition. This almost defeats the purpose of having a
common "helper" procedure, but there are still two reasons it would still
make sense:
1. Modularity (and abstraction) is generally a good thing
2. Any extra work done on out_val will justify the "helper" procedure.

3. Revised Data Model

There is an even more important consideration. Whenever you are


struggling to do something clever, take a step back and consider your
data model. It could be ill-suited for your needs.

In this case, what could we do?

We could break this information into separate tables. For example:


EmpBaseSalary, EmpHoury, EmpBonus, etc. Then we could join them to
the Emp table by employee id. Of course, that just makes the table name
variable instead of the column, so that doesn't really help us, so instead:

We could elongate the employee table, making something like this:

ID;...;SALARY;HOURLY;BONUS;DIVIDEND
1;...;60;NULL;NULL;NULL
2;...;100;NULL;NULL;20

into a separate table mapped by ID:

ID;VALUE;TYPE
1;60;'SALARY'
2;100;'SALARY'
2;20;'DIVIDEND'

That would effectively move the "column name" into the WHERE clause.
That would certainly make the task easier. That is sort of a "reverse
pivot."

Also, that opens the door to add extra columns for effective start and
end dates. We could even do this with views if we wanted to leave the
data model alone.

http://thinkoracle.blogspot.com/2005/07/use-views.html
http://thinkoracle.blogspot.com/2005/09/pivot-and-crosstab-queries.

http://thinkoracle.blogspot.com/2005_09_01_archive.html (5 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

html

That is just one example, but it shows how you need to take a step back
and consider the real-world application.

Here is a link to the Dizwell discussion forum where we discussed this,


and where most of this came from:
http://www.phpbbserver.com/phpbb/viewtopic.php?
t=450&mforum=dizwellforum

// posted by Robert Vollman @ Thursday, September 22, 2005 3 comments

Tuesday, September 20, 2005


Wanted: Your Unwanted Oracle/DB Books
Please excuse the spammy post today. But I would like to ask anyone
who is reading this who may have unwanted Oracle (8 and up) or General
DB (College) books to contact me (email address is in my profile).

Rather than gather dust on your shelf, I can give them a good home. I
will pay for shipping costs to Canada, and you will have my heartfelt
appreciation.

Many thanks!

// posted by Robert Vollman @ Tuesday, September 20, 2005 3 comments

Monday, September 19, 2005


PL/SQL Code Storage: Files vs In-DB Packages
I read this interesting exchange on Steven Feuerstein's Q&A:

http://htmldb.oracle.com/pls/otn/f?p=2853:4:1727923121986559057::
NO::P4_QA_ID:246

Essentially the question is where to stored your PL/SQL stored


procedures. H. Sheehan, Gary Myers, William Robertson, Pete Scott, Scott
Swank, A. Nadrian and I discussed this on the Dizwell Forum.

http://www.phpbbserver.com/phpbb/viewtopic.php?
t=458&mforum=dizwellforum

http://thinkoracle.blogspot.com/2005_09_01_archive.html (6 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

To sum up their positions:

Option 1: In organized, packaged files on your DB server


- Fewer security holes
- Handles failover situations better
- Easier to use version-control system
- Available for a greater number of nice PL/SQL editors
- Harder to inadvertantly overwrite source code, leads to greater
confidence

Option 2: In-the-db packages


- Greater efficiency (pre-loaded)
- Greater code integrity (shows invalidation)
- Search code in USER_SOURCE table
- Use some PL/SQL tools easier
(Note: there are IDEs that integrate with source control and compile
directly into the database)

It seems like the leading camp is Option 2. The advantages of having


your packages pre-loaded into the database are just so significant,
especially since you should be able to find an IDE that integrates directly
with source control and can compile directly into the database. Scott
Swank provided this suggestion:

http://www.oracle.com/technology/products/jdev/101/
howtos/extools/subversion.html

One general consensus, however, is this:


- Code should be contained in packages
- These packages should be wrapped.

// posted by Robert Vollman @ Monday, September 19, 2005 2 comments

Wednesday, September 14, 2005


Analyzing Query Performance
Alternate title: Keeping Tables Small, Revisited

In an earlier article I spoke about how removing old data can help speed
up table scans:

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html

http://thinkoracle.blogspot.com/2005_09_01_archive.html (7 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

During a test in that article, I seemed to detect that querying a view


composed of the 90/10 split of a large table was much faster than
querying that table directly.

I was only trying to demonstrate that it wouldn't be much slower, I did


not expect for it to be faster. I didn't pursue it at the time, but
reproduced those results in 2 separate tests later on.

Incidentally, David Aldridge, who inspired my original article, has a


theory on this:
http://oraclesponge.blogspot.com/2005/08/more-on-partition-not-
quite-pruning.html

So the greater question was:


"How do you determine why a query is faster (or slower) than you
expected?"

The first step is to use SQL Trace and TKProf:


http://download-west.oracle.com/
docs/cd/B10501_01/server.920/a96533/sqltrace.htm#1018

Note: there are MANY sources of information on this. Apart from the
Oracle documentation, I also used articled by Tom Kyte, as well as his
book "Expert One-on-One Oracle."

Here was my test.

1. Set some variables:

ALTER SESSION SET TIMED_STATISTICS=true;


ALTER SYSTEM SET MAX_DUMP_FILE_SIZE=1000;
ALTER SYSTEM SET USER_DUMP_DEST="C:/temp/trace";

2. Create the ReallyBigTable

CREATE TABLE ReallyBigTable AS SELECT * FROM ALL_OBJECTS;

3. Turn on tracing

ALTER SESSION SET SQL_TRACE = TRUE;

4. Run the query

SELECT SUM(object_id) FROM ReallyBigTable

http://thinkoracle.blogspot.com/2005_09_01_archive.html (8 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

WHERE object_id * 2 NOT IN


(SELECT object_id FROM ReallyBigTable);

Note: 00:44:50.07

5. Turn off tracing

ALTER SESSION SET SQL_TRACE = FALSE;

6. Run TKPROF (separate window)

TKPROF robert_ora_3236.trc robert_ora_3236.prf explain='sys/********


as sysdba'
- Save that file somewhere (it will be overwritten later)

7. Create Archive and Active tables.

CREATE TABLE ReallyBigTable_Archive AS SELECT * FROM ReallyBigTable


WHERE object_id < 40000;

CREATE TABLE ReallyBigTable_Active AS SELECT * FROM ReallyBigTable


WHERE object_id >= 40000;

8. Drop ReallyBigTable

DROP TABLE ReallyBigTable;

9. Create the view

CREATE VIEW ReallyBigTable AS


SELECT * FROM ReallyBigTable_Archive
UNION ALL
SELECT * FROM ReallyBigTable_Active;

10. Turn on Tracing

ALTER SESSION SET SQL_TRACE = TRUE;

11. Run the query again

SELECT SUM(object_id) FROM ReallyBigTable


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable);

Elapsed: 00:45:21.04

http://thinkoracle.blogspot.com/2005_09_01_archive.html (9 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

12. Turn off tracing

ALTER SESSION SET SQL_TRACE = FALSE;

13. Run TKPROF (separate window)

TKPROF robert_ora_3236.trc robert_ora_3236.prf explain='sys/********


as sysdba'

Conclusion:

I repeated the test 3 times with tracing on, and each time I could not
reproduce the results. I saw virtually no difference in time elapsed
between querying a big table, and querying a big table

So I guess we're left in the dark as to why querying the view was so much
faster during my earlier tests. Perhaps we can apply Occam's Razor and
the safest conclusion was simply that I goofed.

Either way, it made for an interesting article of how to generate


performance data and query plans. I will leave you with an excerpt from
the TKPROF output:

SELECT SUM(object_id) FROM ReallyBigTable


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable)
call count cpu elapsed disk query
------- ------ -------- ---------- ---------- ----------
Parse 1 0.01 0.00 0 0
Execute 1 0.00 0.00 0 0
Fetch 2 612.03 2690.60 16168915 17030020
------- ------ -------- ---------- ---------- ----------
total 4 612.04 2690.60 16168915 17030020
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: SYS
Rows Row Source Operation
------- ---------------------------------------------------
1 SORT AGGREGATE
20495 FILTER
40764 TABLE ACCESS FULL REALLYBIGTABLE
20269 TABLE ACCESS FULL REALLYBIGTABLE
Rows Execution Plan
------- ---------------------------------------------------

http://thinkoracle.blogspot.com/2005_09_01_archive.html (10 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

0 SELECT STATEMENT GOAL: CHOOSE


1 SORT (AGGREGATE)
20495 FILTER
40764 TABLE ACCESS (FULL) OF 'REALLYBIGTABLE'
20269 TABLE ACCESS (FULL) OF 'REALLYBIGTABLE'

// posted by Robert Vollman @ Wednesday, September 14, 2005 2 comments

Monday, September 12, 2005


20 Oracle Lessons
I started using Oracle with version 8 in 1999. After a few years I changed
companies to a Sybase/SQL-Server shop. But the past year has found me
back working with Oracle, this time version 8, and 9.

It has been an interesting time getting myself back into "game shape"
with Oracle, and digging into version 9. If you've been reading this blog,
you've been able to follow along with me in my adventures.

I decided this was as good a time as any to pause and reflect on some of
the lessons I've learned in this past year.

Oracle:
1. Oracle is very complex.
I always thought "a database is a database" but Oracle is about 4 times
as complex as Sybase/MS-SQL.

2. Fortunately Oracle is well-documented.


I have fallen in love with Oracle documentation. Clear, well-written,
comprehensive and lots of examples.

http://thinkoracle.blogspot.com/2005/07/oracle-docs.html

3. There are many on-line Oracle sites and forums to find help.
The primary benefit of a popular product is that whatever your mistake
is, you're probably not the first person to experience it. There is a huge
on-line Oracle community, and so many places to search for help. My
favourite links and blogs are kept current on this site.

Testing:
4. It's quick, free and very easy to set up a personal Oracle database on
your Windows PC for testing purposes.

http://thinkoracle.blogspot.com/2005_09_01_archive.html (11 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

5. Build proper test cases, and test everything you read before your
implement.
This is part of my personal style that I apply to all my work, regardless of
technology. But I feel it is especially true of a database as complex as
Oracle. Especially with all the different versions out there.

6. Burleson Consulting makes a lot of mistakes.


So test those even more carefully. But remember, even the stellar Tom
Kyte makes mistakes.

http://thinkoracle.blogspot.com/2005/06/expert-one-on-one.html

Coding/Modelling Practises:
7. Document your code.
It makes it easier to reuse good code, and fix bad code. Again, this is my
personal style that I apply to all project, regardless of technology. Do the
best I can, and explain what I'm doing.

8. Specify column/parameter names when writing queries or making


stored procedure calls.

http://thinkoracle.blogspot.com/2005/07/specifying-insert-columns.
html

9. NULLs are very special


This is one of my favourite topics. Casual database programmers might
not be aware of all the special cases related to NULLs, making them a
common cause of honest (but costly) mistakes.

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html
http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html
http://thinkoracle.blogspot.com/2005/09/nulls-in-count.html

10. Data integrity is best accomplished in the database layer (as opposed
to procedure or application layers).
Why use a sophisticated database like Oracle if you're just going to use it
as a data store? Use Oracle's ability to protect your data's integrity, and
then you can fear badly written applications a little bit less.

11. Triggers can be used as a form of "advanced constraint" for data


integrity.

http://thinkoracle.blogspot.com/2005/07/use-constraints.html

http://thinkoracle.blogspot.com/2005_09_01_archive.html (12 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

12. Views are very useful in solving complex queries without affecting
your data model (among many other uses!)

http://thinkoracle.blogspot.com/2005/07/use-views.html

13. A great way to improve performance is to archive/partition data.

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html

14. You can often achieve common table types and procedure
parameters by defining user types, using %TYPE and referencing foreign
keys. Otherwise, use an advanced SQL modeller to develop your PL/SQL.

http://thinkoracle.blogspot.com/2005/06/common-table-column-types.
html

15. Choose carefully between using natural and synthetic keys when
designing your tables.

http://thinkoracle.blogspot.com/2005/06/natural-vs-synthetic-keys.
html

Useful Oracle (other than REGEXP, in Version 10):

16. DECODE is incredibly useful (CASE WHEN can also be used).


I am a huge fan of DECODE, I can't imagine working without it. It is
perhaps poorly named.

http://thinkoracle.blogspot.com/2005/06/decode.html

17. CONNECT BY is useful when you need hierarchical, string


aggregation (stragg).

http://thinkoracle.blogspot.com/2005/06/connect-by.html

18. GROUP BY has a lot of relatives to help write queries for complex
analytic functions: RANK, GROUPING SETS, GROUPING_ID, ROLLUP

http://thinkoracle.blogspot.com/2005/08/compute.html

19. PL/SQL supports OOP (Object-Oriented Programming)

http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html

http://thinkoracle.blogspot.com/2005_09_01_archive.html (13 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

20. Oracle has a lot of handy toolkits


For example UTL_HTTP can be used to achieve very simple screen-
scraping (among other things)

http://thinkoracle.blogspot.com/2005/08/utlhttp.html

One more thing that didn't make the list (because it would push the total
from an even 20 to an odd 21):
When you're having trouble writing a very clever query or procedure, take
a step back and look at your data model. It might be inappropriate for
how you're using it.

Thanks for joining me on this stroll down memory lane!

// posted by Robert Vollman @ Monday, September 12, 2005 4 comments

Friday, September 09, 2005


NULLs in COUNT
Quick, easy one, but it trips up beginners. Something of which to be
mindful. Observe:

SELECT COUNT (*) FROM EMP;


COUNT(*)
----------
14
SELECT COUNT (COMM) FROM EMP;
COUNT(COMM)
-----------
4

Note: 4 instead of 14. But if we do this:

SELECT COMM FROM EMP;

COMM
----------
300
500
1400
0

http://thinkoracle.blogspot.com/2005_09_01_archive.html (14 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

14 rows selected.

We get all 14.

This is expected behaviour. From the Oracle SQL Reference: "If you
specify 'expr' then COUNT returns the number of rows where 'expr' is not
null."

http://download-west.oracle.com/docs/cd/B10501_01/server.920/
a96540.pdf

COUNT can take virtually any parameter, including 1, *, or a column. But


be aware that if you're counting a particular column, NULLs won't be
counted.

Additional reading material:

Everyone knows NULL is one of my favourite topics:


http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html
http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html

Eddie Awad on the difference between COUNT(*) and COUNT(1)


http://awads.net/wp/2005/07/06/count-vs-count1/
(Note: see the links in the comments for more information)

// posted by Robert Vollman @ Friday, September 09, 2005 2 comments

Thursday, September 01, 2005


Pivot and Crosstab Queries
Here is another advanced concept that will come in useful when solving
Oracle problems.

Imagine you're trying to create a result set where the rows need to be
columns, or vice versa. In essence, you need to "pivot" rows into
columns, or vice versa. That is a very common requirement, and this is
where you need to look at a pivot (or crosstab) query to get the job done.

As always, when you want to understand something, you can start by


Asking Tom:
http://asktom.oracle.com/pls/ask/f?

http://thinkoracle.blogspot.com/2005_09_01_archive.html (15 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

p=4950:8:16663421538065257584::NO::
F4950_P8_DISPLAYID,F4950_P8_CRITERIA:766825833740

A simple pivot query is accomplished by basically doing the following:


1. Add some kind of count or row number to your query, if necessary for
the grouping
2. Then use your (revised) original query as a sub-query
3. Use "decode" to turn rows into columns (ie. a "sparse" matrix).
4. Use "max" to "squash" the multiple rows you moved to columns, into
single rows. Don't forget to group by.
(Note: it gets more complicated if you don't know how many columns
you'll need).

Here is another one of Ask Tom's example. It clearly shows how you use
decode to create a "sparse" matrix, and then use max to "squash" it
down.
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:124812348063

Let's look a simple example in slow motion.

Here's the data


CREATE TABLE CFL (season NUMBER(4), team VARCHAR2(16), points
NUMBER(3));
INSERT INTO CFL (season, team, points) VALUES (2004, 'Argonauts', 21);
INSERT INTO CFL (season, team, points) VALUES (2004, 'Alouettes', 28);
INSERT INTO CFL (season, team, points) VALUES (2004, 'Tiger-Cats', 19);
INSERT INTO CFL (season, team, points) VALUES (2004, 'Renegades', 10);
INSERT INTO CFL (season, team, points) VALUES (2003, 'Argonauts', 18);
INSERT INTO CFL (season, team, points) VALUES (2003, 'Alouettes', 26);
INSERT INTO CFL (season, team, points) VALUES (2003, 'Tiger-Cats', 2);
INSERT INTO CFL (season, team, points) VALUES (2003, 'Renegades', 14);
INSERT INTO CFL (season, team, points) VALUES (2002, 'Argonauts', 16);
INSERT INTO CFL (season, team, points) VALUES (2002, 'Alouettes', 27);
INSERT INTO CFL (season, team, points) VALUES (2002, 'Tiger-Cats', 15);
INSERT INTO CFL (season, team, points) VALUES (2002, 'Renegades', 10);

What we want:
A table showing each of these 4 teams and their point tables for these 3
seasons.

So what is our pivot row/column? Season.

Step 1/2: We are using season, so we don't need to create our own

http://thinkoracle.blogspot.com/2005_09_01_archive.html (16 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

grouping field, like count, rownum, or running total (sum) for example.
That would be easy enough to do, but let's keep this simple.

Step 3: Use "decode" to turn the season row into a column. Take a look
at our "sparse" matrix.

SELECT team,
DECODE (season, 2002, points, NULL) Yr2002,
DECODE (season, 2003, points, NULL) Yr2003,
DECODE (season, 2004, points, NULL) Yr2004
FROM (SELECT season, team, points FROM CFL);

TEAM YR2002 YR2003 YR2004


---------------- ---------- ---------- ----------
Argonauts 21
Alouettes 28
Tiger-Cats 19
Renegades 10
Argonauts 18
Alouettes 26
Tiger-Cats 2
Renegades 14
Argonauts 16
Alouettes 27
Tiger-Cats 15
Renegades 10

Step 4: Now let's use max to "squash" this into single rows. Don't forget
GROUP BY.

SELECT team,
MAX (DECODE (season, 2002, points, NULL)) Yr2002,
MAX (DECODE (season, 2003, points, NULL)) Yr2003,
MAX (DECODE (season, 2004, points, NULL)) Yr2004
FROM (SELECT season, team, points FROM CFL)
GROUP BY team;

TEAM YR2002 YR2003 YR2004


---------------- ---------- ---------- ----------
Alouettes 27 26 28
Argonauts 16 18 21
Renegades 10 14 10

http://thinkoracle.blogspot.com/2005_09_01_archive.html (17 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

Tiger-Cats 15 2 19

Pretty cool, eh? Easy, too.

Notice that the key to this is DECODE. If DECODE is not already part of
your toolbelt, I recommend studying up.

http://thinkoracle.blogspot.com/2005/06/decode.html

Ready for a tougher example? Let's look at another Ask Tom:


http://asktom.oracle.com/pls/ask/f?
p=4950:8:16663421538065257584::NO::
F4950_P8_DISPLAYID,F4950_P8_CRITERIA:7086279412131

For further study of pivot queries and analytic functions in general, there
is an awesome write-up in Chapter 12 of Tom Kyte's "Expert One-on-
One Oracle." You'd think I'd get a kickback from Tom Kyte with all the
promotion I'm doing, but the honest truth is that no one explains it as
well as he.

So, do you understand pivot queries now? No problems?

If so, now you're ready for one of Ask Tom's more complex examples:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:6923393629227

Pivot Tables

One final word: don't confuse pivot queries with pivot tables. Pivot tables
are a different concept, and have different uses (most typically to fill in
missing data). Until I blog about pivot tables, check out these two links:

Jonathan Gennick
http://www.oracle.com/technology/oramag/oracle/02-sep/o52sql.html

Laurent Schneider
http://laurentschneider.blogspot.com/2005/08/pivot-table.html

// posted by Robert Vollman @ Thursday, September 01, 2005 13 comments

http://thinkoracle.blogspot.com/2005_09_01_archive.html (18 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

Oracle WTF
Another great way to learn Oracle is to study mistakes.

Generally people have (misguided) reasons behind their mistakes, and


studying them can improve your understanding of Oracle. As such I'd
like you to check out a new blog out there dedicated to the most
spectacular misunderstandings of Oracle:

http://oracle-wtf.blogspot.com/

It's written by William Robertson, James Padfield, Thai Rices, Adrian


Billington and inspired by http://thedailywtf.com.

Another advantage of this blog, as compared to the 20-plus (and


growing) other Oracle blogs out there, is you a more likely to get a laugh
out of it. Or at least a good cry.

For those of you who enjoy the Dizwell Forum, I have gotten into the
habit of posting the occasional WTF there myself:

http://www.phpbbserver.com/phpbb/viewtopic.php?
t=310&mforum=dizwellforum
http://www.phpbbserver.com/phpbb/viewtopic.php?
t=383&mforum=dizwellforum
http://www.phpbbserver.com/phpbb/viewtopic.php?
t=417&mforum=dizwellforum

By the way, "WTF" stands for "What the F." As in "What the F was the
developer thinking?" :)

// posted by Robert Vollman @ Thursday, September 01, 2005 2 comments

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

http://thinkoracle.blogspot.com/2005_09_01_archive.html (19 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers

http://thinkoracle.blogspot.com/2005_09_01_archive.html (20 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

❍ Oracle Master Laurent Schneider


❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007

http://thinkoracle.blogspot.com/2005_09_01_archive.html (21 of 22)1/9/2008 2:49:46 AM


OracleBlog: September 2005

❍ May 2007
❍ June 2007
❍ October 2007

❍ Current Posts

http://thinkoracle.blogspot.com/2005_09_01_archive.html (22 of 22)1/9/2008 2:49:46 AM


OracleBlog: October 2005

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated,
but it is the most powerful tool when it comes to data. That's why when I think data, I think Oracle. I
also enjoy writing, so I use this format to organise my thoughts. Please feel free to discuss any
thoughts you may have on the same topics, even old ones (I will see and respond to such
comments). You may want to start with "LIST ALL ARTICLES" under Archives.

Monday, October 31, 2005


Oracle Packages
What is a "package"?

According to the PL/SQL User's Guide and Reference, "A package is a schema object
that groups logically related PL/SQL types, items and subprograms."

But I believe a package is far more than just a way of logically grouping objects
together.

Before I digress, let's very briefly understand what a package is. It's probably easiest
if you take a look at Oracle's documentation, which has a good description of
packages and some examples:

PL/SQL User's Guide and Reference, Chapter 9: PL/SQL Packages:


http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624.pdf

Put simply, packages have two parts, the specification and the body.

The specification is the interface into the package. It describes all the types,
variables, procedures (etc) within the package. Ideally the specification does not
change.

The body has all the implementation. Inside the body you would actually write the
procedures, assign the values, and have all the details and logic behind the package.
Often (unless you are the developer), you can treat the body as a "black box."

As always, I'll refer you to Dan Morgan to understand the syntax of Oracle PL/SQL
Packages:
http://www.psoug.org/reference/packages.html

Back to the story.

According to one of my favourite PL/SQL Authors Connor McDonald, "The main


reason packages are not more widely adopted is that users are unaware of the

http://thinkoracle.blogspot.com/2005_10_01_archive.html (1 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

benefits they offer."

Beyond the known, obvious advantage of grouping together related items, which is
great for organising your code and "modularity", what are these benefits of which we
are speaking?

1. Objects don't get invalidated when you makes changes to the body. That saves a
lot of recompilation and makes changing the implementation much more painless.
You will still have to recompile if you change the specification, but that's not
something you should be doing very often.

2. You can "overload" subprograms (procedures/functions). You can have several


subprograms with the same name, but with a different number of parameters, or
different types. That is another thing that makes implementation changes more
painless because you can keep legacy code if you like. You can also see the extra
flexibility that offers developers.

3. You can have persistent variables throughout a session without storing anything in
a database table. Packages can have variables and constants that are initialised when
the packages is first used within a session, and then they are available for the
remainder of the session for all future references to anything within that package.
That comes in very handy.

4. Speaking of initialisation, being able to call a procedure automatically the first


time a package is used within a session can also come in very handy.

5. You can take advantage of "encapsulation." In essence, you can hide the
implementation details from users but still give them all the information they need to
use the package. Since they aren't aware of the details, that means you can change
them with minimal impact or risk. Packages also support private subprograms and
variables which are available only to other subprograms within the package, and
remain completely hidden and inaccessible to anything outside the package.

6. You may notice some performance improvement when using packages. When you
first use a package, the entire package may be loaded into memory, meaning fewer
disk I/Os as you use the related items within.

I'm sure there are other advantages, but those are the ones I've noticed.

Let me close with links to my favourite two articles about Packages, from two of my
favourite PL/SQL experts:
Connor McDonald's Chapter 2 from Mastering Oracle PL/SQL: Practical Solutions
http://www.oracle.com/technology/books/pdfs/sample2174ch2.pdf

Steven Feuerstein's article "Picking Your Packages" from May/June 2005 Oracle
Magazine
http://www.oracle.com/technology/oramag/oracle/05-may/o35plsql.html

---
Addition:

http://thinkoracle.blogspot.com/2005_10_01_archive.html (2 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

By the way, to use packages, just prefix the package name using dot notation

Check out PL/SQL Supplied Packages and Types Reference


http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612.pdf

It includes UTL_HTTP and DBMS_OUTPUT


http://thinkoracle.blogspot.com/2005/08/utlhttp.html
http://thinkoracle.blogspot.com/2005/10/dbmsoutputputline.html

But also check out UTL_FILE, DBMS_PIPE, DBMS_ALERT and the DBMS_XML stuff.

// posted by Robert Vollman @ Monday, October 31, 2005 3 comments

Wednesday, October 12, 2005


DBMS_OUTPUT.PUT_LINE
DBMS_OUTPUT.PUT_LINE allows you to write information to a buffer throughout the
execution of a trigger/procedure. That information is available to be read by a
trigger/procedure (using GET_LINE(S)), or dumped to SQL*Plus upon completion of
execution.

One of the most common misconceptions is that PUT_LINE writes data immediately to
SQL*Plus. That is not true. PUT_LINE only puts it in the buffer. You will not see it
before the block has executed. I can prove that with this example (note: you must
load the user_lock package for this):

scott@Robert> BEGIN
2 DBMS_OUTPUT.PUT_LINE('Going to sleep for 10 seconds...');
3 USER_LOCK.SLEEP(1000);
4 DBMS_OUTPUT.PUT_LINE('Woke up after 10 seconds.');
5 END;
6/
Going to sleep for 10 seconds...
Woke up after 10 seconds.

You will have seen both messages come out after 10 seconds as opposed to one
before and one after.

Despite the fact that it doesn't write messages throughout its progress, PUT_LINE can
still make a useful debugging tool. I like the way that the messages can be kept but
easily disabled by using DBMS_OUTPUT.DISABLE. Any PUT_LINE messages are silently
ignored if you have DISABLEd DBMS_OUTPUT (or failed to ENABLE).

To see the messages, you need to call DBMS_OUTPUT.ENABLE. The only parameter is
buffer_size, which, if NULL, will default to 20000. The buffer size can be anywhere
from 2000 to 1000000.

scott@Robert> BEGIN
2 DBMS_OUTPUT.DISABLE;

http://thinkoracle.blogspot.com/2005_10_01_archive.html (3 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

3 DBMS_OUTPUT.PUT_LINE('Disabled');
4 DBMS_OUTPUT.ENABLE;
5 DBMS_OUTPUT.PUT_LINE('Enabled');
6 END;
7/
Enabled

PL/SQL procedure successfully completed.

Incidentally, SQL*Plus's SET SERVEROUTPUT ON will call DBMS_OUTPUT.ENABLE. You


can even use SIZE with that command. SET SERVEROUTPUT also includes formatting
options, such as FORMAT WRAPPED, WORD_WRAPPED and TRUNCATE (along with a
SET LINESIZE) to get the output the way you want it. [EDIT: Fixed Typo]

There are two common errors related to DBMS_OUTPUT.PUT_LINE. The first one is
trying to put more than 255 characters per line.

scott@Robert> DECLARE
2 l_string VARCHAR2(300);
3 BEGIN
4 l_string := '1234567890';
5 l_string := l_string || l_string || l_string || l_string || l_string;
6 l_string := l_string || l_string || l_string || l_string || l_string || l_string;
7 DBMS_OUTPUT.PUT_LINE(l_string);
8 END;
9/
DECLARE
*
ERROR at line 1:
ORA-20000: ORU-10028: line length overflow, limit of 255 chars per line
ORA-06512: at "SYS.DBMS_OUTPUT", line 35
ORA-06512: at "SYS.DBMS_OUTPUT", line 133
ORA-06512: at line 7

The solution here is to use DBMS_OUTPUT.NEW_LINE to split it up into lines. 255 is a


hard limit, if you really want to print a line with more than that, you can write your
own package that does the same thing as DBMS_OUTPUT. That is actually a very
common thing to do. Tom Kyte's has a handy one in Appendix A of "Expert One-on-
One Oracle."

The second common error is overfilling your buffer.

scott@Robert> BEGIN
2 DBMS_OUTPUT.ENABLE(2000);
3 FOR i IN 1..1000 LOOP
4 DBMS_OUTPUT.PUT_LINE('This is line ' || i);
5 END LOOP;
6 END;
7/
This is line 1

http://thinkoracle.blogspot.com/2005_10_01_archive.html (4 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

This is line 105


BEGIN
*
ERROR at line 1:
ORA-20000: ORU-10027: buffer overflow, limit of 2000 bytes
ORA-06512: at "SYS.DBMS_OUTPUT", line 35
ORA-06512: at "SYS.DBMS_OUTPUT", line 198
ORA-06512: at "SYS.DBMS_OUTPUT", line 139
ORA-06512: at line 4

The solution here is increase the size of your buffer, using ENABLE. The maximum
size is 1000000 and that is a hard limit. Once again, you can write your own package
as a workaround.

This example also illustrated that even if you have an exception, the contents of the
buffer until that point is still available.

The alternative to writing your own package is to write your messages to a table.
Then you can query the table at any time to see your debug messages. DBMS_PIPE is
another option to consider.

I will close with two more interesting "gotchas" for DBMS_OUTPUT.PUT_LINE.

scott@Robert> BEGIN
2 DBMS_OUTPUT.PUT_LINE(' What happened to my leading spaces?');
3 END;
4 /
What happened to my leading spaces?

This is an SQL*Plus Gotcha. Just be sure to use FORMAT WRAPPED, like so:

scott@Robert> SET SERVEROUTPUT ON FORMAT WRAPPED


scott@Robert> BEGIN
2 DBMS_OUTPUT.PUT_LINE(' There they are!');
3 END;
4 /
There they are!

Here is the second gotcha.

scott@Robert> DECLARE
2 l_bool BOOLEAN;
3 BEGIN
4 l_bool := TRUE;
5 DBMS_OUTPUT.PUT_LINE(l_bool);

http://thinkoracle.blogspot.com/2005_10_01_archive.html (5 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

6 END;
7/
DBMS_OUTPUT.PUT_LINE(l_bool);
*
ERROR at line 5:
ORA-06550: line 5, column 1:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
ORA-06550: line 5, column 1:
PL/SQL: Statement ignored

DBMS_OUTPUT.PUT_LINE is not overloaded for Booleans. The solution is to either to


write your own package (as mentioned above), or convert from Boolean type to
something else for the PUT_LINE call.

For more information, this package is described in (among other places) Oracle's
Supplied PL/SQL Packages Reference Guide, Chapter 43:
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612.pdf

And here is Dan Morgan's Quick Reference:


http://www.psoug.org/reference/dbms_output.html

// posted by Robert Vollman @ Wednesday, October 12, 2005 6 comments

Thursday, October 06, 2005


ROWNUM and ROWID
Questions:
How do I limit the number of rows returned by a query?
How do I write a query to get the Top-N salaries from the employee table?
How can I add unique, sequential numbers to an existing table?
How can I differentiate between two completely identical rows?
How can I find a faster way to retrieve a queried row?
How can I find the last row processed in a big batch?

There is one thing all these questions have in common: the answer involves either
ROWNUM or ROWID.

So what is ROWNUM and ROWID?

First of all, both are covered in the SQL Reference, Basic Elements of Oracle SQL,
Chapter 2:
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540.pdf

They are also both referred to as pseudo-columns. That is, they are not "real"
columns that will show up when you DESC a table. They don't actually exist anywhere
in the database. But they're available for you to use.

In fact, ROWNUM only exists for a row once it is retrieved from a query. It represents
the sequential order in which Oracle has retrieved the row. Therefore it will always

http://thinkoracle.blogspot.com/2005_10_01_archive.html (6 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

exist, be at least 1, and be unique (among the rows returned by the query). Obviously
it will change from query-to-query. Let's look at a quick example:

scott@Robert> SELECT ROWNUM, ENAME, SAL


2 FROM EMP;
ROWNUM ENAME SAL
---------- ---------- ----------
1 SMITH 800
2 ALLEN 1600
3 WARD 1250
4 JONES 2975
5 MARTIN 1250
6 BLAKE 2850
7 CLARK 2450
8 SCOTT 3000
9 VOLLMAN 5000
10 TURNER 1500
11 ADAMS 1100
12 JAMES 950
13 FORD 3000
14 MILLER 1300

Ok so let's say we want the 5 highest paid employees. Should be easy:

scott@Robert> SELECT ROWNUM, ENAME, SAL


2 FROM EMP
3 WHERE ROWNUM < 6
4 ORDER BY SAL DESC;
ROWNUM ENAME SAL
---------- ---------- ----------
4 JONES 2975
2 ALLEN 1600
3 WARD 1250
5 MARTIN 1250
1 SMITH 800

Whoops! Turns out ROWNUM is assigned before results are ordered, not after.
Knowing that, we can write it like this:

scott@Robert> SELECT ENAME, SAL


2 FROM (SELECT ENAME, SAL FROM EMP ORDER BY SAL DESC) E
3 WHERE ROWNUM < 6;
ENAME SAL
---------- ----------
VOLLMAN 5000

http://thinkoracle.blogspot.com/2005_10_01_archive.html (7 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

SCOTT 3000
FORD 3000
JONES 2975
BLAKE 2850

What about ROWID? ROWID actually represents the physical location of the record/
row in the database. That being the case, it is (according to Oracle documentation)
the fastest way to retrieve a particular row. Faster than an index, even.

Can you use ROWID to differentiate between duplicate rows?


Yes, you can. Since it actually represents the physical location of a row, no two rows
within the same table will have the same ROWID. Notice the caveat I added: within the
same table. If you're using clustering, two records from different tables could
theoretically share the same ROWID.

Do ROWIDs change?
Yes, especially with index organized or partitioned tables. Because ROWIDs represent
the physical location of a record/row, the ROWID will change every time the record is
physically moved.

Can you use ROWID as a primary key?


No, that's not advisable. While the ROWID will be unique, you would ideally want to
use a primary key that doesn't change.

How do you use ROWID to figure out what was the last record that was processed?
Using DBMS_SQL.LAST_ROW_ID to get the ROWID of the last row processed.

You'll see ROWNUM and ROWID pop up occasionally within solutions to problems on
AskTom and various Discussion Forums, so I recommend adding it to your own
toolbelt as well.

// posted by Robert Vollman @ Thursday, October 06, 2005 16 comments

Tuesday, October 04, 2005


Using DECODE to exploit COUNT/NULL feature
Not long ago, I mentioned that if you do a COUNT on a column (as opposed to on *
or a constant), the result will not include rows that have a NULL value for that column.

http://thinkoracle.blogspot.com/2005/09/nulls-in-count.html

Apparently you can exploit this situation, by using DECODE, and improve the
efficiency of your queries.

http://www.akadia.com/services/ora_decode.html

I found that very interesting. However, I had to check it for myself. Why? Because this

http://thinkoracle.blogspot.com/2005_10_01_archive.html (8 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

assertion may be:


1. Applicable only to a different version than mine (9.2.0.6).
2. Misunderstood by me.
3. Just plain wrong.

Note: My first attempt at this was a case of #2, therefore this article was updated
after my error was kindly pointed out by Gary Myers

Here is the test I ran which confirmed the results.

CREATE TABLE ReallyBigTable AS SELECT * FROM all_objects;

**Note: I did this about 15-20 times to get a really big table.

ALTER SESSION SET SQL_TRACE = TRUE;

SELECT rbt1.the_count, rbt1.the_sum,


rbt2.the_count, rbt2.the_sum FROM
(SELECT COUNT(*) the_count, SUM(object_id) the_sum
FROM ReallyBigTable WHERE object_type='TABLE') rbt1,
(SELECT COUNT(*) the_count, SUM(object_id) the_sum
FROM ReallyBigTable WHERE object_type='INDEX') rbt2;

ALTER SESSION SET SQL_TRACE = FALSE;

TKPROF robert_ora_2236.trc robert_ora_2236.prf explain='sys/******** as sysdba'

ALTER SESSION SET SQL_TRACE = TRUE;

SELECT COUNT(DECODE(object_type,'TABLE','*',NULL)) the_count,


SUM(DECODE(object_type,'TABLE',object_id,NULL)) the_sum,
COUNT(DECODE(object_type,'INDEX','*',NULL)) the_count2,
SUM(DECODE(object_type,'INDEX',object_id,NULL)) the_sum2
FROM ReallyBigTable;

ALTER SESSION SET SQL_TRACE = FALSE;

TKPROF robert_ora_2416.trc robert_ora_2416.prf explain='sys/******** as sysdba'

The DECODE version completed twice as quickly, because it only need to make one
pass through the data instead of 2.

Excerpt of the results:

SELECT rbt1.the_count, rbt1.the_sum,


rbt2.the_count, rbt2.the_sum FROM
(SELECT COUNT(*) the_count, SUM(object_id)
the_sum FROM ReallyBigTable
WHERE object_type='TABLE') rbt1,
(SELECT COUNT(*) the_count, SUM(object_id)
the_sum FROM ReallyBigTable

http://thinkoracle.blogspot.com/2005_10_01_archive.html (9 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

WHERE object_type='INDEX') rbt2


call count cpu elapsed disk query
------- ------ -------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0
Execute 1 0.00 0.00 0 0
Fetch 2 0.64 2.97 16994 17542
------- ------ -------- ---------- ---------- ----------
total 4 0.64 2.97 16994 17542
SELECT COUNT(DECODE(object_type,'TABLE','*',NULL)) the_count,
SUM(DECODE(object_type,'TABLE',object_id,NULL)) the_sum,
COUNT(DECODE(object_type,'INDEX','*',NULL)) the_count2,
SUM(DECODE(object_type,'INDEX',object_id,NULL)) the_sum2
FROM ReallyBigTable
call count cpu elapsed disk query
------- ------ -------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0
Execute 1 0.00 0.00 0 0
Fetch 2 0.60 1.76 8498 8771
------- ------ -------- ---------- ---------- ----------
total 4 0.60 1.76 8498 8771

// posted by Robert Vollman @ Tuesday, October 04, 2005 7 comments

Database Specialists
Recently Dr. Tim Hall posted a brief blog on SQL Tuning. He may have based it on a
number of questions on the topic that have popped up recently on some of the
Oracle forums.

http://oracle-base.blogspot.com/2005/10/no-shortcuts-for-sql-tuning.html

You might also have seen Steve Callan's 2-part article on Oracle Performance Tuning
on DBASupport.com:

http://www.dbasupport.com/oracle/ora10g/perfTuning01.shtml

So I was searching for a good article I had once read on this topic, and I found it.
Here it is, courtesy of Ian Jones and Roger Schrag of Database Specialists:

http://www.dbspecialists.com/presentations.html#perf_bottleneck

The articles on their site are sometimes dated, but I still find them useful and
interesting. Here is a particularly fun article on "Database Mysteries" courtesy of Chris
Lawson:

http://www.dbspecialists.com/presentations.html#dba_mysteries

http://thinkoracle.blogspot.com/2005_10_01_archive.html (10 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

// posted by Robert Vollman @ Tuesday, October 04, 2005 1 comments

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I like playing
sports (hockey, soccer, ultimate, basketball, you name it) and military board
games. I also enjoy reading, walking, and playing with my 2 cats Lilly and Brutus. I'm a
database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
❍ Brian Duff's OraBlogs
❍ Eddie Awad's OracleNA
❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
http://thinkoracle.blogspot.com/2005_10_01_archive.html (11 of 13)1/9/2008 2:49:50 AM
OracleBlog: October 2005

❍ Oracle's Ask Tom Kyte


❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007

http://thinkoracle.blogspot.com/2005_10_01_archive.html (12 of 13)1/9/2008 2:49:50 AM


OracleBlog: October 2005

❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

❍ Current Posts

http://thinkoracle.blogspot.com/2005_10_01_archive.html (13 of 13)1/9/2008 2:49:50 AM


OracleBlog: November 2005

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated,
but it is the most powerful tool when it comes to data. That's why when I think data, I think Oracle.
I also enjoy writing, so I use this format to organise my thoughts. Please feel free to discuss any
thoughts you may have on the same topics, even old ones (I will see and respond to such
comments). You may want to start with "LIST ALL ARTICLES" under Archives.

Thursday, November 24, 2005


DBMS_PIPE
You would like to communicate with a 3rd-party application from your PL/SQL
program, for example you want to run a UNIX command. Or perhaps you'd like to
communicate directly with another Oracle session. Whatever your specific
communication needs are, DBMS_PIPE is your solution.

What is DBMS_PIPE?

DBMS_PIPE is a package provided by Oracle that allows two or more sessions in the
same instance to communicate.

If you know anything about UNIX pipes, its a similar concept in Oracle. It is called a
pipe because it connects two (or more) sessions, and messages are queued up
inside, just like a pipe. Each session can take the next received item out of a pipe,
or insert the next item to send. Anybody (with access) can insert or remove
something from the pipe, in any order. Messages can only be removed and read
once - two people can't remove the same message from a pipe.

In more real terms, these pipes are buffers in the system global area (the SGA).
Messages are prepared for loading using PACK_MESSAGE, loaded into a pipe using
SEND_MESSAGE, and read similarly (RECEIVE_MESSAGE then UNPACK_MESSAGE).

There are basically 3 different types of pipes. Briefly:


Implicit Public Pipe: Automatically created when first accessed, disappears when it is
emptym, available to entire schema
Explicit Public Pipe: Created with CREATE_PIPE, freed with REMOVE_PIPE, available to
entire schema
Explicit Private Pipe: Created with CREATE_PIPE and private=true, freed with
REMOVE_PIPE, available only to that userid privileges, or SYSDBA.

Check chapter 45 of the PL/SQL Supplied Packages and Types Reference.


http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612.pdf

http://thinkoracle.blogspot.com/2005_11_01_archive.html (1 of 16)1/9/2008 2:49:55 AM


OracleBlog: November 2005

Example:

For this test, open up two sessions as the SAME user on the SAME instance. Make
sure your user has access to the DBMS_PIPE package.

We are going to have the first instance create the pipe, send in an SQL command,
and have the second instance retrieve that message and execute it. That should
accomplish two things: show the basic usage of DBMS_PIPE, and give Pete Finnigan a
heart attack.

I have largely left out error-checking and handling, for brevity's sake. At many
points throughout the "ORA-23322" error is possible, which is for insufficient
privileges to access that pipe.

Session #1:

DECLARE
l_status NUMBER(2);
BEGIN
-- Create the pipe. 0 is success.
-- Possible error: name in use.
l_status := DBMS_PIPE.CREATE_PIPE (pipename => 'TEST_PIPE',
maxpipesize => 8192, private => TRUE);

-- Let's pack an instruction for another session.


-- Possible error: buffer overflow (4093 bytes of data)
DBMS_PIPE.PACK_MESSAGE(item => 'SELECT SYSDATE FROM DUAL;');

-- Let's stuff it into the pipe


-- We'll use defaults for maxpipesize and timeout
-- Returns 0 on success, 1 for timeout, 3 for interrupt
l_status := DBMS_PIPE.SEND_MESSAGE(pipename => 'TEST_PIPE');

-- Ok we're done, we should get 0 for success


l_status := DBMS_PIPE.REMOVE_PIPE (pipename => 'TEST_PIPE');
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE('SQLCODE: ' || SQLCODE);
END;

Session #2:

DECLARE
l_received_message VARCHAR2(128);
l_message_type NUMBER(2);

http://thinkoracle.blogspot.com/2005_11_01_archive.html (2 of 16)1/9/2008 2:49:55 AM


OracleBlog: November 2005

l_status NUMBER(2);
BEGIN
-- Receive the message, use default timeout
-- If the pipe doesn't exist, Oracle will create it,
-- and wait for a message.
-- Returns 0 on success, 1 on a timeout, 3 for an interrupt
l_status := DBMS_PIPE.RECEIVE_MESSAGE(pipename => 'TEST_PIPE');
-- Ok, so what type are we extracting?
-- 0 nothing, 6 number, 9 varchar2, 11 ROWID, 12 DATE, 23 RAW
l_message_type := DBMS_PIPE.NEXT_ITEM_TYPE;

-- Open up the message, we can get ORA-06556 or ORA-06559


-- if its the wrong time, or nothing is left.
IF (l_message_type = 9) THEN
DBMS_PIPE.UNPACK_MESSAGE(item => l_received_message);
EXECUTE IMMEDIATE(l_received_message);
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE('SQLCODE: ' || SQLCODE);
END;

By the way, I realise that I have removed the pipe in the first session before
accessing that message in the second session. But because there is still a message
in there, the pipe will stick around. To destroy it immediately I would have to purge
it first.

More Examples:

The aforementioned guide has an example on how to use DBMS_PIPE for debugging.
There is also a great example on communication with the shell to execute UNIX
commands (like listing the contents of a directory). These are complete, excellent
examples.

I'll close with some other little notes about DBMS_PIPES:


- There is a constant called maxwait which determines how long the pipe will wait
for a message to be picked up.
- The two major errors with DBMS_PIPE are ORA-23321 (bad pipename) or ORA-
23322 (insufficient privileges).
- You can use PURGE to empty out a pipe, and RESET_BUFFER for the local packing
buffer
- You can use UNIQUE_SESSION_NAME to help distinguish between sessions if there
are several accessing the pipe.

http://thinkoracle.blogspot.com/2005_11_01_archive.html (3 of 16)1/9/2008 2:49:55 AM


OracleBlog: November 2005

// posted by Robert Vollman @ Thursday, November 24, 2005 2 comments

Monday, November 21, 2005


RAW Datatype
Earlier I mentioned the idea of using a RAW datatype for your table's primary key. I
stumbled upon a minor inconvenience with using the RAW datatype today, so I
thought I would take a step back and talk a little bit more about the RAW datatype.
http://thinkoracle.blogspot.com/2005/06/natural-vs-synthetic-keys.html

RAW(size) is used for raw binary data or byte strings of length "size" bytes (must be
specified). The maximum is 2000 bytes, but in PL/SQL it is 32767, which can lead to
interesting situations.

Think of RAW very much like VARCHAR2, but unlike VARCHAR, RAW data will not be
converted depending on the character set (by import/export, for example). More
generally, Oracle will treat this as binary data and will not interpret it as a number,
character, or anything else (generally done when moving data from one system/
session to another).

RAW data can still be viewed as characters (2 characters per byte). Something like
SQL*Plus does this for you automatically when you query. But RAW data is a little
harder to use in pure SQL, because you often have to use HEXTORAW or RAWTOHEX
to do your work (example shortly). However in PL/SQL you can just use the
UTL_RAW package.

Now back to the story.

In the aforementioned article I mentioned using it as a primary key, using SYS_GUID.


The advantages are you get a (generally) unique and randomly-dispersed key that
you should never have to change. Please note: I do not want to get dragged into a
debate on whether or not it is a good idea, I'm just saying its possible, and has
some advantages. And yes, RAW data can be indexed just fine.

Now let me give you an example of the type of minor annoyance you have to deal
with when using RAW datatypes.

Associative arrays, also referred to as:


1. Hash arrays: in other languages, like Perl, that is what they are called
2. "Index-by tables": because they are declared just like nested tables except with
"index by" added to it.
Can not use RAW datatypes as their keys.

For this example I will use "NUMBER" instead of the %ROWTYPE you would have if
using RAW(16) as your primary key.

DECLARE
TYPE ASS_TYPE IS TABLE OF NUMBER INDEX BY RAW(16);
test_ass ASS_TYPE;

http://thinkoracle.blogspot.com/2005_11_01_archive.html (4 of 16)1/9/2008 2:49:55 AM


OracleBlog: November 2005

BEGIN
test_ass(SYS_GUID()) := 1;
test_ass(SYS_GUID()) := 2;
test_ass(SYS_GUID()) := 3;
END;

PLS-00315: Implementation restriction: unsupported table index type

So you have to convert it to VARCHAR2 in order to use it, using RAWTOHEX. You can
use HEXTORAW to turn it back. Here is a working example:

DECLARE
TYPE ASS_TYPE IS TABLE OF NUMBER INDEX BY VARCHAR2(32);
test_ass ASS_TYPE;
BEGIN
test_ass(RAWTOHEX(SYS_GUID())) := 1;
test_ass(RAWTOHEX(SYS_GUID())) := 2;
test_ass(RAWTOHEX(SYS_GUID())) := 3;
END;

---

Related Info:

There is some additional information the Oracle SQL Reference and Oracle
Application Developer's Guide - Fundamentals.

Other binary data types, depending on your version, include BLOB, Bfile, LONG RAW,
and others.

Here is a link to an AskTom discussion on RAW


http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:142612348066

// posted by Robert Vollman @ Monday, November 21, 2005 4 comments

Friday, November 11, 2005


More Oracle Essays
I recently posted an assorted list of Oracle essays from some of my favourite Oracle
authors:
http://thinkoracle.blogspot.com/2005/11/oracle-essays.html

There are so many other great Oracle writers out there pleased to provide free
insights into Oracle. So I thought I'd share a few more with Troy and everyone else.
Remember that each of these authors have written several papers, let me know if
you have trouble locating more work from your favourites.

http://thinkoracle.blogspot.com/2005_11_01_archive.html (5 of 16)1/9/2008 2:49:55 AM


OracleBlog: November 2005

Improving SQL Efficiency Using CASE by Doug Burns


http://doug.burns.tripod.com/case.pdf

Exploiting and Protecting Oracle by Pete Finnigan for PenTest Limited


http://downloads.securityfocus.com/library/oracle-security.pdf

Write Better SQL Using Regular Expressions by Alice Rischert for Oracle
http://www.oracle.com/technology/oramag/webcolumns/2003/
techarticles/rischert_regexp_pt1.html

What, Where, When, Why - Selecting Oracle Development Tools by Ken Atkins from
ODTUG 2001
http://www.arrowsent.com/oratip/whatwhere.doc

Getting Fast Results From STATSPACK by Bjorn Engsig for Miracle A/S
http://www.miracleas.dk/tools/Miracle_1_statspack.pdf

SQL Tuning With Statistics by Wolfgang Breitling for Centrex


http://www.centrexcc.com/SQL%20Tuning%20with%20Statistics.pdf

The VARRAY Data Type by Howard Rogers of Dizwell


http://www.dizwell.com/oracle/articles/the_varray.html

SQL In, XML Out by Jonathan Gennick for Oracle Magazine May/June 2003
http://www.oracle.com/technology/oramag/oracle/03-may/o33xml.html

Planning Extents by Steve Adams for Ixora


http://www.ixora.com.au/tips/creation/extents.htm

Oracle Collections: A Definition in Plain English by Lewis R. Cunningham


http://blogs.ittoolbox.com/oracle/guide/archives/005924.asp

Sorry, no Oracle papers from your favourite blogger! :)

// posted by Robert Vollman @ Friday, November 11, 2005 2 comments

Thursday, November 10, 2005


DUAL Table
What is the DUAL table?

The DUAL Dummy table (as it is sometimes called) is an automatically-generated


table assigned to SYS, but accessible to all users. It has a single column "DUMMY" of
type VARCHAR2(1) which has a single row with a value of 'X'.

scott@Robert> SELECT * FROM DUAL;

http://thinkoracle.blogspot.com/2005_11_01_archive.html (6 of 16)1/9/2008 2:49:55 AM


OracleBlog: November 2005

-
X

scott@Robert> DESC DUAL;


Name Null?
Type
-----------------------------------------------------------------------
--------
-------------------------------------------------
DUMMY
VARCHAR2(1)

Warning: Do not modify the DUAL table! Why would you want to anyway? It is part of
the data dictionary, which you shouldn't modify (that's a topic for another day).

What is it used for?

It is useful because it always exists, and has a single row, which is handy for select
statements with constant expressions. You could just as easily do this with any
other table with a single row, but using DUAL makes it portable among all Oracle
installations.

Example:

SELECT 1+1 FROM DUAL;


1+1
----------
2

The other reason to use the DUAL table isn't just portability, but optimization.
According to Tom Kyte, the Oracle Optimizer knows it is a special one row, one
column table. Eddie Awad tested a related assertion recently:
http://awads.net/wp/2005/11/09/dual-behavior-change/

Why is it called "DUAL"?

It was named "DUAL" because the primary intention of this table was to allow users
to create 2 rows for every row in a table by joining it to this system table. Thus
"DUAL". Chuck explained it in the January/February 2002 issue of Oracle Magazine:
http://www.oracle.com/technology/oramag/oracle/02-jan/o12sendmail.html

Of course, you can quite easily use DUAL to create as many rows as you want, using
LEVEL (or CUBE). Just Ask Tom how this is done:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:40476301944675#40756986348091

Why is it sometimes referred to as a "magic" table?

http://thinkoracle.blogspot.com/2005_11_01_archive.html (7 of 16)1/9/2008 2:49:55 AM


OracleBlog: November 2005

For the answer to this and any remaining questions about DUAL, just Ask Tom:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:1562813956388#14583959098556

Links

Earlier I made mention of the DUAL table, including an example:


http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html

Eddie Awad recently tested Jared Still's assertion of an interesting feature in Oracle
10g. Even if DUAL has more than one row, apparently you can trust it to always
return just a single row. Read more:
http://awads.net/wp/2005/11/08/insert-into-dual/

Selecting from the DUAL table is mentioned in Chapter 8 of the Oracle SQL
Reference Guide:
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540.pdf

// posted by Robert Vollman @ Thursday, November 10, 2005 2 comments

Wednesday, November 09, 2005


10,000?
This marks my 60th post since I started in May, and, according to my stat counter I
have had 10,000 hits.

I was expecting 100, and even if 100 was the current total, it would still be
worthwhile for me to share my thoughts. Knowing that my ideas have been read
10,000 times makes me feel more excited about sharing them.

So whoever all of you are, you have my thanks, and I will definitely continue to write
about Oracle for as long as people are willing to read it!

Cheers!

// posted by Robert Vollman @ Wednesday, November 09, 2005 3 comments

Friday, November 04, 2005


Oracle Essays
Recently I recommended "Oracle Insights," a book containing a series of Oracle-
related essays by some of the top authors in our community. For those who are
interested in reading some more essays, consider some of the following samples
from a variety of my favourite authors on a variety of topics. The best part is that
these are free!

http://thinkoracle.blogspot.com/2005_11_01_archive.html (8 of 16)1/9/2008 2:49:55 AM


OracleBlog: November 2005

Re-building Indexes: When, How, Why by Jonathan Lewis


http://www.jlcomp.demon.co.uk/indexes.doc

Programming Humility: Dealing with the Reality of Errors by Steven Feuerstein of


Quest Software
http://www.odtug.com/Handouts_05/Feuerstein.zip

Locking and Concurrency by Tom Kyte


http://www.dbazine.com/oracle/or-articles/kyte1/

Practical Guide to Oracle Data Warehousing by David Aldridge


http://databasejournal.com/features/oracle/article.php/3098791

Query Tuning Using DBMS_STATS by Dave Ensor


http://www.dbazine.com/oracle/or-articles/ensor6

String Aggregation Techniques by Dr. Tim Hall


http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php

Bind Variables Explained by Mark Rittman


http://www.rittman.net/archives/000832.html

The following two articles are also worth mentioning again.

Why a 99%+ Database Buffer Cache Hit Ratio is Not Ok, by Cary Millsap of Hotsos
http://www.oradream.com/pdf/Why%20a%2099%20Cahe%20Hit%20Ratio%20is%
20Not%20OK.pdf

Why I Invented YAPP by Anjo Kolk (Free registration for download)


http://www.oraperf.com/logon.html?rpage=download.php/yapp_anjo_kolk.pdf

While recommending some reading, I'm also including my favourite Oracle


community debates of 2005:

The great Burleson/Kyte debate on "Predictive Reorganization"


http://asktom.oracle.com/pls/ask/f?p=4950:8:8515227363337669542::NO::
F4950_P8_
DISPLAYID,F4950_P8_CRITERIA:35336203098853

The great Dizwell Forum debate: "Natural vs Surrogate keys"


http://www.phpbbserver.com/phpbb/viewtopic.php?
t=189&mforum=dizwellforum&sid=135

The great Burleson/Lewis debate on "Supersizing your PGA"


http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:47466211228419

http://thinkoracle.blogspot.com/2005_11_01_archive.html (9 of 16)1/9/2008 2:49:55 AM


OracleBlog: November 2005

// posted by Robert Vollman @ Friday, November 04, 2005 0 comments

Wednesday, November 02, 2005


Oracle Insights: Tales of the Oak Table
A recent book review of "Oracle Insights: Tales of the Oak Table" by Doug Burns,
combined with the introduction of Mogens Norgaard's new blog motivated me to
finally finish my own review of his book, which has sat incomplete since I first read
it 6 months ago.

Doug Burns' Book Review of "Oracle Insights:"


http://oracledoug.blogspot.com/2005/10/book-review-oracle-insights-tales-of.
html

Mogens Norgaard's new blog:


http://wedonotuse.blogspot.com/

Oracle Insights is a series of essays from a variety of relatively like-minded authors


that together comprise the Oak Table Network. This network includes some of my
favourite authors, a group of individuals who are very excited about their
experiences with Oracle and are eager to both share their insights, and gain even
more.

For more about the Oak Table Network, visit their web site:
http://www.oaktable.net/main.jsp

Oracle Insights is a wonderful collection of essays from a very talented and


enthusiastic bunch of Oracle experts. It starts with a great history of Oracle, and
then is followed by 10 chapters, basically split evenly between the topics of
performance/tuning and collections of war stories of Oracle projects gone bad.

Being a collection of essays, each chapter is stand-alone, linked together only by


Mogens Norgaard's prefaces. In fact, I really enjoyed the prefaces because they were
very casual and personal. Normally I skip prefaces because they're carefully
scripted, bland advertisements for a book you're already reading, but Mogens were
short, and served to put a human face to each of the authors.

Because of the nature of this book, I will briefly review each of the essays before
going into my overall impression of the book. First, you may want to visit Jonathan
Lewis' site, where he has a synopsis on each chapter as well as some anonymous
reviews (with his responses):
http://www.jlcomp.demon.co.uk/book_rev_2.html

Chapter 1: A Brief History of Oracle, by Dave Ensor

Without question, this is the highlight of the book. It is much longer than the other
essays (maybe he should drop "Brief" from the title), and he does tend to go on from
time to time, but this is still the hardest chapter to put down. It is admittedly not a

http://thinkoracle.blogspot.com/2005_11_01_archive.html (10 of 16)1/9/2008 2:49:56 AM


OracleBlog: November 2005

complete history, but it touches on the evolution of Oracle from Ted Codd's original
paper of Relational Databases to what Oracle is today. It organises Oracle's
responses to Codd's 12 Rules, and then some of the other related hot topics over
the years that shaped Oracle into what it is today: e.g. Transactional Integrity,
Isolation Levels, Privileges, Rule Based Optimizers. It then covers Oracle version-by-
version discussing the new features, their motivations, and their consequences,
right up to and including version 10.

I've heard it said that this chapter alone is worth the price of the book, and its hard
to disagree.

Chapter 2: You Probably Don't Tune Right, by Mogens Norgaard

There are at least 5 chapters that focus on performance and tuning, this being the
first and probably the weakest. Let me qualify that. First of all, I mean that more out
of praise to the other essays than an indictment of this one. Indeed, this essay is (at
least in part) a summary (or high-level view) of the others.

Secondly, this chapter's strength is not in "tuning" but rather on the topic of
Instrumentation. I think that would have made a better essay, and that's what makes
it worth reading.

One word on the style. This chapter is more like a narrative, or a conversation that
the author is having with you. I'll be honest, that's not really my style (although its
great for prefaces). For example, sometimes it gets repetitive. ("the Oracle database
is by far the best database around, technically speaking", next page: "Oracle is
technically the best database around.")

Chapter 3: Waste Not, Want Not, by Connor McDonald

Connor McDonald is perhaps the most talented writer in the crowd, and that's
saying a lot. His essay includes examples of inefficient (or "wasteful") applications,
SQL statements and PL/SQL blocks. Even in this short essay, he describes how he
found these wasteful cases, why they were wasteful, and how to correct them.
Those that learn from example will particularly enjoy his lessons.

Chapter 4: Why I Invented YAPP, by Anjo Kolk

The shortest chapter, and now the third on performance. This chapter is only of
interest to those that have already read (and enjoyed) Anjo Kolk's famous (and
awesome) paper on Yet Another Performance Profiling Method. Here is the link to
that paper (after a free registration):
http://www.oraperf.com/logon.html?rpage=download.php/yapp_anjo_kolk.pdf

Chapter 5: Extended SQL Trace Data by Cary Millsap

This one, you can judge for yourself, because this chapter is available on-line right
here:
http://www.oracle.com/technology/books/pdfs/oaktable_ch5.pdf

http://thinkoracle.blogspot.com/2005_11_01_archive.html (11 of 16)1/9/2008 2:49:56 AM


OracleBlog: November 2005

If you want to hear a little bit more about this chapter, I found that it was consistent
with Cary Millsap's other work, about which you can find a review of mine here:
http://thinkoracle.blogspot.com/2005/05/optimizing-oracle-performance-millsap.
html

Chapter 6: Direct Memory Access, by Kyle Hailey

Because of the developer in me, this was one of my favourite chapters. Kyle Hailey
relays a story about having met and worked with an Oracle master named Roger
Sanders and his "m2" application, which could access the memory Oracle was using
directly. Having opened our minds to the possibilities, his story leads into a
discussion on Oracle's SGA (Shared memory) and DMA, leaving you thirsting for
more. A very memorable chapter for fans of the nuts and bolts, and yet is not that
heavy a read.

Chapter 7: Compulsive Tuning Disorder, by Gaja Krishna Vaidyanatha

It is time not only for yet another chapter on performance and tuning, but also for a
comedy break. Don't get me wrong, there is just as much substance as the other
chapters, especially for fans of the Oracle Wait Interface.

The most valuable contribution of this chapter is the so-called "Cure for CTD". It is a
2-pronged methodology that focuses both on the OWI and the OS. It is very clearly
summarized on page 235: photocopy it and pass it around to your team. After
explaining the system in very clear and specific terms, the chapter closes with 2
appropriate examples. Even your junior DBAs can now look like pros.

If they had decided there were far too many chapters on performance and tuning
(which there are), and decided to only keep one, this chapter would have my vote.

Chapter 8: New Releases and Big Projects, by James Morle

This essay deals with one particular Oracle project gone bad. It starts where the
author joined in, describing the mess his predecessors had gotten themselves into,
and then all the problems they had to contend with along the way. A fun read.

Chapter 9: Testing and Risk Management, by David Ruthven

"Poor engineering practises remain the root cause of application failures and there
is usually very little in the way of contingency planning to avoid and minimise the
impact of such failures." - David Ruthven.

In this chapter, David Ruthven breaks a database application project down, dividing
it into types and levels, and identifies where they often go wrong. He includes
something for everyone, for example I enjoyed his summary on the ingredients to
an effective development environment. He even helps quench the thirst for more on
Instrumentation that was first whetted in Chapter 2.

The second half of his chapter focuses on testing. He touches on functionality tests,
white box and black box tests, regression tests, automated tests, scalability tests -

http://thinkoracle.blogspot.com/2005_11_01_archive.html (12 of 16)1/9/2008 2:49:56 AM


OracleBlog: November 2005

everything you wish your manager had read about.

Chapter 10: Design Disasters, by Jonathan Lewis

More war stories, for fans of Chapter 8! "Now prepare yourself to read all about 'The
World's Worst Oracle Project.'" - Jonathan Lewis.

This chapter describes some of the most common mistakes in development Oracle
database applications. You'll certainly recognise some of them, because so many
people stubbornly cling to certain beliefs. I know I like to bring up several of his
points when I get into common arguments like these:
1. We want our application to be "Database Independent."
2. We will check data integrity at the application level instead of taking advantage of
Oracle's constraint checking abilities.
3. We want to use sequences for our primary keys.

I won't give away too much of this chapter, but its definitely food for thought for
anyone who has ever been (or plans to be) involved in a database application
development project.

Chapter 11: Bad CaRMa, by Tim Gorman

The book closes with another war story. We get a look at Vision, a custom-built
order-entry and customer-service application (a CRM). "This story is about such an
IT project, the most spectacular failure I have ever experienced." - Time Gorman.
(Why do we enjoy the chapters about failures so much?)

Appendix: Join the BAARF Party, by James Morle and Mogens Norgaard

This is a rant against Raid-5. Check out their web site for more:
http://www.baarf.com/

Overall Impression:
This book has been fairly widely praised throughout the Oracle community. It
received 4.5 out of 5 stars on Amazon.com and even PSOUG's Dan Morgan gave it a
very high recommendation:
http://www.psoug.org/bookrev.html

Personally I would love to see many more books like these. I certainly hope there is
a sequel coming up with even more essays from the most gifted and enthusiastic
authors in the Oracle community. I would even love to see more of these essays
expanded into books. This book is a very fun read, and I guarantee every Oracle
specialist will find several essays within that they will enjoy. High recommendation.

// posted by Robert Vollman @ Wednesday, November 02, 2005 2 comments

http://thinkoracle.blogspot.com/2005_11_01_archive.html (13 of 16)1/9/2008 2:49:56 AM


OracleBlog: November 2005

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I like
playing sports (hockey, soccer, ultimate, basketball, you name it) and military
board games. I also enjoy reading, walking, and playing with my 2 cats Lilly and Brutus. I'm a
database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge

http://thinkoracle.blogspot.com/2005_11_01_archive.html (14 of 16)1/9/2008 2:49:56 AM


OracleBlog: November 2005

❍ Oracle Geek Lewis Cunningham


❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007

http://thinkoracle.blogspot.com/2005_11_01_archive.html (15 of 16)1/9/2008 2:49:56 AM


OracleBlog: November 2005

❍ June 2007
❍ October 2007

❍ Current Posts

http://thinkoracle.blogspot.com/2005_11_01_archive.html (16 of 16)1/9/2008 2:49:56 AM


OracleBlog: December 2005

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday, December 21, 2005


Best Of OracleBlog
I got named in ComputerWorld's "Best IT Blogs on the Net." Granted, only
in the "buffer overflow" section, but still - that's pretty cool!

http://www.computerworld.com/blogs/node/1466?source=nlt_blg

Maybe it is another consequence of the Thomas Kyte Effect?

http://thinkoracle.blogspot.com/2005/12/thomas-kyte-effect.html

Anyway, I feel very fortunate for having this new audience, but I feel bad
for having nothing really intelligent to say. So I thought I would link to
some of my favourite earlier posts, and some of my most popular "hits",
to give you an idea of what I like to chat about.

To my more frequent visitors like Doug, Eddie, Laurent, Gary, Peter,


David, William, and so on, as well as any lurkers, I would appreciate
hearing your picks, too.

Here is the brief list of my highlights:

1. NULL

I posted a few articles on this, because there are quite a few errors
casual database programmers may make in their misunderstanding of
NULL and how its treated in Oracle. To put it bluntly, NULL is NOT
nothing! If ever I write a proper article for publication, it will likely be on

http://thinkoracle.blogspot.com/2005_12_01_archive.html (1 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

this topic.

NULL vs Nothing:
http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html
NULLs in Oracle:
http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html
Using NULL to exploit the COUNT/NULL feature:
http://thinkoracle.blogspot.com/2005/10/using-decode-to-exploit-
countnull.html

2. Best Practises

I like to blog a lot on what I feel are best practises for database
programming. Please allow me to pick three of the most general of the
bunch, where I have promoted Views, Constraints and Packages:

Use Views:
http://thinkoracle.blogspot.com/2005/07/use-views.html
Use Constraints:
http://thinkoracle.blogspot.com/2005/07/use-constraints.html
Oracle Packages:
http://thinkoracle.blogspot.com/2005/10/oracle-packages.html

3. Advanced Concepts

Occasionally I blog on a technique that would only come to the attention


of someone who has used Oracle to solve a more complex problem. Here
is one example of that.

Pivot and Crosstab Queries:


http://thinkoracle.blogspot.com/2005/09/pivot-and-crosstab-queries.
html

4. High-Hit Posts

There were two posts that, for various reasons, seem to have higher hit-
counts than the others. Here they are:

Analyzing Query Performance:


http://thinkoracle.blogspot.com/2005/09/analyzing-query-
performance.html
UTL_HTTP:
http://thinkoracle.blogspot.com/2005/08/utlhttp.html

http://thinkoracle.blogspot.com/2005_12_01_archive.html (2 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

5. Putting it all together

In "Oracle by Example" I brought together many concepts into one.


http://thinkoracle.blogspot.com/2005/07/oracle-by-example.html

Throughout my blog you'll also see book reviews, top 20 lists, and lots
of little tips and tricks I discover. As you'll note, I appreciate any
feedback, and I get an email if you leave a comment even on an old post,
so please feel free to do so.

I would also like to direct my new visitors to the blogs I enjoy the most.
You can see the list on the right-hand side, but other than Tom Kyte's,
which you have surely already visited (http://tkyte.blogspot.com), I
would like to draw particular attention to these two:

Doug Burns: http://oracledoug.blogspot.com


Eddie Awad: http://awads.net/wp

I enjoy ALL those blogs, but if you only have time for a couple, please
check those out.

Warning to Doug and Eddie: You might experience the first ever Robert
Vollman Effect!

// posted by Robert Vollman @ Wednesday, December 21, 2005 2 comments

Tuesday, December 20, 2005


The Thomas Kyte Effect
Good grief!

I saw a spike in my statcounter and I checked it out to see if I got


spammed. Instead I am the newest beneficiary of the "Thomas Kyte
Effect."

Well, strictly speaking, the Thomas Kyte Effect is when your blog is
referenced in a blog article of his, but in my case I was simply added to
his list of links. And then bam - several hundred hits today.

With all due respect to Doug, Lisa and Eddie, in one day I've got more
referrals from his blog than everyone else put together.

http://thinkoracle.blogspot.com/2005_12_01_archive.html (3 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

I told Tom we could "cash in" on the "Thomas Kyte Effect" with a few well-
chosen ads, but sadly he wouldn't go for it.

Well, as long as you're all here, I would like to say two things:
1. Welcome to my blog!
2. Please look through my archives, some of my more interesting reads
are in July/August.

Comments are very welcome, even on older posts (I get auto-emailed


when someone posts something).

Also, I like to provide something useful in every post, so here it is: a link
to an article by Steven Feuerstein about how to hide your code:
http://htmldb.oracle.com/pls/otn/f?p=2853:4:6669219410898182474::
NO::P4_QA_ID:4102

// posted by Robert Vollman @ Tuesday, December 20, 2005 1 comments

20 Beginner Oracle Questions


Continuing in my newfound tradition for lists of 20, here is a "cheat
sheet" of 20 common beginner Oracle questions.

Before we begin, one simple warning. Very few of these are complete
answers, consider them pointers or starting points or else the
incomplete understanding could be dangerous.

Edit: This has been highly edited since its original version.

Oracle General:

1. What are the key environment variables?


Among many others, your home and instance:
export ORACLE_HOME=oracle_home_dir
export ORACLE_SID=instance_name

2. How do you shut down or start up an Oracle instance?


Must log on as a sys user:
sqlplus sys/***@instance as sysdba
Then:
shutdown
or
startup

http://thinkoracle.blogspot.com/2005_12_01_archive.html (4 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

3. How do you start and stop a listener?


lsnrctl status
lsnrctl start
lsnrctl stop
http://www.psoug.org/reference/listener.html

4. What are the key Oracle files?


They are in network/admin folder.
tnsnames.ora: list of database connection information (client/server)
sqlnet.ora: communication parameters setup
listener.ora: list of databases to listen for on this machine

5. How do you connect to the database to execute queries?


sqlplus user/password@server_instance
On a default system, sometimes you can use scott/tiger.

6. How do you see the errors from your recently created view/procedure?
show errors;

SQL and PL/SQL:

7. How do you output a line from PL/SQL?


DBMS_OUTPUT.PUT_LINE('Hello.');

8. How do you get the current date?


SELECT sysdate FROM dual;
SELECT systimestamp FROM dual;

9. What are some other syntax considerations?


Commands must end with a semi-colon;
Strings must be single-quoted

SQLPlus:

10. How do you show the structure of a table?


desc table

11. How do I re-execute the most recent query/command?


/

12. How do I see my most recent query?


l (for "list")

13. How do I see the PL/SQL procedure output?

http://thinkoracle.blogspot.com/2005_12_01_archive.html (5 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

SET SERVEROUTPUT ON;

14. How do I execute a SQL file?


@filename.sql

More Advanced:

15. How do I see who is currently connected?


SELECT username, program FROM v$session WHERE username IS NOT
NULL;

Or, courtesy of a colleague of mine, something like this:

SELECT p.SPID "OS_PID", to_char(s.SID,'999') SID, s.serial#,


SUBSTR(p.USERNAME,1,10) "OS_USER", SUBSTR(s.USERNAME,1,16)
"ORACLE_USER",
SUBSTR(TO_CHAR(s.logon_time, 'DD Month YY "at" HH:MI:SS'),1,30)
"LOGON TIME", s.program, s.machine
FROM v$process p, v$session s
WHERE s.PADDR=p.ADDR
AND s.username IS NOT NULL
ORDER BY s.logon_time;

16. How do I find all invalid objects?


Query dba_objects for status = 'INVALID', something like this:
SELECT owner, decode(object_type,'PACKAGE BODY','PACKAGE',
object_type) OBJECT_TYPE, count(object_name)
FROM dba_objects WHERE status = 'INVALID' GROUP BY owner,
object_type;

17. How do I recompile invalid objects?


Must be logged in with privileges, and use this:
@?/rdbms/admin/utlrp.sql

18. How do I compute table and index statistics for a schema?


Answer from Steve Ensslen:
10g: Don't, it can be set up to analyze itself.
Pre-10g: Must be logged in with privileges:
execute DBMS_STATS.GATHER_SCHEMA_STATS('SCOTT');

19. How do I analyze the performance of a query/procedure (query


plans, index choice, etc)?
Many ways, one way is SQL Trace with TKPROF, which I have explained
here:
http://thinkoracle.blogspot.com/2005/09/analyzing-query-

http://thinkoracle.blogspot.com/2005_12_01_archive.html (6 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

performance.html

20. How do I tell which database am I in?


select name from v$database;
or
select instance_name, host_name from v$instance;
or
SELECT SYS_CONTEXT(‘USERENV’,’DB_NAME’) FROM DUAL;
http://thinkoracle.blogspot.com/2005/07/which-instance-am-i-in.html

Bonus:

21. How do I set up an Oracle client?


http://thinkoracle.blogspot.com/2005/06/oracle-client.html

22. How do I get data into and out of Oracle?


http://thinkoracle.blogspot.com/2005/08/import-export.html

// posted by Robert Vollman @ Tuesday, December 20, 2005 12 comments

Monday, December 19, 2005


20 PL/SQL Coding Tips
Gary pointed me to a recent AskTom thread that contained a list of PL/
SQL Coding Practises. The ensuing discussion added a few more, and I'd
like to throw in a few of my own as well. I also think most of these tips
are useful for other languages, but this is first and foremost an Oracle
developer's blog.

Here they are, with the order and wording slightly revised in some cases
(removed the biblical undertones for politically correct reasons), and my
comments after each one. Each of these could be a separate blog on
their own, but I restrained myself to only brief comments.

Design (Pre-Coding):

1. Ask Why

A popular philosophy in the Oracle blogging community, and


championed by Tom Kyte, is the notion of asking why. Why is this code
being written, why is it being done the way that it is, etc.

From Tom Kyte's Blog: http://tkyte.blogspot.com/2005/05/why.html

http://thinkoracle.blogspot.com/2005_12_01_archive.html (7 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

2. Gather requirements thoroughly

Based on the experiences of many, gather all the requirements and do


not begin anything until all parties have agreed on what the end result
will have to be in order to be considered successful.

3. Design, including for scalability and security, first.

With the exception of quasi-prototypes and small proofs of concept, no


coding should begin until it has been designed. This is the time to think
about scalability and security. Those aren't issues to tackle after the fact.

4. Set up proper testing/development/debugging environment

I find that developers are far more effective if they have a reliable,
accurate and convenient environment for testing and debugging. Also, it
is usually better to set that up first, rather than patching something
together on the fly.

5. Use source control

"Consider source control non-optional, and a factor on which your job


depends." - a former director of mine. That simplifies your decision,
doesn't it?

6. Choose the right tools

Notepad and SQL*Plus might work for you now, but for a larger project
you might want to consider a different IDE. You'll also want to look at
source control systems, and code libraries.

7. Write test cases before coding

It seems like many people agree on this rule, but consider it a fantasy
because how often do you see this done in practise? Ideally you would do
this right after #2 (gather requirements thoroughly). That way you can
say "when these tests pass, you are done."

Coding:

8. Check and handle errors

Up front, decide a common way of handling errors in the EXCEPTIONS


block. You can figure out what works best, customer error types, an
error table, an error file, whatever works as long as you are checking and

http://thinkoracle.blogspot.com/2005_12_01_archive.html (8 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

handling all errors.

For starters, check Chapter 7 of the PL/SQL User's Guide and Reference:
Handling PL/SQL Errors:
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/
a96624.pdf

9. Comment your code

This one resulted in a lot of debate on the thread. No, commenting your
code is not a substitute for making your code readable, but then again,
neither is making your code readable a substitute for commenting.
Indeed, I agree with the one suggestion that you should write your
comments BEFORE you write the code!

10. Use proper indexes

11. Maximise SQL and minimise PL/SQL

There are books written on the efficiency gain of preferring SQL over PL/
SQL.

12. Instrument your code for debugging

Choose your favourite method: debug statements judiciously places


throughout your code, or perhaps using DBMS_PROFILE (that is definitely
a topic I'll do soon), or something else entirely. As long as you have a
way to troubleshoot bugs and performance issues later on.

13. Make use of bulk processing

14. Minimise client code and maximise server code.

Generally servers are more powerful and built for this type of work. You
also want to minimise trips back and forth to the server.

15. Use bind variables, not concatenation

Not just for performance reasons, but also for security (thwart SQL
injection). I think Tom Kyte made his living off this topic for awhile.

I blogged about bind variables once: http://thinkoracle.blogspot.


com/2005/06/bind-variables-in-plsql.html

16. Think in sets.

http://thinkoracle.blogspot.com/2005_12_01_archive.html (9 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

17. Use procedures/functions to name and modularize your code for


reuse

Don't just create one big massive function that does many, specific
things. Best to break it out into specific tasks, which can be optimized
and reused. Also makes you think more about your detailed design.

18. Use unique and meaningful names

Unique names can be found easier in the code with "Find". Meaningful
names make your code easier to understand. If you can't think of a
meaningful name for a procedure/variable, maybe you don't have a clear
idea on its purpose and you need to re-think your design.

Coding and Afterwards:

19. Stress test your code with significant data, and benchmark it

Doesn't matter how much time you spent thinking about performance
and bottlenecks during the design and implementation, you might still
have missed a few things.

20. Perform a code review with your peers.

Code reviews are good to find mistakes, but also for knowledge transfer.
I also think you take more pride in your work when you have the
opportunity to share it, rather than just hide in a cubicle as an
anonymous coder.

Comments are welcome, but I also encourage you to visit the thread and
follow up to the wider audience there:
http://asktom.oracle.com/pls/ask/f?
p=4950:8:18231831513891656743::NO::F4950_P8_DISPLAYID,
F4950_P8_CRITERIA:51960184066540

Steven Feuerstein is also one of my favourite champions on good PL/SQL


programming. Here is a previous blog on one of his articles on
refactoring (the link to which is within):
http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-
refactoring.html

// posted by Robert Vollman @ Monday, December 19, 2005 5 comments

http://thinkoracle.blogspot.com/2005_12_01_archive.html (10 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

Thursday, December 15, 2005


Oracle and Perl
I work with several different databases for several different clients on
several different operating systems, often with only remote access to a
shell (as opposed to a desktop). Therefore I like to become familiar with
very common and simple technologies, like vi, sqlplus (for Oracle) and
Perl.

Writing my useful tools in Perl is very handy because I can run them
anywhere, and they can work for all databases just by having a switch on
the connection string. But of course today's example will focus on
Oracle. Perl is also very good at handling and manipulating data: perfect
for database utility scripts.

There are many different ways to write code in Perl. Some refer to Perl as
a write-only language because it is a lot easier to write than it is to read.
But I'll keep my sample simple.

#!/usr/local/perl
use DBI;
# Get a database handle by connecting to the database
$dbh = DBI->connect("dbi:Oracle:host=servername;sid=dbname",
'scott','tiger', {RaiseError => 1, AutoCommit => 1})
or die "Can't connect to database $DBI::errstr\n";
# Put together your query string
my $sql = 'SELECT * FROM emp';
# Instead you could do $dbh->do($sql) or execute
$sth = $dbh->prepare($sql);
while (@rows = $sth->fetchrow_array()) {

# You can access a specific field like this: $rows[0];


print "@rows\t";
}
print "\n";
$sth->finish();
# If you did an update, you could $dbh->commit()
# or $dbh->rollback() before disconnecting
$dbh->disconnect();

For more information, here is a quick and dirty FAQ:

http://thinkoracle.blogspot.com/2005_12_01_archive.html (11 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

http://www.orafaq.com/faqperl.htm

Here are some really good on-line samples


http://www.cri.univ-rennes1.fr/documentations/DBDOracle.html

There is a book on Oracle and Perl that described a bunch of Oracle DBA
utilities written in Perl. I have not read it myself, so check it out before
purchasing (and let me know what you thought).
"Perl for Oracle DBAs" by Andy Duncan and Jared Still
http://www.amazon.com/gp/product/0596002106/002-3253639-
8672853?v=glance&n=283155

// posted by Robert Vollman @ Thursday, December 15, 2005 0 comments

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald

http://thinkoracle.blogspot.com/2005_12_01_archive.html (12 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

The Oak Table


● Cary Millsap and Hotsos


● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005_12_01_archive.html (13 of 14)1/9/2008 2:50:00 AM


OracleBlog: December 2005

❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

❍ Current Posts

http://thinkoracle.blogspot.com/2005_12_01_archive.html (14 of 14)1/9/2008 2:50:00 AM


OracleBlog: January 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, January 24, 2006


Gathering Requirements
I wanted to briefly follow up on Tip #2 on my recent post about PL/
SQL Coding.
http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html

I am not intending to convince anyone WHY they should spend time


gathering requirements, but rather simply HOW to do it. However, let
it be known that there are people whose careers are entirely based
on the requirements gathering process, that there are volumes of
books on the subject, and there exists methods much more
sophisticated and involved that what I am going to describe here.

This post is understandably technology-independent, which is good


because it is based on my experience along with some articles I've
read recently, which has involved a variety of industries and
technologies.

Step 1: State Your Vision

Before prattling off a list of what the software must do, you should
start by naming some clear, concise key objectives. The basic idea is
that all the requirements you are about to list match these key
objectives.

Ideally I like to mention in this brief opening statement how the


stakeholder's needs can be fulfilled, pain reduced, and/or gain
received.

http://thinkoracle.blogspot.com/2006_01_01_archive.html (1 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

What Are Requirements?

A requirement is based on a specific business-driven need that is


necessary to accomplish the stated project vision. Each requirement
should be enumerated (or otherwise identifiable), and should only
describe WHAT should be provided, not HOW, and should thus not
necessarily discuss implementation details. A requirement should
also be testable/verifiable, and mention how that is planned to be
done.

As I alluded to in Tip #1, my conviction is that the rationale behind a


requirement is a necessary step. By explaining WHY something is
necessary we can help keep the requirements complete, clear,
concise, consistent and maybe some other things that start with c.

Depending on the application, requirements can be related to the


functionality, the business interaction (with users), or the technical
requirements (eg: time, space, performance, scalability, security,
disaster recovery).

For example, requirements can include anything from business rules,


the budget, the interface (web-based vs desktop), reporting abilities,
performance (number of concurrent users), completion date/
schedule, security needs, hardware, software, error/fault-tolerance,
user technical level, system maintenance requirements, and so on.

How to Gather Requirements

Is this a brand new product, or is it meant to either replace or


compete with another product? If the latter, you should evaluate what
that product does, and how it can be improved.

Identify all the stakeholders, such as users, management and the


nerds (technical folk). Talk to them either one-on-one or in groups.

Techniques

In my experience, I simply write a document. For more sophisticated


approaches, you can look into use-case models, unified modeling
language (UML), automatic requirements generation tools,
prototypes, storyboard, agile software development or any other host
of techniques.

One word about prototypes. Go ahead and use prototypes to help

http://thinkoracle.blogspot.com/2006_01_01_archive.html (2 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

users express their needs. But when you're done, throw the prototype
away. Tell management that a quality product will take time to
develop, and working with hastily-thrown together prototype code is
just going to wind up with a real mess. Trust me: Chuck it!

Common Requirements Errors

Based on some research articles, the most common types of errors


when writing requirements are (in order):
1. Incorrect assumptions
2. Omitted requirements
3. Inconsistent requirements
4. Ambiguous requirements

What's Next?

Remember that requirements gathering is a cyclical process. Despite


having a single author responsible for this document, there should
be several stakeholders conducting several rounds of reviews and
inspections. In fact, you should have a way to track the history of the
requirements document, and it should be possible to revise it, even
after it is finalized (this is the real world, after all).

Prioritize your requirements. You may even want to move some


requirements to a "future release" section.

In my requirements document, I als like to add the following sections:


1. A list of all the assumptions that were made during the
requirements gathering process, and why.
2. A list of constraints on either the software, the design, or the
development process
3. A reference to any industry standards to which you want the
software to conform (eg: ANSI SQL), and why.
4. A summary of how we expect the system to be used: how many
concurrent users, transactions per day, etc.
5. Project-specific details, like the manpower, time, skill sets,
deadlines, licenses, equipment that will be needed.
6. A project glossary of terms used in this application, including
acronyms.

Granted this was just one man's very basic look at requirements
gathering, but for many small to mid-sized projects, that should get
us started in the right direction.

http://thinkoracle.blogspot.com/2006_01_01_archive.html (3 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

// posted by Robert Vollman @ Tuesday, January 24, 2006 2 comments

Friday, January 20, 2006


Odds and Ends
PL/SQL vs J2EE, Part 2

I knew there was going to be some discussion following up my


previous post on using stored procedures instead of embedding SQL
in your J2EE application. Some of it you can read in the comments,
others you can find on other people's blogs.

Original Article
Tim Hall's Response (and Here).
Harry Boswell's Response
Dizwell Discussion: Database Independence

I also saw a similar discussion that had taken place over a year ago.
Check out these posts by Mark Rittman and Dave Warnock for a
Point-Counterpoint on the debate.

Mark Rittman
Dave Warnock's Response

Gary Myers and Harold Ramis Separated At Birth

Gary Myers

http://thinkoracle.blogspot.com/2006_01_01_archive.html (4 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

Harold Ramis

In seriousness, I've enjoyed Gary Myers' blog for quite some time, but
I particularly enjoyed his recent series of blogs on the 12 SELECTs of
Christmas, so I thought I would highlight it for you to enjoy again.
12 Selects of Christmas, Part I
12 Selects of Christmas, Part II
12 Selects of Christmas, Part III
12 Selects of Christmas, Part IV

Neat Tricks

Some time ago I posted an article on UTL_HTTP that gave Pete


Finnigan a security-related heart attack. Just when he was
recovering, Doug Burns posted a neat little trick that will give him
another stroke. Apparently within SQL*Plus you can execute an SQL
script somewhere on the Internet. Try it!

UTL_HTTP Post
Pete Finnigan
Doug Burns

Blog Updates

I've noticed Tony Andrews, whose blog I quoted in my last post, has
some new content including an interesting So Doku Solver in PL/SQL.
Check it out here, and hope he continues to post:
Tony Andrews PL/SQL So Doku Solver

Another new Oracle blog to check out is Yas'. I've enjoyed several of
his postings recently, so its hard to pick just one to highlight, but

http://thinkoracle.blogspot.com/2006_01_01_archive.html (5 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

given its similarity to my recent post on Bulk Binding and FORALL,


here is one on BULK COLLECT.
My FORALL
Yas' BULK COLLECT

Ask Tom

I spend a fair bit of my Oracle web-surfing time over on AskTom. If


you ask many of us, we'll say its an invaluable source of information,
and also houses some very interesting discussions. Here are three
samples of discussions I've been following recently.

Driving Tables
Introduction to Analytical Functions
Batch Processing

Old Post Updates

The original intention of this blog was to have a place to organise my


thoughts on things that I have learned about Oracle. Therefore,
generally a post here is merely one of the early stages of my
exploration on a particular topic. I usually continue my exploration,
and doubtlessly continue to find interesting articles on the same
topics. Here are two examples.

You may have noticed that I talk a lot about NULL, how funny it is,
and how misunderstandings lead to errors. I mentioned recently that
if I were to write an article it would probably be about NULLs. I was
flipping through an Oracle magazine I had missed from last Summer
and saw that Lex de Haan and Jonathan Gennick had beaten me to it.
Nulls: Nothing to Worry About

Last Fall I blogged on using ROWNUM and ROWID, and I just recently
found an awesome post on AMIS to demonstrate the power of using
ROWNUM to improve performance.
Original Post on ROWNUM
Alex Nuijten on ROWNUM

Finally

My final order of business is related to Oracle only in that it involves


one of our favourite PL/SQL experts, Steven Feuerstein. Steven
recently started a personal blog, and even posted an article in
response to a questionable comment I left on Eddie's Blog.

http://thinkoracle.blogspot.com/2006_01_01_archive.html (6 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

Eddie Awad
Steven Feuerstein is a nut?

But rather than talk about nuts, I would really like to highlight just
how much Steven Feuerstein's work has helped me, and how it can
help others. You can see my blog is littered with examples, here is
another, about how to hide your code:

Steven Feuerstein Q&A: Hiding PL/SQL


My Article about Steven Feuerstein on Refactoring

// posted by Robert Vollman @ Friday, January 20, 2006 0 comments

Wednesday, January 18, 2006


PL/SQL vs J2EE
Let's say you're designing an enterprise-wide OLTP Web Application
with Data Warehousing, Reporting and multiple interfaces to various
external systems for large volumes of data. Where do you put your
business logic? Do you embed your SQL into your Java code, or do
you keep your SQL in the database, and write stored procedures?

Regardless of your answer, you are wandering into one of the older
and more heated arguments in this community. (Classic examples of
one: here and here) I don't mean to re-ignite it, but I do want to
understand it.

"It is a religious war though, they cannot be won by reason or


objectivity." - Tom Kyte

It would appear like Java programmers hate stored procedures. They


are viewed as hard to maintain, and not scalable. To them, scalability
means spreading out the workload, running on several small
machines.

Some don't even like to write the SQL themselves, instead preferring
to use a framework like Hybernate or TopLink do it, and then rest
their heads on their pillows at night dreaming of fewer errors/
portability issues and better performance. But even if they can't
achieve the better performance the database guys keep bragging
about, they're more than happy to accept greater ease of
development and maintainability in exchange.

http://thinkoracle.blogspot.com/2006_01_01_archive.html (7 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

Plus, Java programmers love choices. Lots of tools, unit testing


packages, libraries - all open source - not to mention a huge
community. They wouldn't want to get attached to any database
vendor, especially one that is expensive and proprietary.

"If you want portability keep logic out of SQL." - Martin Fowler

At the other end of the spectrum are the database specialists. They
walk around with print-outs of all the horrible SQL statements Java
programmers have written that are choking the database, with
serialization and loads of parsing. "Leave the SQL to us!" they plead
in vain, "it's too hard for you, especially with this crappy database
design!" They may secretly admire the Java progammers ability to
write procedural or object-oriented code, but they believe that they
lack the key to unlocking database performance: "set-based"
mentality.

They look at a Java application and all they can see if multiple
database trips where the SQL could have been combined into a single
stored procedure making one trip. They examine their EJB containers
and then lecture the programmers on recognising and understanding
the difference between read-write and read-only situations.

The database specialist isn't as impressed by the Java programmer's


triumphant removal from database dependence, for if you aren't
tying yourself to a database you are losing out on all its power.

Where does that leave us?

The fundamental question is where the business logic should be.

The Java programmer, who sometimes refers to it as domain logic,


wants business logic out of the database, often in the name of
database independence. Even without this argument, they see live or
non-relational data, in different formats, much of it transient and
with complex rules ... why write piles of unmaintainable PL/SQL for
that? They may concede that some validation constraints are OK, but
even that isn't for sure.

Here is an argument on avoiding putting your Domain Logic into SQL,


from none other than Martin Fowler:
http://www.martinfowler.com/articles/dblogic.html

"Do not use stored procedures to implement business logic. This

http://thinkoracle.blogspot.com/2006_01_01_archive.html (8 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

should be done in Java business objects." - Rod Johnson

The database specialist views business rules as data rules and thus
belongs close to the data. If there are some business rules or
business relationships between various entities, well that should be
enforced in the same place where the data is stored: the database.
You've bought expensive, sophisticated software capable of
managing your data in a fast, reliable, scaleable way: use it!

Consider a very simple argument put forward by database specialist


Tony Andrews about putting the business logic in the database:
http://tonyandrews.blogspot.com/2005/04/business-logic-apis.html

Here is an article about a database-centric approach to J2EE


application development:
http://www.oracle.com/technology/pub/articles/odtug_award.pdf

A Final Plea

I don't think there really is a right answer and a wrong answer in


general terms. But armed with an awareness of the debate, its basic
framework and a few starting points, we can make the decisions that
make sense on a project-by-project basis.

Note: This is one of the first times I've put up a non-technical post,
so I'll be curious if there is any demand for more.

// posted by Robert Vollman @ Wednesday, January 18, 2006 15 comments

Tuesday, January 17, 2006


Bulk Binding: FORALL
When writing your PL/SQL stored procedure bear in mind that SQL
statements are still sent to the SQL Engine as opposed to the PL/SQL
Engine. Therefore in cases where you are executing several SQL
statements in a loop, the resulting context switches could cause a
noticeable performance problem.

One solution to this performance solution is the use of "bulk


binding." What is that? Well first, you may recall that binding
variables allows you to tie the current value of a variable into an SQL
statement.
http://thinkoracle.blogspot.com/2005/06/bind-variables-in-plsql.

http://thinkoracle.blogspot.com/2006_01_01_archive.html (9 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

html

"Bulk Binding" refers to a process whereby you can tie the current
values of all the elements in an entire collection into a single
operation. By using bulk binds, only one context switch is made
between the PL/SQL and SQL Engines, to pass the entire collection,
thus avoiding those performance issues.

So how is this done? In this case, using FORALL.

Let's look at an example from the Oracle documentation of how you


might do something without any knowledge of bulk binding:

DECLARE
TYPE NumList IS VARRAY(20) OF NUMBER;
depts NumList := NumList(10,30,70);
BEGIN
FOR i IN depts.FIRST..depts.LAST LOOP
UPDATE emp SET sal = sal + 100 WHERE deptno = depts(i);
END LOOP;
END;

Using timing techniques I've explained before, here is what I came up


with:
http://thinkoracle.blogspot.com/2005/09/analyzing-query-
performance.html

call count cpu elapsed disk query


------- ------ -------- ---------- ---------- ----------
Parse 1 0.00 0.00 0
0
Execute 3 0.01 0.00 0
9
Fetch 0 0.00 0.00 0
0
------- ------ -------- ---------- ----------
----------
total 4 0.01 0.00 0
9

Instead, we can use FORALL like this:

http://thinkoracle.blogspot.com/2006_01_01_archive.html (10 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

DECLARE
TYPE NumList IS VARRAY(20) OF NUMBER;
depts NumList := NumList(10,30,70);
BEGIN
FORALL i IN depts.FIRST..depts.LAST
UPDATE emp SET sal = sal + 100 WHERE deptno = depts(i);
END;

And get this:

call count cpu elapsed disk query


------- ------ -------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0
Execute 1 0.00 0.01 0 9
Fetch 0 0.00 0.00 0 0
------- ------ -------- ---------- ---------- ----------
total 2 0.00 0.01 0 9

Notice 1 execute instead of 3. Of course we won't see any


performance difference on a small sample size, but here I am just
illustrating the point.

You may notice the absense of the keyword "LOOP" in the FORALL
example. That is because despite its similar appearances and syntax
in this example, FORALL is not a loop. It takes a single SQL
statement, and the index i can be used only as an index into the
collection.

You can find more information about FORALL in the PL/SQL User's
Guide and Reference: http://download-west.oracle.com/docs/cd/
B10501_01/appdev.920/a96624.pdf

Another useful trick is the use of SQL%BULK_ROWCOUNT (SQL is the


implicit cursor used by the SQL engine for DML operations). It can be
indexed the same way as the collection.

DECLARE
TYPE NumList IS VARRAY(20) OF NUMBER;
depts NumList := NumList(10,30,70);
BEGIN
FORALL i IN depts.FIRST..depts.LAST
UPDATE emp SET sal = sal + 100 WHERE deptno = depts(i);

http://thinkoracle.blogspot.com/2006_01_01_archive.html (11 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

FOR i IN depts.FIRST..depts.LAST LOOP


DBMS_OUTPUT.PUT_LINE('Affected Rows for ' || depts(i) || ' is ' || SQL%
BULK_ROWCOUNT(i));
END LOOP;
END;

Affected Rows for 10 is 3


Affected Rows for 30 is 6
Affected Rows for 70 is 0

The only error I can foresee getting with FORALL is this one:
ORA-22160: element at index does not exist
And you will only get that if you are somehow binding to an index
that does not exist.

You may also get complaints if you use the index in an expression,
which is not supported:
PLS-00430: FORALL iteration variable i is not allowed in this context

Now that I've spoken about avoiding unnecessary context switches


executing SQL statements, what about unnecessary context switches
in getting information FROM the SQL engine? Are those avoidable?
Yes, using BULK COLLECT. I'll write more about that shortly.

Links:
Dan Morgan has more than just a reference on this topic, he has lots
of really good examples: http://www.psoug.org/reference/
bulk_collect.html

There is also a short but good write-up on bulk binding in the


Application Developer's Guide: Fundamentals, look under Chapter 9:
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/
a96590.pdf

Dr. Tim Hall has some several good write-ups with good examples:
http://www.oracle-base.com/articles/8i/BulkBinds8i.php

// posted by Robert Vollman @ Tuesday, January 17, 2006 1 comments

Sunday, January 15, 2006


Oracle DO NOTs
http://thinkoracle.blogspot.com/2006_01_01_archive.html (12 of 17)1/9/2008 2:50:04 AM
OracleBlog: January 2006

Here is another interesting discussion taking place on AskTom about


Oracle DO NOTs:

http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:53901314988148

After Tom responded, a lot of people got into it. I had some ideas
myself, but decided not to make one of my famous Top 20 Lists after
all, since it wound up similar to this one:

http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html

For those of you who are curious, here is more or less what was
covered by Tom or his guests:

Tom:
1. Don't accept string literals from end users and concatenate them
into your SQL. In other words, use binds. This isn't just for efficiency,
its more to prevent execution of malicious code. Yes, I know I did
this one when demonstrating DBMS_PIPE.http://thinkoracle.blogspot.
com/2005/11/dbmspipe.html

2. Don't test on an empty or near-empty database (you need real


volumes)

3. Don't test with a single user (you'll miss scalability issues)

4. Don't forget to use a source control system.

5. Don't wing it as you go along, design in advance.

One responded (our buddy Bill) that you shouldn't do anything


without a spec.

6. Don't take advice from experts without testing to see if it applies


to you.

7. Don't optimize by hypothesize. Test!

From Others:

8. Don't reinvent the wheel, use built-in packages

9. Don't ignore the Oracle documentation, there is a wealth of


information there.

http://thinkoracle.blogspot.com/2006_01_01_archive.html (13 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

10. Don't use technologies because they are cool.

11. Don't hesitate to throw away bad code, rewriting can be better
than refactoring.

This actually resulted in some debate. Sometimes you want to let


sleeping dogs lie. That is, if the code works, don't spend days re-
factoring it unless you need to.

12. Don't write code without documentation/comments

Here is a great language-neutral link: http://tlug.up.ac.za/old/


htwuc/unmain.html

13. Don't name variables arbitrarily.

14. Don't skip your unit-testing

15. Don't comment your SQL to override the optimizer plan unless
you are sure.

16. Don't forget to update comments when you update code.

17. Don't forget to instrument your code.

What is instrumentation? Well, read Mogens Norgaard, or start with


this link:
http://tkyte.blogspot.com/2005/06/instrumentation.html

18. Don't forget to mention dependencies when commenting code.

19. Don't expect the same database on two different hosts to work
exactly the same.

20. Don't modify init.ora parameters without documenting the


originals.

21. Don't neglect to collect histogram data when you run stats.

Well this may have turned into a Top 20 (well, 21) list, but none of
these are my own. If you find this interesting, the link to the
discussion is at the top.

// posted by Robert Vollman @ Sunday, January 15, 2006 0 comments

http://thinkoracle.blogspot.com/2006_01_01_archive.html (14 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
❍ Brian Duff's OraBlogs
❍ Eddie Awad's OracleNA
❍ Pete Finnigan's Aggregator

http://thinkoracle.blogspot.com/2006_01_01_archive.html (15 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

❍Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006

http://thinkoracle.blogspot.com/2006_01_01_archive.html (16 of 17)1/9/2008 2:50:04 AM


OracleBlog: January 2006

❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

❍ Current Posts

http://thinkoracle.blogspot.com/2006_01_01_archive.html (17 of 17)1/9/2008 2:50:04 AM


OracleBlog: March 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated,
but it is the most powerful tool when it comes to data. That's why when I think data, I think Oracle. I
also enjoy writing, so I use this format to organise my thoughts. Please feel free to discuss any
thoughts you may have on the same topics, even old ones (I will see and respond to such comments).
You may want to start with "LIST ALL ARTICLES" under Archives.

Wednesday, March 29, 2006


About Me
Optimizer Name: Robert
There is a great debate in the database application Vollman
development community. I have encountered many Location: Calgary,
developers who prefer putting all their business logic in Alberta, Canada
the application code and using the database only as a
glorified file system. I was born and raised in Ottawa,
and have lived in Calgary since
You pick your battles carefully with these developers. I
1991. I like playing sports
always thought the "line of last defense" was data
(hockey, soccer, ultimate,
integrity rules. When I encountered a particularly
basketball, you name it) and
stubborn developer, I decided that I would focus on
military board games. I also
convincing him to, at the very least, use his expensive
enjoy reading, walking, and
RDBMS to protect his data's integrity (through use of
playing with my 2 cats Lilly and
constraints and keys).
Brutus. I'm a database
However, I have learned that there is actually a whole application specialist, whatever
other battlefield to my rear. I just came across a that is.
database application that overrides the optimizer. Every
database query this application ever executes includes a View my complete profile
forced index.

What do I mean? Why does that bother me? Let me take a


short step back to explain what I mean.
Best Links
● Ask Tom Kyte
Think about when you execute a query to access some ● Oracle Docs
data. That data you are requesting could be from several ● Dan Morgan and PSOUG
tables, spread all over the disk. The optimizer does many ● Steven Feuerstein
things, among them to choose how every query is ● Jonathan Lewis
executed. That means, for instance, it selects in which ● FAQ
order the tables will be joined, and which indexes will be ● Connor McDonald
used to access the data. ● The Oak Table
Cary Millsap and Hotsos
In the past, presumably when this application was

written, Oracle used a rule-based optimizer (RBO), which ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006_03_01_archive.html (1 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

used a set of rules to determine how to access the data. ● Anjo Kolk and OraPerf
The RBO did not always make ideal choices. Neither did ● Dizwell Oracle Wiki
the early versions of the cost-based optimizer (CBO). ● My Personal Blog
That is why many developers took advantage of their
ability to override the optimizers and tell it (for example)

Aggregators
which join order or indexes to use.

But that's the past. Let's talk about the present.


Brian Duff's OraBlogs

For several years now, I've never experienced a ❍ Eddie Awad's OracleNA
legitimate need to override the optimizer. Usually re- ❍ Pete Finnigan's Aggregator
generating my DBMS_STATS is all I need to do in order to ❍ Oracle's Bloglist
guarantee good choices. ❍ Oracle Base Aggregator

As Jonathan Lewis describes in his latest book Cost-


Based Oracle Fundamentals, the CBO has come a long
Top Blogs
Oracle's Ask Tom Kyte
way. You are doing yourself a great disservice when you

Oracle Guru Jonathan Lewis


aren't updating your applications to take advantage of it.

❍ Blogger of the Year Eddie Awad


Both his book, and Oracle's Database Performance and ❍ Data Warehouser David Aldridge
Tuning Guide describe the optimizer in more detail, and ❍ Oracle Geek Lewis Cunningham
present the various ways you can leverage its power. I ❍ Database Expert James Koopmann
really can't think of any reason why we still need to fight ❍ Dizwell's Howard Rogers
these battles with even the most stubborn of developers. ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
// posted by Robert Vollman @ Wednesday, March 29, 2006 5 ❍ Oracle Award Winner Mark
Rittman
comments
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim
Tuesday, March 28, 2006 Hall
UKOUG's Andrew (Arfur C.) Clarke
Bookmark This Page ❍

Newbie DBA Lisa Dobson


To ease the task of browsing my archives, I've put

together an organised list of my previous posts. ❍ Coffee-Drinking DBA Jon Emmons


Bookmark this, because I will keep it up to date. I will ❍ Chris Foot
also include a link to this post under Archives. ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
Note: If you comment on an older article, I will get an ❍ DBA Coskan Gundogar
automatic email. So I will see it and I will respond to it, ❍ Oracle WTF
so please feel free to do so!

For Newbies:
ARCHIVES
❍ LIST ALL ARTICLES
Tuesday, December 20, 2005 ❍ May 2005
20 Beginner Oracle Questions ❍ June 2005
❍ July 2005
Friday, June 17, 2005 ❍ August 2005
Asking For Help - Tips on where to go and how to do it.
❍ September 2005
October 2005
Wednesday, July 19, 2006

http://thinkoracle.blogspot.com/2006_03_01_archive.html (2 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

Finding Information - How do you find answers to other ❍ November 2005


questions? ❍ December 2005
❍ January 2006
Thursday, July 14, 2005 ❍ February 2006
Oracle Docs - For when people tell you to RTFM! ❍ March 2006
April 2006
Best Practises:

❍ May 2006
Thursday, October 19, 2006 ❍ June 2006
3 Easy Ways to Improve Your PL/SQL - Improving your ❍ July 2006
code through instrumentation and bulk processing. ❍ August 2006
❍ September 2006
Friday, March 09, 2007 ❍ October 2006
40 Tips From Tom (Kyte) ❍ November 2006
❍ December 2006
Tuesday, June 14, 2005
January 2007
Bind Variables in PL/SQL - Short answer: PL/SQL binds

February 2007
all variables (with some exceptions like dynamic SQL)

❍ March 2007
Tuesday, January 24, 2006 ❍ April 2007
Gathering Requirements ❍ May 2007
❍ June 2007
Wednesday, March 01, 2006 ❍ October 2007
Handling exceptions - A how-to guide.
❍ Current Posts
Friday, March 10, 2006
Handling Performance Issues

Wednesday, August 17, 2005


Keeping Tables Small - In terms of number of rows, not
columns. Improve performance.

Monday, October 31, 2005


Oracle Packages - And why/how you should use them.

Monday, July 11, 2005


Specifying INSERT Columns - Why it's a good habit.

Wednesday, May 18, 2005


Steven Feuerstein on Refactoring

Tuesday, July 26, 2005


Use Constraints - A how-to guide for people to whom I
BEG to let the database handle the data's integrity.

Monday, July 25, 2005


Use Views - Why they're handy.

Tuesday, September 12, 2006


Using Numerical Fields - Don't use them for fields that

http://thinkoracle.blogspot.com/2006_03_01_archive.html (3 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

aren't real numbers.

Oracle Packages:

Wednesday, October 12, 2005


DBMS_OUTPUT.PUT_LINE

Thursday, November 24, 2005


DBMS_PIPE - For communication between sessions

Sunday, August 14, 2005


UTL_HTTP - Including an example of how to get a stock
quote from the Internet.

Top 20 Lists:

Sunday, January 15, 2006


Oracle DO NOTs - From AskTom

Tuesday, December 20, 2005


20 Beginner Oracle Questions

Monday, September 12, 2005


20 Oracle Lessons - After my first few months of
blogging.

Monday, December 19, 2005


20 PL/SQL Coding Tips - Inspired by an AskTom thread

Tuesday, October 17, 2006


Software Vendor Customer Support - How to improve
your luck when dealing with support (ok there are only
14)

Book Reviews:

Wednesday, June 22, 2005


Expert One-on-One - A couple of mistakes from my
favourite Oracle book.

Monday, May 16, 2005


Optimizing Oracle Performance (Millsap, Holt)

Wednesday, November 02, 2005


Oracle Insights: Tales of the Oak Table

Thursday, June 23, 2005


PL/SQL Books - A list of my three favourite PL/SQL books

Templates:

http://thinkoracle.blogspot.com/2006_03_01_archive.html (4 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

Thursday, June 30, 2005


OOP in PL/SQL? Yep

Wednesday, July 13, 2005


Stored Procedure template

Great Debates:

Tuesday, June 21, 2005


Natural vs Synthetic keys - Choosing primary keys.

Wednesday, March 29, 2006


Optimizer - Should we be overriding it in our application?

Monday, September 19, 2005


PL/SQL Code Storage: Files vs In-DB Packages

Wednesday, January 18, 2006


PL/SQL vs J2EE - Where should you put the business
logic?

NULLs:

Friday, September 09, 2005


NULLs in COUNT - Why counting on a column might get
you a different total.

Friday, June 10, 2005


NULLs in Oracle

Tuesday, May 17, 2005


NULL vs Nothing - ANSI SQL is unlike programming
languages because NULL is not nothing.

Gotchas!

Monday, June 13, 2005


Blank Lines and SQLPlus

Friday, May 20, 2005


Multiple Foreign Keys on the Same ID

Monday, July 04, 2005


SQLCODE and SQLERRM in INSERTs

How-To Guides:

Wednesday, September 14, 2005


Analyzing Query Performance - using SQLTRACE and

http://thinkoracle.blogspot.com/2006_03_01_archive.html (5 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

TKPROF

Friday, May 04, 2007


ANSI Joins - Or do you want to stick with the old school
style?

Tuesday, February 14, 2006


BPEL - For SOA

Tuesday, January 17, 2006


Bulk Binding: FORALL - Improve performance of bulk
updates.

Thursday, September 22, 2005


Column Name as a Variable

Thursday, June 16, 2005


Common Table Column Types - Two tables with columns
on the same type, but not actually related.

Wednesday, August 24, 2005


COMPUTE - How to emulate a feature found in other
languages

Saturday, June 18, 2005


Connect By - Heirarchical queries, something you need
to know.

Monday, June 20, 2005


Decode - CASE's precursor.

Thursday, November 10, 2005


DUAL Table - You've seen it, what is it?

Thursday, May 19, 2005


Dynamically assigning size of varchar2 - You do it in
other languages, can you do it in PL/SQL (and how)?

Wednesday, May 25, 2005


ENUM in Oracle - Emulating a common programming
feature in PL/SQL.

Friday, July 01, 2005


Extra Columns in a GROUP BY

Tuesday, May 09, 2006


Finding Nearby Rows. Three methods of solving similar
requirements.

Monday, August 01, 2005

http://thinkoracle.blogspot.com/2006_03_01_archive.html (6 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

Import Export

Monday, May 28, 2007


Multirow Inserts - Does Oracle support the ANSI SQL
standard of inserting multiple rows? No. But here's how
you can fake it.

Thursday, May 26, 2005


NOCOPY Hint - Improve performance by changing how
variables are passed to PL/SQL procedures.

Saturday, July 23, 2005


Oracle BOOLEAN - PL/SQL has BOOLEAN, here's how to
emulate it in Oracle's SQL

Friday, July 29, 2005


Oracle By Example - Bringing several concepts together
to solve a problem.

Friday, June 24, 2005


Oracle Client - How to install

Tuesday, July 04, 2006


Oracle and Java

Monday, October 30, 2006


Oracle Passwords - Answering your common questions

Thursday, December 15, 2005


Oracle and Perl

Thursday, February 02, 2006


Oracle and SOA - Covers Oracle's Service-Oriented
Architecture at a high level

Wednesday, February 22, 2006


Oracle Sequences - This is the one Oracle carried on its
main page

Thursday, September 01, 2005


Pivot and Crosstab Queries - A very useful technique for
turning rows into columns, and vice versa

Monday, April 03, 2006


Pivot Queries Using Variable Number of Columns - Part 2
on pivot queries, when you don't know how many
columns you need in advance.

Friday, September 30, 2005


PL/SQL Procedure Call Overhead - Is there one?

http://thinkoracle.blogspot.com/2006_03_01_archive.html (7 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

Friday, August 11, 2006


PL/SQL Procedure Call Overhead Re-visited - By Zsolt
Lajosfalvi

Saturday, September 02, 2006


Protecting PL/SQL Code - Using wrap.

Tuesday, May 24, 2005


Random Numbers - How to generate them.

Monday, November 21, 2005


RAW Datatype

Tuesday, June 27, 2006


Recursion vs Iteration - What are they, what are the
advantages of each one?

Tuesday, June 13, 2006


Refreshing Data - A High-level picture of the flow and
what to keep in mind when designing your data import
strategy

Thursday, October 06, 2005


ROWNUM and ROWID - And how they're used to solve
various issues, and improve retrieval times.

Tuesday, February 07, 2006


TRANSLATE - What it is, how to use it.

Wednesday, August 10, 2005


UNION ALL - How and when to avoid performance hits

Monday, April 17, 2006


Updating Views - Can you do it, and if so, when.

Monday, June 27, 2005


Using Bad Names in Oracle

Tuesday, October 04, 2005


Using DECODE to exploit COUNT/NULL feature -
Applying DECODE and our knowledge of COUNT/NULL
together in a little trick to speed up a query.

Wednesday, June 15, 2005


Variable Constraints - Can you use variables in
constraints? How?

Friday, November 10, 2006


View Constraints - Can you manage integrity using views?

http://thinkoracle.blogspot.com/2006_03_01_archive.html (8 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

Monday, July 18, 2005


Which instance am I in?

Tuesday, May 30, 2006


Windowing Clauses - How they are used to empower
your analytic functions.

Other:

Monday, February 26, 2007


Fun With Tom Kyte - Get a laugh out of Oracle's king of
wit

Thursday, April 05, 2007


Oracle Beefs - Here are mine. What are yours?

Tuesday, October 31, 2006


Oracle Gurus - What makes an Oracle guru?

Tuesday, February 21, 2006


Oracle Interview Questions - How to come up with useful
ones.

Sunday, June 03, 2007


SQL Interview Questions - Here's what I ask. Prepare for
your interviews.

Friday, May 25, 2007


What Makes a Great Oracle Blog?

// posted by Robert Vollman @ Tuesday, March 28, 2006 1 comments

Friday, March 10, 2006


Handling Performance Issues
Typically performance issues are handled by looking for
common symptoms and trying common solutions. Given
a sufficient level of experience, this is successful quite
often with minimal effort. But there are times where this
does not work and you need a more systematic approach.

Let's take a look at one approach, bearing in mind:


1. This is a rough, first, high-level pass
2. It is NOT Oracle (or even database) specific
3. I am not including the details on the HOW

Also, some people may notice Cary Millsap's influence in

http://thinkoracle.blogspot.com/2006_03_01_archive.html (9 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

this approach.

1. Rank the most significant performance issues, by


specific application, from the business user's perspective.

2. Carefully measure the total time currently taken for


each of these specific applications.

3. Determine exactly how fast the application would


need to run in order to meet the business user's needs.

Now, for each business application in order of


importance, perform steps starting at 4-9:

4. Break down the specific application into tasks.

5. Carefully measure how often each task is currently


being executed, how long each execution currently
takes, and from that, how much total time it currenty
takes and what % of total time each task represents.

Now, for each specific task in order of total % of time


taken, perform steps 6-9:

6. If you COMPLETELY ELIMINATED the time taken by this


task and all tasks below it, would the performance goal
be met?
YES: Continue, with step 7-9
NO: Stop until the situation changes. Continue to the
next application, steps 4-9.

7. Predict how to reduce time spent for this task, either


by:
a) Reducing the number of times this task is being done
OR
b) Reducing the time it takes to execute a task once

Note: If required, recursively perform steps 4-9 by


breaking the task down further into sub-tasks.

8. Perform a cost-benefit analysis of your plan in step 7.


Is it worthwhile? If so, do it.

9. Have you reached the performance goal of this


application?
YES: Proceed to the next application and perform steps
4-9.
NO: Proceed to the next task and repeat steps 6-9.

Notes:
1. By doing things in order of business importance

http://thinkoracle.blogspot.com/2006_03_01_archive.html (10 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

a) the users are most likely to experience results


b) anything we "harm" is, by definition, less important
2. By addressing tasks in order of time spent
a) we get the best results first
b) adverse results will only affect tasks that take less time
3. By defining success up front, and performing a cost-
benefit analysis before taking action, we can avoid
wasting time by stopping either
a) when the goal is met
b) when the goal is proven to be impossible.

Since this is a rough sketch, I especially invite people's


thoughts.

// posted by Robert Vollman @ Friday, March 10, 2006 4 comments

Wednesday, March 01, 2006


Handling exceptions
I've got a checklist of tasks I like to complete before
beginning a new project. One important item on my list
is to decide on how my exceptions are going to be
handled.

By deciding in advance, I can save time by implementing


exception handling only once, and also have much more
consistent code. I also find that once I begin a project,
I'm focusing on the logic and can easily miss handling
exceptions properly, so my code is much more robust
thinking about it in advance.

So what is an exception?

Well an exception is more about what it represents


rather than what it IS. The existence of an exception
means that something unexpected has failed in the run-
time execution of your code. It also means that this
execution has stopped.

Actually, I am slightly oversimplying the case, because


you can actually create and raise an exception yourself
without an unexpected failure, but generally you are only
going to do this if you have either found something
wrong, or you want to infuriate whoever is maintaining
your code.

Ok, so you've got an exception. Now what?

Good question. Your first choice is to do nothing. That

http://thinkoracle.blogspot.com/2006_03_01_archive.html (11 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

will cause your code block to fail, giving whatever


executed this block an opportunity to do something. If
you executed the block from SQL*Plus, (edit) all the (non-
COMMITed) work in your block and all (non-
autonomous) sub-blocks will be rolled back by the
database.

Your other option is to do something. Your only


opportunity to do this is in the EXCEPTION section of
your block. In this section you can examine the type of
exception, and handle it however you please.

Briefly, it looks like this:

EXCEPTION
WHEN ONE_KIND_OF_ERROR THEN
-- Do something here
WHEN OTHERS THEN
-- Handle all left over cases here
END

Once you're in there, you can get information about your


error by looking at SQLCODE and SQLERRM, which
contain the number and a text message for the latest
exception. Oddly enough (here's a little "gotcha") you
can't just insert these values to a table, for reasons I
discovered last July.

Incidentally, here is what the "do nothing" (edit or "hide


the error") option looks like:

EXCEPTION WHEN OTHERS THEN NULL;

Edit: Read Tom Kyte's comments to learn why some


people will strangle you with their bare hands if you ever
do this.

I want to do something. Uhh ... what should I do?

That's an even better question, and one that not a lot of


books or articles actually focus on. That's because you
have to figure out for yourself what you want to do when
something goes wrong. Do you want to write a message
to a table that you can query later? Are there some
business-specific steps you want to do? Do you want to
email yourself? Do you want to write to a log? Do you
want to send a text message to output?

http://thinkoracle.blogspot.com/2006_03_01_archive.html (12 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

Whatever you decide to do, don't forget to do any clean


up, because this is your only chance. Like I said,
execution of your code block is over, and there is no
avoiding that, so if you have something to do, do it now!

What if I don't want the execution to stop?

Too bad! The only way around that is to decide what


code falls into this category, and wrap it in its own,
nested block. Let me explain (and demonstrate).

Let's say you have several tasks to perform, and


regardless of whether the first one succeeds or not, you
want to continue to do the other tasks. Since execution
stops the moment you get an exception, this is a case
where you should wrap the first task in its own block,
and handle the exception there. It doesn't even have to
be a separate function/procedure, you can just create an
anonymous block right then and there, like this:

BEGIN
BEGIN
-- Do task one.
EXCEPTION
-- Handle it!
END
-- Do task two
-- Do task three ...
EXCEPTION
-- Handle exceptions from task two, three, ...
END

Don't forget to actually handle the exception in your


nested block! As I said before, unhandled exceptions
stop the execution of whatever called your block, too.

Incidentally, in some cases you actually want to stop the


execution of the calling block, but you still want to do
something right now in your current, failed block. But if
you handle it, then the exception is gone, and the calling
block will therefore just continue its execution. In that
case, you can re-raise the exception. The only caveat is
that whatever called your block will think that the
exception came from your exception handling code, not
the original point of failure. Keep that in mind.

Good stuff. So what do you do?

http://thinkoracle.blogspot.com/2006_03_01_archive.html (13 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

Personally, I like to define an exception package.

There I can do a few things. I like to define my own


exceptions (including number and text message) using
PRAGMA EXCEPTION_INIT. Then I can throw my custom
exceptions around.

But more importantly I can write a few different


procedures that can handle exceptions in standard ways,
and then all I have to do in my exception blocks is
choose which way I want to handle an error, and then
send the required information (usually SQLCODE and
SQLERRM) to these standard procedures.

Needless to say, I can put these packages together quite


quickly by re-using tested, trusted code from previous
projects.

A word on rollback

I mentioned previously that if you don't handle your


exceptions, SQL*Plus will rollback your work. It is
probably better for you if you decide what gets
committed, and what gets rolled back, and when.
Therefore you should be sure to include COMMIT
(preferably with SAVEPOINTs) and ROLLBACK
appropriately in your code. And while ROLLBACK is a
topic for another day, I should at least tell you to be
aware of autonomous transactions, which are special
blocks that will commit its work right away, regardless of
whether its calling block rolled back or not.

Whew, anything else?

Yeah, one more thing. Exceptions in the DECLARE block


can't be caught in the same block, but rather by the
calling block. Keep that in mind in your EXCEPTION block
when your block calls blocks with a DECLARE section.

In closing, it's important to note that this is a huge topic,


and I can't do it justice in one page. Fortunately Oracle
has a great write-up on handling PL/SQL Errors in the PL/
SQL User's Guide and Reference, see Chapter 7. It even
includes a list of pre-defined exceptions and what they
mean.

But the true master of PL/SQL Exception Handling is


doubtlessly Steven Feuerstein. I urge you to buy his book
on Oracle PL/SQL Programming, and check out Chapter 8
on exception handling. If at all possible, attend one of

http://thinkoracle.blogspot.com/2006_03_01_archive.html (14 of 15)1/9/2008 2:50:08 AM


OracleBlog: March 2006

his live presentations.

// posted by Robert Vollman @ Wednesday, March 01, 2006 10

comments

http://thinkoracle.blogspot.com/2006_03_01_archive.html (15 of 15)1/9/2008 2:50:08 AM


OracleBlog: April 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated, but it is the
most powerful tool when it comes to data. That's why when I think data, I think Oracle. I also enjoy writing, so I
use this format to organise my thoughts. Please feel free to discuss any thoughts you may have on the same
topics, even old ones (I will see and respond to such comments). You may want to start with "LIST ALL
ARTICLES" under Archives.

Monday, April 17, 2006


Updating Views
I was recently asked by a former colleague "Can you insert data in an Oracle table through a
View?"

In some cases, yes you can, and it actually serves as a handy technique to manage security on
your data. Here's what I mean: you can restrict access to a base table, and then create a view
containing only rows and columns that you wish to be accessible. That is just one of the many
handy uses of views. Quick hint: read up on the WITH CHECK OPTION to prevent changes to
base table rows to which you're trying to restrict access.

Now why did I say "in some cases?" Because inserting/updating data in a View depends on the
View. Why? Well a View is just a stored query against some base tables. When you're executing
DML operations on a View, Oracle actually executes those DML operations appropriately on
the base tables. And there are some cases where it is impossible for Oracle to do that. Let's
look at one simple example.

-- Create our data


CREATE TABLE BaseTable (field1 NUMBER(8), field2 NUMBER(8));
INSERT INTO BaseTable (field1, field2) VALUES (5, 10);
CREATE OR REPLACE VIEW UpdateViewYes
AS SELECT field1, field2 FROM BaseTable;
CREATE OR REPLACE VIEW UpdateViewNo
AS SELECT field1 + field2 addfield FROM BaseTable;
-- This won't work
SQL> UPDATE UpdateViewNo SET addfield = 16;
UPDATE UpdateViewNo SET addfield = 16
*
ERROR at line 1:
ORA-01733: virtual column not allowed here
-- This should work
UPDATE UpdateViewYes SET field1 = 6 WHERE field1 = 5;
SQL> UPDATE UpdateViewYes SET field1 = 6 WHERE field1 = 5;
1 row updated.
-- Look at our data now
SQL> SELECT * FROM BaseTable;
FIELD1 FIELD2
---------- ----------
6 10

http://thinkoracle.blogspot.com/2006_04_01_archive.html (1 of 8)1/9/2008 2:50:12 AM


OracleBlog: April 2006

In this example, UpdateViewNo.addfield is the addition of two columns. How would Oracle
know how to divide the new value we assigned? This argument would hold for any situation
where the View had a pseudocolumn or expression column, like this example, or perhaps one
created through the use of DECODE. Of course, these rows could still be deleted.

The Oracle SQL Reference details other situations where your View couldn't be updated. For
example, and along the same lines of reasoning, if the View contains a SET, DISTINCT, GROUP
BY, GROUP, ORDER BY, CONNECT BY, START WITH, then Oracle can't perform any update or
insert operations on the View. Same goes if you have a collection expression or a subquery in
a SELECT list.

USER_UPDATABALE_COLUMNS

Not sure if your View can be updated or not? Well you can simply try and see, but there is
another way. Find your View in the USER_UPDATABLE_COLUMNS table and see for yourself.

SQL> SELECT table_name, column_name, updatable


2 FROM user_updatable_columns
3 WHERE table_name LIKE 'UPDATEVIEW%';
TABLE_NAME COLUMN_NAME UPD
------------------------- ------------------------- ---
UPDATEVIEWNO ADDFIELD NO
UPDATEVIEWYES FIELD1 YES
UPDATEVIEWYES FIELD2 YES

WITH READ ONLY

What if you don't want anyone to update obase tables using your View? You can explicitly
prevent users from modifying the base table through your View by creating it with the WITH
READ ONLY clause. That signals to Oracle that your View is meant for querying only.

Join Views

Thus far I've been talking only about cases where the View is based on a single base table.
What about when the View joins one or more base tables? This is referred to as a Join View.

Updating join views is a whole different ball of wax. Simply put, you may be able to update
one base table through the view, provided your join clause uses a unique index. Otherwise,
there are workarounds. To learn more on this, read Norman Dunbar's article in Jonathan
Lewis' Oracle User's Co-Operative FAQ.

Briefly put, you can create a update trigger on that view to update the data in the base tables
appropriately. There is also an example on Building Complex Updatable Views Using Triggers
in the Application Developer's Guide, Chapter 15.

For more information on Views, including a list of what disqualifies a view from being
updateable, a description of Join Views, details of the WITH READ ONLY clause, examples and
much more, consult the Oracle SQL Reference, Chapter 16.

http://thinkoracle.blogspot.com/2006_04_01_archive.html (2 of 8)1/9/2008 2:50:12 AM


OracleBlog: April 2006

// posted by Robert Vollman @ Monday, April 17, 2006 3 comments

Monday, April 03, 2006


Pivot Queries Using Variable Number of Columns
Pivot queries (also known as crosstab queries) are a special kind of query that can turn rows
into columns for special reporting needs. For example, if you have a table/view with three
columns (employee name, year, and salary), and you need a view that shows employee name
and salary over the years (as a single row), then a pivot query is what you want. Essentially,
you want to "pivot" the year column from being rows to being a column.

I presented a simple, introductory example last September that used Canadian Football
League teams and their points per season as an example. That example worked fine at the
time, but what happened at the end of the CFL season? You entered some new rows of data to
reflect the results of the 2005 season, but the query is hard-coded to show only 2002-2004
seasons. What should you do now? Re-write your query after every season? Fortunately, there
is a better way. That is why today I would like to expand on this example to show you how to
write a pivot query in the common case where you have an undefined number of columns (in
this case, seasons/years).

First of all, let's add the 2005 season to our data. Also remember why I like to name my
columns when I insert (or call stored procedures):
INSERT INTO CFL (season, team, points) VALUES (2005, 'Argonauts', 22);
INSERT INTO CFL (season, team, points) VALUES (2005, 'Alouettes', 20);
INSERT INTO CFL (season, team, points) VALUES (2005, 'Renegades', 14);
INSERT INTO CFL (season, team, points) VALUES (2005, 'Tiger-Cats', 10);

Our problem is that we don't know how many columns we need when we write the query. We
only know how many columns we'll need at the time the query is executed. That sounds like a
job for dynamic SQL which, along with REF CURSORs, can build an appropriate query at the
time we call it. That technique is described in detail by Tom Kyte in his book Expert One-on-
One Oracle, in Chapter 12 on Analytic Functions. I will apply this technique to our specific
problem in an upcoming article.

Tom describes another way to get around this issue on his famous AskTom website. You can
leave the seasons as rows (allowing you to have as few or as many as you need), and pivot the
non-season columns instead. His solution leads us to another way of tackling this "I don't
know how many columns I'll need" problem. Make season/points a single column.

Solution #1: Leave Seasons as rows and pivot the Team column.

CREATE OR REPLACE TYPE Teams AS OBJECT


(team VARCHAR2(16), points NUMBER(3));

CREATE OR REPLACE TYPE Seasons AS TABLE OF Teams;

SELECT c1.season,
CAST(MULTISET(SELECT c2.team, sum(c2.points) tot_points
FROM CFL c2 WHERE c1.season = c2.season
GROUP BY c2.team) AS Seasons) Standings
FROM CFL c1
GROUP BY season;

SEASON

http://thinkoracle.blogspot.com/2006_04_01_archive.html (3 of 8)1/9/2008 2:50:12 AM


OracleBlog: April 2006

----------
STANDINGS(TEAM, POINTS)
--------------------------------------------------------------------------------
2002
SEASONS(TEAMS('Alouettes', 27), TEAMS('Argonauts', 16), TEAMS('Renegades', 10), TEAMS
('Tiger-Cats', 15))

2003
SEASONS(TEAMS('Alouettes', 26), TEAMS('Argonauts', 18), TEAMS('Renegades', 14), TEAMS
('Tiger-Cats', 2))

2004

SEASON
----------
STANDINGS(TEAM, POINTS)
--------------------------------------------------------------------------------
SEASONS(TEAMS('Alouettes', 28), TEAMS('Argonauts', 21), TEAMS('Renegades', 10), TEAMS
('Tiger-Cats', 19))

2005
SEASONS(TEAMS('Alouettes', 20), TEAMS('Argonauts', 22), TEAMS('Renegades', 14), TEAMS
('Tiger-Cats', 10))

Solution #2: Pivot Seasons, just like we did before, and create an array for seasons and points.

CREATE OR REPLACE TYPE SeasonResult AS OBJECT


(season NUMBER(4), points NUMBER(3));

CREATE OR REPLACE TYPE TeamResult AS TABLE OF SeasonResult;

SELECT c1.team,
CAST(MULTISET(SELECT c2.season, sum(c2.points) tot_points
FROM CFL c2 WHERE c1.team = c2.team
GROUP BY c2.season) AS TeamResult) Results
FROM CFL c1
GROUP BY team;

TEAM
----------------
RESULTS(SEASON, POINTS)
--------------------------------------------------------------------------------
Alouettes
TEAMRESULT(SEASONRESULT(2002, 27), SEASONRESULT(2003, 26), SEASONRESULT(2004, 28),
SEASONRESULT(2005, 20))

Argonauts
TEAMRESULT(SEASONRESULT(2002, 16), SEASONRESULT(2003, 18), SEASONRESULT(2004, 21),
SEASONRESULT(2005, 22))

Renegades

TEAM
----------------
RESULTS(SEASON, POINTS)
--------------------------------------------------------------------------------

http://thinkoracle.blogspot.com/2006_04_01_archive.html (4 of 8)1/9/2008 2:50:12 AM


OracleBlog: April 2006

TEAMRESULT(SEASONRESULT(2002, 10), SEASONRESULT(2003, 14), SEASONRESULT(2004, 10),


SEASONRESULT(2005, 14))

Tiger-Cats
TEAMRESULT(SEASONRESULT(2002, 15), SEASONRESULT(2003, 2), SEASONRESULT(2004, 19),
SEASONRESULT(2005, 10))

There are two consequences of this approach that are less than ideal. The query itself is a
little bit complicated, involves creating types and, secondly, if we made a view from this
query, its harder to use. (Example: Query that view to get me the season record for each
team). Fortunately there is a simple change we can make that gives us a query as simple as
our original example, and where we can create a view that can be more easily used for other
queries.

Before I tell you what it is, observe one thing about Tom's solution (#1). In the simpler
example where we knew how many columns (seasons) we'd need, we pivoted the seasons. In
this example, where we didn't know how many seasons we had, we pivoted the other columns
(team, points).

We are in the fortunate position where we know how many teams we have. Why not pivot
"team" column, and then do it largely like our simpler example?

CREATE OR REPLACE VIEW CFLBySeason AS


SELECT season,
MAX(DECODE(team, 'Argonauts', points, NULL)) Argonauts,
MAX(DECODE(team, 'Alouettes', points, NULL)) Alouettes,
MAX(DECODE(team, 'Renegades', points, NULL)) Renegades,
MAX(DECODE(team, 'Tiger-Cats', points, NULL)) TigerCats
FROM CFL
GROUP BY season;

SELECT * FROM CFLBySeason;

SEASON ARGONAUTS ALOUETTES RENEGADES TIGERCATS


---------- ---------- ---------- ---------- ----------
2002 16 27 10 15
2003 18 26 14 2
2004 21 28 10 19
2005 22 20 14 10

Not only do we have a simpler query, but we can leverage the power of views to keep things
simple. By turning this query into a view (called, for example, CFLBySeason), we can address
other requirements very easily.

Example:
1. Show me the most points any team has had in any one season. And it would be simple
enough to change this example to show total and/or average season performance as well.

SELECT MAX(Argonauts) Argonauts,


MAX(Alouettes) Alouettes,
MAX(Renegades) Renegades,
MAX(TigerCats) TigerCats
FROM CFLBySeason;

http://thinkoracle.blogspot.com/2006_04_01_archive.html (5 of 8)1/9/2008 2:50:12 AM


OracleBlog: April 2006

2. Show me how lopsided the division was each season

SELECT Season,
(Argonauts + Alouettes) TorMtl,
(Renegades + TigerCats) OttHam
FROM CFLBySeason;

3. I only care about Toronto. I want to see their season-by-season point totals.

SELECT Season, Argonauts FROM CFLBySeason;

I will admit that pivot queries can get complicated, but given how often they are the easiest
solution to complex requirements, it is worth the investment to understand them.

// posted by Robert Vollman @ Monday, April 03, 2006 0 comments

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I like playing sports
(hockey, soccer, ultimate, basketball, you name it) and military board games. I also enjoy
reading, walking, and playing with my 2 cats Lilly and Brutus. I'm a database application specialist,
whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

http://thinkoracle.blogspot.com/2006_04_01_archive.html (6 of 8)1/9/2008 2:50:12 AM


OracleBlog: April 2006

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006

http://thinkoracle.blogspot.com/2006_04_01_archive.html (7 of 8)1/9/2008 2:50:12 AM


OracleBlog: April 2006

❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

❍ Current Posts

http://thinkoracle.blogspot.com/2006_04_01_archive.html (8 of 8)1/9/2008 2:50:12 AM


OracleBlog: May 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics, even
old ones (I will see and respond to such comments). You may want to start with "LIST ALL
ARTICLES" under Archives.

Tuesday, May 30, 2006


Windowing Clauses
Answer: "Analytic Functions"

Question: "I have become quite comfortable, perhaps even adept, with
basic SQL queries. I am ready to learn how to do more with my data. What
do you recommend I study?"

Given how often I write about analytic functions, my answer may not come
as a surprise. To those who have been studying along with me, I would
like to add one more tool to our toolbelts. Following up on my recent
article about finding nearby rows, I would like to touch on windowing
clauses.

Life Without Windowing Clauses

Quick, find me the average of a value for all rows in a table. No problem,
right? Use the analytic function AVG.

Note: Sample data can be found at the end of the article.

SELECT AVG(votes) FROM elections;

AVG(VOTES)
----------------------
357315.2307692307692307692307692307692308

Great. Now, find me that average only for a certain range of data, say from

http://thinkoracle.blogspot.com/2006_05_01_archive.html (1 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

elections in 1990s only. Again, no problem.

SELECT AVG(votes) FROM elections WHERE election BETWEEN 1990 and


1999;

AVG(VOTES)
----------------------
461947.5

Ok. Now, for each row, find me the average from a 10 year range before
and after.

Um... errr...

How about the simply the average including the preceding and succeeding
rows?

Um ... errr ... what was the link to your article on finding nearby rows
again?

To the Rescue

Well you can relax. I am about to show you how to answer these
questions, and others like it. We'll answer these questions using
windowing clauses, which are the integral part of analytic functions that
define the set of rows you wish to work with.

First let's review analytic functions. You can go read Chapter 6 of the SQL
Reference, but generally, an analytic function comes in the following form:

ANALYTIC FUNCTION (ARGUMENT) OVER (QUERY PARTITION CLAUSE,


ORDER BY CLAUSE, WINDOWING CLAUSE);

Using windowing clauses, you can define which row to start with, which
row to end with including, if you wish, in reference to a specific row
(either by a range, or row number).

Now to let you off the hook. Here is an example of how to use windowing
clauses to determine the average of a column for a 10-year range, and an
average including the rows immediately before and after.

SELECT election, leader, votes,


CEIL(AVG(votes) OVER (ORDER BY election RANGE BETWEEN 10 preceding
AND 10 following)) ten_year,
CEIL(AVG(votes) OVER (ORDER BY election ROWS BETWEEN 1 preceding

http://thinkoracle.blogspot.com/2006_05_01_archive.html (2 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

AND 1 following)) before_after


FROM elections;

ELECTION LEADER VOTES TEN_YEAR


BEFORE_AFTER
-------- ------------ ------------ ------------
-------------
1959 Kirby 98730 93184
75004
1963 Harradance 51278 144122
93184
1967 Lougheed 129544 189250
159252
1971 Lougheed 296934 251124
265414
1975 Lougheed 369764 358565
358265
1979 Lougheed 408097 399552
455449
1982 Lougheed 588485 420075
454455
1986 Getty 366783 434118
440838
1989 Getty 367244 442418
391336
1993 Klein 439981 457035
430380
1997 Klein 483914 467097
517049
2001 Klein 627252 492060
509420
2004 Klein 417092 509420 522172

Armed with the knowledge of the windowing clause, we are finally


beginning to unleash the full power of analytic functions. With that in
mind, a closer look at the other two types of clauses are in order.

Query Partition Clause

Strictly speaking, the windowing clause is not the only way to define the
set of rows you wish to work with. The query partition clause can achieve
that same goal by grouping your data on a single, specific value (or set of

http://thinkoracle.blogspot.com/2006_05_01_archive.html (3 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

values).

For example, say we wanted the average number of votes by leader. No


problem using GROUP BY, right?

SELECT leader, AVG(votes) avg_votes FROM elections GROUP BY leader;

LEADER AVG_VOTES
-------------------------------- ----------------------
Getty 367013.5
Harradance 51278
Kirby 98730
Klein 492059.75
Lougheed 358564.8

By using the partitioning clause we can achieve the same result, but use it
in other ways. For example, to compare the average to every row.

SELECT election, leader, votes,


CEIL(votes - AVG (votes) OVER (PARTITION BY leader)) diff
FROM elections ORDER BY diff desc;

ELECTION LEADER VOTES DIFF


-------- ------------- --------- ---------
1982 Lougheed 588485 229921
2001 Klein 627252 135193
1979 Lougheed 408097 49533
1975 Lougheed 369764 11200
1989 Getty 367244 231
1963 Harradance 51278 0
1959 Kirby 98730 0
1986 Getty 366783 -230
1997 Klein 483914 -8145
1993 Klein 439981 -52078
1971 Lougheed 296934 -61630
2004 Klein 417092 -74967
1967 Lougheed 129544 -229020

Putting the partitioning clause and the windowing clause together is like
mixing chocolate and peanut butter. Alone, they're great, together they're

http://thinkoracle.blogspot.com/2006_05_01_archive.html (4 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

even better. We could solve such complex problems as "For each row,
show me the average that includes the immediately preceding and
succeeding rows that share the same id."

Further Reading

Other than the SQL Reference, and Chapter 19 "SQL for Analysis" of the
Data Warehousing Guide, my primary sources include Chapter 12 of Tom
Kyte's "Expert One-on-One Oracle" and Daniel Morgan's on-line reference.

Beyond that, there are a lot of fine articles on specific applications. For
beginners, I would review an anonymous contribution to Howard Rogers'
wiki introduction to analytic functions, which also includes a great
example.

I will close with the final ingredient to analytic functions, the order by
clause.

Creating Rolling Averages

By using the order by clause within the context of the analytic function,
we can create rolling averages.

SELECT election, leader, votes,


CEIL(AVG (votes) OVER (ORDER BY election)) rolling_avg
FROM elections;

ELECTION LEADER VOTES ROLLING_AVG


-------- ------------- ---------- -------------
1959 Kirby 98730 98730
1963 Harradance 51278 75004
1967 Lougheed 129544 93184
1971 Lougheed 296934 144122
1975 Lougheed 369764 189250
1979 Lougheed 408097 225725
1982 Lougheed 588485 277548
1986 Getty 366783 288702
1989 Getty 367244 297429
1993 Klein 439981 311684
1997 Klein 483914 327342
2001 Klein 627252 352334
2004 Klein 417092 357316

http://thinkoracle.blogspot.com/2006_05_01_archive.html (5 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

--

Sample data used in this article:

CREATE TABLE elections (election NUMBER(4), party VARCHAR2(32), leader


VARCHAR2(32), seats NUMBER(2), votes NUMBER(7), tot_seats NUMBER(2),
tot_votes NUMBER(7));

INSERT INTO elections VALUES (2004, 'PC', 'Klein', 61, 417092, 83,
890700);
INSERT INTO elections VALUES (2001, 'PC', 'Klein', 74, 627252, 83,
1013152);
INSERT INTO elections VALUES (1997, 'PC', 'Klein', 63, 483914, 83,
845713);
INSERT INTO elections VALUES (1993, 'PC', 'Klein', 51, 439981, 83,
989025);
INSERT INTO elections VALUES (1989, 'PC', 'Getty', 59, 367244, 83,
829189);
INSERT INTO elections VALUES (1986, 'PC', 'Getty', 61, 366783, 83,
713654);
INSERT INTO elections VALUES (1982, 'PC', 'Lougheed', 75, 588485, 79,
944936);
INSERT INTO elections VALUES (1979, 'PC', 'Lougheed', 74, 408097, 79,
710963);
INSERT INTO elections VALUES (1975, 'PC', 'Lougheed', 69, 369764, 75,
590200);
INSERT INTO elections VALUES (1971, 'PC', 'Lougheed', 49, 296934, 75,
639862);
INSERT INTO elections VALUES (1967, 'PC', 'Lougheed', 6, 129544, 65,
498351);
INSERT INTO elections VALUES (1963, 'PC', 'Harradance', 0, 51278, 63,
403444);
INSERT INTO elections VALUES (1959, 'PC', 'Kirby', 1, 98730, 65, 413516);

// posted by Robert Vollman @ Tuesday, May 30, 2006 0 comments

Tuesday, May 09, 2006


Finding Nearby Rows
Today's question is how do you find rows that have values nearest the
value of a given row?

http://thinkoracle.blogspot.com/2006_05_01_archive.html (6 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

Although there are many different variations on this central theme, in


order to solve problems of this nature, you'll need to know:

1. The given column's value for the given row


2. The difference between each row's value and the value of the given row
3. That row's difference's relationship to all the other rows.

Step 1 is easy, 2 and 3 are more difficult.

For starters, let's say my requirement is to find the 2 battles that started
nearest the beginning of the battle of Batoche. Here's how I first attacked
that problem.
Note: You can find my test data at the end of this blog if you want to try it
for yourself.

SELECT loc, difference FROM


(SELECT a.loc, ABS(a.start_date - b.start_date) difference
FROM battles a,
(SELECT start_date FROM battles WHERE loc = 'BATOCHE') b
ORDER BY difference)
WHERE rownum < 3;

LOC DIFFERENCE
-------------------- ----------------------
BATOCHE 0
CUT KNIFE 7
FISH CREEK 15

Despite my use of ROWNUM to get just the two closest rows, I will admit
that my result is not satisfying, because I don't like going through the
same data more than once. Once to find the value of the given row, and
another to figure out the differences. Blech!

I do have a better solution, but first let's say my requirements are a little
tougher, to the point where this solution won't even work. For example:

1. In the above example, the two nearest rows both happened to be prior
to the given row. Let's say my requirements are to find the rows
immediately preceding the given row, and the rows immediately
succeeding it.

AND let's also say

http://thinkoracle.blogspot.com/2006_05_01_archive.html (7 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

2. I want the TWO rows immediately before and immediately after instead
of just one.

What then?

RANK

For starters, we can use the analytic function RANK instead of ROWNUM
for an easier way to get the order in which the rows are presented.

Once again, the 'b' query gives us the rank of our given row, and now the
'a' query will get a list of all the locations and their respective RANK. Now
we can take as many rows as we want from that centrepoint.

SELECT loc FROM


(SELECT a.loc, ABS(a.battle_num - b.battle_num) distance FROM
(SELECT loc, RANK() OVER (ORDER BY start_date) battle_num FROM battles)
a,
(SELECT loc, RANK() OVER (ORDER BY start_date) battle_num FROM battles)
b
WHERE b.loc = 'BATOCHE')
WHERE distance BETWEEN 1 AND 2;

LOC
--------------------
FISH CREEK
CUT KNIFE
FRENCHMAN'S BUTTE
LOON LAKE

I'm still annoyed about the inelegance of the solution, because we're still
going through my data more than once. Is there a better way?

LEAD and LAG

With LEAD and LAG you can access multiple rows without a self-join
(joining a table to itself). With that, we can do all sorts of fancy things,
such as figure out how many days have passed since the last battle
started, and how long until the next one began.

SELECT loc, start_date,


start_date - LAG(start_date, 1, NULL) OVER (ORDER BY start_date) AS

http://thinkoracle.blogspot.com/2006_05_01_archive.html (8 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

last_battle,
LEAD(start_date, 1, NULL) OVER (ORDER BY start_date) - start_date AS
next_battle
FROM battles;

Back to the task at hand, armed with LAG and LEAD, we can create a list of
all rows including the value of the previous row, and the value of the next
one. From that, its pretty trivial to select the rows we want.

SELECT loc FROM (SELECT loc,


LAG(loc, 1, NULL) OVER (ORDER BY start_date) previous_battle,
LEAD(loc, 1, NULL) OVER (ORDER BY start_date) next_battle
FROM battles)
WHERE previous_battle = 'BATOCHE' OR next_battle = 'BATOCHE';

LOC
--------------------
CUT KNIFE
FRENCHMAN'S BUTTE

That's very nice! But what about the requirement to get the TWO rows
immediately preceding and succeeding the given row, can we still do that
with LAG and LEAD?

The SQL Reference describes how to use LAG and LEAD, under Chapter 6,
Functions. There it is explained that the second parameter to LAG and
LEAD is the number of rows to look. So we can look 2 battles before and
after Batoche, and use DECODE to make it a single column.

SELECT loc FROM


(SELECT loc, DECODE(LAG(loc, 1, NULL) OVER (ORDER BY start_date),
'BATOCHE', 1, 0) +
DECODE(LAG(loc, 2, NULL) OVER (ORDER BY start_date), 'BATOCHE', 1, 0) +
DECODE(LEAD(loc, 1, NULL) OVER (ORDER BY start_date), 'BATOCHE', 1, 0)
+
DECODE(LEAD(loc, 2, NULL) OVER (ORDER BY start_date), 'BATOCHE', 1, 0)
near_batoche
FROM battles)
WHERE near_batoche > 0;

LOC
--------------------

http://thinkoracle.blogspot.com/2006_05_01_archive.html (9 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

FISH CREEK
CUT KNIFE
FRENCHMAN'S BUTTE
LOON LAKE

Depending how many rows you want, this query will get bigger and uglier,
so you may want to revert to using the RANK example instead. If you like
the looks of LAG and LEAD, Tim Hall has a good introduction article worth
reviewing.

Performance

I guess the big question is related to the performance implications of each


approach. Granted I have a small amount of data, but here are the
differences I observed

ROWNUM example, 2 nearest rows:


Slowest of the three, had more parse, executes and queries than the other
two combined. The query came in three pieces, the first two of which had
full table accesses, the last of which having a nested loop with a table
access, a sort, and a view.

RANK example, looking 1 or 2 rows:


No real difference between 1 or 2 rows. Slower than LAG/LEAD with
double the parse/execute/fetch. Came in two pieces, the first of which
had a full access, the second of which had 2 nested loops, 2 full accesses,
and 2 sorts, including one that was cartesian (49 rows).

LAG/LEAD example, looking 1 or 2 rows:


No real difference between 1 or 2 rows. Faster of the three, lowest parse/
execute/fetch. Came in two pieces, both of which had a full access, but
the second of which also had a sort and a view.

In terms of performance, it looks like LAG/LEAD wins, on this sample


data.

Sample data:
CREATE TABLE battles (loc VARCHAR2(20), start_date DATE, canadian
VARCHAR2(20), rebel VARCHAR2(20));
INSERT INTO battles VALUES ('DUCK LAKE', '26-March-1885', 'Crozier',
'Dumont');
INSERT INTO battles VALUES ('FORT PITT', '15-April-1885', 'Dickens', 'Big

http://thinkoracle.blogspot.com/2006_05_01_archive.html (10 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

Bear');
INSERT INTO battles VALUES ('FISH CREEK', '24-April-1885', 'Middleton',
'Dumont');
INSERT INTO battles VALUES ('CUT KNIFE', '2-May-1885', 'Otter',
'Poundmaker');
INSERT INTO battles VALUES ('BATOCHE', '9-May-1885', 'Middleton',
'Dumont');
INSERT INTO battles VALUES ('FRENCHMAN''S BUTTE', '28-May-1885',
'Strange', 'Wandering Spirit');
INSERT INTO battles VALUES ('LOON LAKE', '3-June-1885', 'Steele',
'Wandering Spirit');

Bonus: My favourite recent blog article was James Koopmann's recent


write-up on storing Word Documents in Oracle.

// posted by Robert Vollman @ Tuesday, May 09, 2006 2 comments

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis

http://thinkoracle.blogspot.com/2006_05_01_archive.html (11 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

http://thinkoracle.blogspot.com/2006_05_01_archive.html (12 of 13)1/9/2008 2:50:16 AM


OracleBlog: May 2006

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

❍ Current Posts

http://thinkoracle.blogspot.com/2006_05_01_archive.html (13 of 13)1/9/2008 2:50:16 AM


OracleBlog: June 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, June 27, 2006


About Me
Recursion vs Iteration Name: Robert
When writing code to do repetitive tasks, the Vollman
two primary approaches are iteration and Location: Calgary,
recursion. Generally you can use either one Alberta, Canada
interchangeably, but potentially with different
performance and complexity.
I was born and raised in Ottawa,
A recursive function calls itself (possibly more and have lived in Calgary since
than once), with different parameters, and 1991. I like playing sports
defines an exit clause that is guaranteed to be (hockey, soccer, ultimate,
reached. basketball, you name it) and
military board games. I also
CREATE OR REPLACE FUNCTION enjoy reading, walking, and
FIBONACCI_REC (in_number IN NUMBER) playing with my 2 cats Lilly and
RETURN NUMBER DETERMINISTIC Brutus. I'm a database
AS application specialist, whatever
BEGIN that is.
CASE
WHEN in_number = 1 THEN RETURN 1; View my complete profile
WHEN in_number = 2 THEN RETURN 1;
ELSE RETURN (FIBONACCI_REC (in_number -
1) + FIBONACCI_REC (in_number - 2));
END CASE;
Best Links
Ask Tom Kyte
END;

● Oracle Docs
An iterative function includes a loop, which ● Dan Morgan and PSOUG

http://thinkoracle.blogspot.com/2006_06_01_archive.html (1 of 10)1/9/2008 2:50:20 AM


OracleBlog: June 2006

iterates a pre-determined number of times, ● Steven Feuerstein


or checks for an exit clause every time ● Jonathan Lewis
through. ● FAQ
● Connor McDonald
CREATE OR REPLACE FUNCTION FIBONACCI_IT
The Oak Table
(in_number IN NUMBER)

Cary Millsap and Hotsos


RETURN NUMBER DETERMINISTIC

Steve Adams and Ixora


AS ●

fib1 NUMBER := 1; ● Anjo Kolk and OraPerf


fib2 NUMBER := 1; ● Dizwell Oracle Wiki
fib3 NUMBER := 1; ● My Personal Blog
fib4 NUMBER;
BEGIN
FOR fib4 IN 3 .. in_number
LOOP Aggregators
fib3 := fib1 + fib2; Brian Duff's OraBlogs

fib1 := fib2; Eddie Awad's OracleNA
fib2 := fib3;

Pete Finnigan's Aggregator


END LOOP;

Oracle's Bloglist
RETURN fib3;

Oracle Base Aggregator


END; ❍

The advantages and disadvantages of the two Top Blogs


are not always obvious, and you should really ❍ Oracle's Ask Tom Kyte
take it on a case-by-case basis. When in ❍ Oracle Guru Jonathan Lewis
doubt: test it. But generally: ❍ Blogger of the Year Eddie Awad
Data Warehouser David Aldridge
1. Recursion may be slower, and use greater

Oracle Geek Lewis Cunningham


resources, because of the extra function calls.

❍ Database Expert James Koopmann


2. Recursion may lead to simpler, shorter, ❍ Dizwell's Howard Rogers
easier-to-understand functions, especially for ❍ Oracle Master Laurent Schneider
mathematicians who are comfortable with ❍ Security Expert Pete Finnigan
induction formulae. ❍ Oracle Award Winner Mark
Rittman
Either way, one of the most critical aspects of Doug Burns
writing either a recursive or an iterative

Oracle ACE of the Year Dr. Tim


function is to have an exit clause (or "base

Hall
case" for recursions) that is checked at every
UKOUG's Andrew (Arfur C.) Clarke
recursion/iteration and is guaranteed to be

reached at some finite point, given any input. ❍ Newbie DBA Lisa Dobson
Otherwise you will get either: ❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
Infinite Recursion: More and more functions ❍ The Pythian DBA Team Blog

http://thinkoracle.blogspot.com/2006_06_01_archive.html (2 of 10)1/9/2008 2:50:20 AM


OracleBlog: June 2006

being spawned, never closing, using up DBA Don Seiler


resources until there are none left, possibly ❍ DBA Coskan Gundogar
crashing the system. ❍ Oracle WTF

Infinite loop: A loop that cycles forever,


burning CPU and never completing.
ARCHIVES
❍ LIST ALL ARTICLES
I can illustrate this point with my recursive ❍ May 2005
example above. Do NOT try this, but if you ❍ June 2005
inserted a negative number, what do you ❍ July 2005
think would happen? Infinite recursion. ❍ August 2005
September 2005
Now you have not only the basics on iteration

October 2005
and recursion, but, based on the topic I chose

November 2005
for the sample code, knowledge that I saw "Da ❍

Vinci Code" recently. ❍ December 2005


❍ January 2006
// posted by Robert Vollman @ Tuesday, June 27, ❍ February 2006
❍ March 2006
2006 13 comments
❍ April 2006
❍ May 2006
❍ June 2006
Sunday, June 18, 2006
July 2006
Meeting Tom Kyte

August 2006
"You have redeemed my faith, after last year's

September 2006
presentation, which was such a

October 2006
disappointment."- One of Tom Kyte's biggest

fans in COUG ❍ November 2006


❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

❍ Current Posts

Renowned Oracle expert and author of highly

http://thinkoracle.blogspot.com/2006_06_01_archive.html (3 of 10)1/9/2008 2:50:20 AM


OracleBlog: June 2006

popular blog, pictured here with Tom Kyte.

I first met Tom Kyte about twenty minutes


before his presentation about his favourite
features in Oracle 10g. When I went up to
introduce myself, I figured he was putting the
final touches on his presentation, but he was
actually answering questions for his AskTom
web site. I guess you have to find the time for
that somewhere!

Due in part to his reputation for fine speeches


(his biggest fan notwithstanding), there were
quite a few people in attendance. Tom reports
having answered 33,000 different Oracle-
related questions. I wonder how many people
were there hoping they could find that one
question that pushed him over the edge.
Sadly, no such luck.

I enjoyed the presentation myself, despite still


being on Oracle 9. Based on some of the
features, including DBMS_SQLTUNE which
uses SQL Profiles to find patterns in your data
that can help speed up queries, I wonder how
long before he comes to town announcing
that the next release of Oracle is sentient.

I was a little surprised to hear his excitement


about DBMS_ADVANCED_REWRITE, which
allows you to tell Oracle "listen, when I write
this query, what I REALLY want is this
completely different query." I can't believe I'm
going to have to learn to start typing
"FOR_REAL" after all my queries. Maybe in
Oracle 11 we'll need
"NO_SERIOUSLY_I_MEAN_IT".

On a more serious note, it sounds like Oracle


10 has a lot more bells and whistles
ultimately aimed to speed things up. Take PL/
SQL compilation for example. When you
"CREATE OR REPLACE" it will check whether a
recompilation is really necessary, and will also

http://thinkoracle.blogspot.com/2006_06_01_archive.html (4 of 10)1/9/2008 2:50:20 AM


OracleBlog: June 2006

look for optimizations within your code. I


guess the end result is a little bit more
overhead to check for things, but faster
results, especially for inexperienced
programmers.

Afterwards we all retired to Bottlescrew Bill's


for COUG's annual social, where I enjoyed
Tom's stories almost as much as his
presentation. In contrast to the light-hearted
ribbing with which I began this post, virtually
everyone ranks him as one of the very best
Oracle speakers. I'm really glad he paid us a
visit, and look forward to hearing him again.

// posted by Robert Vollman @ Sunday, June 18, 2006 0

comments

Tuesday, June 13, 2006


Refreshing Data
Moving data from one database to another is
a very common task for a database
administrator. So common, in fact, that I have
never bothered to write about it, because
most DBAs already have their own preferred
method.

http://thinkoracle.blogspot.com/2006_06_01_archive.html (5 of 10)1/9/2008 2:50:20 AM


OracleBlog: June 2006

If you haven't chosen your approach yet, allow


me to show you the general flow, some points
to keep in mind, and some of the decisions
you'll have to make based upon the nature of
your data and the tools at your disposal.

1. Lose Your Integrity

What do you do when you have one tables


that relies on another, through a foreign key?
In order to avoid having your import fail, you
would need to have the tables loaded in the
right order. Or, you could just disable all
constraints.

Why all constraints? Why not just the foreign


keys? Well, checking constraints takes time.
Presumably this is data you're grabbing from
an environment where these constraints have
already been checked, why check them again?
If you don't trust that data, don't worry, you'll
catch the errors when you try to re-enable the
constraints later on.

You may want to disable triggers while you're


at it. Presumably those have already fired
when the data was first entered, and those
can be time consuming as well.

While you're in the disabling mood, drop your


indexes. It will just take time to update them
with every row you insert. Just drop them now
and re-create them when you're done. Much
faster over-all.

One more thing, you want to do these and all


subsequent steps with logging turned off.
Why keep a redo log of each transaction?
That's just taking time and space. Chances
are your mentality is that either all the data
gets in, or all of it doesn't.

2. Wipe Out Your Data

http://thinkoracle.blogspot.com/2006_06_01_archive.html (6 of 10)1/9/2008 2:50:20 AM


OracleBlog: June 2006

You may already have data in the target


database that you want to replace. You could
insert your data in such a way that it checks if
the data already exists before adding it. But
that takes time and effort. Instead, you may
just want to wipe out and re-insert all your
data.

What is the best way to eliminate your data?


Don't use "delete." Delete is for selectively
deleting a subset of rows, or if you want to be
able to rollback your work. Instead, in this
case, truncate your data. No logging: much
faster.

By the way, when you're truncating, you'll be


glad that you disabled your foreign key
constraints. Otherwise you'd have to be very
careful in the order you truncated your tables.

You may want to consider using "reuse


storage" which will keep the space reserved
for the data. Since you're probably going to
be inserting a roughly equal or superior
amount of data, this will save you from having
to expand your extents during the import.

An alternative to all this is to drop all the


tables and then have your import process re-
create the tables with the data involved. That
option is only appealing if you're not 100%
confident the table structure is the same,
otherwise I don't see the point.

Before you wipe out your data, I'm assuming


either you already have a backup, or you don't
care about this data. Otherwise, you should
have done this first:

3. Dump Your Data

Which is outside the scope of this article. :)

4. Copy Your Dump

http://thinkoracle.blogspot.com/2006_06_01_archive.html (7 of 10)1/9/2008 2:50:20 AM


OracleBlog: June 2006

5. Import the Data

There are many different tools you can use to


import your data, and each one has many
different methods and options. Here is a brief
list of your choices which, of course, depend
on how you dumped your data.

SQL*Loader/SQLLDR (Check the Oracle Server


Utilities Guide, Part 2)
IMP utility
Oracle 10g Data Pump Export and Import
(DBMS_DATAPUMP)
Oracle Data Manager (Oracle Enterprise
Manager Console)
Your own custom application (possibly using
Oracle Call Interface/OCI).

If your data import is still ridiculously slow,


ask yourself if you're using RAID 5. Are you?
RAID 5 is slow, man. No getting around that,
that's the nature of the beast.

6. Restore Your Integrity

Now that the job is done, it is time to restore


your integrity (and lose your faith in man). Re-
enable your constraints, and triggers, and
restore your indexes. This may take some
time, so get a coffee.

7. Recalculate Statistics

In order for the optimizer to work effectively


you'll need to re-calculate your statistics
(DBMS_STATS.GATHER_SCHEMA_STATISTICS).
If it knows how big the tables are, the
optimizer will be able to make the best
choices in query plans. You can import the
statistics, if they were kept up-to-date in
your production system, but might as well
gather them now.

http://thinkoracle.blogspot.com/2006_06_01_archive.html (8 of 10)1/9/2008 2:50:20 AM


OracleBlog: June 2006

That's it!

This was by no means meant to be a


comprehensive step-by-step guide with an
exhaustive list of everything to consider. But
at least now I've made an attempt to draw out
the basic flow, and some of the things you
should keep in mind. Hopefully this will help
you design a solution of your own, most
appropriate for your data and how you use it.

// posted by Robert Vollman @ Tuesday, June 13, 2006 3

comments

Wednesday, June 07, 2006


Call For Topics
This morning I read that fellow Oracle blogger
Tim Hall is looking for Oracle topics on which
to base his next article. It occurs to me that
since changing positions a few months ago
that I have dealt with Oracle a lot less than
previously, and am open to hearing some
ideas.

Virtually all my articles are based on


questions I get from customers or colleagues,
or problems I have to solve in my day-to-day
work. There are times when that stream is a
trickle, and times when its a raging river.

Right now its a trickle. But I'd like to keep up


the momentum rather than have this blog go
the way of my Sybase blog.

And don't confine your questions to my area


of interest (development), because I happen
to know that several other excellent bloggers
like Eddie Awad, Gary Myers, Tom Kyte, Doug
Burns and others may also pick up on any
ideas you leave in my comments.

Well maybe not Tom, I think he gets enough

http://thinkoracle.blogspot.com/2006_06_01_archive.html (9 of 10)1/9/2008 2:50:20 AM


OracleBlog: June 2006

questions. :)

// posted by Robert Vollman @ Wednesday, June 07,

2006 2 comments

http://thinkoracle.blogspot.com/2006_06_01_archive.html (10 of 10)1/9/2008 2:50:20 AM


OracleBlog: July 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, July 25, 2006


About Me
Ask Tom Name: Robert
In keeping with the theme of my most recent Vollman
post, I just couldn't stop laughing at Tom's Location: Calgary,
most recent response to a question about Alberta, Canada
recursive sql.
I was born and raised in Ottawa,
// posted by Robert Vollman @ Tuesday, July 25, 2006 4
and have lived in Calgary since
comments 1991. I like playing sports
(hockey, soccer, ultimate,
basketball, you name it) and
Wednesday, July 19, 2006 military board games. I also
enjoy reading, walking, and
Finding Information playing with my 2 cats Lilly and
QUESTION Brutus. I'm a database
application specialist, whatever
Hi Robert,
that is.
I don't understand the meaning of any of the
items on the query plan. View my complete profile

Is there some document that would explain


what they are? If there is, where can I get it? Best Links
Thanks. ● Ask Tom Kyte
● Oracle Docs
ANSWER ● Dan Morgan and PSOUG

http://thinkoracle.blogspot.com/2006_07_01_archive.html (1 of 7)1/9/2008 2:50:23 AM


OracleBlog: July 2006

That's the best kind of question. Instead of ● Steven Feuerstein


sending me a query plan and asking me to ● Jonathan Lewis
interpret it for you, you're asking me for the ● FAQ
means to do it yourself. Which is good ● Connor McDonald
because there is so much I don't understand ● The Oak Table
about Oracle that I would have to study up to ● Cary Millsap and Hotsos
help you anyway.
● Steve Adams and Ixora
Oracle Documentation ● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
I love Oracle documentation. I can usually find ● My Personal Blog
what I want in there, complete with examples
and explanations. So let's start there.

Once you have navigated to Oracle's


documentation page, you'll want to select
Aggregators
Brian Duff's OraBlogs

"View Library" and then go thorugh the ❍ Eddie Awad's OracleNA
searching page. ❍ Pete Finnigan's Aggregator
Choosing the right phrase can be tricky. In ❍ Oracle's Bloglist
this case, try TKPROF, Query Plan, Execution ❍ Oracle Base Aggregator
Plan.
Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark
Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim
Hall
Searching with any of these three phrases ❍ UKOUG's Andrew (Arfur C.) Clarke
points rather conclusively at the Oracle
❍ Newbie DBA Lisa Dobson
Performance Tuning Guide and Reference. ❍ Coffee-Drinking DBA Jon Emmons
Taking a look through it, it seems to have lots ❍ Chris Foot
of information to get you started on how to
❍ The Pythian DBA Team Blog

http://thinkoracle.blogspot.com/2006_07_01_archive.html (2 of 7)1/9/2008 2:50:23 AM


OracleBlog: July 2006

understand the execution plans you see in the DBA Don Seiler

TKPROF output. ❍ DBA Coskan Gundogar


❍ Oracle WTF
Ask Tom

The second thing I like to do is Ask Tom. He


ARCHIVES
has answered 33,000 questions, meaning that ❍ LIST ALL ARTICLES
in any case, my question was probably ❍ May 2005
already asked. Sometimes his answers include ❍ June 2005
links to other information. ❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
Searching our three chosen phrases points to ❍ December 2006
one Ask Tom article in particular that might ❍ January 2007
be helpful. ❍ February 2007
March 2007
Google

❍ April 2007
Sometimes I can google around to find ❍ May 2007
articles on a topic. Normally I favour sources I ❍ June 2007
trust, like Jonathan Lewis or something. In ❍ October 2007
this case, googling found me this article:
❍ Current Posts
Use EXPLAIN PLAN and TKRPOF To Tune Your
Applications, by Roger Schrag

Still Stuck?

If you've gone through these sources and you

http://thinkoracle.blogspot.com/2006_07_01_archive.html (3 of 7)1/9/2008 2:50:23 AM


OracleBlog: July 2006

still haven't found the information you're


looking for, it's time for a degree of
intrepidity.

I would certainly want to contact my fellow


Oracle specialists. But rather than contact one
individually with an open-ended question, I
would post a message to a forum or message
board, making sure to highlight what I had
already looked for, what I had already found,
and specifically how it came up short.

It is possible that the information I'm looking


for has never been written. If so, that would
be a great opportunity for me to do some
research and make my own, new contribution
to the Oracle community.

// posted by Robert Vollman @ Wednesday, July 19,

2006 2 comments

Tuesday, July 04, 2006


Oracle and Java
Last December I wrote about how to create a
simple Perl application that connected to your
Oracle database, it is high time that I showed
you how to do the same in Java.

What You'll Need

1. An Oracle database. Make sure you can


tnsping your ORACLE_SID. Better yet, make
sure you can connect with sqlplus.

2. Java. It's a free download from Sun. I'm


using 1.5, but I've tested this on several
versions.

3. You don't need the client installed because


we're using the thin client. If you want to use
OCI but don't want to install the full Oracle
client, download the instant client.

http://thinkoracle.blogspot.com/2006_07_01_archive.html (4 of 7)1/9/2008 2:50:23 AM


OracleBlog: July 2006

Set your PATH

As part of your Java installation, you must


have set the path to your jdk\bin. Make sure
that's there and add it if not.

Set your CLASSPATH

If you're using Java 1.4 or greater, then


ojdbc14.jar contains the classes you need.
You'll find it in ORACLE_HOME/jdbc/lib.

And more information on this? You can unzip


the jar file and look at the files inside with
some Java tools, search the Internet or, best
yet, check out ORACLE_HOME/jdbc/doc/
javadoc.tar. That's a complete API: all the
classes and their parameters.

If you're using an older version, you'll want


something like classes12.jar instead. Follow
the installation instructions. But do NOT
include this if you're on 1.4 or greater. You
want one or the other, not both.

There is also one thing that seems to always


get me when I start a java project. I always
forget to add the local directory to the
CLASSPATH. Save yourself the 20 wasted
minutes and put it first.

C:\temp>echo %CLASSPATH%
.;c:\oracle\product\10.1.0\db\jdbc\lib
\ojdbc14.jar

Include Your Classes

Though you may want others, here are the


main classes you'll need to import. The
former should be part of your Java SDK, the
latter is in the aforementioned ojdbc14.jar.

import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;

http://thinkoracle.blogspot.com/2006_07_01_archive.html (5 of 7)1/9/2008 2:50:23 AM


OracleBlog: July 2006

Create an OracleDataSource

Once you've created an OracleDataSource,


you'll be free to write your SQL calls. My
example below shows the syntax for a default
installation, you'll need to modify that second
line as appropriate.

OracleDataSource ods = new


OracleDataSource();
ods.setURL("jdbc:oracle:thin:scott/
tiger@localhost:1521:ORCL");
Connection conn = ods.getConnection();

Check the documentation, there are other


ways of doing this.

Query Away!

There are many ways to use your connection


to query your database. Here is one quick
sample I found.

Statement stmt = conn.createStatement();


ResultSet rset = stmt.executeQuery("select
'Hello World' from dual");
while (rset.next())
System.out.println(rset.getString(1));

Compile and Execute

You'll need to compile your application before


you execute.

javac JdbcVersion.java
java JdbcVersion

If you get this error:

Exception in thread "main" java.lang.


NoClassDefFoundError

Then check your CLASSPATH very carefully.


You can run java with the -verbose option to

http://thinkoracle.blogspot.com/2006_07_01_archive.html (6 of 7)1/9/2008 2:50:23 AM


OracleBlog: July 2006

see if you get more information about what's


missing.

That's it!

For more information, review the


documentation to which the README file
points you:

1. The new technical white paper

2. The online JDBC doc for the most updated


information

3. The revised JDBC FAQ

4. The JDBC Developer's Guide and Reference

// posted by Robert Vollman @ Tuesday, July 04, 2006 1

comments

http://thinkoracle.blogspot.com/2006_07_01_archive.html (7 of 7)1/9/2008 2:50:23 AM


OracleBlog: August 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, August
About Me
11, 2006
Name: Robert Vollman
PL/SQL Location: Calgary, Alberta, Canada
Procedure
Call I was born and raised in Ottawa, and have lived in
Calgary since 1991. I like playing sports (hockey,
Overhead soccer, ultimate, basketball, you name it) and military board games.
Re-visited I also enjoy reading, walking, and playing with my 2 cats Lilly and
Zsolt Lajosfalvi Brutus. I'm a database application specialist, whatever that is.
wrote such an
interesting View my complete profile
comment in
response to
my earlier post
about PL/SQL
Best Links
Ask Tom Kyte
Procedure Call

Oracle Docs
Overhead that

Dan Morgan and PSOUG


I felt it

Steven Feuerstein
deserved its

Jonathan Lewis
own space. ●

● FAQ
What follows is ● Connor McDonald
exclusively the ● The Oak Table
work of Zsolt. ● Cary Millsap and Hotsos
My results ● Steve Adams and Ixora
from verifying ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2006_08_01_archive.html (1 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

his tests follow ● Dizwell Oracle Wiki


at the end. ● My Personal Blog

Zsolt:

In my
experience the
Aggregators
overhead of Brian Duff's OraBlogs

PLSQL ❍ Eddie Awad's OracleNA


procedure ❍ Pete Finnigan's Aggregator
invocations is ❍ Oracle's Bloglist
so small that ❍ Oracle Base Aggregator
you'll most
probably never
have to think
Top Blogs
Oracle's Ask Tom Kyte
about it. In

Oracle Guru Jonathan Lewis


99.99% of all ❍

cases the "real" ❍ Blogger of the Year Eddie Awad


overhead ❍ Data Warehouser David Aldridge
comes from ❍ Oracle Geek Lewis Cunningham
the way you do ❍ Database Expert James Koopmann
things inside ❍ Dizwell's Howard Rogers
the procedure ❍ Oracle Master Laurent Schneider
(s) and not ❍ Security Expert Pete Finnigan
from the ❍ Oracle Award Winner Mark Rittman
procedure ❍ Doug Burns
invocation
Oracle ACE of the Year Dr. Tim Hall
itself. So

UKOUG's Andrew (Arfur C.) Clarke


putting as

Newbie DBA Lisa Dobson


much code ❍

into a single ❍ Coffee-Drinking DBA Jon Emmons


procedure as ❍ Chris Foot
you can won't ❍ The Pythian DBA Team Blog
help. :-) ❍ DBA Don Seiler
❍ DBA Coskan Gundogar
Let's take a ❍ Oracle WTF
look at a very
basic example.
Run this:
ARCHIVES
❍ LIST ALL ARTICLES
DECLARE ❍ May 2005
nLoops ❍ June 2005
CONSTANT ❍ July 2005
NUMBER := ❍ August 2005

http://thinkoracle.blogspot.com/2006_08_01_archive.html (2 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

10000000; ❍ September 2005


nStart NUMBER; ❍ October 2005
PROCEDURE ❍ November 2005
calculate IS December 2005
BEGIN

January 2006
NULL;

February 2006
END calculate;

March 2006
BEGIN ❍

dbms_output. ❍ April 2006


enable ❍ May 2006
(buffer_size ❍ June 2006
=> 10000); ❍ July 2006
❍ August 2006
nStart := ❍ September 2006
dbms_utility. ❍ October 2006
get_time();
November 2006
FOR i IN 1..

December 2006
nLoops LOOP

January 2007
calculate();

END LOOP; ❍ February 2007


dbms_output. ❍ March 2007
put_line('time: ' ❍ April 2007
|| ROUND ❍ May 2007
((dbms_utility. ❍ June 2007
get_time() - ❍ October 2007
nStart)/100, 3)
|| ' s'); ❍ Current Posts

nStart :=
dbms_utility.
get_time();
FOR i IN 1..
nLoops LOOP
NULL;
END LOOP;
dbms_output.
put_line('time: '
|| ROUND
((dbms_utility.
get_time() -
nStart)/100, 3)
|| ' s');
END;

http://thinkoracle.blogspot.com/2006_08_01_archive.html (3 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

On my server
the output
was:
time: 4.33 s
time: 1.47 s

I ran it around
10 times and
got quite
similiar results
with a very
small
deviation. This
shows that
even in a
magnitude of
10 million
invocations,
the overhead is
minimal (~3s
which is 66% in
this case). Of
course this is
nothing like a
real world
situation. :-)

Let's do some
work in the
procedure.
What if we
pass in a
parameter and
return a value
(make it a
function)?

DECLARE
nLoops
CONSTANT
NUMBER :=
10000000;

http://thinkoracle.blogspot.com/2006_08_01_archive.html (4 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

nStart NUMBER;
nTemp
NUMBER;
FUNCTION
calculate
(nParam IN
NUMBER)
RETURN
NUMBER IS
BEGIN
RETURN
nParam + 1;
END calculate;
BEGIN
dbms_output.
enable
(buffer_size
=> 10000);

nTemp := 0;
nStart :=
dbms_utility.
get_time();
FOR i IN 1..
nLoops LOOP
nTemp :=
calculate
(nTemp);
END LOOP;
dbms_output.
put_line('time: '
|| ROUND
((dbms_utility.
get_time() -
nStart)/100, 3)
|| ' s');

nTemp := 0;
nStart :=
dbms_utility.
get_time();
FOR i IN 1..
nLoops LOOP

http://thinkoracle.blogspot.com/2006_08_01_archive.html (5 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

nTemp :=
nTemp + 1;
END LOOP;
dbms_output.
put_line('time: '
|| ROUND
((dbms_utility.
get_time() -
nStart)/100, 3)
|| ' s');
END;
/

The output is:


time: 12.24 s
time: 3.75 s

The overhead
seems to be
quite "big"
compared to
the previous
test (~8.5s,
which is ~70%
in this case),
however this is
still as much
unrealistic as
the previous
one was. :-)
Generally you
could say that
the more work
you do inside
the function
call (or
procedure), the
less
percentage the
overhead will
be.

Let's do the
test again with

http://thinkoracle.blogspot.com/2006_08_01_archive.html (6 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

a bit more
work inside
the function ...

DECLARE
nLoops
CONSTANT
NUMBER :=
10000000;
nStart NUMBER;
nTemp
NUMBER;
FUNCTION
calculate
(nParam IN
NUMBER)
RETURN
NUMBER IS
BEGIN
RETURN POWER
(nParam + 1,
2) - POWER
(nParam, 2);
END calculate;
BEGIN
dbms_output.
enable
(buffer_size
=> 10000);

nTemp := 0;
nStart :=
dbms_utility.
get_time();
FOR i IN 1..
nLoops LOOP
nTemp :=
calculate
(nTemp);
END LOOP;
dbms_output.
put_line('time: '
|| ROUND

http://thinkoracle.blogspot.com/2006_08_01_archive.html (7 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

((dbms_utility.
get_time() -
nStart)/100, 3)
|| ' s');

nTemp := 0;
nStart :=
dbms_utility.
get_time();
FOR i IN 1..
nLoops LOOP
nTemp :=
POWER(nTemp
+ 1, 2) -
POWER(nTemp,
2);
END LOOP;
dbms_output.
put_line('time: '
|| ROUND
((dbms_utility.
get_time() -
nStart)/100, 3)
|| ' s');
END;
/

time: 47.28 s
time: 31.1 s

Now the
overhead is
~16s which is
~34% of the
total running
time.

All of the
above tests
use very fast,
builtin
arithemtical
functions. Let's
take an

http://thinkoracle.blogspot.com/2006_08_01_archive.html (8 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

example that
is a lot more
realistic ... eg.
we generate
some output
to a browser.
The
procedures in
the SYS.htp
package do a
lot more (and
versatile) work
than any of the
above
examples. I've
split this test
into two parts
to avoid
misleading
results due to
the internal
workings of
the SYS.htp
package. I've
also decreased
the loop count
so the server
won't run out
of memory
(since SYS.htp
maintains an
internal buffer
of all the
strings the you
send to the
output). :-)

DECLARE
nLoops
CONSTANT
NUMBER :=
1000000;
nStart NUMBER;

http://thinkoracle.blogspot.com/2006_08_01_archive.html (9 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

sTemp
VARCHAR2
(200);
PROCEDURE
calculate
(sParam IN
VARCHAR2) IS
BEGIN
htp.p(sParam);
END calculate;
BEGIN
dbms_output.
enable
(buffer_size
=> 10000);
sTemp := LPAD
('a', 200, 'a');

htp.init();
nStart :=
dbms_utility.
get_time();
FOR i IN 1..
nLoops LOOP
calculate
(sTemp);
END LOOP;
dbms_output.
put_line('time: '
|| ROUND
((dbms_utility.
get_time() -
nStart)/100, 3)
|| ' s');

htp.init();
END;
/

And the
procedure-free
version ...

DECLARE

http://thinkoracle.blogspot.com/2006_08_01_archive.html (10 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

nLoops
CONSTANT
NUMBER :=
1000000;
nStart NUMBER;
sTemp
VARCHAR2
(200);
PROCEDURE
calculate
(sParam IN
VARCHAR2) IS
BEGIN
htp.p(sParam);
END calculate;
BEGIN
dbms_output.
enable
(buffer_size
=> 10000);
sTemp := LPAD
('a', 200, 'a');

htp.init();
nStart :=
dbms_utility.
get_time();
FOR i IN 1..
nLoops LOOP
htp.p(sTemp);
END LOOP;
dbms_output.
put_line('time: '
|| ROUND
((dbms_utility.
get_time() -
nStart)/100, 3)
|| ' s');

htp.init();
END;
/

You should run

http://thinkoracle.blogspot.com/2006_08_01_archive.html (11 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

them in two
separate
sessions,
otherwise you
can easily end
up with false
results due to
the package
state of SYS.
htp.

My results
were:
time: 23.7 s
time: 23.27 s

You can see


that the
overhead is
less than 0.5s,
which makes
up less than
2% of the total
running time.

After all these


tests proove
only one thing:
the overhead
seriously
depends on
the number of
parameters,
the type of
parameters,
etc. However
in real-world
situations you
should rarely
worry about
overhead of
procedure
invocations. :-)

http://thinkoracle.blogspot.com/2006_08_01_archive.html (12 of 13)1/9/2008 2:50:26 AM


OracleBlog: August 2006

Robert:
My results
were very
similar to
Zsolt's:

anonymous
block
completed
time: 11.28 s
time: 4.26 s

anonymous
block
completed
time: 51.18 s
time: 43.24 s

anonymous
block
completed
time: 20.37 s

anonymous
block
completed
time: 19.53 s

// posted by
Robert
Vollman @ Friday,
August 11, 2006 2

comments

http://thinkoracle.blogspot.com/2006_08_01_archive.html (13 of 13)1/9/2008 2:50:26 AM


OracleBlog: September 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday, September 13, 2006


Something To Do Right Now
If you're still using any of the default Oracle username/passwords on
any of your databases, go change it now.

I could blog about this for 1-2 pages, but for two reasons:
1. I think it is an obvious (but oft-neglected) thing to do, and
2. You can use the time you would have spent reading my persuasive
arguments to actually go change your passwords.

So go do it now.

// posted by Robert Vollman @ Wednesday, September 13, 2006 0 comments

Tuesday, September 12, 2006


Using Numerical Fields
What is a number? The definition is one of the longest I've seen, but
generally it refers to a quantity (or sum, total, count) of units.
Quantities can be subjected to all sorts of calculations, such as
addition, subtraction, multiplication and division.

Sometimes numbers are used for ordering, as well. So it makes sense


to compare one number to another, not only as being greater or
lesser than another, but also by what number of units it is greater.

http://thinkoracle.blogspot.com/2006_09_01_archive.html (1 of 8)1/9/2008 2:50:29 AM


OracleBlog: September 2006

Which brings me to my point. I've been asked on more than one


occasion why I sometimes favour the use of VARCHAR2 in situations
where others are using NUMBER. Take, for example, my earlier post
on creating an appropriate Boolean type.

Some developers think I should have used NUMBER(1) as the type,


denote True as 1, False as 0, and have a check to make sure the
value is either 0 or 1.

That solution also works. But there is a reason I don't use it.

It is true that this method has its advantages, not the least of which
is comfort to programmers who are used to that (most programming
languages make that conversion implicitly). They also claim that you
can use multiplication for AND operations, and addition for OR
operations.

Or can you? True * False = False, so ok, multiplication seems to work


fine. But addition? True + True = 2. 2 is not a valid value. And what
about subtraction and division? "Oh those don't apply" Then it's not
an appropriate use of NUMBER, in my mind. What about square root?
What is True to the exponent False? And so on.

I don't mean to pick on this one example. I've seen cases where
NUMBER is used for all sorts of things: dates, credit card numbers,
social insurance/security numbers, street address house numbers,
zip codes, and so on. In some of these cases (though not necessarily
all), it would have been more appropriate to create a type: a
VARCHAR2 restricted to numerical characters, and then use that one
type for all such instances.

No, this is not a critical point. NUMBER will work just fine, and I have
no stories about how people got into trouble by using NUMBER for
something that wasn't. But consider the importance of having
precision and accuracy in your data. Shouldn't we be equally precise
in your description of the data?

That is why I generally prefer using NUMBER only in cases where the
field actually is by definition a number, a quantity of units, and
eligible for all numerical operations. I'd love to hear your thoughts on
this matter too.

// posted by Robert Vollman @ Tuesday, September 12, 2006 8 comments

http://thinkoracle.blogspot.com/2006_09_01_archive.html (2 of 8)1/9/2008 2:50:29 AM


OracleBlog: September 2006

Saturday, September 02, 2006


Protecting PL/SQL Code
There are two broad categories of reasons why PL/SQL programmers
wouldn't want others to read their code:

Reason #1 Protection
The programmers wish to protect their code from theft, misuse or
alteration (among other things).

Reason #2 Malicious Reasons


The code is meant to do harm, or may have some potentially
dangerous errors they wish to cover up.

I don't believe in hidden code, because open code is easier to debug,


reuse, and it is obviously easier to detect (deliberately or
accidentally) harmful code.

But regardless of whether code you have received from a vendor or


contractor is protected or not, you should be testing it thoroughly
before using it anyway. Plus, these methods are already thoroughly
documented in a number of places, not the least of which by expert
Steven Feuerstein and also in Oracle's documentation.

In fact, the example I'm using is from Oracle's documentation.

Normally, after creating a stored procedure, the source code can be


access through a SOURCE table, like so:

SQL> SELECT text FROM USER_SOURCE


SQL> WHERE name = 'WRAPTEST' order by line;

TEXT
-----------------------------------------------------------

PROCEDURE wraptest IS
TYPE emp_tab IS TABLE OF emp%ROWTYPE INDEX BY PLS_INTEGER;
all_emps emp_tab;
BEGIN
SELECT * BULK COLLECT INTO all_emps FROM emp;
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE('Emp Id: ' || all_emps(i).empno);
END LOOP;
END;

http://thinkoracle.blogspot.com/2006_09_01_archive.html (3 of 8)1/9/2008 2:50:29 AM


OracleBlog: September 2006

How can we avoid this?

My first thought is simply not to load the procedure into the


database at all. Leave the procedure as an SQL file on the server, and
execute it remotely. About a year ago, I engaged some Oracle
programmers in such an approach, check that earlier article for a
brief discussion on the advantages and disadvantages of keeping
your code out of the database:
PL/SQL Code Storage: Files vs In-DB Packages

Anyone with access to the server will can still read your code, using
an editor of some kind. But perhaps your server is capable of
restricting access to your satisfaction.

You'll note that those Oracle programmers largely agreed that if your
code is in the database, it should be wrapped and/or part of a
package. First let's look at wrapping.

Wrapping, otherwise known as obfuscation, is a method of changing


your human-readable PL/SQL code into text that is readable only by
Oracle. In that sense, it can be compiled and executed like any other
code, but it is protected in the sense that it won't make sense to
anyone except Oracle.

You can learn how to use the wrap utility from either Dan Morgan, or
Oracle's PL/SQL User's Guide and Reference (Appendix C), but I'll
show you what I mean right now.

1. Put your PL/SQL code in an SQL file.


2. From the command line, issue the wrap command. The syntax is
wrap iname=input_file [oname=output_file]

wrap iname=wraptest.sql oname=wraptest.plb

3. From SQL*Plus, execute the resulting PLB file to load the stored
procedure, and even execute it for verification (omitted here).

SQL> @wraptest.plb

Procedure created.

4. Try to read the code, either by opening the PLB file, or querying a
SOURCE table. PLB is a standard Oracle extension, sometimes
referred to as "PL/SQL Binary." But it isn't binary, it's text: you can go

http://thinkoracle.blogspot.com/2006_09_01_archive.html (4 of 8)1/9/2008 2:50:29 AM


OracleBlog: September 2006

ahead and read it.

SQL> SELECT text FROM USER_SOURCE WHERE name = 'WRAPTEST'


order by line;

(garbage removed)

Now is wrapping a perfect solution? Well no. First of all, Oracle


doesn't claim that it is undecipherable. Edited: In fact, leading Oracle
security expert Pete Finnigan has made a presentation available that
summarizes how to read wrapped code.

It also has a few annoying limitations, none of which I'll prove here,
but they include the fact that you can't wrap triggers (just call a
wrapped proc from your trigger), can't be copied to an earlier
release, and all Oracle comments (--) are deleted.

I hear there may be a superior solution in Oracle 10, as part of the


DBMS_DDL package. That solution doesn't even require a command-
line step, it can be done directly in the database. If you're ahead of
me, and using Oracle 10, give it a try using Dan Morgan's reference
for the syntax.

Speaking of packages, the more important lesson to learn from those


Oracle programmers was to put your code into packages. You can
make the specification public, so everyone can understand them, and
then restrict access (and wrap) the implementation details.

Using packages and wrapping your code is the standard method of


protection. As a closing note, there are plenty of other compelling
reasons to use Oracle packages too. I wrote about that once before,
and also included some links where you can get the finer details on
how to use them:
Oracle Packages - And why/how you should use them.

// posted by Robert Vollman @ Saturday, September 02, 2006 4 comments

About Me
http://thinkoracle.blogspot.com/2006_09_01_archive.html (5 of 8)1/9/2008 2:50:29 AM
OracleBlog: September 2006

Name: Robert Vollman


Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad

http://thinkoracle.blogspot.com/2006_09_01_archive.html (6 of 8)1/9/2008 2:50:29 AM


OracleBlog: September 2006

❍ Data Warehouser David Aldridge


❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006

http://thinkoracle.blogspot.com/2006_09_01_archive.html (7 of 8)1/9/2008 2:50:29 AM


OracleBlog: September 2006

❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

❍ Current Posts

http://thinkoracle.blogspot.com/2006_09_01_archive.html (8 of 8)1/9/2008 2:50:29 AM


OracleBlog: October 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, October 31,


About Me
2006
Name: Robert Vollman
Oracle Gurus Location: Calgary, Alberta, Canada
"Becoming an Oracle
guru doesn't take I was born and raised in Ottawa, and have
remarkable intelligence lived in Calgary since 1991. I like playing
or a pricey Harvard sports (hockey, soccer, ultimate, basketball, you name it)
degree, but it does take and military board games. I also enjoy reading, walking,
persistence, drive, and a and playing with my 2 cats Lilly and Brutus. I'm a
dedication to database application specialist, whatever that is.
excellence."
- Don Burleson, How to
View my complete profile
become an Oracle Guru

Despite the appearance


of merely trying to Best Links
promote his team (most ● Ask Tom Kyte
notably Steve Karam), ● Oracle Docs
Mr. Burleson actually ● Dan Morgan and PSOUG
raises some interesting ● Steven Feuerstein
points on a thought-
Jonathan Lewis
provoking question.

● FAQ
What Makes an Oracle ● Connor McDonald
Guru? ● The Oak Table
● Cary Millsap and Hotsos
So what does it take to ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006_10_01_archive.html (1 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

become an Oracle guru, ● Anjo Kolk and OraPerf


according to him? I'll ● Dizwell Oracle Wiki
group his dozen points ● My Personal Blog
into the underlying
broad categories:

1. Credentials
A stellar education with
Aggregators
prestigious degrees, Brian Duff's OraBlogs

awards, and ❍ Eddie Awad's OracleNA


certifications. ❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
2. Communicating Their ❍ Oracle Base Aggregator
Knowledge
Via insightful blogs,
publishing
Top Blogs
Oracle's Ask Tom Kyte
opportunities, and ❍

polished ❍ Oracle Guru Jonathan Lewis


communications skills. ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
3. Attitude ❍ Oracle Geek Lewis Cunningham
Seeks challenging job ❍ Database Expert James Koopmann
opportunities, and is ❍ Dizwell's Howard Rogers
characterized by a "can ❍ Oracle Master Laurent Schneider
do" attitude.
❍ Security Expert Pete Finnigan
Who Are the Gurus? ❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
Before I can properly ❍ Oracle ACE of the Year Dr. Tim Hall
evaluate Mr. Burleson's ❍ UKOUG's Andrew (Arfur C.) Clarke
assertions, I need to ❍ Newbie DBA Lisa Dobson
know who the Oracle ❍ Coffee-Drinking DBA Jon Emmons
gurus are. So I ❍ Chris Foot
unleashed the "Google The Pythian DBA Team Blog
Guru Wars" (say that five

DBA Don Seiler


times fast). Here are the

DBA Coskan Gundogar


results of this dubious

test: ❍ Oracle WTF

Most popular results for ARCHIVES


"Oracle Guru" on Google ❍ LIST ALL ARTICLES
878 Jonathan Lewis ❍ May 2005
762 Tom Kyte ❍ June 2005
646 Don Burleson ❍ July 2005

http://thinkoracle.blogspot.com/2006_10_01_archive.html (2 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

486 Mike Ault ❍ August 2005


216 Steve Adams ❍ September 2005
3 Robert Vollman :) ❍ October 2005
❍ November 2005
Do they all meet December 2005
Burleson's Three

January 2006
Criteria? Well the criteria

February 2006
are fairly subjective, but

March 2006
from what I know of ❍

these 5, they certainly ❍ April 2006


do. ❍ May 2006
❍ June 2006
But let me ask two ❍ July 2006
questions: ❍ August 2006
1. Is there something ❍ September 2006
MORE to being an Oracle ❍ October 2006
guru?
November 2006
2. Is there something

December 2006
extraneous in Burleson's

January 2007
Requirements? ❍

❍ February 2007
What is a Guru? ❍ March 2007
❍ April 2007
In my experience, guru ❍ May 2007
simply means anyone ❍ June 2007
with a very high level of October 2007
knowledge and

understanding. ❍ Current Posts


Generally I think it is
also implied that they
have a following of some
kind.

Strictly translated, guru


can mean "teacher" -
and in many places like
India and Indonesia I
understand that guru is
generally used in that
sense. Certainly we
picture gurus as having
mentors.

Reviewing Burleson's

http://thinkoracle.blogspot.com/2006_10_01_archive.html (3 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

Three Criteria

With that in mind, let's


take one final pass
through the three
criteria.

1. Credentials

Our first goal must be to


get past the
subjectiveness of this
criteria. After all, who is
to decide which degree
is prestigious enough,
which certifications are
necessary, and which
awards qualify?

That being said, it's fair


to say that an Oracle
guru would certainly be
capable of earning a
post-secondary degree,
Oracle certification, and
an Oracle ACE. But I
would also suppose that
they may not have had
the opportunity nor the
desire to pursue this.
These may be necessary
to PROMOTE oneself as a
guru, but not necessarily
to BE one.

Nevertheless, this is still


a valid criteria. But
instead of tangible
things like degrees,
certifications and
awards, which (if I may
be so bold) would be
possible (though
extremely difficult) to

http://thinkoracle.blogspot.com/2006_10_01_archive.html (4 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

accumulate without
attaining a thorough
understanding of Oracle,
we need to measure it
based upon the actual
understanding.

How do you measure an


actual understanding of
Oracle? I don't have that
answer, but I might
propose to test their
understanding, through
questions and problems.
Then again, I suppose
that's what academic
institutions, award
review boards and
certification exams do ...

2. Communicating Their
Knowledge

I didn't like this criteria


at first because it
excluded some amazing
DBAs with whom I have
had the pleasure to
work. However, given
the definition of a guru I
reviewed, it would seem
like educating others is
a necessary qualification.

Still, I've seen some


people communicate a
relatively mediocre
understanding of Oracle
through numerous
papers and books and
blogs. I've also seen
brilliant writers publish
only a single book (if
any), and an unarguable

http://thinkoracle.blogspot.com/2006_10_01_archive.html (5 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

guru like Jonathan


Lewis, until very
recently, had no blog at
all.

I've seen some people


answer countless
questions on Oracle
forums, and yet never
really impart true insight
or wisdom.

So again, this criteria


suffers from
subjectiveness. How do
we measure how
effectively a potential
guru has communicated
their knowledge?
Number of students?
Questions answered?
The students'
understanding of
Oracle? Some
combination thereof? If
so, how do we test the
understanding of the
students if I've already
conceded above that I
don't know how to
measure someone's
understand of Oracle in
the first place?

3. Attitude

Despite being the most


subjective criteria of the
three, I found the
attitude that Oracle
gurus share to be the
most interesting, and
the one on which I wish
Don Burleson had

http://thinkoracle.blogspot.com/2006_10_01_archive.html (6 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

elaborated further.

I like the way he


describe Oracle gurus as
those that seek
challenges, and have a
"can do" attitude. To me,
those two qualities
perfectly sum up how
I've been able identify
good sources of
mentorship in my
career. Some people
might have fantastic
knowledge and
experience, but like to
stick to what they know,
and are stubbornly
cynical about any
problem that falls
outside their comfort
zone.

Wrapping Up

Sadly, I really don't think


I've answered any
questions or cleared
anything up on this
matter, and I apologise
for that. However, if I
have helped to promote
and advance the
discussion, then I'm glad
I took the time to share
my thoughts with
everyone. I'd love to
hear yours: what makes
an Oracle guru?

// posted by Robert
Vollman @ Tuesday, October

31, 2006 15 comments

http://thinkoracle.blogspot.com/2006_10_01_archive.html (7 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

Monday, October 30,


2006
Oracle
Passwords
Hallowe'en is a time of
fright and mystery, and
some of the most
common, mysterious
Oracle questions I
collect involve
passwords. Here are
some tricks and treats:

How do you change an


Oracle password? ... If
you/the user forgot it?
How are Oracle
passwords stored?
Does it look the same
for two different users
using the same
password?
Do the SQL Trace files
reveal your secret
password?
How do you hide your
password from others
when running scripts?
How do you set/enforce
your password policy in
Oracle?
Which password-related
error messages can you
get in Oracle, and what
do they mean?

The scary truth is that


there is no mystery to
any of the answers. Each

http://thinkoracle.blogspot.com/2006_10_01_archive.html (8 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

answer can be readily


found in either the
Oracle Documentation
(more specifically, the
Oracle Administrator's
Guide), or among the
plentiful resources of
the Internet. It's all in
knowing where to look!
I've collected a few
answers to get you
started.

Changing Your Oracle


Password

If you already know your


Oracle password, you
can change it using an
SQL*Plus session by
simply typing
"password" and
following the
instructions.

If you have the


privileges, you can also
change a password
using ALTER USER.

ALTER USER username


IDENTIFIED BY password;

That is also the trick if


you have lost your
password. Of course,
you must have the
privileges.

Hopefully its not the


privileged user you've
lost the password for,
but if that's the case,
you can always try to the

http://thinkoracle.blogspot.com/2006_10_01_archive.html (9 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

default Oracle
usernames and
passwords (but
presumably you changed
it already). Perhaps you
want to allow more
users SYSDBA privileges?
I'll get to that ...

How Oracle Passwords


Are Stored

You can see the


usernames and
encrypted passwords in
the DBA_USERS table
(assuming you have
privileges).

SELECT username,
password FROM
dba_users WHERE
username = 'SCOTT';

If two users have the


same password, will it
mean they'll have the
same encrypted
password? NO. You can
try it yourself, or just
ask my featured blogger
Steve Callan. Steve also
explains how a DBA
can't determine your
secret password by
reading SQL TRACE of
your session.

Steve also turns us onto


a little trick where we
can save that encrypted
password and re-set it
after it was (accidentally

http://thinkoracle.blogspot.com/2006_10_01_archive.html (10 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

or deliberately) changed
using ALTER USER.

ALTER USER username


IDENTIFIED BY VALUES
'encrypted password';

Check out the Dizwell


wiki for a cleaner
example of restoring an
encrypted password.

Your Oracle Password


Policy

Steve also mentioned a


certain password policy
script, which you should
find here:

$ORACLE_HOME/rdbms/
admin/utlpwdmg.sql

Oracle supports some


fairly sophisticated
password policies, not
just requiring a certain
length or requiring
numerics. I won't
elaborate on the details,
which you can find in
the Oracle Administrator
Guide.

There are plenty of (non-


Oracle-specific) articles
out there on the need
for a strong password
policies. For instance,
according to a fact sheet
from Red Database
Security, changing the
minimum length of a

http://thinkoracle.blogspot.com/2006_10_01_archive.html (11 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

password from 8
characters to 9 can
make the different
between 2 days and 57
for a brute force attack!

Oracle Password Error


Messages

Speaking of Red
Database Security, they
did the job of
summarizing the various
error messages you can
get when you try to log
in, and what they mean.

ORA_28000: The
account is locked
Wait for
PASSWORD_LOCK_TIME
or contact your DBA

ORA-28001: The
password has expired
Change the password or
contact your DBA

ORA-00988: Missing or
invalid password(s)
Use double quotes for
the password (e.g. alter
user scott identified by "!
alex";)

ORA-01017: Invalid
username/password;
logon denied
Contact your DBA if the
problem still persists

The Password File

I mentioned two things

http://thinkoracle.blogspot.com/2006_10_01_archive.html (12 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

above:
1. Your encrypted
passwords are stored in
the database, accessible
through DBA_USERS.
2. You can grant SYSDBA
privileges to other users.

If my first point is
correct, what is the
password file? And what
does the second point
have to do with
anything? Well, put 1
and 2 together. The
password file is how you
grant those SYSDBA
privileges to other users.

How? By using ORAPWD:


The Oracle Password File
Utility. You'll find it in
$ORACLE_HOME/bin,
and you can create the
file like so:

orapwd file=filename
password=syspassword
entries=maxsysdbas
force=Y

You can find more


information in the
Oracle Administrator's
Guide, right at the top.

Speaking of which, here


is another error you
might get: ORA-01996.
In this case, you were
trying to grant SYSDBA
privileges to a user when
you already have
assigned this to the

http://thinkoracle.blogspot.com/2006_10_01_archive.html (13 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

maximum number of
users. Use this utility to
increase your limit.

Finally ...

You wrote a script which


connects to Oracle, and
you're worried that other
users can see the login
credentials you used to
execute the script. What
is the correct way
around this?

Connor McDonald
discusses four ways,
using OS accounts,
internal accounts, /
NOLOG and a last-resort
sqlplus trick.

Alternatively we can do
what we always do when
we want to know
something about Oracle,
we Ask Tom. Or, more
precisely, we assume
someone already has
and find out what he
said. In this case, he
instructs us to use the
'identified externally'
directive.

Normally I make a
reference to Tom Kyte
the final word, but this
time the honour will go
to someone equally
worthy: Jonathan Lewis.
His blog is long overdue,
and you can find his link

http://thinkoracle.blogspot.com/2006_10_01_archive.html (14 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

second from the top,


right next to Tom's
(sorry Eddie).

// posted by Robert
Vollman @ Monday, October

30, 2006 3 comments

Tuesday, October 24,


2006
Oracle
Conferences
If you follow the various
blogs on the right, you'll
see that practically
everybody (except me) is
currently attending
Oracle OpenWorld 2006.
It's an annual convention
held in San Francisco
late in the year. Lasts
about 4 days, and costs
around 2000 USD$.

I'd love to attend Oracle


OpenWorld some day. Or
practically any
conference. I would
especially like to visit
the annual conference
hosted by UKOUG. It
generally takes place
shortly after Oracle
OpenWorld, and its
about the same cost, but
maybe a few hundred
bucks cheaper. Makes
up for the airfare to
Birmingham.

Maybe for a warm-up I'd

http://thinkoracle.blogspot.com/2006_10_01_archive.html (15 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

finally meet up with Dan


Morgan at the Puget
Sound Oracle User's
Group's OracleDay in
Seattle. It's one day, and
I'm pretty sure its cheap
(or free) for members. If
you're not in my area,
check out the calendar I
got from the OTN web
site that lists some of
the local user groups
annual meetings.

Judging from that list,


there are three other
conferences I would
keep my eye on:

1. Oracle Development
Tool Users Group
Kaleidoscope, in June, to
be held in Daytona
Florida next year.
2. The 2nd ever PL/SQL-
specific OPP 2007, for 2
days in February/March
in San Francisco.
3. Oracle Applications
User Group Collaborate
2007 in Las Vegas next
April for 4 days.

If ever I do go to my first
Oracle convention, I'll be
sure to mention it here
and hopefully I can meet
some of you there.

// posted by Robert
Vollman @ Tuesday, October

24, 2006 2 comments

http://thinkoracle.blogspot.com/2006_10_01_archive.html (16 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

Thursday, October 19,


2006
3 Easy Ways to
Improve Your
PL/SQL
Want to know what has
been calling the PL/SQL
Procedure you've written?
Want to know how to tell
how far along your long-
running PL/SQL
Procedure is?
What to know how to
write fast mass insert/
deletes like a pro?

I have found you the


answer for all three,
courtesy of my fine
colleagues featured
among my links. Allow
me to guide you through
these three great articles.

Who Is Calling Your


Procedure?

The answer to our first


question comes courtesy
of Oracle's Blogger of
the Year Eddie Awad.

Eddie won this award


not just by virtue of
being first in an
alphabetical listing, but
also by the sheer volume
of focused articles of
high interest, each one
backed up by references
and proven tests. His
article about OWA_UTIL.

http://thinkoracle.blogspot.com/2006_10_01_archive.html (17 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

WHO_CALLED_ME is no
exception. His article
includes:
1. A working example
you can cut and paste,
2. A link to Oracle's
documentation, and
3. A link to Dan
Morgan's syntax
reference

Thanks to his diligence,


it literally took only
minutes to add this type
of instrumentation to my
existing code. When
something goes wrong, I
know exactly who called
my procedure, and
where. This even works
if the calling code is
wrapped. (Proof
forthcoming)

Given how easy it is, I


plan on testing the
overhead/performance
to see how feasible it
would be to start using
this as a metric by
creating this table and
adding this line:

CREATE TABLE
MyProcCalls
(caller_name VARCHAR2
(100), line_number
NUMBER(8));

INSERT INTO
MyProcCalls
(caller_name,
line_number) VALUES
(caller_name,

http://thinkoracle.blogspot.com/2006_10_01_archive.html (18 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

line_number);

Then I'll start looking


like a pro already.

How Far Along Is My


Procedure?

This answer comes from


my newest featured
blogger Andy Campbell.
He has been an Oracle
DBA for 7 years and, like
me, started a blog to
record the things he
learns and doesn't want
to forget.

Let's take advantage of


Andy's experience on
how to instrument our
PL/SQL code further by
including calls to
DBMS_APPLICATION_INFO
to record our
procedure's on-going
progress.

Andy explains, complete


with examples, how to
use this supplied
package (available as far
back as Oracle 7) to
have your procedure
write information into
session-tracking tables
using SET_MODULE and
then SET_ACTION.

Of course the big pay-


off comes at the end of
his article where he
executes his long-
running procedure and

http://thinkoracle.blogspot.com/2006_10_01_archive.html (19 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

then queries the session-


tracking tables like V
$SESSION to find out
how far along the
procedure is. Brilliant!

Let me supplement his


article with the following
three references:

1. Supplied Packages
References, Chapter 3:
DBMS_APPLICATION_INFO

2. Another one of my
favourite featured
bloggers, Oracle ACE of
the Year Tim Hall, is
reknowned for his great
articles. He also has a
write-up on how to use
DBMS_APPLICATION_INFO
and the V$SESSION
tables.

3. Finally, what list of


mine would be complete
without including Dan
Morgan's reference?

Thanks to Andy's
working example, it
literally took me minutes
to further instrument my
PL/SQL code and fool
people into thinking
they were written by a
true Oracle pro.

How Do I Write Mass


Inserts/Deletes Like a
Pro?

http://thinkoracle.blogspot.com/2006_10_01_archive.html (20 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

If we're going to code


like a pro, we need to
take at least one page
out of Tom Kyte's
playbook. Tom Kyte's
work is beloved for its
passion, dedication,
completeness and
accuracy.

Tom's has a passionate


distaste for bad
practises, including
slow-by-slow
processing.
Programmers unused to
thinking in sets are at a
distinct disadvantage
when programming
database applications.
Why? Because they do
their inserts and deletes
one-by-one in a for
loop.

As database
programmers know, this
approach is completely
unnecessary and
wasteful. They know
instead to look for a
solution that does some
kind of bulk processing
when doing inserts,
deletes or updates on a
large number of records.

Tom illustrates this


point with a specific
case where particularly
bad Oracle code had
been written.

http://thinkoracle.blogspot.com/2006_10_01_archive.html (21 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

The original requirement


was to prune down a list
of employees, removing
duplicate employees by
choosing the one with
the most recent hiring
date.

What did the original


programmer do? First,
created a big master
table of all employees,
then when through them
in a loop, each time
deleting employees that
produced more than one
record when grouped by
employee number.

Study how it was done


by the original
programmer. It might
not look like an
altogether unfamiliar
approach. But what do
you think about this
result?

Well, you may find that


the result was not only
very slow because it
would loop as often as
your most common
duplicate, but potentially
logically incorrect
because it would remove
an employee entirely if it
had duplicate records
with the same hiring
date.

Instead look how a true


pro handles this
situation. Tom handles

http://thinkoracle.blogspot.com/2006_10_01_archive.html (22 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

this case in a single,


efficient SQL statement.

He breaks the problem


down to its simplest
form: we need a list of
each employee with its
data, with only a single
row per employee
representing the most
recent hiring date.

Therefore Tom
populates such a table
by first adding a column
signifying the most
recent hiring date for
each employee (using
PARTITION BY, a
technique we've
discussed many times
before), then by
selecting only the rows
where the hiring date
and this most recent
hiring date match.

I admit this third tip is a


little harder to digest
than the first two,
because you have to
learn how to think like a
pro. Break a problem
down, and approach it
like a database would by
thinking in sets.

Summary

The true secret behind


these three tips is
actually to read. There
are a lot of Oracle
professionals just like

http://thinkoracle.blogspot.com/2006_10_01_archive.html (23 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

you, and we're fortunate


that so many of them
are generous with their
knowledge. Thanks!!!

Looking for more great


articles whenever I'm
quiet? Please bookmark
the links along the side
of the page. And visit
the articles in my
archives: you may have
especially missed some
of the early ones.

// posted by Robert
Vollman @ Thursday, October

19, 2006 0 comments

Tuesday, October 17,


2006
Software
Vendor
Customer
Support
Having worked in
technical support for
software vendors for 4
years, I know a few
strategies that can help
customers get the best
response.

1. Get training
Rely on the assistance of
the software vendor for
as little as possible.
Invest in training your
own people by signing
them up for courses

http://thinkoracle.blogspot.com/2006_10_01_archive.html (24 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

and, more importantly,


giving them the time to
learn the product and
how your company uses
it. Once knowledgeable,
your expert can get the
best results from the
vendor.

2. Avoid customizations
No product is going to
fit your needs exactly,
and it's tempting just to
make little fixes here
and there, but resist the
urge. Just because you
can do something, it
does not necessarily
follow that you should.
Consider leaving the
software as-is and just
changing your process.
Customizations can
cause problems, become
(legitimate or not)
obstacles preventing the
vendor from providing
you assistance, and
make upgrades more
problematic.

3. Stay current, but not


too current
Generally the vendor
offers the best support
for versions immediately
before the latest version.
If your version is too old,
they may have fewer
people that know it and
they may stop
supporting it altogether.
You don't want to stay

http://thinkoracle.blogspot.com/2006_10_01_archive.html (25 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

too current - let the


other customers find the
bugs in the latest
releases. Of course, if
you need the
functionality in the latest
version and the vendor
is prepared to give you
extra support for being
a guinea pig, go for it.

4. Allow for remote


access
Generally you should
never allow the vendors
on to your system, but
sometimes it will be
necessary, so be set up
to make that as easy as
possible.

5. Wait until you have


time
There is no point
opening a ticket with
them until your
resources have the time
to act on whatever they
suggest. Take too long
to respond and your
item will be
downgraded, perhaps
permanently. If
something is low priority
and you just want it "on
the record", then make
sure you say so.

6. Assign the right


priority
Every software vendor
will have standard
definitions where you
define the severity/

http://thinkoracle.blogspot.com/2006_10_01_archive.html (26 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

priority/impact of a
problem. It is tempting
to assign a higher
priority, but once you're
downgraded you may be
given a lower priority
than items that were
opened correctly at this
new downgraded level.
You can also get a
reputation that may
cause truly important
items to get
downgraded in the
future. Any way you slice
it, clearly explain the
business impact of your
problem, regardless of
priority, to avoid any
problems.

7. Answer the standard


questions in advance
Don't wait for them to
ask you the usual
questions: When did this
start, what changed, etc.
Anticipate their
questions and answer
them up front. Look
back at the questions
they usually ask as a
clue.

8. Provide a complete,
independent test case
Doing a little work
beforehand can save a
lot of time later.
Eliminate distractions
and narrow the problem
down to a simple,
reproducible step-by-

http://thinkoracle.blogspot.com/2006_10_01_archive.html (27 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

step description that will


work anywhere. Try to
use default data
wherever possible. A
test case is worth a
thousand words, so this
will save you days or
weeks of back-and-
forth explanations.

9. Provide all logs,


configuration files
Don't wait for them to
ask, go ahead and attach
all relevant configuration
files and logs. Tell them
what you've already tried
(from standard
troubleshooting
techniques in the
manual) and what the
results were for those
tests.

10. Make it as easy as


possible
Try to make your case
look as simple and clear
as possible. Some
vendors measure their
service representatives
by how many items they
close to the customer's
satisfaction. So they like
to pick off the low
hanging fruit. If your
case looks hard, it may
get neglected, or
assigned to someone
not new or skilled
enough to dodge the
tough ones.

11. Open separate tickets

http://thinkoracle.blogspot.com/2006_10_01_archive.html (28 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

Try not to lump


everything into one
ticket, or you risk having
your problem only
partially solved. Why not
open a separate item,
and have them work on
your issues in parallel? If
they're somewhat
related, you can always
say so in your
description. Worse case
scenario, solving one
solves the other and you
can just close both.

12. Escalate when you're


stuck
If you're not getting
anywhere, ask for the
issue to be escalated to
the manager. S/he will
make sure the right
people are working on it,
that there is a resolution
plan, and communicate
that information to you.
Keep going up if you
have to, managers have
managers too.

13. If you need extra,


pay for it.
If, for whatever reason,
you can't do certain
things for yourself, or
you need some extra
help from the software
vendor, offer to pay.
Money talks! You will get
results far faster and
more reliably than if you
just try to threaten or

http://thinkoracle.blogspot.com/2006_10_01_archive.html (29 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

cajole them into it.

14. Make sure the


solution is permanent
Try to keep the focus on
identifying and solving
the root cause, not the
consequence. It is
almost always advisable
to end a resolution with
a documentation
enhancement or a new
item in their solutions
knowledge base.
Volunteer to proof read
it.

Note: I originally wrote


this article in April, but it
was on my personal
blog. It occurs to me
that the Oracle
professionals that read
this blog might be
supporting 3rd-party
Oracle-based
applications, or perhaps
dealing with Oracle
support directly, and
therefore would enjoy
this article too.

Also, given my lack of


material lately, this is
the best way to confirm I
am still alive. :)

// posted by Robert
Vollman @ Tuesday, October

17, 2006 3 comments

http://thinkoracle.blogspot.com/2006_10_01_archive.html (30 of 31)1/9/2008 2:50:33 AM


OracleBlog: October 2006

http://thinkoracle.blogspot.com/2006_10_01_archive.html (31 of 31)1/9/2008 2:50:33 AM


OracleBlog: November 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday,
About Me
November 14,
Name: Robert Vollman
2006
Location: Calgary, Alberta, Canada
100,000
more? I was born and raised in Ottawa, and have lived in
18 months. Calgary since 1991. I like playing sports (hockey,
107 posts. soccer, ultimate, basketball, you name it) and military board
110,000 reads. games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever
Not too long ago that is.
I reacted with
humble View my complete profile
incredulity that
10,000 people
had read what I
had to say about
Best Links
Oracle. ● Ask Tom Kyte
● Oracle Docs
Here I am, ● Dan Morgan and PSOUG
exactly one year ● Steven Feuerstein
later, and there ● Jonathan Lewis
have been ● FAQ
100,000 more
Connor McDonald
visits. I'm almost

The Oak Table


afraid to

Cary Millsap and Hotsos


continue, will I ●

be talking about ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006_11_01_archive.html (1 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

1,000,000 in ● Anjo Kolk and OraPerf


November 2007? ● Dizwell Oracle Wiki
● My Personal Blog
I wonder why
people are
reading my blog
because, despite
how numerous
Aggregators
we are, it seems Brian Duff's OraBlogs

like every other ❍ Eddie Awad's OracleNA


Oracle blogger ❍ Pete Finnigan's Aggregator
knows this ❍ Oracle's Bloglist
material far ❍ Oracle Base Aggregator
better than I. So
I've taken the
time to ask some
Top Blogs
Oracle's Ask Tom Kyte
of you why.

❍ Oracle Guru Jonathan Lewis


Although it ❍ Blogger of the Year Eddie Awad
would be nice if ❍ Data Warehouser David Aldridge
someone did me ❍ Oracle Geek Lewis Cunningham
the compliment ❍ Database Expert James Koopmann
of disputing my ❍ Dizwell's Howard Rogers
claim, instead it ❍ Oracle Master Laurent Schneider
appears that my ❍ Security Expert Pete Finnigan
lack of expertise ❍ Oracle Award Winner Mark Rittman
is part of the
Doug Burns
appeal. It seems

Oracle ACE of the Year Dr. Tim Hall


the average

UKOUG's Andrew (Arfur C.) Clarke


Oracle user out ❍

there is closer to ❍ Newbie DBA Lisa Dobson


my level rather ❍ Coffee-Drinking DBA Jon Emmons
than some ❍ Chris Foot
expert like, say, ❍ The Pythian DBA Team Blog
Laurent ❍ DBA Don Seiler
Schneider or Jeff ❍ DBA Coskan Gundogar
Hunter. ❍ Oracle WTF

Perhaps that
makes my work
ARCHIVES
LIST ALL ARTICLES
more accessible.

May 2005
The complexities

June 2005
of Oracle often

❍ July 2005

http://thinkoracle.blogspot.com/2006_11_01_archive.html (2 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

make you feel ❍ August 2005


dumb, so you ❍ September 2005
can come to me ❍ October 2005
to feel smart November 2005
again. :)

❍ December 2005
In that vein, I'd ❍ January 2006
like to get some ❍ February 2006
of you started on ❍ March 2006
your own blogs. ❍ April 2006
You may feel ❍ May 2006
intimidated ❍ June 2006
because of all ❍ July 2006
the experts out ❍ August 2006
there, but if ❍ September 2006
anything I'm
October 2006
proof that you

November 2006
don't have to be

December 2006
an Oracle guru

January 2007
to make a

contribution. ❍ February 2007


❍ March 2007
I think you'd be ❍ April 2007
surprised at just ❍ May 2007
how warm a ❍ June 2007
reception you'll ❍ October 2007
receive no
matter what level ❍ Current Posts
you're at. If you'd
like to give it a
try, I'm offering
you an audience
on my blog. I'd
be happy to
answer
questions,
review your first
few posts, and
invite others
here to do the
same, until you
have decided
whether or not

http://thinkoracle.blogspot.com/2006_11_01_archive.html (3 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

blogging is for
you.

My contact
information is in
my profile, I look
forward to
hearing from
you! And thanks
for reading!

// posted by Robert
Vollman @ Tuesday,
November 14,
2006 3 comments

Friday,
November 10,
2006
View
Constraints
You have a table
with all your
company's
financial
transactions.
There is another
table which
references a
subset of these
financial
transactions (ie.
transactions with
certain
properties).

Your current
solution to
maintain the
integrity is to set

http://thinkoracle.blogspot.com/2006_11_01_archive.html (4 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

up a foreign key,
referencing the
transactions
table, and then
write a trigger to
make sure that
any records
reference only
transactions that
have the correct
properties.

However, you
were struck with
a brilliant idea to
use views for a
more elegant
solution. You
create a view on
the transactions
table that
contains only the
proper subset,
and then set up
a foreign key to
the view instead.

You create the


view, including
the appropriate
primary key
constraint, and
you're all set to
go. Except when
you create your
table to
reference that
view, you see
this:

ERROR at line 1:
ORA-02270: no
matching unique
or primary key

http://thinkoracle.blogspot.com/2006_11_01_archive.html (5 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

for this column-


list

Have you done


something
wrong?

No. You've come


up with a very
clever solution,
but
unfortunately
one that isn't
supported.
According to
Oracle's SQL
Reference,
"Oracle does not
enforce view
constraints.
However, you
can enforce
constraints on
views through
constraints on
base tables."

Of course,
referencing the
base table
doesn't do you
any good,
because there
are transactions
in there that
aren't valid
references for
your new table.
Quoting Dan
Morgan: "The
point of the
syntax is to
prevent

http://thinkoracle.blogspot.com/2006_11_01_archive.html (6 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

violations when
people do DML
(inserts, updates,
deletes through
the view). It does
not truly serve
the same
purpose as a
"real" primary
key and can not
be used in the
same way."

However,
reading on, both
Table 17-3
(Object Privileges
Available for
Particular
Objects) and this
sentence seems
to offer some
hope that your
solution can be
achieved. "To
create a foreign
key constraint, in
addition, the
parent table or
view must be in
your own
schema, or you
must have the
REFERENCES
privilege on the
columns of the
referenced key in
the parent table
or view."

Alas, the
documentation is
misleading here.

http://thinkoracle.blogspot.com/2006_11_01_archive.html (7 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

It's talking about


the view itself
having a foreign
key, not the
primary. Observe.

SQL> CREATE
TABLE basetable
2 (id VARCHAR2
(32) PRIMARY
KEY, amount
NUMBER(10),
other_columns
VARCHAR2(32));

Table created.

SQL> GRANT
REFERENCES (id)
ON basetable TO
PUBLIC;

Grant succeeded.

SQL> CREATE OR
REPLACE
base_view
2 AS SELECT *
FROM basetable
WHERE amount >
100;

View created.

SQL> ALTER view


base_view ADD
CONSTRAINT
pk_view PRIMARY
KEY (id) RELY
DISABLE
NOVALIDATE;

View altered.

SQL> GRANT

http://thinkoracle.blogspot.com/2006_11_01_archive.html (8 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

REFERENCES (id)
ON base_view TO
PUBLIC;

Grant succeeded.

SQL> CREATE
TABLE referring
(person
VARCHAR2(32)
PRIMARY KEY,
2 base_id
REFERENCES
base_view(id));
CREATE TABLE
referring (person
VARCHAR2(32)
PRIMARY KEY,
*
ERROR at line 1:
ORA-02270: no
matching unique
or primary key
for this column-
list

That is not to say


that there isn't a
more elegant
solution to your
problem. One of
the many things
I've learned
about Oracle is
this: if
something clever
isn't working, re-
examine your
schema.

In fact that is
precisely the
advice that
Oracle ACE

http://thinkoracle.blogspot.com/2006_11_01_archive.html (9 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

Andrew "Arfur
C." Clarke gave
someone in your
exact same
position, who
had wisely
posted his
problem to a
forum (instead of
asking a dummy
like me).

For instance, you


could instead
create a table
representing the
subset of
financial
transactions you
want, and
another
identically-
structured table
for all other
transactions, and
then your
transactions
table could be a
view of both.
That's what one
expert
considered.
However, I'm not
sure that's what
you want:
maintaining two
identical tables.
Plus, now your
financial
transactions
table is a view
and can't be
referenced,

http://thinkoracle.blogspot.com/2006_11_01_archive.html (10 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

putting you in
the same boat
for some other
table.

I didn't intend to
offer a specific
suggestion for
your schema
because it would
require knowing
a lot more about
your business,
these tables, and
what your
requirements
really are. I'm
just saying that
there may be an
elegant solution
if you take a
closer look.

I preach views
because they
serve so many
useful purposes.
Unfortunately,
managing this
type of integrity
constraint
directly isn't one
of them. Stick to
your trigger.

// posted by Robert
Vollman @ Friday,
November 10,
2006 2 comments

http://thinkoracle.blogspot.com/2006_11_01_archive.html (11 of 12)1/9/2008 2:50:36 AM


OracleBlog: November 2006

http://thinkoracle.blogspot.com/2006_11_01_archive.html (12 of 12)1/9/2008 2:50:36 AM


OracleBlog: December 2006

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, December
About Me
04, 2006
Name: Robert Vollman
REGEXP_LIKE Location: Calgary, Alberta, Canada
Recently I invited
anyone who has I was born and raised in Ottawa, and have lived
been considering in Calgary since 1991. I like playing sports
joining the Oracle (hockey, soccer, ultimate, basketball, you name it) and
blogging community military board games. I also enjoy reading, walking, and
to jump right in. playing with my 2 cats Lilly and Brutus. I'm a database
Please, help me application specialist, whatever that is.
encourage John H:
View my complete profile
Robert,

Way cool blog. I


really need to create Best Links
one too. I like to ● Ask Tom Kyte
adhere to best Oracle Docs
practices and love to

Dan Morgan and PSOUG


read stuff from Tom

Steven Feuerstein
K. and Steven F.!

● Jonathan Lewis
I have a question on ● FAQ
regular expression ● Connor McDonald
check constraints ● The Oak Table
and was wondering ● Cary Millsap and Hotsos
if you can help: ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006_12_01_archive.html (1 of 6)1/9/2008 2:50:39 AM


OracleBlog: December 2006

● Anjo Kolk and OraPerf


alter table ● Dizwell Oracle Wiki
logical_address ● My Personal Blog
modify (address_ip
check (

regexp_like
(address_ip,'((^([2][0-
Aggregators
5]{2}\.|[2][0-4][0-9] Brian Duff's OraBlogs

\.| ❍ Eddie Awad's OracleNA


([0-1]\d\d)\.|\d\d\.| ❍ Pete Finnigan's Aggregator
\d\.)) ❍ Oracle's Bloglist
([2][0-5]{2}\.|[2][0-4] ❍ Oracle Base Aggregator
[0-9]\.|
([0-1]\d\d)\.|\d\d\.|
\d\.){2})(([2][0-5]{2}
Top Blogs
Oracle's Ask Tom Kyte
$)| ❍

([0-1]\d\d$)|(\d\d$)| ❍ Oracle Guru Jonathan Lewis


(\d$))'))) ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
Isn't there a better ❍ Oracle Geek Lewis Cunningham
way to write this? ❍ Database Expert James Koopmann
Oh! the pattern ❍ Dizwell's Howard Rogers
works in a Oracle Master Laurent Schneider
regexp_substr but

Security Expert Pete Finnigan


not in the

Oracle Award Winner Mark Rittman


regexp_like. Thanks

Doug Burns
in advance... ❍

❍ Oracle ACE of the Year Dr. Tim Hall


I applaud what John ❍ UKOUG's Andrew (Arfur C.) Clarke
is trying to do: ❍ Newbie DBA Lisa Dobson
manage the integrity ❍ Coffee-Drinking DBA Jon Emmons
of the data in the ❍ Chris Foot
database. His ❍ The Pythian DBA Team Blog
request is a common ❍ DBA Don Seiler
one, and I wish it ❍ DBA Coskan Gundogar
were even more ❍ Oracle WTF
common. Too many
databases are
designed to simply
ARCHIVES
trust that whatever ❍ LIST ALL ARTICLES
application is ❍ May 2005
providing the IP ❍ June 2005
address has already ❍ July 2005

http://thinkoracle.blogspot.com/2006_12_01_archive.html (2 of 6)1/9/2008 2:50:39 AM


OracleBlog: December 2006

checked it. ❍ August 2005


❍ September 2005
Unfortunately, I'm ❍ October 2005
limited in what November 2005
assistance I can

December 2005
provide with regards

January 2006
to regular

February 2006
expressions. Since

March 2006
I'm still using Oracle

April 2006
9, I can't take

advantage of one of ❍ May 2006


the finest features of ❍ June 2006
Oracle 10. I get a lot ❍ July 2006
of questions about ❍ August 2006
REGEXP in the past ❍ September 2006
year and a half, but I ❍ October 2006
can't offer much ❍ November 2006
more than those ❍ December 2006
links to articles and ❍ January 2007
references. ❍ February 2007
Wanting to offer ❍ March 2007
John something of ❍ April 2007
value, I wondered ❍ May 2007
how I would address ❍ June 2007
this issue in Oracle ❍ October 2007
9. I recall coming
across this once ❍ Current Posts
before, but we
actually chose to
store the IP address
as a 32-bit integer
which, by the way, is
the same way our OS
stored it. I wrote a
quick procedure that
would convert that
32-bit integer into a
readable IP address
(or "dotted-quad"
notation). The
specific details are
proprietary to the

http://thinkoracle.blogspot.com/2006_12_01_archive.html (3 of 6)1/9/2008 2:50:39 AM


OracleBlog: December 2006

company for which I


worked at the time,
but it should be easy
enough to reproduce
if you went that
route.

Of course, this
approach didn't
check that the 32-
bit integer was
convertible to an IP
address valid to my
application. That
problem, however, is
a specific case of a
very common
general requirement:
write a constraint to
check the validity of
a string. Briefly, in a
case like this, I
would convert the IP
address to special
coded string using
TRANSLATE, and
then CHECK if that
string matched a set
pattern. Further, in
particular complex
cases, I often resort
to checking the
constraint with a
trigger.

In the end, I
suggested John post
this question in an
Oracle forum. There
are lots of people
there, including
things who are
familiar with REGEXP

http://thinkoracle.blogspot.com/2006_12_01_archive.html (4 of 6)1/9/2008 2:50:39 AM


OracleBlog: December 2006

(unlike me) who can


give him a hand. But
I believe he came up
with a satisfactory
solution on his own.
I'm including it here,
and I know he would
appreciate a critique
if anyone familiar
with REGEXP has
something to offer.

alter table
logical_address
add constraint
la_address_ip_chk
check (
regexp_like(
address_ip,
'((^([2][0-5]{2}\.|[2]
[0-4][0-9]\.|([0-1]\d
\d)\.|\d\d\.|\d\.))([2]
[0-5]'||
'{2}\.|[2][0-4][0-9]\.|
([0-1]\d\d)\.|\d\d\.|
\d\.){2})(([2][0-5]{2}
$)|'||
'([0-1]\d\d$)|(\d\d
$)|(\d$))'
)
);

alter table
logical_address
add constraint
la_address_mac_chk
check (
regexp_like
(address_mac,
'((([0-9]|[A-Z]){2})(:))
{5}([0-9]|[A-Z]){2}|
((([0-9]|[A-Z]){2})(-))
{5}'||

http://thinkoracle.blogspot.com/2006_12_01_archive.html (5 of 6)1/9/2008 2:50:39 AM


OracleBlog: December 2006

'([0-9]|[A-Z]){2}'
)
);

alter table
logical_address
add constraint
la_port_chk
check (
regexp_like
(address_port,'[0! -9]
{5}| [0-9]{4}')
);

// posted by Robert
Vollman @ Monday,
December 04, 2006 2

comments

http://thinkoracle.blogspot.com/2006_12_01_archive.html (6 of 6)1/9/2008 2:50:39 AM


OracleBlog: January 2007

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated, but it
is the most powerful tool when it comes to data. That's why when I think data, I think Oracle. I also enjoy
writing, so I use this format to organise my thoughts. Please feel free to discuss any thoughts you may
have on the same topics, even old ones (I will see and respond to such comments). You may want to
start with "LIST ALL ARTICLES" under Archives.

Thursday, January 25, 2007


About Me
REPOST: Pivot and Crosstab Queries Name: Robert
Here is another advanced concept that will come in useful Vollman
when solving Oracle problems. Location: Calgary,
Alberta, Canada
Imagine you're trying to create a result set where the rows
need to be columns, or vice versa. In essence, you need to
"pivot" rows into columns, or vice versa. That is a very I was born and raised in Ottawa,
common requirement, and this is where you need to look and have lived in Calgary since
at a pivot (or crosstab) query to get the job done. 1991. I like playing sports
(hockey, soccer, ultimate,
As always, when you want to understand something, you basketball, you name it) and
can start by Asking Tom. military board games. I also
enjoy reading, walking, and
A simple pivot query is accomplished by basically doing the playing with my 2 cats Lilly and
following: Brutus. I'm a database
1. Add some kind of count or row number to your query, if application specialist, whatever
necessary for the grouping that is.
2. Then use your (revised) original query as a sub-query
3. Use "decode" to turn rows into columns (ie. a "sparse" View my complete profile
matrix).
4. Use "max" to "squash" the multiple rows you moved to
columns, into single rows. Don't forget to group by.
(Note: it gets more complicated if you don't know how
Best Links
Ask Tom Kyte
many columns you'll need). ●

● Oracle Docs
Here is another one of Ask Tom's examples. It clearly ● Dan Morgan and PSOUG
shows how you use decode to create a "sparse" matrix, and ● Steven Feuerstein
then use max to "squash" it down. ● Jonathan Lewis
● FAQ
Let's look a simple example in slow motion. ● Connor McDonald
The Oak Table
Here's the data

CREATE TABLE CFL (season NUMBER(4), team VARCHAR2 ● Cary Millsap and Hotsos
(16), points NUMBER(3)); ● Steve Adams and Ixora
INSERT INTO CFL (season, team, points) VALUES (2004, ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2007_01_01_archive.html (1 of 4)1/9/2008 2:50:42 AM


OracleBlog: January 2007

'Argonauts', 21); ● Dizwell Oracle Wiki


INSERT INTO CFL (season, team, points) VALUES (2004, ● My Personal Blog
'Alouettes', 28);
INSERT INTO CFL (season, team, points) VALUES (2004,

Aggregators
'Tiger-Cats', 19);
INSERT INTO CFL (season, team, points) VALUES (2004,
'Renegades', 10);
Brian Duff's OraBlogs
INSERT INTO CFL (season, team, points) VALUES (2003,

Eddie Awad's OracleNA


'Argonauts', 18);

Pete Finnigan's Aggregator


INSERT INTO CFL (season, team, points) VALUES (2003, ❍

'Alouettes', 26); ❍ Oracle's Bloglist


INSERT INTO CFL (season, team, points) VALUES (2003, ❍ Oracle Base Aggregator
'Tiger-Cats', 2);
INSERT INTO CFL (season, team, points) VALUES (2003, Top Blogs
'Renegades', 14); ❍ Oracle's Ask Tom Kyte
INSERT INTO CFL (season, team, points) VALUES (2002, ❍ Oracle Guru Jonathan Lewis
'Argonauts', 16); Blogger of the Year Eddie Awad
INSERT INTO CFL (season, team, points) VALUES (2002,

Data Warehouser David Aldridge


'Alouettes', 27);

Oracle Geek Lewis Cunningham


INSERT INTO CFL (season, team, points) VALUES (2002,

Database Expert James Koopmann


'Tiger-Cats', 15); ❍

INSERT INTO CFL (season, team, points) VALUES (2002, ❍ Dizwell's Howard Rogers
'Renegades', 10); ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
What we want: ❍ Oracle Award Winner Mark
A table showing each of these 4 teams and their point Rittman
tables for these 3 seasons. ❍ Doug Burns
Oracle ACE of the Year Dr. Tim
So what is our pivot row/column? Season.

Hall
Step 1/2: We are using season, so we don't need to create ❍ UKOUG's Andrew (Arfur C.) Clarke
our own grouping field, like count, rownum, or running ❍ Newbie DBA Lisa Dobson
total (sum) for example. That would be easy enough to do, ❍ Coffee-Drinking DBA Jon Emmons
but let's keep this simple. ❍ Chris Foot
❍ The Pythian DBA Team Blog
Step 3: Use "decode" to turn the season row into a column. ❍ DBA Don Seiler
Take a look at our "sparse" matrix. ❍ DBA Coskan Gundogar
Oracle WTF
SELECT team, ❍

DECODE (season, 2002, points, NULL) Yr2002,


DECODE (season, 2003, points, NULL) Yr2003, ARCHIVES
DECODE (season, 2004, points, NULL) Yr2004 ❍ LIST ALL ARTICLES
FROM (SELECT season, team, points FROM CFL); ❍ May 2005
❍ June 2005
TEAM YR2002 YR2003 YR2004 ❍ July 2005
---------------- ---------- ---------- ---------- ❍ August 2005
Argonauts 21 ❍ September 2005
Alouettes 28 ❍ October 2005
Tiger-Cats 19
❍ November 2005
Renegades 10
❍ December 2005
Argonauts 18
❍ January 2006

http://thinkoracle.blogspot.com/2007_01_01_archive.html (2 of 4)1/9/2008 2:50:42 AM


OracleBlog: January 2007

Alouettes 26 ❍ February 2006


Tiger-Cats 2 ❍ March 2006
Renegades 14 ❍ April 2006
Argonauts 16 ❍ May 2006
Alouettes 27 ❍ June 2006
Tiger-Cats 15
❍ July 2006
Renegades 10
❍ August 2006
❍ September 2006
❍ October 2006
Step 4: Now let's use max to "squash" this into single rows. ❍ November 2006
Don't forget GROUP BY. ❍ December 2006
January 2007
SELECT team,

February 2007
MAX (DECODE (season, 2002, points, NULL)) Yr2002,

March 2007
MAX (DECODE (season, 2003, points, NULL)) Yr2003,

April 2007
MAX (DECODE (season, 2004, points, NULL)) Yr2004 ❍

FROM (SELECT season, team, points FROM CFL) ❍ May 2007


GROUP BY team; ❍ June 2007
❍ October 2007
TEAM YR2002 YR2003 YR2004
❍ Current Posts
---------------- ---------- ---------- ----------
Alouettes 27 26 28
Argonauts 16 18 21
Renegades 10 14 10
Tiger-Cats 15 2 19

Pretty cool, eh? Easy, too.

Notice that the key to this is DECODE. If DECODE is not


already part of your toolbelt, I recommend studying up.

Ready for a tougher example? Let's look at another Ask


Tom.

For further study of pivot queries and analytic functions in


general, there is an awesome write-up in Chapter 12 of
Tom Kyte's "Expert One-on-One Oracle." You'd think I'd get
a kickback from Tom Kyte with all the promotion I'm doing,
but the honest truth is that no one explains it as well as he.

So, do you understand pivot queries now? No problems?

If so, now you're ready for one of Ask Tom's more complex
examples.

Pivot Tables

One final word: don't confuse pivot queries with pivot


tables. Pivot tables are a different concept, and have

http://thinkoracle.blogspot.com/2007_01_01_archive.html (3 of 4)1/9/2008 2:50:42 AM


OracleBlog: January 2007

different uses (most typically to fill in missing data). Until I


blog about pivot tables, check out these two links:

Jonathan Gennick Updated


Laurent Schneider

Originally posted September 1, 2005

// posted by Robert Vollman @ Thursday, January 25, 2007 3 comments

http://thinkoracle.blogspot.com/2007_01_01_archive.html (4 of 4)1/9/2008 2:50:42 AM


OracleBlog: February 2007

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, February
About Me
26, 2007
Name: Robert Vollman
Fun With Location: Calgary, Alberta, Canada
Tom Kyte
As devoted I was born and raised in Ottawa, and have lived in
readers may have Calgary since 1991. I like playing sports (hockey,
noticed, my new soccer, ultimate, basketball, you name it) and military board
job doesn't involve games. I also enjoy reading, walking, and playing with my 2
nearly as much cats Lilly and Brutus. I'm a database application specialist,
work with Oracle. I whatever that is.
stay sharp by
reading Ask Tom, View my complete profile
the very site that
has provided me
with 90% of the
answers that I
Best Links
can't find in Oracle ● Ask Tom Kyte
Oracle Docs
documentation or ●

Dan Morgan and PSOUG


figure out on my ●

own. ● Steven Feuerstein


● Jonathan Lewis
Those of you who ● FAQ
may find it nerdly ● Connor McDonald
to spend lunch ● The Oak Table
hours reading ● Cary Millsap and Hotsos
Oracle Q&A are ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2007_02_01_archive.html (1 of 7)1/9/2008 2:50:45 AM


OracleBlog: February 2007

actually really ● Anjo Kolk and OraPerf


missing out. It's ● Dizwell Oracle Wiki
far more ● My Personal Blog
entertaining than
you may realise.
To prove my
point, just from
posts updated in
Aggregators
Brian Duff's OraBlogs
the past week

Eddie Awad's OracleNA


alone, here are ❍

some little ❍ Pete Finnigan's Aggregator


hilarious ❍ Oracle's Bloglist
comments that ❍ Oracle Base Aggregator

Top Blogs
can only come
from Tom Kyte.
❍ Oracle's Ask Tom Kyte
1. Archiving Huge ❍ Oracle Guru Jonathan Lewis
Database ❍ Blogger of the Year Eddie Awad
Data Warehouser David Aldridge
This question is a

Oracle Geek Lewis Cunningham


tad vague, ❍

ambiguous and ❍ Database Expert James Koopmann


unanswerable. ❍ Dizwell's Howard Rogers
How long is a ❍ Oracle Master Laurent Schneider
piece of string? ❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
2. ❍ Doug Burns
Internationalization ❍ Oracle ACE of the Year Dr. Tim Hall
UKOUG's Andrew (Arfur C.) Clarke
Translation table

Newbie DBA Lisa Dobson


used for

Coffee-Drinking DBA Jon Emmons


processing input ❍

was: ❍ Chris Foot


❍ The Pythian DBA Team Blog
wud = would ❍ DBA Don Seiler
u = you ❍ DBA Coskan Gundogar
ur = your ❍ Oracle WTF
abt = about

I think your
ARCHIVES
keyboard might be ❍ LIST ALL ARTICLES
on the fritz? ❍ May 2005
Vowels are ❍ June 2005
disappearing left ❍ July 2005

http://thinkoracle.blogspot.com/2007_02_01_archive.html (2 of 7)1/9/2008 2:50:45 AM


OracleBlog: February 2007

and right ❍ August 2005


❍ September 2005
3. SQL Query
❍ October 2005
November 2005
Joins are not evil.

❍ December 2005
Databases were ❍ January 2006
BORN to join. ❍ February 2006
❍ March 2006
Joins are not evil. ❍ April 2006
May 2006
4. Collection

June 2006
Variable Types

❍ July 2006
Your naming ❍ August 2006
convention would ❍ September 2006
drive me utterly ❍ October 2006
nuts ❍ November 2006
❍ December 2006
5. What Don't You ❍ January 2007
Like About Oracle? ❍ February 2007
March 2007
*((char*)0) = "go

April 2007
away";

❍ May 2007
6. Backup Recovery ❍ June 2007
❍ October 2007
You have done it
totally wrong. ❍ Current Posts

Do it right.

Look - there is
one thing and one
thing only a DBA
is not allowed to
mess up. We can
fix everything
EXCEPT a bad
backup.
Everything else is
just a mistake.
Screwing up your
backups is far far

http://thinkoracle.blogspot.com/2007_02_01_archive.html (3 of 7)1/9/2008 2:50:45 AM


OracleBlog: February 2007

beyond a mistake
-- it is grounds
for immediate
"good bye, you are
the weakest link".

Could you, in
theory, perhaps --
maybe -- get
lucky and be able
to use them?
maybe,
sometimes, on
Tuesday when it is
raining.

Is it smart (NOT)
Is it the right way
(NOT)
Is it even a teeny
tiny bit reliable
(NOT)

I fail to see how


your example
even "makes
sense".

BONUS:

Q: TOM you are


not only expert of
Oracle but also
Windows.....
Thanks it worked.

A: I think I've just


been insulted :)

7. Fast Refresh is
Taking Longer
Than Complete
Refresh of
Materialized View

http://thinkoracle.blogspot.com/2007_02_01_archive.html (4 of 7)1/9/2008 2:50:45 AM


OracleBlog: February 2007

Just set:

fast=true

in the init.ora.

Sorry - it is
Monday and my
sense of humor is
just getting
warmed up :)

8. REDO Logs
Generated from
PL/SQL

Allow me to be
blunt. That would
be stupid. 100%.

9. Logminer

Tell the DBA ok

They will hate


themselves for
totally messing up
their lives.

I don't know what


else to say - this
is a horrible idea,
a great way for the
DBA to ensure
they have a job for
life - but a job
that no human
being would
actually want.

10. Designing
Tables

http://thinkoracle.blogspot.com/2007_02_01_archive.html (5 of 7)1/9/2008 2:50:45 AM


OracleBlog: February 2007

Q: How can we
achieve, easier
developer
understanding of
the table design,
without one
explaining the
table design
document / ER
Model.
A: Telepathy I
suppose?

BONUS: The All-


Time Classic

Oracle Database

Q: Dear tom can u


tell me the
meaning of
recursive query?

"U" is not available.

I have never met


this "U" person.

Do you know how


to contact "U" -
they get a lot of
requests, it would
be great if I could
pass the questions
on to them.

May "I" answer the


question?

// posted by Robert
Vollman @ Monday,
February 26, 2007 6

comments

http://thinkoracle.blogspot.com/2007_02_01_archive.html (6 of 7)1/9/2008 2:50:45 AM


OracleBlog: February 2007

http://thinkoracle.blogspot.com/2007_02_01_archive.html (7 of 7)1/9/2008 2:50:45 AM


OracleBlog: March 2007

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, March 09,


About Me
2007
Name: Robert Vollman
40 Tips From Location: Calgary, Alberta, Canada
Tom
Everybody learns I was born and raised in Ottawa, and have lived
their lessons, and so in Calgary since 1991. I like playing sports
will you. The only (hockey, soccer, ultimate, basketball, you name it) and
variable is how military board games. I also enjoy reading, walking, and
expensive the lesson playing with my 2 cats Lilly and Brutus. I'm a database
is. While there is no application specialist, whatever that is.
substitute for direct,
first-hand View my complete profile
experience, the
cheapest way to learn
a lesson is to benefit
from the experience
Best Links
of others. ● Ask Tom Kyte
● Oracle Docs
My favourite source ● Dan Morgan and PSOUG
of cheap lessons is ● Steven Feuerstein
Ask Tom. I've ● Jonathan Lewis
compiled a sample ● FAQ
collection of Tom's ● Connor McDonald
Wisdom from just the The Oak Table
articles updated in

Cary Millsap and Hotsos


the past week.

Steve Adams and Ixora


Review this list and

http://thinkoracle.blogspot.com/2007_03_01_archive.html (1 of 10)1/9/2008 2:50:47 AM


OracleBlog: March 2007

consider how many ● Anjo Kolk and OraPerf


free lessons are ● Dizwell Oracle Wiki
contained in the past ● My Personal Blog
7 years of archived
information!

The number next to


every tip has a
Aggregators
hyperlink to the Brian Duff's OraBlogs

appropriate question. ❍ Eddie Awad's OracleNA


I included this ❍ Pete Finnigan's Aggregator
because I remember ❍ Oracle's Bloglist
that Tom's credo is ❍ Oracle Base Aggregator

Top Blogs
"Trust, but Verify."
Trust in Tom's
wisdom, but check Oracle's Ask Tom Kyte
the context of his

Oracle Guru Jonathan Lewis


advice so you can see

Blogger of the Year Eddie Awad


if it applies to your

situation, is still valid ❍ Data Warehouser David Aldridge


today, and that it ❍ Oracle Geek Lewis Cunningham
wasn't one of those ❍ Database Expert James Koopmann
rare cases where he ❍ Dizwell's Howard Rogers
got it wrong. ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
As a bonus for those ❍ Oracle Award Winner Mark Rittman
who enjoyed my last Doug Burns
post about Tom's

Oracle ACE of the Year Dr. Tim Hall


more entertaining

UKOUG's Andrew (Arfur C.) Clarke


side, I've included a

Newbie DBA Lisa Dobson


bit more of his biting ❍

Coffee-Drinking DBA Jon Emmons


humour too.

❍ Chris Foot
1. Row-level locking ❍ The Pythian DBA Team Blog
has no overhead, not ❍ DBA Don Seiler
for 1 lock, not for 1 ❍ DBA Coskan Gundogar
billion locks ❍ Oracle WTF

ARCHIVES
2. Reads are never
blocked, and reads
don't block ❍ LIST ALL ARTICLES
3. The best UI is a ❍ May 2005
command line ❍ June 2005
4. Always use ❍ July 2005

http://thinkoracle.blogspot.com/2007_03_01_archive.html (2 of 10)1/9/2008 2:50:47 AM


OracleBlog: March 2007

packages, for all ❍ August 2005


good, real, ❍ September 2005
production code ❍ October 2005
4a. Never use a ❍ November 2005
standalone procedure ❍ December 2005
except for demos, January 2006
tests and standalone

February 2006
utilities that call

March 2006
nothing and are

called by nothing. ❍ April 2006


4b. Packages break ❍ May 2006
the dependency ❍ June 2006
chain, support ❍ July 2006
encapsulation, ❍ August 2006
increase namespace, ❍ September 2006
support overloading ❍ October 2006
and session ❍ November 2006
variables, and ❍ December 2006
promote overall good ❍ January 2007
coding techniques ❍ February 2007
5. Use the same
❍ March 2007
source control April 2007
techniques for PL/

May 2007
SQL as you would for

June 2007
any other language

(C, Java, VB) ❍ October 2007


6. Use dbms_stats
Current Posts
instead of Analyze

6a. Easier to
automate, the stated/
preferred way of
collecting statistics,
can analyze external
tables, gathers
statistics need for
CBO (and nothing
extra)
7. Serializable does
not imply serial
ordering
8. To be useful, know
more than just the

http://thinkoracle.blogspot.com/2007_03_01_archive.html (3 of 10)1/9/2008 2:50:47 AM


OracleBlog: March 2007

technology, know the


business and the
goals of your
organisation
9. Joins are not evil.
Databases were born
to join.
10. Never compare
strings to dates, and
dates to strings.
Compare dates to
dates, strings to
strings, numbers to
numbers and never
any other
combination.
11. Beware of implicit
conversions of dates
and numbers. Avoid
implicit like the
plague, explicit is
good
12. Never
TO_NUMBER a
number, never
TO_DATE a date
13. Stop using YY in
your date formatting,
now and forever
14. Autonomous
transactions as a
feature was a huge
mistake, they are
rarely used in a
manner that is safe.
15. Never copy online
redolog when your
database is in
archivelog mode
16. Never restore the
online redo log files
17. Rollback is not

http://thinkoracle.blogspot.com/2007_03_01_archive.html (4 of 10)1/9/2008 2:50:47 AM


OracleBlog: March 2007

just for
modifications, this is
fundamental about
Oracle
18. Stop committing
until your transaction
is complete
19. Don't use a loop
when a single query
will do
19a. Use bulk
processing instead of
slow-by-slow
processing
20. For performance
reasons, call PL/SQL
(or worse, Java) from
SQL if and where
there is quite simply
no other way
21. Large databases
are neither slow nor
scary
22. Analytical
functions are for
those who crave,
desire or just
sometimes NEED
speed.
23. The way to
understand is to do
24. Soft parse
percentage? 99% and
above is good.
25. Select only the
columns you need,
not *
26. When designing a
table, put the most
frequently access
columns first, those
most likely to be

http://thinkoracle.blogspot.com/2007_03_01_archive.html (5 of 10)1/9/2008 2:50:47 AM


OracleBlog: March 2007

NULL last, but don't


overnalyse it.
27. Disk is cheap.
Data integrity,
priceless.
28. You cannot put
CPU in the bank and
save it for later. If
you are at 99.99%
utilization -- pat
yourself on the back,
you've done well.
29. Analytics rock.
Analytics roll.
30. Don't use the
slower UNION when
UNION ALL will do
31. Never never
never do dynamically
what you can do
statitically, in PL/SQL.
32. You want to
scale? Use static SQL
in PL/SQL, all binds,
all the time.
33. Triggers are evil.
34. Magic should be
avoided. Experience
tells me this.
35. Never create stuff
as "sys" or "sysdba",
thats a special
magical account not
to be used by you or
me.
36. Be careful doing
anything non-
transactional in a
trigger. It won't
rollback when the
transaction rolls back.
36a. Be very careful

http://thinkoracle.blogspot.com/2007_03_01_archive.html (6 of 10)1/9/2008 2:50:47 AM


OracleBlog: March 2007

using any routine


that starts with UTL_
in a trigger, they're
generally non-
transactional
37. Use
dbms_application_info
package to allow you
to show a
procedure's progress
in v$session.
38. The sheer beauty
of PL/SQL is that your
concerns with other
languages, like
"parse once; execute
many" and using bind
variables are done
automatically and
transparently.
39. Cursor sharing is
a bad thing, if you
don't need it
40. Not binding is
actually harder to do
than binding (and
less secure)

More Tom Humour!

Refresh on
Materialized View

Q: see oracle bug no


2088032
A: And then scratch
your head and ask
"why am I reading
this bug report which
doesn't have
anything to do with
my problem?"

http://thinkoracle.blogspot.com/2007_03_01_archive.html (7 of 10)1/9/2008 2:50:47 AM


OracleBlog: March 2007

Update Statement
Not that I don't
believe you -- but --
I don't believe you.

Oracle PL/SQL -
Performance Tuning
- Comments in Code
In response to
someone saying their
code review team
told them to remove
comments from the
code for performance
reasons. I just KNEW
a good retort was
coming.

Oh my gosh.

I have never heard of


anything so - well, I
won't be that blunt,
fill in your favorite
word.
...
get a new code
review team, one that
actually knows how
to review code
...
umm, they are sort of
"not correct"

DBMS_JOB Package
This is one of Tom's
favourite comebacks
to someone saying "it
doesn't work."

My car won't start


either. why not?

Umm, define "does

http://thinkoracle.blogspot.com/2007_03_01_archive.html (8 of 10)1/9/2008 2:50:47 AM


OracleBlog: March 2007

not work"

String Concatenation
Q: Can you do the
same thing in
Microsoft SQL server
2000....
A: That would be a
good question for
askbill@ms.com....

Restoring a file
stored in a database
hahahahaha, ouch.
sorry I just fell out of
my chair.

Hmm, the bigger the


database, the slower
it is. Interesting.

But completely and


utterly wrong.

CPU Utilization
Q: How can I reduce
CPU utilization of
Oracle database?
A: shutdown abort
works well ;)

Refresh Complete
and Rollback
Q: I have read/heard/
been told that
snapshots are a lot of
overhead.
A: I heard that
business travelers
better not goto bars
cause there are
people that will drug
you and take out

http://thinkoracle.blogspot.com/2007_03_01_archive.html (9 of 10)1/9/2008 2:50:47 AM


OracleBlog: March 2007

your kidneys to sell


on the black market.

Rollback Segments
Q: insert /*+ append
nologging */ into t
select * from t_stging
where country_code
= 'US'
A: That insert is just
the same as:
insert /*+ append
hello world!!!! how
you DOING? */ into
t ......

// posted by Robert
Vollman @ Friday, March

09, 2007 1 comments

http://thinkoracle.blogspot.com/2007_03_01_archive.html (10 of 10)1/9/2008 2:50:47 AM


OracleBlog: April 2007

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, April 05, 2007


About Me
Oracle Beefs Name: Robert Vollman
I've got very few beefs with Location: Calgary, Alberta, Canada
Oracle. It is extremely
complicated and tough to
I was born and raised in Ottawa, and have
learn compared to other
lived in Calgary since 1991. I like playing
relational databases, but
sports (hockey, soccer, ultimate, basketball, you name
that's partially offset by the
it) and military board games. I also enjoy reading,
tremendous
walking, and playing with my 2 cats Lilly and Brutus.
documentation, and the
I'm a database application specialist, whatever that is.
huge Oracle community.

Don't get me wrong, I love View my complete profile


Oracle. I'm regularly
impressed by the
sophisticated and often Best Links
clever ways it handles the ● Ask Tom Kyte
requirements of an RDBMS, ● Oracle Docs
and quick to recommend
Dan Morgan and PSOUG
its use. But before making

Steven Feuerstein
that recommendation, I

Jonathan Lewis
make it clear that this ●

advantage has a trade-off: ● FAQ


expense. ● Connor McDonald
● The Oak Table
Oracle is expensive by ● Cary Millsap and Hotsos
itself, both in money and ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2007_04_01_archive.html (1 of 5)1/9/2008 2:50:50 AM


OracleBlog: April 2007

in resources. Furthermore, ● Anjo Kolk and OraPerf


it can be difficult to find ● Dizwell Oracle Wiki
people that know it well, or ● My Personal Blog
to train your own staff. You
better be sure that you are
planning on taking
advantage of the benefits
of using a more powerful,
Aggregators
Brian Duff's OraBlogs
fast and reliable RDBMS

Eddie Awad's OracleNA


before choosing Oracle. ❍

Too often I have seen ❍ Pete Finnigan's Aggregator


software developed for ❍ Oracle's Bloglist
Oracle, but seemingly ❍ Oracle Base Aggregator

Top Blogs
going to great pains to
actually AVOID using the
packages, features and ❍ Oracle's Ask Tom Kyte
facilities Oracle has built- Oracle Guru Jonathan Lewis
in to maintain data

Blogger of the Year Eddie Awad


integrity and speed up

Data Warehouser David Aldridge


data access.

❍ Oracle Geek Lewis Cunningham


My other beefs with Oracle ❍ Database Expert James Koopmann
are mostly just pet peeves. ❍ Dizwell's Howard Rogers
It still boggles me how ❍ Oracle Master Laurent Schneider
they can refuse to ❍ Security Expert Pete Finnigan
introduce a Boolean type ❍ Oracle Award Winner Mark Rittman
because we don't NEED it, ❍ Doug Burns
and yet introduce all sorts ❍ Oracle ACE of the Year Dr. Tim Hall
of convoluted features (like
UKOUG's Andrew (Arfur C.) Clarke
DBMS_ADVANCED_REWRITE,

Newbie DBA Lisa Dobson


another pet peeve). I also

Coffee-Drinking DBA Jon Emmons


wish that constraints on

Chris Foot
views could be enforced.

❍ The Pythian DBA Team Blog


Speaking of pet peeves, ❍ DBA Don Seiler
there has been a whole ❍ DBA Coskan Gundogar
discussion on AskTom over ❍ Oracle WTF
the past couple of years.
Here are my top ten most ARCHIVES
interesting: ❍ LIST ALL ARTICLES
❍ May 2005
1. The "table or view does
June 2005
not exist" error message

❍ July 2005

http://thinkoracle.blogspot.com/2007_04_01_archive.html (2 of 5)1/9/2008 2:50:50 AM


OracleBlog: April 2007

should include the name of ❍ August 2005


the invalid table/view. ❍ September 2005
October 2005
2. A lot of people

November 2005
mentioned wanting better

December 2005
formatting in SQL*Plus ❍

❍ January 2006
3. Niall Litchfield has a ❍ February 2006
good rumination about ❍ March 2006
binds that started a bit of a ❍ April 2006
discussion: ❍ May 2006
June 2006
I really don't see why

July 2006
"select cols from tab where

August 2006
pk = 10;" should be ❍

radically worse than "select ❍ September 2006


cols from tab where pk = : ❍ October 2006
b1;" I know why it is, I just ❍ November 2006
wish it wasn't. ❍ December 2006
❍ January 2007
4. Look for Alberto ❍ February 2007
Dell'Era's desire for better ❍ March 2007
instrumentation. I find April 2007
Oracle's instrumentation

May 2007
far superior to others

June 2007
RDBMS, but I agree there's

always room for ❍ October 2007


improvement.
❍ Current Posts
5. Customized errors
messages for constraint
violations, like in Sybase.
Example: alter table
widgets add constraint
cost_chk check (cost <
100) error "Widget cost
must be less than $100";

6. There were some who


wanted to be able to
disable implicit type
conversion

7. Check out Connor

http://thinkoracle.blogspot.com/2007_04_01_archive.html (3 of 5)1/9/2008 2:50:50 AM


OracleBlog: April 2007

McDonald's 19 suggestions
(what, he couldn't think of
1 more to make a round
number?)

8. Better support for


business rules in the
database. I interpret this as
being able to support
multi-table check
constraints without
restoring to triggers: I'd
love that. ANSI has it.

9. Stop treating empty


strings as NULL (I'm not
touching this one, I'm just
saying it's interesting).

10. Having an auto-


incrementing identity
column, without using
sequences and such.

Incidentally, don't expect


Tom to defend Oracle on
every point. He himself has
a few beefs I've heard over
the years: autonomous
transactions, "WHEN
OTHERS" exception
handling, triggers, and
others.

Final point: please check


out and enjoy some blogs
that are new among my
links: Don Seiler and
Coskan Gundogar.

// posted by Robert
Vollman @ Thursday, April 05,

2007 5 comments

http://thinkoracle.blogspot.com/2007_04_01_archive.html (4 of 5)1/9/2008 2:50:50 AM


OracleBlog: April 2007

http://thinkoracle.blogspot.com/2007_04_01_archive.html (5 of 5)1/9/2008 2:50:50 AM


OracleBlog: May 2007

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, May
About Me
28, 2007
Name: Robert Vollman
Multirow Location: Calgary, Alberta, Canada
Inserts
While I was born and raised in Ottawa, and have lived in
attempting to Calgary since 1991. I like playing sports (hockey,
insert several soccer, ultimate, basketball, you name it) and military board games.
rows into a I also enjoy reading, walking, and playing with my 2 cats Lilly and
table in our Brutus. I'm a database application specialist, whatever that is.
Oracle
database, a View my complete profile
colleague
dutifully
copied the
exact ANSI/ISO
Best Links
SQL standard ● Ask Tom Kyte
syntax for his ● Oracle Docs
purposes. ● Dan Morgan and PSOUG
Guess what ● Steven Feuerstein
happened? ● Jonathan Lewis
● FAQ
INSERT INTO
Connor McDonald
table

The Oak Table


(column1,

Cary Millsap and Hotsos


column2) ●

VALUES ● Steve Adams and Ixora


(value1, ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2007_05_01_archive.html (1 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

value2), ● Dizwell Oracle Wiki


(value1, ● My Personal Blog
value2);

ERROR at line 1:
ORA-00933:
SQL command
Aggregators
not properly Brian Duff's OraBlogs

ended ❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
Unlike some ❍ Oracle's Bloglist
other ❍ Oracle Base Aggregator
databases
(DB2,
PostgreSQL,
Top Blogs
Oracle's Ask Tom Kyte
MySQL), Oracle

Oracle Guru Jonathan Lewis


doesn't ❍

support ❍ Blogger of the Year Eddie Awad


multirow ❍ Data Warehouser David Aldridge
inserts (yet). ❍ Oracle Geek Lewis Cunningham
Instead, you ❍ Database Expert James Koopmann
need to ❍ Dizwell's Howard Rogers
execute these ❍ Oracle Master Laurent Schneider
as separate ❍ Security Expert Pete Finnigan
statements. ❍ Oracle Award Winner Mark Rittman
Doug Burns
INSERT INTO

Oracle ACE of the Year Dr. Tim Hall


table ❍

(column1, ❍ UKOUG's Andrew (Arfur C.) Clarke


column2) ❍ Newbie DBA Lisa Dobson
VALUES ❍ Coffee-Drinking DBA Jon Emmons
(value1, ❍ Chris Foot
value2); ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
1 row created. ❍ DBA Coskan Gundogar
Oracle WTF
INSERT INTO

table
(column1, ARCHIVES
column2) ❍ LIST ALL ARTICLES
VALUES ❍ May 2005
(value1, ❍ June 2005
value2); ❍ July 2005
❍ August 2005

http://thinkoracle.blogspot.com/2007_05_01_archive.html (2 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

1 row created. ❍ September 2005


October 2005
Edit: Courtesy

November 2005
of Laurent

December 2005
Schneider (see

January 2006
the ❍

comments), ❍ February 2006


here are two ❍ March 2006
"tricks" in ❍ April 2006
inserting ❍ May 2006
several rows ❍ June 2006
with the same ❍ July 2006
statement. ❍ August 2006
September 2006
Method #1:

October 2006
INSERT ALL

November 2006
INTO table ❍

(column1, ❍ December 2006


column2) ❍ January 2007
VALUES ❍ February 2007
(value1, value2) ❍ March 2007
INTO table ❍ April 2007
(column1, ❍ May 2007
column2) ❍ June 2007
VALUES ❍ October 2007
(value1, value2)
...etc... ❍ Current Posts
SELECT * FROM
DUAL;

Method #2:
INSERT INTO
table
(column1,
column2)
SELECT value1,
value2 FROM
DUAL UNION
ALL
SELECT value1,
value2 FROM
DUAL UNION
ALL
...etc...

http://thinkoracle.blogspot.com/2007_05_01_archive.html (3 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

SELECT value1,
value2 FROM
DUAL;

The moral of
the story is not
to expect
Oracle to
comply with
the ANSI/ISO
SQL standard
every time. In
some ways,
like this one,
they do not
comply, and of
course Oracle
offers many
extensions to
the standard.

For more
information,
consult
Appendix B of
the Oracle SQL
Reference,
which deals
very briefly
with how your
version of
Oracle
complies with
the standard.

As for the ANSI


SQL standard
itself, I'm not
aware of any
free on-line
source. If you
want one,
you'll have to

http://thinkoracle.blogspot.com/2007_05_01_archive.html (4 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

purchase a
copy directly
from ANSI/ISO.
There are
different levels
of standard
compliance,
Oracle
qualifies as
entry-level
compliance. I
don't know
exactly what
standards are
entry-level and
which ones
aren't, but
apparently
multi-row
inserts aren't.

// posted by
Robert
Vollman @ Monday,
May 28, 2007 5

comments

Friday, May
25, 2007
What
Makes a
Great
Oracle
Blog?
Along the side
of my page,
you'll see my
favourite
Oracle blogs
listed. I

http://thinkoracle.blogspot.com/2007_05_01_archive.html (5 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

carefully
maintain this
list of fellow
enthusiasts
whose
opinions and
insights I most
especially want
to follow
among the
seemingly
hundreds of
Oracle blogs
that are out
there. Studying
them, I think
you'll find that
each of them
share the same
core qualities
listed below.

1. Accuracy

Accuracy is an
absolute must.
Just because
its an informal
blog from an
independent
individual
shouldn't
relieve it from
the same
standard of
accuracy that
you'd find in a
paper
published by
Oracle
themselves.

For just one


example,

http://thinkoracle.blogspot.com/2007_05_01_archive.html (6 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

consider
Jonathan Lewis'
blog, and his
track record of
reliable
solutions. But
you don't have
to be a guru to
be accurate!
Indeed, if your
articles are
targetted to
novices, that's
even more
reason why
you should
make sure
everything you
write is fully
tested and
error-free,
right?

2. Relevance

The occasional
off-topic
article can be a
pleasant
change of
pace, as can
writing about
some other
unrelated
technology.
But write too
many, and
then nobody
knows if
they're going
to get an
insight into the
performance of

http://thinkoracle.blogspot.com/2007_05_01_archive.html (7 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

the MINUS
operator, or
something
about spiders.

A great blog
must
consistently
provide
material
relevant to the
community.
Readers can
also quickly
sniff out and
abandon
bloggers who
are doing
nothing more
than marketing
their products,
their books, or
their services.

By contrast,
consider Pete
Finnigan's
blog. Each and
every visit, I
know I'm going
to get his
latest insight
into Oracle
security
matters. Comb
his articles,
and I doubt
you'll come
across any
covering the
details of his
hotel room at
UKOUG or a

http://thinkoracle.blogspot.com/2007_05_01_archive.html (8 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

rant about
Wordpress.

Bear in mind,
that a great
Oracle article
doesn't
necessarily
have to be
technical to be
relevant. For
example,
consider
Coskan
Gundogar's
recent series
aimed at new
DBAs, and
invalid DBAs,
which you'll
find to be not
only relevant,
but also
thought-
provoking.

3. Genuine
Insight

A great Oracle
blog has to be
more than just
a syntax
reference.
Some crappy
blogs do
nothing more
than recycle
someone else's
work, either by
linking or
actually
copying it,

http://thinkoracle.blogspot.com/2007_05_01_archive.html (9 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

which falls
anywhere
between
plagiarism,
and a complete
waste of time.

Instead, a
great Oracle
article is the
one that shows
you HOW to
solve
problems. It
teaches you a
new approach
to using Oracle
technology.
Among my
favourites are
the articles
that provide
insights that I
couldn't find
anywhere else,
and that I'm
not likely to
have
experienced or
figured out on
my own.

The blogs that


compose the
list on the side
are replete
with examples,
but consider
Andrew "Arfur
C" Clarke, and
his recent post
on the INSERT
ALL syntax. His

http://thinkoracle.blogspot.com/2007_05_01_archive.html (10 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

article, which
was built on
Pythian article
about multi-
table inserts,
guides us
through his
thinking (with
examples), all
the way to his
neat solution.

4. Readability

Oracle is very
complex
technology.
Some people
think that they
are impressing
everyone by
showing how
they're capable
of coming up
with
sophisticated
and complex
solutions. What
a load of crap.
Anyone can do
that, and no
one wants to
read about it.
A great Oracle
blog, by
contrast, can
take a
complicated
problem and
make it look so
easy and
simple that
even Shrek can

http://thinkoracle.blogspot.com/2007_05_01_archive.html (11 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

understand it.

A great Oracle
blog uses easy,
simple, every
day language,
and
remembers
that not all its
readers enjoy
English as their
first language.
These blogs
rarely forget to
explain and
define all the
acronyms,
abbreviations
and industry
terms used.

As just one
example,
consider Lewis
Cunningham's
latest article
about implicit
vs explicit
conversion. A
big part of
Lewis'
popularity is
his ability to
present his
ideas in clear,
plain language
accessible to
readers of all
levels. Notice
as well that his
articles deliver
specific,
relevant, useful

http://thinkoracle.blogspot.com/2007_05_01_archive.html (12 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

Oracle insights.

5. Posting
Frequently

A great blog
doesn't need
to have a new
article each
and every day,
but if there
isn't new
material of
some kind of
regular basis,
people may
assume its
been
abandoned.
Blogging on a
regular basis
allows people
to become
familiar and
comfortable
with its style
and approach,
and look
forward to its
perspective on
future topics.

Like most
readers, I only
have the time
to regularly
follow a
limited
numbers of
blogs (in my
case, up to
20). How many
of my favourite
blogs did I

http://thinkoracle.blogspot.com/2007_05_01_archive.html (13 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

have to stop
following
because the
author stopped
blogging
regularly? (Edit:
List removed
because it was
easily
misunderstood
as criticism)

6. Concise,
tested,
working
examples

Your article
may have been
accurate for
your purposes,
for your
version, and in
your
environment,
but what about
mine? Of
course I trust
you, but by
providing a
concise,
tested,
working
example, I can
verify if your
solutions are
accurate for
me in my
world.

A great Oracle
blogger knows
that examples
are critical for

http://thinkoracle.blogspot.com/2007_05_01_archive.html (14 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

communication.
Despite your
best efforts, if
the reader still
doesn't
understand the
material, they
at least have a
working
example to
play with until
they do. They
can even use it
as a basis for
future
research,
including
coming back
to you with
questions. If
you need an
example,
consider
Laurent
Schneider, who
has become
famous for
helping
thousands by
posting
working
solutions, both
on Oracle
forums and his
blog.

7. Googlability.

Within a week,
most people
have read a
newly-posted
article. Then it

http://thinkoracle.blogspot.com/2007_05_01_archive.html (15 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

dies off, and is


usually
forgotten,
never to be
read again.
After all, how
often do you
find yourself
browsing the
archives?
Never ... not
when you're
keeping up
with all the
new articles.
This
phenomenon
is especially
tragic for the
great articles
written by new
bloggers
before they
become
popular and/or
start appearing
on aggregators
(for example,
Don Seiler,
who has
maintained an
excellent blog
for years but
was only
recently added
to some
aggregators).

By including
searchable
phrases within
the article and
in its titles,

http://thinkoracle.blogspot.com/2007_05_01_archive.html (16 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

there's a good
chance that it
can be picked
up by Google
when someone
is researching
that particular
topic. Great
articles include
common
search
phrases, like
Oracle error
messages,
specific
commands,
and popular
expressions.

8. Opportunity
for Discourse

A great article
is one that
covers an
interesting
topic that not
only ties into
the work of
other bloggers,
but even
stimulates
further
discussion. All
the blogs in
my list allow
comments,
and in every
case the
comments are
read and
followed up
upon.

http://thinkoracle.blogspot.com/2007_05_01_archive.html (17 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

Writing articles
that generate
discussions
makes us more
than just a
collection of
random
observations,
and into a true
Oracle
blogging
community. It
evolves us into
a community
with articles
that build on
the ideas of
others, and
that becomes
more than just
the sum of its
blogs.

9. Pointers to
more
information

Typically the
restrictions
imposed by
the blogging
medium allows
only a short
look at a
particular
topic.
Therefore, in
anticipation of
the thirst for
more
information
that it
stimulates, a

http://thinkoracle.blogspot.com/2007_05_01_archive.html (18 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

great blog
consistently
directs the
reader to such
sources.
Furthermore,
this helps
readers who
are
experiencing
similar
problems (but
not the exact
same one).

For a great
example, look
no further than
the 2006
Oracle blogger
of the year
Eddie Awad.
His recent
article on
forward
declaration
and mutual
recursion not
only contains
information
hard to find
elsewhere,
working
examples, and
an active
discussion, but
Eddie also
unfailingly
links to Oracle
documentation.

10.
Enthusiasm,

http://thinkoracle.blogspot.com/2007_05_01_archive.html (19 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

and Humour

Oracle can be
dry, I admit it.
It can
sometimes feel
like a big,
complex,
bloated mass
of three-letter
initials and
acronyms.
That's why it's
a treat to catch
the humour
and/or
enthusiasm a
colleague
might have for
a particular
topic.

Don't forget
that the most
popular Oracle
blog of all is
undoubtedly
Tom Kyte's,
who is well-
reknowned for
both his
tireless
enthusiasm,
and his
entertaining
style (and wit).
As for humour,
the perfect
example is the
Oracle WTF
maintained by
William
Robertson et al.

http://thinkoracle.blogspot.com/2007_05_01_archive.html (20 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

But the energy


doesn't
necessarily
have to be
humourous,
nor positive
and uplifting.
Negative,
critical or
cynical rants
written with
equal energy
can be highly
captivating,
such as
Dizwell's
Howard
Rogers' rants,
which are the
stuff of
legends. (As
are Tim Hall's)

Great Oracle
Blogs

I would like to
thank my
fellow Oracle
bloggers listed
to the side,
both past,
present and
future. Your
insights have
consistently
improved my
understanding,
interest and
appreciation
for Oracle.
That is

http://thinkoracle.blogspot.com/2007_05_01_archive.html (21 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

certainly the
hallmark of a
great Oracle
blog.
Furthermore,
you have all
been a great
influence in my
own blog (ie
THIS blog),
which surely
wouldn't have
been this much
fun to write
without you.

With that in
mind, I just
updated my
list with
another great
Oracle blog,
that of Chris
Foot. I
recommend
reading his
latest series on
his favourite
features in
Oracle 10g.

// posted by
Robert
Vollman @ Friday,
May 25, 2007 16

comments

Friday, May
04, 2007
ANSI
Joins

http://thinkoracle.blogspot.com/2007_05_01_archive.html (22 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

Like most of
us, I still join
tables in my
SQL queries
the old-school
way. Simply
put:

SELECT
whatever
FROM table1
t1, table2 t2
WHERE t1.id =
t2.id
AND t1.value >
10;

But
increasingly
often I run into
people who
use ANSI joins
instead. They
were either
introduced to
SQL with
Oracle 9 (or
Sybase 12,
etc), and were
taught to use
the SQL
standard way,
or else they
made the
conversion at
some point in
the past few
years. They
would instead
write that
query like this:

SELECT
whatever

http://thinkoracle.blogspot.com/2007_05_01_archive.html (23 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

FROM table1 t1
JOIN table2 t2
USING (id)
WHERE t1.value
> 10;

Then they look


at me all
smug ... "Look
how I have
separated the
JOIN clauses
from the
WHERE
clauses. Isn't
that infinitely
more readable?
Now go back
to your cave."

I confess, I do
like the
elegance of
separating
those clauses.
Our business
analysts find
that format
much more
readable, too,
as do those
who use
several
different
databases.
Every time they
see one of my
queries,
especially a full
outer join or a
(+) in it, their
nose starts to
bleed.

http://thinkoracle.blogspot.com/2007_05_01_archive.html (24 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

Incidentally, if
the columns
are named
differently,
you'd use this
syntax instead
(which is less
of a leap for
old school SQL
lovers):

SELECT
whatever
FROM table1 t1
JOIN table2 t2
ON (t1.id1 = t2.
id2)
WHERE t1.value
> 10;

And, of course,
you can have
multiple joins,
and can even
nest one join
inside another.
You can use all
the different
types of joins,
like INNER,
OUTER, LEFT,
RIGHT, UPSIDE-
DOWN, INSIDE-
OUT, whatever.
Ok, not those
last two. Tim
Hall has some
examples.

I started using
ANSI joins for
the first time
recently. There

http://thinkoracle.blogspot.com/2007_05_01_archive.html (25 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

certainly
doesn't seem
to be any
performance
hit. Of course,
I wasn't
expecting one,
because you'd
think Oracle
would be
smart enough
to do both
things the
exact same
way. I can't say
for certain if
one is better
than the other,
I guess you
have to look at
it case-by-
case with your
profiling tools.
But I certainly
haven't seen
any difference.

The one thing


I'm not crazy
about is the
NATURAL JOIN.
In the example
above, if id
was the only
column that
those two
tables had in
common, they
could specify is
as a NATURAL
JOIN and leave
off the USING.
To wit:

http://thinkoracle.blogspot.com/2007_05_01_archive.html (26 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

SELECT
whatever
FROM table1 t1
NATURAL JOIN
table2 t2
WHERE t1.value
> 10;

What a
NATURAL JOIN
actually does,
is join the two
tables on all
columns that
exist in both
tables. It does
mean your
query will still
work if the
structure of
the table
changes, but is
that really
what you want?
Call me a
caveman, but I
like to
explicitly state
exactly what I
want a query
to do, and that
includes
exactly on
which columns
I want to join.

If you think I'm


being too
harsh, you
should Ask
Tom for his
opinion:

http://thinkoracle.blogspot.com/2007_05_01_archive.html (27 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

"Natural joins
-- a bug
waiting to
happen.",
"I strongly,
vehemently
strongly,
discourage the
use of this
feature called
natural joins.",
"To join tables
by their
column names
-- how
patently just a
bad idea",
"Never never
never use this
feature."

I don't intend
to use this one
criticism to
denounce ANSI
joins
altogether, far
from it.
Traditional
joins
(especially full
outer joins)
can look
messy,
especially the
aforementioned
group of new
graduates,
business
analysts and
multi-database
SQL
programmers.

http://thinkoracle.blogspot.com/2007_05_01_archive.html (28 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

Not everyone
has really
enjoyed
moving from
the traditional
join syntax to
ANSI syntax,
including Doug
Burns and Jeff
Moss.

As you can see


from the dates
on those, I'm
not the first
one to write
about this (but
hopefully the
last). I thought
Mark Rittman
was the first to
expound on
this, over 3
years ago, but
he links to Jim
Czuprynski,
who appears to
be truly the
earliest
crusader for
the USE of
ANSI joins,
over 4 years
ago. But,
reminiscent of
Wrath of Khan,
it was actually
Eddie Awad
who first put
the bug of
ANSI joins into
my ear. He's

http://thinkoracle.blogspot.com/2007_05_01_archive.html (29 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

got a crash
course on the
different types
of ANSI joins,
but of course,
that type of
information
you can find
almost
anywhere.

I'm not going


to endorse that
you
immediately
switch to ANSI
joins,
especially
since if you
haven't by
now, you
probably have
no such
intention
anyway. But I
think it makes
a lot of sense
for my fellow
cavemen to at
least be aware
of it, and know
how to use it.

// posted by
Robert
Vollman @ Friday,
May 04, 2007 7

comments

http://thinkoracle.blogspot.com/2007_05_01_archive.html (30 of 31)1/9/2008 2:50:54 AM


OracleBlog: May 2007

http://thinkoracle.blogspot.com/2007_05_01_archive.html (31 of 31)1/9/2008 2:50:54 AM


OracleBlog: June 2007

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Sunday, June
About Me
03, 2007
Name: Robert Vollman
SQL Location: Calgary, Alberta, Canada
Interview
Questions I was born and raised in Ottawa, and have lived in
You pick up Calgary since 1991. I like playing sports (hockey,
the soccer, ultimate, basketball, you name it) and military board games.
candidate's I also enjoy reading, walking, and playing with my 2 cats Lilly and
resume and it Brutus. I'm a database application specialist, whatever that is.
proudly
proclaims "SQL View my complete profile
Expert: 10

Best Links
Years." Your
boss trusts
you, as the Ask Tom Kyte
technical

Oracle Docs
expert on the

Dan Morgan and PSOUG


team, to

participate ● Steven Feuerstein


briefly in the ● Jonathan Lewis
interview to ● FAQ
gauge this ● Connor McDonald
individual's ● The Oak Table
knowledge of ● Cary Millsap and Hotsos
SQL. Where to ● Steve Adams and Ixora
begin? ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2007_06_01_archive.html (1 of 9)1/9/2008 2:50:57 AM


OracleBlog: June 2007

● Dizwell Oracle Wiki


I have asked ● My Personal Blog
literally
hundreds of
different
questions
during
Aggregators
interviews Brian Duff's OraBlogs

over the past ❍ Eddie Awad's OracleNA


decade. Some ❍ Pete Finnigan's Aggregator
were simple ❍ Oracle's Bloglist
questions that ❍ Oracle Base Aggregator

Top Blogs
were
nevertheless
remarkably Oracle's Ask Tom Kyte
effective ways

Oracle Guru Jonathan Lewis


of rating a

Blogger of the Year Eddie Awad


candidate's

Data Warehouser David Aldridge


comfort-level ❍

in SQL, ❍ Oracle Geek Lewis Cunningham


whereas ❍ Database Expert James Koopmann
others just ❍ Dizwell's Howard Rogers
wasted ❍ Oracle Master Laurent Schneider
precious ❍ Security Expert Pete Finnigan
interview time. ❍ Oracle Award Winner Mark Rittman
Let me save ❍ Doug Burns
you the latter! ❍ Oracle ACE of the Year Dr. Tim Hall
UKOUG's Andrew (Arfur C.) Clarke
First I ask the

Newbie DBA Lisa Dobson


candidate how ❍

they would ❍ Coffee-Drinking DBA Jon Emmons


personally rate ❍ Chris Foot
their own ❍ The Pythian DBA Team Blog
understanding ❍ DBA Don Seiler
of SQL. I'm ❍ DBA Coskan Gundogar
also curious ❍ Oracle WTF
what
databases and
tools they've
ARCHIVES
LIST ALL ARTICLES
used to write

May 2005
their SQL. This

gives me a ❍ June 2005


good idea ❍ July 2005
❍ August 2005

http://thinkoracle.blogspot.com/2007_06_01_archive.html (2 of 9)1/9/2008 2:50:57 AM


OracleBlog: June 2007

where I should ❍ September 2005


begin my ❍ October 2005
questioning. ❍ November 2005
December 2005
Basic

January 2006
Questions ❍

❍ February 2006
Asking a ❍ March 2006
question ❍ April 2006
about joins is ❍ May 2006
the common ❍ June 2006
consensus for ❍ July 2006
an opening ❍ August 2006
question. More
September 2006
specifically,

October 2006
does the

November 2006
candidate ❍

know the ❍ December 2006


different types ❍ January 2007
of joins, or at ❍ February 2007
least the ❍ March 2007
difference ❍ April 2007
between an ❍ May 2007
inner join and ❍ June 2007
an outer join? ❍ October 2007

Assuming that ❍ Current Posts


goes well, I
follow up with
a question
that involves
using GROUP
BY and/or
HAVING. For
example,
given an
EMPLOYEE
table and a
DEPARTMENT
table, how
would you
select the
combined
salary of each

http://thinkoracle.blogspot.com/2007_06_01_archive.html (3 of 9)1/9/2008 2:50:57 AM


OracleBlog: June 2007

department
that has a
higher
combined
salary than
mine?

Intermediate
Questions

With the sanity


checks out of
the way, we
can get into
some more
meaningful
technical
discussions.
Among my
favourites is to
solicit their
perspective of
what NULL is
and what it
means. After
all, to write
correct SQL
queries, isn't
this
understanding
important?
How many
queries have
you read that
caused
problems
because the
author
mishandled
NULLs? Will
this candidate
make the
same mistake?

http://thinkoracle.blogspot.com/2007_06_01_archive.html (4 of 9)1/9/2008 2:50:57 AM


OracleBlog: June 2007

Do they know
that NULL and
nothing are
different, and
in what ways?
Do they know
that neither
NULL = NULL
nor NULL <>
NULL are true?

Before
proceeding to
the grand
finale, I
pepper the
candidate with
variations of
the following
three
questions that,
though
simple, seem
to have done
an exemplary
job narrowing
down
someone's
level of
experience.
First, do they
know the four
isolation
levels?
Secondly, do
they know
what a bind
variable is and
why they
should be
used (do they
even know
what a soft

http://thinkoracle.blogspot.com/2007_06_01_archive.html (5 of 9)1/9/2008 2:50:57 AM


OracleBlog: June 2007

parse is)?
Finally, what is
the DUAL
table?

Advanced
Questions

All of this is
leading up to
analytic
functions, one
of my true
litmus tests to
the proficiency
of one's
knowledge of
SQL. There are
literally
dozens of
questions I
have asked:
YOU need to
pick one that
specifically
relates to the
type of work
relevant to the
open position.
Here are some
possibilities to
choose from:
- Open with
the basic
concept of
selecting data
over a
partition (a
running total,
perhaps)
- Follow-up
by writing a
Top-N query

http://thinkoracle.blogspot.com/2007_06_01_archive.html (6 of 9)1/9/2008 2:50:57 AM


OracleBlog: June 2007

- Put together
a standard
pivot/crosstab
query
- Try handling
hierarchical/
recursive
queries (using
CONNECT BY)

I feel there is
no real need
to know the
exact analytic
function and
write out the
precise syntax,
but to truly
qualify your
SQL at the
higher level
requires the
ability to know
how to truly
unleash the
power of an
Oracle
database. So
tell me, did
they head in
the right
direction, or
ask for a glass
of water and
slip out?

Wrapping Up

Generally I
have managed
to keep the
discussion
under the

http://thinkoracle.blogspot.com/2007_06_01_archive.html (7 of 9)1/9/2008 2:50:57 AM


OracleBlog: June 2007

previously
unrealistic 15-
minute limit
that's imposed
upon me. On
rare occasions
I'm treated to
the delightful
combination
of a candidate
that has
breezed
through the
interview and
a boss taking
his time re-
joining us. In
that case, I've
been known to
serve up some
advanced
history
questions.
Who is Ted
Codd? Did
they know
about his 12
rules? Do they
get a blank
expression on
their face
when I ask
them what
"System R" is?

At the very
least, even if
they know SQL
backwards and
forwards,
they'll still
have
something

http://thinkoracle.blogspot.com/2007_06_01_archive.html (8 of 9)1/9/2008 2:50:57 AM


OracleBlog: June 2007

interesting to
look up when
they get home.

// posted by
Robert
Vollman @ Sunday,
June 03, 2007 16

comments

http://thinkoracle.blogspot.com/2007_06_01_archive.html (9 of 9)1/9/2008 2:50:57 AM


OracleBlog: October 2007

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Sunday, October 21, 2007


Global Temporary Tables
I listened intently to the new Oracle programmer as he described all the
struggles he's been having on his first big project. As I've done many
times already in his short career, I interrupt with some words of wisdom.

"It's time to add Global Temporary Tables to your toolbelt."

"What are those?" he asks, as he opens the directory with the Oracle
documentation. I smile. He has already learned where I always send him
first.

"They're the ultimate work tables," I continue. "They're permanent


tables, where you can add and modify session-specific data without
affecting other sessions."

"What's so special about that?" he asks. "Even with regular tables, you
can add and modify the data all you want without affecting other
sessions. Just don't commit, and remember to rollback when your
session is done."

"Oh yeah? And what about all the persistent work you're doing in your
session? How do you commit that?"

"Oh yeah. Does it allow for indexes, and triggers, and views with
regular tables?"

"Yep, all of that. See for yourself, it's easy. You've got the manual in

http://thinkoracle.blogspot.com/2007_10_01_archive.html (1 of 7)1/9/2008 2:50:59 AM


OracleBlog: October 2007

front of you, so you drive."

Then I watched as he opened one session, and created a global


temporary table.

SQL> CREATE GLOBAL TEMPORARY TABLE worktable (x NUMBER(3));


Table created.

He opened another session and was pleased to see the table there. He
then added a row in the first session, committed it, and was planning to
use the other session to see if the data was there. But instead he was in
for a little surprise.

SQL> INSERT INTO worktable (x) VALUES (1);


1 row created.
SQL> SELECT * FROM worktable;
X
----------
1
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
no rows selected

"Hey!" he shouted. Heads popped up in nearby cubicles. "Where did it


go?"

"Keep reading," I said, gesturing towards the "ON COMMIT" options for
Global Temporary Tables. "By default, every time you commit your data,
it is assumed that you want to clear out your work tables. Try
PRESERVE."

He dropped the table, and tried again.

SQL> CREATE GLOBAL TEMPORARY TABLE worktable


2 (x NUMBER(3))
3 ON COMMIT PRESERVE ROWS;
Table created.
SQL> INSERT INTO worktable (x) VALUES (1);
1 row created.

http://thinkoracle.blogspot.com/2007_10_01_archive.html (2 of 7)1/9/2008 2:50:59 AM


OracleBlog: October 2007

SQL> SELECT * FROM worktable;


X
----------
1
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
X
----------
1

"That's better," he smiled. Now let's check the other session.

SQL> SELECT * FROM worktable;


no rows selected

"Excellent. So this data will remain there until my session ends?"

"Yep. Try it." He exited his session, logged back in, and sure enough
the data was gone. "This is great. But what if I want to get rid of the
data at some point in my session?"

"Truncate. Truncating the work table will only truncate the data in your
session, not all the data."

"Hey neat. Thanks, this will be very useful. What are you doing for lunch
later?"

"Aren't you even going to try it? What, you're just going to trust me?" I
said. I think he was a little surprised that I would I'd rather talk about
work tables than lunch. Frankly, so am I. Thankfully, he worked quickly,
typing first in his second session.

SQL> INSERT INTO worktable (x) VALUES (2)


1 row created.
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
X
----------

http://thinkoracle.blogspot.com/2007_10_01_archive.html (3 of 7)1/9/2008 2:50:59 AM


OracleBlog: October 2007

2
SQL> TRUNCATE TABLE worktable;
Table truncated.
SQL> SELECT * FROM worktable;
no rows selected
SQL> commit;
Commit complete.

"I don't think you need all those commits," I laughed. "But ok, now look
back in your first session. If the row you added previously isn't there,
then I'm a big fat liar. Otherwise, we can talk about lunch."

SQL> SELECT * FROM worktable;


X
----------
1

"So how about sushi?" he asked.

"Sushi?" I groaned. "Haven't you learned anything from me?"

// posted by Robert Vollman @ Sunday, October 21, 2007 5 comments

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

http://thinkoracle.blogspot.com/2007_10_01_archive.html (4 of 7)1/9/2008 2:50:59 AM


OracleBlog: October 2007

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns

http://thinkoracle.blogspot.com/2007_10_01_archive.html (5 of 7)1/9/2008 2:50:59 AM


OracleBlog: October 2007

❍ Oracle ACE of the Year Dr. Tim Hall


❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2007_10_01_archive.html (6 of 7)1/9/2008 2:50:59 AM


OracleBlog: October 2007

❍ Current Posts

http://thinkoracle.blogspot.com/2007_10_01_archive.html (7 of 7)1/9/2008 2:50:59 AM


OracleBlog

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Sunday, October 21, 2007


Global Temporary Tables
I listened intently to the new Oracle programmer as he described all the
struggles he's been having on his first big project. As I've done many
times already in his short career, I interrupt with some words of wisdom.

"It's time to add Global Temporary Tables to your toolbelt."

"What are those?" he asks, as he opens the directory with the Oracle
documentation. I smile. He has already learned where I always send him
first.

"They're the ultimate work tables," I continue. "They're permanent


tables, where you can add and modify session-specific data without
affecting other sessions."

"What's so special about that?" he asks. "Even with regular tables, you
can add and modify the data all you want without affecting other
sessions. Just don't commit, and remember to rollback when your
session is done."

"Oh yeah? And what about all the persistent work you're doing in your
session? How do you commit that?"

"Oh yeah. Does it allow for indexes, and triggers, and views with
regular tables?"

"Yep, all of that. See for yourself, it's easy. You've got the manual in

http://thinkoracle.blogspot.com/ (1 of 16)1/9/2008 2:51:03 AM


OracleBlog

front of you, so you drive."

Then I watched as he opened one session, and created a global


temporary table.

SQL> CREATE GLOBAL TEMPORARY TABLE worktable (x NUMBER(3));


Table created.

He opened another session and was pleased to see the table there. He
then added a row in the first session, committed it, and was planning to
use the other session to see if the data was there. But instead he was in
for a little surprise.

SQL> INSERT INTO worktable (x) VALUES (1);


1 row created.
SQL> SELECT * FROM worktable;
X
----------
1
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
no rows selected

"Hey!" he shouted. Heads popped up in nearby cubicles. "Where did it


go?"

"Keep reading," I said, gesturing towards the "ON COMMIT" options for
Global Temporary Tables. "By default, every time you commit your data,
it is assumed that you want to clear out your work tables. Try
PRESERVE."

He dropped the table, and tried again.

SQL> CREATE GLOBAL TEMPORARY TABLE worktable


2 (x NUMBER(3))
3 ON COMMIT PRESERVE ROWS;
Table created.
SQL> INSERT INTO worktable (x) VALUES (1);
1 row created.

http://thinkoracle.blogspot.com/ (2 of 16)1/9/2008 2:51:03 AM


OracleBlog

SQL> SELECT * FROM worktable;


X
----------
1
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
X
----------
1

"That's better," he smiled. Now let's check the other session.

SQL> SELECT * FROM worktable;


no rows selected

"Excellent. So this data will remain there until my session ends?"

"Yep. Try it." He exited his session, logged back in, and sure enough
the data was gone. "This is great. But what if I want to get rid of the
data at some point in my session?"

"Truncate. Truncating the work table will only truncate the data in your
session, not all the data."

"Hey neat. Thanks, this will be very useful. What are you doing for lunch
later?"

"Aren't you even going to try it? What, you're just going to trust me?" I
said. I think he was a little surprised that I would I'd rather talk about
work tables than lunch. Frankly, so am I. Thankfully, he worked quickly,
typing first in his second session.

SQL> INSERT INTO worktable (x) VALUES (2)


1 row created.
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
X
----------

http://thinkoracle.blogspot.com/ (3 of 16)1/9/2008 2:51:03 AM


OracleBlog

2
SQL> TRUNCATE TABLE worktable;
Table truncated.
SQL> SELECT * FROM worktable;
no rows selected
SQL> commit;
Commit complete.

"I don't think you need all those commits," I laughed. "But ok, now look
back in your first session. If the row you added previously isn't there,
then I'm a big fat liar. Otherwise, we can talk about lunch."

SQL> SELECT * FROM worktable;


X
----------
1

"So how about sushi?" he asked.

"Sushi?" I groaned. "Haven't you learned anything from me?"

// posted by Robert Vollman @ Sunday, October 21, 2007 5 comments

Sunday, June 03, 2007


SQL Interview Questions
You pick up the candidate's resume and it proudly proclaims "SQL
Expert: 10 Years." Your boss trusts you, as the technical expert on the
team, to participate briefly in the interview to gauge this individual's
knowledge of SQL. Where to begin?

I have asked literally hundreds of different questions during interviews


over the past decade. Some were simple questions that were
nevertheless remarkably effective ways of rating a candidate's comfort-
level in SQL, whereas others just wasted precious interview time. Let me
save you the latter!

First I ask the candidate how they would personally rate their own
understanding of SQL. I'm also curious what databases and tools

http://thinkoracle.blogspot.com/ (4 of 16)1/9/2008 2:51:03 AM


OracleBlog

they've used to write their SQL. This gives me a good idea where I
should begin my questioning.

Basic Questions

Asking a question about joins is the common consensus for an opening


question. More specifically, does the candidate know the different types
of joins, or at least the difference between an inner join and an outer
join?

Assuming that goes well, I follow up with a question that involves using
GROUP BY and/or HAVING. For example, given an EMPLOYEE table and a
DEPARTMENT table, how would you select the combined salary of each
department that has a higher combined salary than mine?

Intermediate Questions

With the sanity checks out of the way, we can get into some more
meaningful technical discussions. Among my favourites is to solicit
their perspective of what NULL is and what it means. After all, to write
correct SQL queries, isn't this understanding important? How many
queries have you read that caused problems because the author
mishandled NULLs? Will this candidate make the same mistake? Do they
know that NULL and nothing are different, and in what ways? Do they
know that neither NULL = NULL nor NULL <> NULL are true?

Before proceeding to the grand finale, I pepper the candidate with


variations of the following three questions that, though simple, seem to
have done an exemplary job narrowing down someone's level of
experience. First, do they know the four isolation levels? Secondly, do
they know what a bind variable is and why they should be used (do they
even know what a soft parse is)? Finally, what is the DUAL table?

Advanced Questions

All of this is leading up to analytic functions, one of my true litmus


tests to the proficiency of one's knowledge of SQL. There are literally
dozens of questions I have asked: YOU need to pick one that
specifically relates to the type of work relevant to the open position.
Here are some possibilities to choose from:
- Open with the basic concept of selecting data over a partition (a
running total, perhaps)
- Follow-up by writing a Top-N query
- Put together a standard pivot/crosstab query

http://thinkoracle.blogspot.com/ (5 of 16)1/9/2008 2:51:03 AM


OracleBlog

- Try handling hierarchical/recursive queries (using CONNECT BY)

I feel there is no real need to know the exact analytic function and write
out the precise syntax, but to truly qualify your SQL at the higher level
requires the ability to know how to truly unleash the power of an Oracle
database. So tell me, did they head in the right direction, or ask for a
glass of water and slip out?

Wrapping Up

Generally I have managed to keep the discussion under the previously


unrealistic 15-minute limit that's imposed upon me. On rare occasions
I'm treated to the delightful combination of a candidate that has
breezed through the interview and a boss taking his time re-joining us.
In that case, I've been known to serve up some advanced history
questions. Who is Ted Codd? Did they know about his 12 rules? Do they
get a blank expression on their face when I ask them what "System R" is?

At the very least, even if they know SQL backwards and forwards, they'll
still have something interesting to look up when they get home.

// posted by Robert Vollman @ Sunday, June 03, 2007 16 comments

Monday, May 28, 2007


Multirow Inserts
While attempting to insert several rows into a table in our Oracle
database, a colleague dutifully copied the exact ANSI/ISO SQL standard
syntax for his purposes. Guess what happened?

INSERT INTO table (column1, column2)


VALUES (value1, value2), (value1, value2);

ERROR at line 1:
ORA-00933: SQL command not properly ended

Unlike some other databases (DB2, PostgreSQL, MySQL), Oracle doesn't


support multirow inserts (yet). Instead, you need to execute these as
separate statements.

INSERT INTO table (column1, column2)


VALUES (value1, value2);

1 row created.

http://thinkoracle.blogspot.com/ (6 of 16)1/9/2008 2:51:03 AM


OracleBlog

INSERT INTO table (column1, column2)


VALUES (value1, value2);

1 row created.

Edit: Courtesy of Laurent Schneider (see the comments), here are two
"tricks" in inserting several rows with the same statement.

Method #1:
INSERT ALL
INTO table (column1, column2)
VALUES (value1, value2)
INTO table (column1, column2)
VALUES (value1, value2)
...etc...
SELECT * FROM DUAL;

Method #2:
INSERT INTO table (column1, column2)
SELECT value1, value2 FROM DUAL UNION ALL
SELECT value1, value2 FROM DUAL UNION ALL
...etc...
SELECT value1, value2 FROM DUAL;

The moral of the story is not to expect Oracle to comply with the ANSI/
ISO SQL standard every time. In some ways, like this one, they do not
comply, and of course Oracle offers many extensions to the standard.

For more information, consult Appendix B of the Oracle SQL Reference,


which deals very briefly with how your version of Oracle complies with
the standard.

As for the ANSI SQL standard itself, I'm not aware of any free on-line
source. If you want one, you'll have to purchase a copy directly from
ANSI/ISO. There are different levels of standard compliance, Oracle
qualifies as entry-level compliance. I don't know exactly what standards
are entry-level and which ones aren't, but apparently multi-row inserts
aren't.

// posted by Robert Vollman @ Monday, May 28, 2007 5 comments

Friday, May 25, 2007

http://thinkoracle.blogspot.com/ (7 of 16)1/9/2008 2:51:03 AM


OracleBlog

What Makes a Great Oracle Blog?


Along the side of my page, you'll see my favourite Oracle blogs listed. I
carefully maintain this list of fellow enthusiasts whose opinions and
insights I most especially want to follow among the seemingly hundreds
of Oracle blogs that are out there. Studying them, I think you'll find that
each of them share the same core qualities listed below.

1. Accuracy

Accuracy is an absolute must. Just because its an informal blog from an


independent individual shouldn't relieve it from the same standard of
accuracy that you'd find in a paper published by Oracle themselves.

For just one example, consider Jonathan Lewis' blog, and his track
record of reliable solutions. But you don't have to be a guru to be
accurate! Indeed, if your articles are targetted to novices, that's even
more reason why you should make sure everything you write is fully
tested and error-free, right?

2. Relevance

The occasional off-topic article can be a pleasant change of pace, as


can writing about some other unrelated technology. But write too many,
and then nobody knows if they're going to get an insight into the
performance of the MINUS operator, or something about spiders.

A great blog must consistently provide material relevant to the


community. Readers can also quickly sniff out and abandon bloggers
who are doing nothing more than marketing their products, their
books, or their services.

By contrast, consider Pete Finnigan's blog. Each and every visit, I know
I'm going to get his latest insight into Oracle security matters. Comb his
articles, and I doubt you'll come across any covering the details of his
hotel room at UKOUG or a rant about Wordpress.

Bear in mind, that a great Oracle article doesn't necessarily have to be


technical to be relevant. For example, consider Coskan Gundogar's
recent series aimed at new DBAs, and invalid DBAs, which you'll find to
be not only relevant, but also thought-provoking.

3. Genuine Insight

A great Oracle blog has to be more than just a syntax reference. Some

http://thinkoracle.blogspot.com/ (8 of 16)1/9/2008 2:51:03 AM


OracleBlog

crappy blogs do nothing more than recycle someone else's work, either
by linking or actually copying it, which falls anywhere between
plagiarism, and a complete waste of time.

Instead, a great Oracle article is the one that shows you HOW to solve
problems. It teaches you a new approach to using Oracle technology.
Among my favourites are the articles that provide insights that I
couldn't find anywhere else, and that I'm not likely to have experienced
or figured out on my own.

The blogs that compose the list on the side are replete with examples,
but consider Andrew "Arfur C" Clarke, and his recent post on the
INSERT ALL syntax. His article, which was built on Pythian article about
multi-table inserts, guides us through his thinking (with examples), all
the way to his neat solution.

4. Readability

Oracle is very complex technology. Some people think that they are
impressing everyone by showing how they're capable of coming up with
sophisticated and complex solutions. What a load of crap. Anyone can
do that, and no one wants to read about it. A great Oracle blog, by
contrast, can take a complicated problem and make it look so easy and
simple that even Shrek can understand it.

A great Oracle blog uses easy, simple, every day language, and
remembers that not all its readers enjoy English as their first language.
These blogs rarely forget to explain and define all the acronyms,
abbreviations and industry terms used.

As just one example, consider Lewis Cunningham's latest article about


implicit vs explicit conversion. A big part of Lewis' popularity is his
ability to present his ideas in clear, plain language accessible to readers
of all levels. Notice as well that his articles deliver specific, relevant,
useful Oracle insights.

5. Posting Frequently

A great blog doesn't need to have a new article each and every day, but
if there isn't new material of some kind of regular basis, people may
assume its been abandoned. Blogging on a regular basis allows people
to become familiar and comfortable with its style and approach, and
look forward to its perspective on future topics.

http://thinkoracle.blogspot.com/ (9 of 16)1/9/2008 2:51:03 AM


OracleBlog

Like most readers, I only have the time to regularly follow a limited
numbers of blogs (in my case, up to 20). How many of my favourite
blogs did I have to stop following because the author stopped blogging
regularly? (Edit: List removed because it was easily misunderstood as
criticism)

6. Concise, tested, working examples

Your article may have been accurate for your purposes, for your
version, and in your environment, but what about mine? Of course I
trust you, but by providing a concise, tested, working example, I can
verify if your solutions are accurate for me in my world.

A great Oracle blogger knows that examples are critical for


communication. Despite your best efforts, if the reader still doesn't
understand the material, they at least have a working example to play
with until they do. They can even use it as a basis for future research,
including coming back to you with questions. If you need an example,
consider Laurent Schneider, who has become famous for helping
thousands by posting working solutions, both on Oracle forums and his
blog.

7. Googlability.

Within a week, most people have read a newly-posted article. Then it


dies off, and is usually forgotten, never to be read again. After all, how
often do you find yourself browsing the archives? Never ... not when
you're keeping up with all the new articles. This phenomenon is
especially tragic for the great articles written by new bloggers before
they become popular and/or start appearing on aggregators (for
example, Don Seiler, who has maintained an excellent blog for years
but was only recently added to some aggregators).

By including searchable phrases within the article and in its titles,


there's a good chance that it can be picked up by Google when
someone is researching that particular topic. Great articles include
common search phrases, like Oracle error messages, specific
commands, and popular expressions.

8. Opportunity for Discourse

A great article is one that covers an interesting topic that not only ties
into the work of other bloggers, but even stimulates further discussion.
All the blogs in my list allow comments, and in every case the

http://thinkoracle.blogspot.com/ (10 of 16)1/9/2008 2:51:03 AM


OracleBlog

comments are read and followed up upon.

Writing articles that generate discussions makes us more than just a


collection of random observations, and into a true Oracle blogging
community. It evolves us into a community with articles that build on
the ideas of others, and that becomes more than just the sum of its
blogs.

9. Pointers to more information

Typically the restrictions imposed by the blogging medium allows only


a short look at a particular topic. Therefore, in anticipation of the thirst
for more information that it stimulates, a great blog consistently directs
the reader to such sources. Furthermore, this helps readers who are
experiencing similar problems (but not the exact same one).

For a great example, look no further than the 2006 Oracle blogger of
the year Eddie Awad. His recent article on forward declaration and
mutual recursion not only contains information hard to find elsewhere,
working examples, and an active discussion, but Eddie also unfailingly
links to Oracle documentation.

10. Enthusiasm, and Humour

Oracle can be dry, I admit it. It can sometimes feel like a big, complex,
bloated mass of three-letter initials and acronyms. That's why it's a
treat to catch the humour and/or enthusiasm a colleague might have
for a particular topic.

Don't forget that the most popular Oracle blog of all is undoubtedly
Tom Kyte's, who is well-reknowned for both his tireless enthusiasm,
and his entertaining style (and wit). As for humour, the perfect example
is the Oracle WTF maintained by William Robertson et al.

But the energy doesn't necessarily have to be humourous, nor positive


and uplifting. Negative, critical or cynical rants written with equal
energy can be highly captivating, such as Dizwell's Howard Rogers'
rants, which are the stuff of legends. (As are Tim Hall's)

Great Oracle Blogs

I would like to thank my fellow Oracle bloggers listed to the side, both
past, present and future. Your insights have consistently improved my
understanding, interest and appreciation for Oracle. That is certainly

http://thinkoracle.blogspot.com/ (11 of 16)1/9/2008 2:51:03 AM


OracleBlog

the hallmark of a great Oracle blog. Furthermore, you have all been a
great influence in my own blog (ie THIS blog), which surely wouldn't
have been this much fun to write without you.

With that in mind, I just updated my list with another great Oracle blog,
that of Chris Foot. I recommend reading his latest series on his
favourite features in Oracle 10g.

// posted by Robert Vollman @ Friday, May 25, 2007 16 comments

Friday, May 04, 2007


ANSI Joins
Like most of us, I still join tables in my SQL queries the old-school way.
Simply put:

SELECT whatever
FROM table1 t1, table2 t2
WHERE t1.id = t2.id
AND t1.value > 10;

But increasingly often I run into people who use ANSI joins instead.
They were either introduced to SQL with Oracle 9 (or Sybase 12, etc),
and were taught to use the SQL standard way, or else they made the
conversion at some point in the past few years. They would instead
write that query like this:

SELECT whatever
FROM table1 t1
JOIN table2 t2 USING (id)
WHERE t1.value > 10;

Then they look at me all smug ... "Look how I have separated the JOIN
clauses from the WHERE clauses. Isn't that infinitely more readable?
Now go back to your cave."

I confess, I do like the elegance of separating those clauses. Our


business analysts find that format much more readable, too, as do
those who use several different databases. Every time they see one of
my queries, especially a full outer join or a (+) in it, their nose starts to
bleed.

Incidentally, if the columns are named differently, you'd use this syntax

http://thinkoracle.blogspot.com/ (12 of 16)1/9/2008 2:51:03 AM


OracleBlog

instead (which is less of a leap for old school SQL lovers):

SELECT whatever
FROM table1 t1
JOIN table2 t2 ON (t1.id1 = t2.id2)
WHERE t1.value > 10;

And, of course, you can have multiple joins, and can even nest one join
inside another. You can use all the different types of joins, like INNER,
OUTER, LEFT, RIGHT, UPSIDE-DOWN, INSIDE-OUT, whatever. Ok, not
those last two. Tim Hall has some examples.

I started using ANSI joins for the first time recently. There certainly
doesn't seem to be any performance hit. Of course, I wasn't expecting
one, because you'd think Oracle would be smart enough to do both
things the exact same way. I can't say for certain if one is better than
the other, I guess you have to look at it case-by-case with your
profiling tools. But I certainly haven't seen any difference.

The one thing I'm not crazy about is the NATURAL JOIN. In the example
above, if id was the only column that those two tables had in common,
they could specify is as a NATURAL JOIN and leave off the USING. To wit:

SELECT whatever
FROM table1 t1
NATURAL JOIN table2 t2
WHERE t1.value > 10;

What a NATURAL JOIN actually does, is join the two tables on all
columns that exist in both tables. It does mean your query will still
work if the structure of the table changes, but is that really what you
want? Call me a caveman, but I like to explicitly state exactly what I
want a query to do, and that includes exactly on which columns I want
to join.

If you think I'm being too harsh, you should Ask Tom for his opinion:
"Natural joins -- a bug waiting to happen.",
"I strongly, vehemently strongly, discourage the use of this feature
called natural joins.",
"To join tables by their column names -- how patently just a bad idea",
"Never never never use this feature."

I don't intend to use this one criticism to denounce ANSI joins


altogether, far from it. Traditional joins (especially full outer joins) can

http://thinkoracle.blogspot.com/ (13 of 16)1/9/2008 2:51:03 AM


OracleBlog

look messy, especially the aforementioned group of new graduates,


business analysts and multi-database SQL programmers.

Not everyone has really enjoyed moving from the traditional join syntax
to ANSI syntax, including Doug Burns and Jeff Moss.

As you can see from the dates on those, I'm not the first one to write
about this (but hopefully the last). I thought Mark Rittman was the first
to expound on this, over 3 years ago, but he links to Jim Czuprynski,
who appears to be truly the earliest crusader for the USE of ANSI joins,
over 4 years ago. But, reminiscent of Wrath of Khan, it was actually
Eddie Awad who first put the bug of ANSI joins into my ear. He's got a
crash course on the different types of ANSI joins, but of course, that
type of information you can find almost anywhere.

I'm not going to endorse that you immediately switch to ANSI joins,
especially since if you haven't by now, you probably have no such
intention anyway. But I think it makes a lot of sense for my fellow
cavemen to at least be aware of it, and know how to use it.

// posted by Robert Vollman @ Friday, May 04, 2007 7 comments

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
http://thinkoracle.blogspot.com/ (14 of 16)1/9/2008 2:51:03 AM
OracleBlog

● Ask Tom Kyte


● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot

http://thinkoracle.blogspot.com/ (15 of 16)1/9/2008 2:51:03 AM


OracleBlog

❍ The Pythian DBA Team Blog


❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/ (16 of 16)1/9/2008 2:51:03 AM


OracleBlog: Oracle Sequences

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I think
data, I think Oracle. I also enjoy writing, so I use this format to organise my thoughts. Please
feel free to discuss any thoughts you may have on the same topics, even old ones (I will see and
respond to such comments). You may want to start with "LIST ALL ARTICLES" under Archives.

Wednesday, February 22, 2006


About Me
Oracle Sequences Name: Robert
Proactively maintaining your database ... something Vollman
some people do only AFTER a problem of some kind. Location: Calgary,
Alberta, Canada
Case in point, a customer recently asked us what
sequences are being used as primary keys, what are
their maximum values, and are any in danger of I was born and raised in Ottawa,
running out. Guess what motivated that and have lived in Calgary since
investigation? 1991. I like playing sports
(hockey, soccer, ultimate,
Most of this is rather trivial using only the basketball, you name it) and
ALL_SEQUENCES table. military board games. I also
enjoy reading, walking, and
1. What sequences are being used, and do they roll playing with my 2 cats Lilly and
over or run out? Brutus. I'm a database
application specialist, whatever
SELECT cycle_flag, sequence_name FROM that is.
ALL_SEQUENCES;
View my complete profile
2. Which sequences are being used as primary keys?

That's trickier. See, even if you're using a sequence


as a primary key, there's no way to tell by just Best Links
looking at a table somewhere. The INSERT ● Ask Tom Kyte
commands could be calling that sequence directly. ● Oracle Docs
Edit Or, it could be inserted by a trigger. I'm not Dan Morgan and PSOUG
aware of any easy, reliable way to determine if

Steven Feuerstein
sequences are being used as primary keys without

Jonathan Lewis
looking table by table.

● FAQ
However, generally that is what people like to use ● Connor McDonald

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (1 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Sequences

sequences for, so there's a good chance that all the The Oak Table

sequences are being used as keys somewhere. ● Cary Millsap and Hotsos
● Steve Adams and Ixora
3. Which sequences are in danger of running out? ● Anjo Kolk and OraPerf
Dizwell Oracle Wiki
SELECT sequence_name, (max_value - last_number)/ ●

increment_by sequences_left ● My Personal Blog


FROM ALL_SEQUENCES
ORDER BY sequences_left;

4. What happens when a sequence runs out? Aggregators


Brian Duff's OraBlogs
Well that depends if its a roll-over or not.

❍ Eddie Awad's OracleNA


CREATE SEQUENCE rollover_seq MINVALUE 1 START ❍ Pete Finnigan's Aggregator
WITH 1 INCREMENT BY 1 MAXVALUE 3 CYCLE ❍ Oracle's Bloglist
NOCACHE; ❍ Oracle Base Aggregator

Top Blogs
CREATE SEQUENCE runout_seq MINVALUE 1 START
WITH 1 INCREMENT BY 1 MAXVALUE 3 NOCYCLE
NOCACHE; ❍ Oracle's Ask Tom Kyte
Oracle Guru Jonathan Lewis
CREATE TABLE sequence_table (roll NUMBER(1), ❍

runout NUMBER(1)); ❍ Blogger of the Year Eddie Awad


❍ Data Warehouser David Aldridge
Run this three times: ❍ Oracle Geek Lewis Cunningham
INSERT INTO sequence_table (roll, runout) VALUES ❍ Database Expert James Koopmann
(rollover_seq.NEXTVAL, runout_seq.NEXTVAL); ❍ Dizwell's Howard Rogers
Oracle Master Laurent Schneider
On the fourth time:

Security Expert Pete Finnigan


ORA-08004: sequence RUNOUT_SEQ.NEXTVAL

Oracle Award Winner Mark


exceeds MAXVALUE and cannot be instantiated ❍

Rittman
But the other one rolls over: ❍ Doug Burns
INSERT INTO sequence_table (roll, runout) VALUES ❍ Oracle ACE of the Year Dr. Tim
(rollover_seq.NEXTVAL, 4); Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
scott@Robert> SELECT * FROM sequence_table; ❍ Newbie DBA Lisa Dobson
ROLL RUNOUT ❍ Coffee-Drinking DBA Jon Emmons
---------- ---------- ❍ Chris Foot
1 1 ❍ The Pythian DBA Team Blog
2 2 ❍ DBA Don Seiler
3 3 ❍ DBA Coskan Gundogar
2 4
❍ Oracle WTF

ARCHIVES
Why is it 2,4 instead of 1,4? Well we "used up" the 1 ❍ LIST ALL ARTICLES
on the misfire, so now we have a "gap." Every time ❍ May 2005

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (2 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Sequences

NEXTVAL is "called", the sequence increments. ❍ June 2005


CURRVAL doesn't. Of course, CURRVAL gives you ❍ July 2005
last_number, which is one that's presumably already ❍ August 2005
in use. ❍ September 2005
October 2005
By the way, as usual, you can get some better

November 2005
examples, and a better reference, from Dan

December 2005
Morgan's library.

❍ January 2006
Those looking for an equivalent to AUTONUMBER in ❍ February 2006
other RDBMS may find that using an Oracle ❍ March 2006
sequence is close to the same functionality. Edit Just ❍ April 2006
use the sequence's NEXTVAL as your insert for your ❍ May 2006
key, or in a trigger, like so: ❍ June 2006
❍ July 2006
-- Won't work: August 2006
CREATE TABLE MyTable (seq_id NUMBER(1) DEFAULT

September 2006
rollover_seq.NEXTVAL);

October 2006
ORA-00984: column not allowed here

❍ November 2006
-- Will work: ❍ December 2006
CREATE TABLE MyTable (seq_id NUMBER(1)); ❍ January 2007
❍ February 2007
CREATE OR REPLACE TRIGGER trig_seq BEFORE ❍ March 2007
INSERT ON MyTable April 2007
FOR EACH ROW

May 2007
BEGIN

June 2007
SELECT rollover_seq.NEXTVAL into :new.seq_id

October 2007
FROM dual; ❍

END;

To prevent this post from getting longer than it


needs to be, I'll just send you to AskTom to read a
discussion about the performance of using Oracle
sequences as primary keys.

One final word, about the NOCACHE command I


used up there. The default CACHE value is 20, so I
had to use NOCACHE because it would try to CACHE
more values than the sequence had. CACHE actually
CACHEs the next few values for quicker access. But
if ever there is a system failure, those previously-
retrieved sequence numbers are gone. You'll be left
with a "gap."

Of course, gaps may not be the end of the world for


you. If they are, you'll need to use ALTER SEQUENCE

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (3 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Sequences

to fix them. I've already mentioned two ways to get


gaps with sequences, here's one more. If you do a
transaction with NEXTVAL and then rollback, the
sequence doesn't roll back to where you started.
That'll create a gap, too.

// posted by Robert Vollman @ Wednesday, February 22, 2006

Comments:
"it [a sequence number] could the default value of a
column"
Not yet it can't.
create table seqqy (id number default seq.nextval)
*
ERROR at line 1:
ORA-00984: column not allowed here

Another 'gotcha' worth checking is where you use a


sequence number to populate a column, and the
sequence number is about to hit the limit posed by
the column's data size. Yes, your sequence might
go up to several gazillion, but if you've defined the
column as number(6), then your millionth customer
will be your last.

One trick to pick up where sequences are used is to


compare the HIGH_VALUE in ALL_TAB_COLUMNS to
the LAST_NUMBER in ALL_SEQUENCES. No
guarantees of course.
# posted by Gary Myers : Wednesday, 22 February, 2006

Sloppy!!!

Fixed it. Thanks!


# posted by Robert Vollman : Thursday, 23 February, 2006

This is one of those things where terminology is off


and the devil is in the details. A sequence can't be a
primary key because it's not a field in a table. A
sequence is just number generator. A field in a
table can use the sequence for population, but
inside of Oracle, there is no relation. In your code

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (4 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Sequences

(your trigger, insert statement) you can link them,


but they really are two different things.

Examples: There's not really to stop me from


saying,
UPDATE my_table set seq_id = 12 where seq_id = 1;
as long as 12 hasn't been used yet.
or alternatively I can sit at my desk a run
select rollover_seq.nextval from dual;
over and over and burn up values but have no effect
on the table.

Just a couple fo more gotchas. Other than that, you


are spot on.
# posted by Nuggie99 : Thursday, 23 February, 2006

Jon's got it right:


http://www.lifeaftercoffee.com/2006/02/17/how-
to-create-auto-increment-columns-in-oracle/
# posted by Robert Vollman : Thursday, 23 February, 2006

And Howard's got a great summary on doing an


"autonumber"
http://dizwell.com/main/content/view/61/83/
# posted by Robert Vollman : Thursday, 23 February, 2006

I'm curious how you would fix gaps with ALTER


SEQUENCE.
# posted by Peter Nosko : Friday, 24 February, 2006

Peter,

I didn't really go into detail with that because its


kind of a hack. It's just how I do it. I'll show you
using the SAME example as above.

CREATE SEQUENCE rollover_seq MINVALUE 1 START


WITH 1 INCREMENT BY 1 MAXVALUE 3 CYCLE
NOCACHE;
CREATE SEQUENCE runout_seq MINVALUE 1 START
WITH 1 INCREMENT BY 1 MAXVALUE 3 NOCYCLE
NOCACHE;

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (5 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Sequences

CREATE TABLE sequence_table (roll NUMBER(1),


runout NUMBER(1));

Run this four times, observe the error on the fourth


(same as in the article):
INSERT INTO sequence_table (roll, runout) VALUES
(rollover_seq.NEXTVAL, runout_seq.NEXTVAL);

Note: If you got the gap some other way, you may
need to ROLLBACK first, otherwise you'll have to be
even more clever to fix it, seeing that you've got a
value you'll need to "skip" next time.

Now do this:
ALTER SEQUENCE rollover_seq INCREMENT BY -1;
SELECT rollover_seq.NEXTVAL FROM dual;
ALTER SEQUENCE rollover_seq INCREMENT BY 1;

Now try it:


INSERT INTO sequence_table (roll, runout) VALUES
(rollover_seq.NEXTVAL, 4);

SELECT * FROM sequence_table;


ROLL RUNOUT
---------- ----------
11
22
33
14

Cheers,
Robert
# posted by Robert Vollman : Saturday, 25 February, 2006

Thank you for the explanation. I love the irony of


using INCREMENT BY -1 (A.K.A. rollback) to fix gaps
caused by a ROLLBACK! ;)

But when you said to use ALTER SEQUENCE to fix


gapS, two thoughts came to mind-- that Oracle had
finally provided an ALTER SEQUENCE name START
WITH nnn to reset a sequence to a new starting
point (no such luck). Dropping and recreating has
negative side effects like lost grants and invalidated
dependencies. The other even better thought-- that
several non-consecutive gaps that had occurred

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (6 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Sequences

over time in target keys could be filled-in or


"reclaimed" [insert magic here]. Oh well, it was just
wishful thinking on my part. Your hack will come in
useful for the former without producing the
unwanted side effects. Thanks again. :)
# posted by Peter Nosko : Saturday, 25 February, 2006

But what about the performance in such a


sequential PK ? The b-tree associated will be so
unbalanced because of the inserts of sequential
numbers. What do you think about that?
# posted by Anonymous : Tuesday, 28 February, 2006

Anonymous,

The AskTom link I provided has a discussion on


performance.

As for what I think, well I stayed away from that on


purpose.

So many people use a primary key that goes 1,2,3...


when there is no need for a sequential key.

In most cases, you can use SYS_GUID - that will give


you a unique key that is spread out across your
disk, reducing the amount of contention on that
sequence, and on the part of the disk that houses
the most recently added rows.

See a discussion on choosing primary keys here

In the end, it ALL depends on how the table is used.


There are all sorts of alternatives and tricks.

My argument against sequential primary keys is the


same argument against database independence. Is
it a legitimate business need, or not? If not, why
bother with it?
# posted by Robert Vollman : Tuesday, 28 February, 2006

Don't flame me too badly but why can't we have


autogenerated sequeces for PK's like many other
db's have? I find sequences to be a little dated these

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (7 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Sequences

days and prefer the simplicity of autogenerated pk's.


# posted by lycovian : Wednesday, 01 March, 2006

Lycovian,

Let me turn it around on you. Why do you need


autogenerated sequences? How often is it a
legitimate business need that all rows have a
sequential number assigned to it?

Anyway, you can still have your autonumber, its just


a few extra steps (sequence and a trigger).

Oracle tends to be that way. It's more powerful, but


also more complex.

Why doesn't it just have autonumber? I don't know.


The same reason it doesn't have Boolean I guess.

My advice is to Ask Tom.


# posted by Robert Vollman : Wednesday, 01 March, 2006

Is there any query I can run that would tell me


which tables have data that was generated from a
particular sequence?
# posted by Anonymous : Tuesday, 07 March, 2006

Anonymous,

No. In the original article, look at my answer to the


second question.

A sequence isn't linked to data in a table in any way,


even if that's where it originally came from.

The only thing I can think of to determine whether


data came from a sequence or not is to audit and
log all inserts/updates.

Robert
# posted by Robert Vollman : Tuesday, 07 March, 2006

Anonymous: Binary trees get unbalanced, but B-

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (8 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Sequences

trees don't. There is a common misconception that


B-trees are binary trees, but they are quite different.

B-trees have a much higher fan-out, often in the


order of 100s, depending on the block size and on
the average key size. B-trees with more than 5
levels are rare.

Also, B-trees grow in the opposite direction of


binary trees. Whenever a B-tree needs to be
expanded, either a sibling or a new root is created,
never a new child. When this idea appeared (some
30+ years ago), it was a radical shift of view.

The number of nodes affected by rebalancing a B-


tree is much less than for binary trees. This number
is always less than twice the height of the B-tree.

I advice naming PK-generating sequences similar to


the primary keys, for example: [name]_SEQ and
[name]_PK.

This enables easy identification of sequence-


primary key pairs.

For legacy systems, you have to go through the


trouble of manually identifying these pairs. Once
you have done so, I suggest that you create
synonyms for the sequences, where the synonyms
are named similar to the primary keys. Use the
synonyms in any new code as well as a
documentation of the legacy.

Regards,
# posted by Roy Brokvam : Thursday, 09 March, 2006

From AskTom: (http://asktom.oracle.com/pls/ask/f?


p=4950:8:::::F4950_P8_DISPLAYID:474483191697)

"When Oracle goes to split an index block, there is


an optimization (known as the
90/10 split). If we notice that you are always
inserting increase values (as
you would with a primary key on a sequence), we do
a 90/10 split -- 90% of the
data goes "left", 10% of the data goes right."

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (9 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Sequences

# posted by Anonymous : Thursday, 21 September, 2006

This is how I determine sequence - table


associations. I use it to generate hibernate maping
files for oracle with the sequence information.

CREATE OR REPLACE FUNCTION


tiggerbodytovarchar (trgname IN VARCHAR2)
RETURN VARCHAR2
IS
tmp VARCHAR2 (4000);
BEGIN
SELECT trigger_body
INTO tmp
FROM user_triggers
WHERE trigger_name = trgname;

RETURN tmp;
END;
/

CREATE MATERIALIZED VIEW table_table_seqname


BUILD IMMEDIATE
AS
SELECT table_name,
UPPER(REGEXP_SUBSTR(REGEXP_SUBSTR( LOWER
(tiggerbodytovarchar(trigger_name)), '([[:alpha:]|_])+
\.nextval'),'[[:alpha:]|_]+')) AS seq
FROM user_triggers
WHERE
triggering_event = 'INSERT' AND
status = 'ENABLED';
/

CREATE MATERIALIZED VIEW table_sequence


BUILD IMMEDIATE
AS
SELECT table_table_seqname.table_name, seq.*
FROM table_table_seqname
INNER JOIN user_sequences seq
ON UPPER(seq.sequence_name) = seq;
/
# posted by Jeff Wilde : Wednesday, 31 January, 2007

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (10 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Sequences

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/02/oracle-sequences.html (11 of 11)1/9/2008 2:51:07 AM


OracleBlog: Oracle Interview Questions

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday,
About Me
February 21,
Name: Robert Vollman
2006
Location: Calgary, Alberta, Canada
Oracle
Interview I was born and raised in Ottawa, and have lived in
Questions Calgary since 1991. I like playing sports (hockey,
soccer, ultimate, basketball, you name it) and military board
"We're
games. I also enjoy reading, walking, and playing with my 2 cats
interviewing an
Lilly and Brutus. I'm a database application specialist, whatever
Oracle guy
that is.
tomorrow, can
you give me a
few questions View my complete profile
to ask him?"

Not an
uncommon
Best Links
Ask Tom Kyte
request. The

Oracle Docs
problem is, ●

there are ● Dan Morgan and PSOUG


literally ● Steven Feuerstein
thousands of ● Jonathan Lewis
potential Oracle ● FAQ
questions, but ● Connor McDonald
it all depends ● The Oak Table
on what are ● Cary Millsap and Hotsos
you trying to ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (1 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

achieve. So I ● Anjo Kolk and OraPerf


pushed back: ● Dizwell Oracle Wiki
● My Personal Blog
"What kind of
Oracle-related
skills would the
candidate need
that you want
Aggregators
to ask for?" Brian Duff's OraBlogs

"You tell us. We ❍ Eddie Awad's OracleNA


just want to ❍ Pete Finnigan's Aggregator
know if he ❍ Oracle's Bloglist
knows Oracle. ❍ Oracle Base Aggregator
Whatever an
Oracle guy
would need to
Top Blogs
Oracle's Ask Tom Kyte
know."

❍ Oracle Guru Jonathan Lewis


Pretty soon ❍ Blogger of the Year Eddie Awad
thereafter I ❍ Data Warehouser David Aldridge
figured out that ❍ Oracle Geek Lewis Cunningham
it was a ❍ Database Expert James Koopmann
pointless ❍ Dizwell's Howard Rogers
conversation to ❍ Oracle Master Laurent Schneider
continue, ❍ Security Expert Pete Finnigan
although I did ❍ Oracle Award Winner Mark Rittman
love the way he
Doug Burns
summarized

Oracle ACE of the Year Dr. Tim Hall


dozens of very

UKOUG's Andrew (Arfur C.) Clarke


different ❍

positions into ❍ Newbie DBA Lisa Dobson


that one term: ❍ Coffee-Drinking DBA Jon Emmons
"Oracle Guy." ❍ Chris Foot
❍ The Pythian DBA Team Blog
Nevertheless, it ❍ DBA Don Seiler
got me ❍ DBA Coskan Gundogar
thinking. What ❍ Oracle WTF
makes for a
good technical
question? I
ARCHIVES
have ❍ LIST ALL ARTICLES
conducted, or ❍ May 2005
been invited to, ❍ June 2005
several ❍ July 2005

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (2 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

interviews, so it ❍ August 2005


got me to ❍ September 2005
thinking about ❍ October 2005
which ❍ November 2005
questions were December 2005
most effective

January 2006
at getting to

February 2006
the heart of the

matter: "Will ❍ March 2006


this candidate ❍ April 2006
succeed ❍ May 2006
technically in ❍ June 2006
this role?" ❍ July 2006
❍ August 2006
Elements of a ❍ September 2006
Good Technical October 2006
Interview

November 2006
Question.

❍ December 2006
1. Must require ❍ January 2007
knowledge of ❍ February 2007
the area, ❍ March 2007
including ❍ April 2007
domain and ❍ May 2007
philosophy, to ❍ June 2007
solve. ❍ October 2007

I don't think it's


enough that a
candidate
demonstrates
proficiency with
the technology.
I like to see if
they
understand the
overall
philosophy of
the product
(Oracle, in this
case): What
needs was it
meant to
provide, what

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (3 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

kind of
problems was it
designed to
solve, how does
it accomplish
those tasks.

2. Must require
overall
technical skill/
experience/
understanding
to solve.

I mean to say
that a good
question shows
if the candidate
understands
(for example)
relational
databases
themselves, not
just a particular
relational
database.
Carrying this
example, does
your C++
developer
understand
algorithms and
software
design?

3. Does not
require
knowledge of
precise syntax

In my mind,
anyone can
look something
up in a manual.

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (4 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

You don't need


to walk into an
empty
boardroom and
know exactly
how something
is called. I don't
think
knowledge of
syntax is a
reliable
indicator of the
suitability of a
candidate.

For example,
you could have
a good
candidate
"blank out" on
the syntactic
details, and you
could also have
a bad candidate
who swallowed
a reference
manual the
night before
the interview.

Now, I would
be worried if
the candidate
didn't know
BASIC syntax.
But I don't want
to waste
precious time
asking basic
questions, and
if he is truly is
that
inexperienced, I

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (5 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

should be able
to figure it out
in other ways.

4. Can be
answered
quickly.

Time is
precious in an
interview, and
you shouldn't
need long,
convoluted
questions to
determine
whether or not
a candidate
"gets it." A
good question
demonstrates
quickly if the
candidate is on
the right path,
or wouldn't get
it regardless of
how much time
he had.

5. Is not a
"gotcha"

I've met some


interviewers
that seem to
use the
opportunity not
to evaluate the
candidate, but
to prove how
clever they are
(either to the
candidate or
the manager).

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (6 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

They do this by
asking really
obscure tricks,
sometimes
referred to as
"gotchas."

The problem
with asking
questions in
the obscure
corners is that
even very
experienced
candidates may
not have
worked in that
area and, if
they have, may
not have
stumbled
across that
particular gem.

Just remember,
the purpose of
the interview
isn't to make
YOU look
clever, and
asking silly
questions
might make a
great candidate
think "what
kind of clown
show am I
getting myself
into?"

6. Has many
possible
solutions and
approaches

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (7 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

The most
effective
questions I
have ever
asked, or been
asked, were the
ones that
triggered lively
technical
discussions
between the
interviewer and
the candidate.
Why? You get
to catch a
glimpse not
only of the
candidates
thinking
process, but
also how he
communicates.
I also like the
added benefit
of not
punishing (in
fact, rewarding)
those that
approach
problems
differently than
the interviewer.

7. Requires
asking for more
information (or
make
assumptions).

Personally, I
believe one of
the keys to
success in IT is

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (8 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

to define a
problem before
approaching it.
That's why I
lean towards
these types of
questions. Did
the candidate
come back, or
just try to solve
it? If he came
back, what kind
of questions
did he ask? In
the face of an
incompletely-
defined
problem, did he
get stuck, or
did he make
some
assumptions
and continue? If
so, what
assumptions
did he make?

8. Is relevant to
the business/
job being
considered

Would you hire


a cleaning
service with
award-winning
carpet cleaning
if you had
hardwood
floors? Would
you hire a
running back
who excels in

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (9 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

bad weather if
you played in a
dome? Would
you hire an
accomplished
science-fiction
writer to author
your
biography? No?
Then why
probe for
technical skills
that don't
directly apply
to the position
you're
attempting to
fill?

Closing
Thoughts

Incidentally, in
the end I
referred the
manager in
question to a
couple of links
which have
hundreds of
Oracle-
interview
questions. You
can pick your
favourites but,
more likely, you
can read them
until you come
up with good
ideas that suit
your needs.

http://www.

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (10 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

orafaq.com/
forum/
t/9760/2/
http://www.
databasejournal.
com/features/
oracle/article.
php/3085171

As an aside,
that last article
was written by
one of my
preferred
columnists,
James
Koopmann. He
hasn't written
much recently,
but check out
his archives,
he's got some
great articles
there. For
instance, check
out his series
on Oracle
Session Tracing.

// posted by Robert
Vollman @ Tuesday,
February 21, 2006

Comments:
Rob,

James is one of
my favorites
also. You can
read more of

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (11 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

his stuff at
ittoolbox.

Of course if you
make it that
far, might as
well check out
mine! heh

Actually it was
reading James'
blog that got
me started.

Thanks,

LewisC
# posted by
LewisC :
Tuesday, 21
February, 2006

Thanks Lewis! I
always love
promoting
authors others
may not have
stumbled
across yet.

You'll notice, by
the way, that
you're already
on my blog list!
I've enjoyed
your blog ever
since I found
your posts
about
Collections
months ago.

Cheers!

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (12 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle Interview Questions

Robert
# posted by
Robert
Vollman : Tuesday,
21 February, 2006

This post has


been removed
by a blog
administrator.
# posted by
Smithy :
Monday, 11
September, 2006

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/02/oracle-interview-questions.html (13 of 13)1/9/2008 2:51:09 AM


OracleBlog: Oracle and SOA

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday,
About Me
February 02,
Name: Robert Vollman
2006
Location: Calgary, Alberta, Canada
Oracle
and SOA I was born and raised in Ottawa, and have lived in
I went to a Calgary since 1991. I like playing sports (hockey,
seminar soccer, ultimate, basketball, you name it) and military board
yesterday in games. I also enjoy reading, walking, and playing with my 2 cats
downtown Lilly and Brutus. I'm a database application specialist, whatever
Calgary where that is.
Oracle was
unveiling its View my complete profile
SOA Solution to
all the big
Canadian oil
and gas giants.
Best Links
SOA is the ● Ask Tom Kyte
latest buzz- ● Oracle Docs
acronym for ● Dan Morgan and PSOUG
"Service- ● Steven Feuerstein
Oriented ● Jonathan Lewis
Architecture." ● FAQ
Connor McDonald
What is SOA?

● The Oak Table


SOA is not a ● Cary Millsap and Hotsos
technology or ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/02/oracle-and-soa.html (1 of 9)1/9/2008 2:51:13 AM


OracleBlog: Oracle and SOA

something you ● Anjo Kolk and OraPerf


install. It is a ● Dizwell Oracle Wiki
concept, or ● My Personal Blog
rather an
approach to
modelling your
system, and
one that is
Aggregators
Brian Duff's OraBlogs
different from

Eddie Awad's OracleNA


the standard ❍

client/server ❍ Pete Finnigan's Aggregator


model you may ❍ Oracle's Bloglist
be used to. As ❍ Oracle Base Aggregator

Top Blogs
opposed to
large,
proprietary ❍ Oracle's Ask Tom Kyte
applications Oracle Guru Jonathan Lewis
that do

Blogger of the Year Eddie Awad


everything, SOA

Data Warehouser David Aldridge


is a design

Oracle Geek Lewis Cunningham


meant to try to ❍

integrate ❍ Database Expert James Koopmann


numerous and ❍ Dizwell's Howard Rogers
diverse ❍ Oracle Master Laurent Schneider
software ❍ Security Expert Pete Finnigan
applications ❍ Oracle Award Winner Mark Rittman
with common ❍ Doug Burns
interfaces, in ❍ Oracle ACE of the Year Dr. Tim Hall
the name of ❍ UKOUG's Andrew (Arfur C.) Clarke
code reuse/ ❍ Newbie DBA Lisa Dobson
maintainability,
Coffee-Drinking DBA Jon Emmons
and adaptibility.

Chris Foot
The notion of

The Pythian DBA Team Blog


using a group

of independent ❍ DBA Don Seiler


applications to ❍ DBA Coskan Gundogar
accomplish a ❍ Oracle WTF

ARCHIVES
shared task is
also sometimes
referred to as ❍ LIST ALL ARTICLES
grid computing. ❍ May 2005
June 2005
Everyone knows

❍ July 2005

http://thinkoracle.blogspot.com/2006/02/oracle-and-soa.html (2 of 9)1/9/2008 2:51:13 AM


OracleBlog: Oracle and SOA

that "Web ❍ August 2005


Services" are ❍ September 2005
one of the ❍ October 2005
hottest things November 2005
lately. An SOA

December 2005
is essentially a

January 2006
collection of

February 2006
such services, ❍

communicating ❍ March 2006


with one ❍ April 2006
another, ❍ May 2006
generally ❍ June 2006
through XML. ❍ July 2006
(Of course I am ❍ August 2006
over- ❍ September 2006
simplifying ❍ October 2006
things: SOA can ❍ November 2006
involve any kind December 2006
of self-

January 2007
contained

February 2007
service

communicating ❍ March 2007


in any way.) ❍ April 2007
❍ May 2007
SOA is not ❍ June 2007
specific to any ❍ October 2007
technology,
indeed every
"family" of
technologies
has its own SOA
solution, and
usually you can
mix-and-match
your own.
However, open-
source XML-
based
technologies
such as BPEL,
SOAP and WSDL
are very
commonly used.

http://thinkoracle.blogspot.com/2006/02/oracle-and-soa.html (3 of 9)1/9/2008 2:51:13 AM


OracleBlog: Oracle and SOA

For more
information
about SOA in
general, visit
OASIS's web
site:
OASIS Open
Standard for
SOA

What is Oracle's
SOA Solution?

It was inevitable
that Oracle
would join in
the fray and
devise SOA-
based
solutions. At
the very least as
part of its
"Oracle Fusion"
project to
integrate
PeopleSoft and
JD Edwards.
Notice the
recent
acquisitions of
Kurian, Collaxa
and Oblix were
all steps along
the SOA path.

Oracle's SOA
solution leans
heavily towards
J2EE, their
preferred
language in
which to

http://thinkoracle.blogspot.com/2006/02/oracle-and-soa.html (4 of 9)1/9/2008 2:51:13 AM


OracleBlog: Oracle and SOA

develop your
Web Services.
They want you
to use the
perhaps poorly-
named
JDeveloper as
your IDE for
developing your
Web Services
with Oracle
Containers
(OC4J).
JDeveloper
includes the
toolset Oracle
Application
Development
Framework
(ADF) which
also includes
Oracle TopLink
for object-
relational
mapping. Of
course they
suggest you
use the Oracle
Application
Server for these
Web Services.
Get more
information on
this from
Oracle's
whitepaper:
Oracle's
JDeveloper
White Paper

One of the new


components is
the BPEL

http://thinkoracle.blogspot.com/2006/02/oracle-and-soa.html (5 of 9)1/9/2008 2:51:13 AM


OracleBlog: Oracle and SOA

Process
Manager,
acquired with
Collaxa, which
is an
application that
includes several
tools to develop
BPEL models
and the
underlying Web
Services. This is
where you
define which
services are
called, and
when. Grab this
whitepaper for
more on that:
Oracle's BPEL
White Paper

For those who


want more
details, I am
preparing a
future post on
BPEL, followed
by some of
these other
acronyms I've
mentioned.
Note to Eddie:
Half the
presenters
pronounced it
"bipple" and the
other half
pronounced it
"b-pull."

That
summarizes my

http://thinkoracle.blogspot.com/2006/02/oracle-and-soa.html (6 of 9)1/9/2008 2:51:13 AM


OracleBlog: Oracle and SOA

introductory
post on Oracle
and SOA. I will
be writing
articles with
more meat and
technical details
over the next
couple of
weeks, but for
those who are
intrigued and
just can't wait,
here are some
Oracle white
papers on SOA:
Oracle E-
Business and
SOA
IDC: Oracle's
SOA Platform

For more
information
about Oracle's
SOA Solution,
visit their web
site:
Oracle's Main
SOA Site

// posted by Robert
Vollman @ Thursday,
February 02, 2006

Comments:
Robert,
You probably
went to the
same seminar

http://thinkoracle.blogspot.com/2006/02/oracle-and-soa.html (7 of 9)1/9/2008 2:51:13 AM


OracleBlog: Oracle and SOA

that I went to
on Tuesday in
Vancouver.

One of the
more
interesting
point that I
noted was on
Jason S
presentation on
their case study
of a client who
is doing SOA
work and the
point was that
they had to
build another
front end layer
on top of BPEL
Process
Manager for the
clients Business
Analysts as the
BPEL front end
was deemed to
be too complex
for the BAs to
use.
# posted by
Peter K :
Thursday, 02
February, 2006

Liked your blog.


Look forward to
your post about
BPEL.
Cheers,
Venkatesh
# posted by
Venkatesh :

http://thinkoracle.blogspot.com/2006/02/oracle-and-soa.html (8 of 9)1/9/2008 2:51:13 AM


OracleBlog: Oracle and SOA

Thursday, 09
February, 2006

Nice blog
Robert. looking
forward to
know more
about BPEL. Can
you list career
opportunity in
Oracle SOA.

Ashok
# posted by
ashok : Tuesday,
20 November, 2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/02/oracle-and-soa.html (9 of 9)1/9/2008 2:51:13 AM


OracleBlog: BPEL

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, February 14, 2006


About Me
BPEL Name: Robert
BPEL (Business Process Execution Language) is Vollman
an xml-based language for use with the Location: Calgary,
Service-Oriented Architecture (SOA) to Alberta, Canada
software development.
I was born and raised in Ottawa,
Simply put, BPEL is an XML-based standard
and have lived in Calgary since
used to define business processes, generally
1991. I like playing sports
by demonstrating how relevant Web Services
(hockey, soccer, ultimate,
connect and communicate. You would use
basketball, you name it) and
BPEL to layout the general business flow and
military board games. I also
how the Web Services are used. In the end,
enjoy reading, walking, and
you have a particularly-formatted XML file
playing with my 2 cats Lilly and
running on a BPEL Server.
Brutus. I'm a database
To do this, Oracle provides the BPEL Process application specialist, whatever
that is.
Manager. This is a BPEL IDE that will generate
your BPEL XML file, and then run it on a BPEL
View my complete profile
Engine running on top of the Oracle
Application Server. There are lots of other
engines out there, BPEL and SOA is by no
means unique to Oracle. In fact, here is an Best Links
Open Source BPEL Server, ActiveBPEL. ● Ask Tom Kyte
● Oracle Docs
BPEL has its roots in IBM and Microsoft's WSFL Dan Morgan and PSOUG
and XLANG. It was originally called BPEL4WS

http://thinkoracle.blogspot.com/2006/02/bpel.html (1 of 4)1/9/2008 2:51:15 AM


OracleBlog: BPEL

(BPEL for Web Services), but was renamed WS- ● Steven Feuerstein
BPEL. BPEL was meant to replace WSCI ● Jonathan Lewis
("Whiskey"), which Oracle put forward with ● FAQ
Sun and SAP a few years ago for the same ● Connor McDonald
purpose (designing the coordination of Web ● The Oak Table
Services). And if that is not enough acronyms ● Cary Millsap and Hotsos
for you, I'll just note that BPEL uses WSDL to
Steve Adams and Ixora
determine the format of the messages to be

Anjo Kolk and OraPerf


sent among the various Web Services.

● Dizwell Oracle Wiki


For those wanting a quick hands-on "taste" of ● My Personal Blog
BPEL, here is what I did.

Aggregators
1. Start BPEL Server
2. Start the BPEL Designer, which is part of
JDeveloper
Brian Duff's OraBlogs
3. Connected to the BPEL Console through a

Eddie Awad's OracleNA


web browser

Pete Finnigan's Aggregator


4. Create a new "BPEL Process Project" in ❍

JDeveloper ❍ Oracle's Bloglist


5. Made a few minor changes to the default ❍ Oracle Base Aggregator
project
6. Toggled to Source and saw my changes in Top Blogs
the XML ❍ Oracle's Ask Tom Kyte
7. Validated the changes using the "BPEL ❍ Oracle Guru Jonathan Lewis
Validation Browser." ❍ Blogger of the Year Eddie Awad
8. Generated a nice JPG of my BPEL business
Data Warehouser David Aldridge
process

❍ Oracle Geek Lewis Cunningham


❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark
Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim
Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog

http://thinkoracle.blogspot.com/2006/02/bpel.html (2 of 4)1/9/2008 2:51:15 AM


OracleBlog: BPEL

DBA Don Seiler


❍ DBA Coskan Gundogar


❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
9. Deployed the project to the default BPEL ❍ February 2006
Server I had started ❍ March 2006
10. Found the deployed service in the BPEL ❍ April 2006
Console ❍ May 2006
11. From the BPEL Console, entered a ❍ June 2006
parameter and initiated my BPEL process
July 2006
12. Still from the BPEL Console, audited the

August 2006
flow and examined the XML messages that

September 2006
went back and forth ❍

❍ October 2006
Thus concludes my introductory post on BPEL. ❍ November 2006
Next I'm going to find some Web Services out ❍ December 2006
there and build a more significant business ❍ January 2007
process. When I do, I'll be sure to post an ❍ February 2007
article with my JPG and what I thought of ❍ March 2007
some of the bells and whistles. ❍ April 2007
❍ May 2007
// posted by Robert Vollman @ Tuesday, February 14,
❍ June 2007
2006 ❍ October 2007

Comments:
Just wanted to let you know that your blog is
really informative and gives the needed
"essence" to novoice people like me.

Great going and please continue writing on all

http://thinkoracle.blogspot.com/2006/02/bpel.html (3 of 4)1/9/2008 2:51:15 AM


OracleBlog: BPEL

latest stuff.

- blogreader
# posted by Anonymous : Friday, 17 February, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/02/bpel.html (4 of 4)1/9/2008 2:51:15 AM


OracleBlog: TRANSLATE

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, February 07,


About Me
2006
Name: Robert Vollman
TRANSLATE Location: Calgary, Alberta, Canada
TRANSLATE is a useful
little function that can I was born and raised in Ottawa, and have
replace given characters in lived in Calgary since 1991. I like playing
the first string with other sports (hockey, soccer, ultimate, basketball, you name
given characters. it) and military board games. I also enjoy reading,
TRANSLATE will go walking, and playing with my 2 cats Lilly and Brutus.
through the provided I'm a database application specialist, whatever that is.
string looking for any
instance of characters in
View my complete profile
the first list and, when
found, replace them with
the corresponding
character in the second Best Links
list. Any characters in the ● Ask Tom Kyte
given string that don't ● Oracle Docs
show up in the first list are ● Dan Morgan and PSOUG
left alone. ● Steven Feuerstein
If the first list is longer ● Jonathan Lewis
than the second list, that ● FAQ
means that some ● Connor McDonald
characters have no ● The Oak Table
corresponding character. ● Cary Millsap and Hotsos
In that case, such ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/02/translate.html (1 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

characters are simply ● Anjo Kolk and OraPerf


replaced with nothing (ie. ● Dizwell Oracle Wiki
deleted). So if you want to ● My Personal Blog
remove a character, put
them at the end of your
first list. It clearly doesn't
make sense for the second
list to be longer than the
Aggregators
Brian Duff's OraBlogs
first list, nor does it make

Eddie Awad's OracleNA


sense to have duplicates ❍

in the first list (although it ❍ Pete Finnigan's Aggregator


certainly makes sense in ❍ Oracle's Bloglist
the second list). If you do ❍ Oracle Base Aggregator

Top Blogs
have inconsistent
duplicates in your first list,
Oracle seems to choose ❍ Oracle's Ask Tom Kyte
the character in the Oracle Guru Jonathan Lewis
second list corresponding

Blogger of the Year Eddie Awad


to its first occurence in the

Data Warehouser David Aldridge


first list.

❍ Oracle Geek Lewis Cunningham


By the way, the two lists ❍ Database Expert James Koopmann
are actually passed as ❍ Dizwell's Howard Rogers
strings, but it makes more ❍ Oracle Master Laurent Schneider
sense to picture them as ❍ Security Expert Pete Finnigan
lists. C programmers will ❍ Oracle Award Winner Mark Rittman
be most comfortable, ❍ Doug Burns
because they are used to ❍ Oracle ACE of the Year Dr. Tim Hall
interpreting strings as
UKOUG's Andrew (Arfur C.) Clarke
arrays of characters, and

Newbie DBA Lisa Dobson


that's what we're dealing

Coffee-Drinking DBA Jon Emmons


with here. ❍

❍ Chris Foot
TRANSLATE is under ❍ The Pythian DBA Team Blog
chapter 6 (Functions) of ❍ DBA Don Seiler
Oracle's SQL Reference. ❍ DBA Coskan Gundogar
❍ Oracle WTF
Let's look at a first, simple
example to remove the
dashes in a phone number
ARCHIVES
and replace them with ❍ LIST ALL ARTICLES
dots to form some kind of ❍ May 2005
standard syntax. ❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2006/02/translate.html (2 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

scott@Robert> ❍ August 2005


SELECT ❍ September 2005
TRANSLATE ❍ October 2005
('(619)455- ❍ November 2005
1998', ')-(', '..') ❍ December 2005
PHONE_NO ❍ January 2006
FROM DUAL; ❍ February 2006
March 2006
PHONE_NO

------------ ❍ April 2006


619.455.1998 ❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
Complex constraints are a ❍ September 2006
particularly good use for ❍ October 2006
TRANSLATE. Let's presume November 2006
you have a column that

December 2006
represents a special code

January 2007
in your company where

the 4th character must be ❍ February 2007


a digit, and the first digit. ❍ March 2007
Well, you may know that ❍ April 2007
INSTR can tell you where ❍ May 2007
the first occurence of a ❍ June 2007
particular character is, but ❍ October 2007
you're looking for 10
characters, how can that
be done? Quite easily,
because with TRANSLATE
you can change all
characters to a single one.

CREATE TABLE
MyTable
(special_code
VARCHAR2(32)
CHECK (INSTR
(TRANSLATE
(special_code,
'123456789',
'000000000'),
'0') = 4));

http://thinkoracle.blogspot.com/2006/02/translate.html (3 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

scott@Robert>
INSERT INTO
MyTable
(special_code)
VALUES
('abc123');

1 row created.

scott@Robert>
INSERT INTO
MyTable
(special_code)
VALUES
('abcd1234');
INSERT INTO
MyTable
(special_code)
VALUES
('abcd1234')
*
ERROR at line
1:
ORA-02290:
check
constraint
(SCOTT.
SYS_C008454)
violated

That is an excellent
technique of how
TRANSLATE can be applied
to a problem. As a side
note, we can use RPAD to
generate that second list
for us if it is very long.

CREATE TABLE
MyTable
(special_code

http://thinkoracle.blogspot.com/2006/02/translate.html (4 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

VARCHAR2(32)
CHECK (INSTR
(TRANSLATE
(special_code,
'123456789',
RPAD('0', 9,
'0')), '0') = 4));

Let's say you have a


special column that should
ONLY have numbers. How
can you do that? Well how
about you delete them all,
and then see if you have
an empty string? That
would look something like
this:

CREATE TABLE
MyTable
(numeric_only
VARCHAR2(32)
CHECK
(TRANSLATE
(numeric_only,
'0123456789',
'') IS NULL));

scott@Robert>
INSERT INTO
MyTable
(numeric_only)
VALUES
('abc123');

1 row created.

Oops? What happened? I'll


show you this little feature
of TRANSLATE:

http://thinkoracle.blogspot.com/2006/02/translate.html (5 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

scott@Robert>
SELECT
TRANSLATE
('abc123',
'0123456789',
'') FROM DUAL;

T
-

The truth is, if the second


list is empty, it seems to
wipe out the entire string.
Fortunately there is a
pretty easy way around
this. Just make sure the
second string isn't empty.
Map some non-important
character to the same
character, like so:

scott@Robert>
SELECT
TRANSLATE
('abc123',
'$0123456789',
'$') FROM
DUAL;

TRA
---
abc

Let's try this new


constraint:

CREATE TABLE
MyTable

http://thinkoracle.blogspot.com/2006/02/translate.html (6 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

(numeric_only
VARCHAR2(32)
CHECK
(TRANSLATE
(numeric_only,
'$0123456789',
'$') IS NULL));

scott@Robert>
INSERT INTO
MyTable
(numeric_only)
VALUES
('1234');

1 row created.

scott@Robert>
INSERT INTO
MyTable
(numeric_only)
VALUES
('abc123');
INSERT INTO
MyTable
(numeric_only)
VALUES
('abc123')
*
ERROR at line
1:
ORA-02290:
check
constraint
(SCOTT.
SYS_C008456)
violated

Much better! You know, if


we wanted to allow some
non-numeric characters,
but no more than 2, we

http://thinkoracle.blogspot.com/2006/02/translate.html (7 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

could use LENGTH to do


that.

CREATE TABLE
MyTable
(max_2
VARCHAR2(32)
CHECK
(LENGTH
(TRANSLATE
(max_2,
'$0123456789',
'$')) <= 2));

scott@Robert>
INSERT INTO
MyTable
(max_2)
VALUES
('abc123');
INSERT INTO
MyTable
(max_2)
VALUES
('abc123')
*
ERROR at line
1:
ORA-02290:
check
constraint
(SCOTT.
SYS_C008459)
violated

scott@Robert>
INSERT INTO
MyTable
(max_2)
VALUES
('ab123');

1 row created.

http://thinkoracle.blogspot.com/2006/02/translate.html (8 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

As a quick aside, you'll


notice that I specify my
column names when I'm
doing an insert. Why, you
may ask, do I do that? Well
don't you think what I'm
doing is clearer to you, the
reader, when I specify
which values I'm inserting?
Furthermore, if the
schema of a table
changes, my INSERT
command will still work,
assuming the schema
change doesn't affect the
columns I'm using, and
that there are no new
parameters that require a
value.

You can do so much with


TRANSLATE when
combined with other
functions, such as (to
name just a few):

INSTR: gets the position of


the first matching
character
TRIM: take away spaces, or
specific, single characters
(also see LTRIM, RTRIM)
UPPER: converts all
characters to upper case
(also see LOWER)
RPAD: creates a string of
the same character (also
see LPAD)
LENGTH: calculates the
length of a string

Despite the simplicity of

http://thinkoracle.blogspot.com/2006/02/translate.html (9 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

the function, it comes in


useful in complex
constraints and
transformations, both by
itself and in concert with
other Oracle functions.

As a final note, for those


of you needing something
other than the 1-to-1
switch that TRANSLATE
allows, and instead
needing to replace one
substring with another,
you want to use REPLACE.
Doubtlessly that will be
the topic of a later post.

Dan Morgan's Reference


on TRANSLATE:
http://www.psoug.org/
reference/
translate_replace.html

// posted by Robert
Vollman @ Tuesday, February 07,

2006

Comments:
Great article.

In 10G, I believe that


TRANSLATE/REPLACE can
often be replaced with the
use of regular expression
functions like
REGEXP_REPLACE. Regular
expressions are very
powerful if you know how
to use them (especially
how to construct patterns).

http://thinkoracle.blogspot.com/2006/02/translate.html (10 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

Another example of the


use of TRANSALTE,
REPLACE and
REGEXP_REPLACE can be
found at: oraqa.
com/2006/01/30/how-to-
seperate-character-data-
from-numeric-data/
# posted by Eddie Awad :
Tuesday, 07 February, 2006

Good examples. By the


way Morgan's Library is a
nice site for references
and examples.
# posted by yas : Wednesday,
08 February, 2006

I am interested to know
about the compatibility of
Oracle 10g on a Pentium
III machine. I got to know
that its recommended
requirement is PIV, but it
can also be used on PIII.
Can you tell me the
problems we will face if we
install 10g on a PIII?

Also, if Oracle 9i has


better performance than
10g on a PIII machine.
Please help.
# posted by Amit Mohanty :
Wednesday, 08 February, 2006

Thanks Eddie: You are


right. Can't wait until we
migrate more into 10g.

http://thinkoracle.blogspot.com/2006/02/translate.html (11 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

Yas: Yes, Morgan's Library


is great, which is why its
under my links, and I
reference it in practically
every post, including this
one!

Amit: I've never tried to


install neither Oracle 9 nor
10 on a P3 machine. Try
posting your question to
an Oracle newsgroup,
such as:
http://www.orafaq.com/
forum/
http://www.dbasupport.
com/forums/
http://forums.oracle.com/
forums/
or comp.databases.oracle
# posted by Robert Vollman :
Wednesday, 08 February, 2006

Rob,

Great article. Never


thought about creating a
check constraint like that.
That could be very
powerful.

I like and use Morgan's


library also. He must
spend as much time on
that as we do blogging. ;-)

Thanks,

LewisC
# posted by LewisC : Sunday,
19 February, 2006

http://thinkoracle.blogspot.com/2006/02/translate.html (12 of 13)1/9/2008 2:51:18 AM


OracleBlog: TRANSLATE

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/02/translate.html (13 of 13)1/9/2008 2:51:18 AM


OracleBlog: SourceForge

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, February
About Me
02, 2006
Name: Robert Vollman
SourceForge Location: Calgary, Alberta, Canada
Have you been
overlooking the I was born and raised in Ottawa, and have lived
wealth of handy in Calgary since 1991. I like playing sports
tools and code on (hockey, soccer, ultimate, basketball, you name it) and
SourceForge? military board games. I also enjoy reading, walking, and
playing with my 2 cats Lilly and Brutus. I'm a database
SourceForge.net is a
application specialist, whatever that is.
web site that hosts
literally hundreds of
View my complete profile
thousands of
projects. Its an
excellent source of
open source Best Links
development ● Ask Tom Kyte
projects. You can ● Oracle Docs
download software Dan Morgan and PSOUG
and source code

Steven Feuerstein
and collaborate with

Jonathan Lewis
others on projects.

● FAQ
Having trouble ● Connor McDonald
designing your ● The Oak Table
software? Search ● Cary Millsap and Hotsos
SourceForge for ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/02/sourceforge.html (1 of 4)1/9/2008 2:51:21 AM


OracleBlog: SourceForge

similar projects and ● Anjo Kolk and OraPerf


see what they did. ● Dizwell Oracle Wiki
● My Personal Blog
Want to avoid re-
inventing a wheel?
Find something
suitable to your
purposes at
Aggregators
SourceForge. Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


Let's look at a quick ❍ Pete Finnigan's Aggregator
example. The ❍ Oracle's Bloglist
simplest example I ❍ Oracle Base Aggregator
could find is a little
PL/SQL script that
generates a package
Top Blogs
Oracle's Ask Tom Kyte
based on a table. ❍

I'm not promoting ❍ Oracle Guru Jonathan Lewis


this particular ❍ Blogger of the Year Eddie Awad
script, I'm just using ❍ Data Warehouser David Aldridge
it as an example. ❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
You can fetch the ❍ Dizwell's Howard Rogers
simple example ❍ Oracle Master Laurent Schneider
here:
Security Expert Pete Finnigan
http://sourceforge.

Oracle Award Winner Mark Rittman


net/projects/

Doug Burns
plsqlgenpkg/

❍ Oracle ACE of the Year Dr. Tim Hall


UKOUG's Andrew (Arfur C.) Clarke
Download it, and

inside the zip file ❍ Newbie DBA Lisa Dobson


you'll find some PL/ ❍ Coffee-Drinking DBA Jon Emmons
SQL. Go ahead and ❍ Chris Foot
run it: it will ask for ❍ The Pythian DBA Team Blog
a table name, and a ❍ DBA Don Seiler
package name. It ❍ DBA Coskan Gundogar
will then generate ❍ Oracle WTF
some PL/SQL that
you can use to
generate a package
ARCHIVES
LIST ALL ARTICLES
for your table. Easy

as that. ❍ May 2005


❍ June 2005
That is pretty typical ❍ July 2005

http://thinkoracle.blogspot.com/2006/02/sourceforge.html (2 of 4)1/9/2008 2:51:21 AM


OracleBlog: SourceForge

of SourceForge. ❍ August 2005


Hunt around and ❍ September 2005
find some useful ❍ October 2005
applications. There ❍ November 2005
are PL/SQL Editors December 2005
and PL/SQL Plug-Ins

January 2006
to various IDEs (like

February 2006
Eclipse). I've seen

March 2006
Java programs that ❍

can monitor your ❍ April 2006


database. All sorts ❍ May 2006
of things. ❍ June 2006
❍ July 2006
Might be a good ❍ August 2006
place to share your ❍ September 2006
open source tools, ❍ October 2006
no? Especially the
November 2006
ones on which

December 2006
you're looking for

January 2007
feedback. ❍

❍ February 2007
I recommend ❍ March 2007
rooting through ❍ April 2007
SourceForge from ❍ May 2007
time to time if you ❍ June 2007
don't already. ❍ October 2007

// posted by Robert
Vollman @ Thursday,

February 02, 2006

Comments:
Here is a handy link:

oracle.com/
technology/
community/
opensource_projects.
html
# posted by Eddie

http://thinkoracle.blogspot.com/2006/02/sourceforge.html (3 of 4)1/9/2008 2:51:21 AM


OracleBlog: SourceForge

Awad : Thursday, 02
February, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/02/sourceforge.html (4 of 4)1/9/2008 2:51:21 AM


OracleBlog: 20 Beginner Oracle Questions

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, December 20, 2005


About Me
20 Beginner Oracle Name: Robert Vollman
Questions Location: Calgary, Alberta, Canada
Continuing in my newfound
tradition for lists of 20, here is I was born and raised in Ottawa,
a "cheat sheet" of 20 common and have lived in Calgary since
beginner Oracle questions. 1991. I like playing sports (hockey, soccer,
ultimate, basketball, you name it) and military
Before we begin, one simple board games. I also enjoy reading, walking, and
warning. Very few of these are playing with my 2 cats Lilly and Brutus. I'm a
complete answers, consider database application specialist, whatever that is.
them pointers or starting points
or else the incomplete View my complete profile
understanding could be
dangerous.

Edit: This has been highly Best Links


edited since its original version. ● Ask Tom Kyte
Oracle Docs
Oracle General:

● Dan Morgan and PSOUG


1. What are the key ● Steven Feuerstein
environment variables? ● Jonathan Lewis
Among many others, your home ● FAQ
and instance: ● Connor McDonald
export ● The Oak Table
ORACLE_HOME=oracle_home_dir ● Cary Millsap and Hotsos

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (1 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

export ● Steve Adams and Ixora


ORACLE_SID=instance_name ● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
2. How do you shut down or ● My Personal Blog
start up an Oracle instance?
Must log on as a sys user:
sqlplus sys/***@instance as
sysdba
Then:
Aggregators
shutdown Brian Duff's OraBlogs

or ❍ Eddie Awad's OracleNA


startup ❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
3. How do you start and stop a ❍ Oracle Base Aggregator
listener?
lsnrctl status
lsnrctl start
Top Blogs
lsnrctl stop Oracle's Ask Tom Kyte

http://www.psoug.org/ ❍ Oracle Guru Jonathan Lewis


reference/listener.html ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
4. What are the key Oracle files? ❍ Oracle Geek Lewis Cunningham
They are in network/admin ❍ Database Expert James Koopmann
folder. ❍ Dizwell's Howard Rogers
tnsnames.ora: list of database ❍ Oracle Master Laurent Schneider
connection information (client/ ❍ Security Expert Pete Finnigan
server) Oracle Award Winner Mark Rittman
sqlnet.ora: communication

Doug Burns
parameters setup

Oracle ACE of the Year Dr. Tim Hall


listener.ora: list of databases to

UKOUG's Andrew (Arfur C.) Clarke


listen for on this machine ❍

❍ Newbie DBA Lisa Dobson


5. How do you connect to the ❍ Coffee-Drinking DBA Jon Emmons
database to execute queries? ❍ Chris Foot
sqlplus user/ ❍ The Pythian DBA Team Blog
password@server_instance ❍ DBA Don Seiler
On a default system, sometimes ❍ DBA Coskan Gundogar
you can use scott/tiger. ❍ Oracle WTF
6. How do you see the errors
from your recently created view/ ARCHIVES
procedure? ❍ LIST ALL ARTICLES
show errors; ❍ May 2005
❍ June 2005

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (2 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

SQL and PL/SQL: ❍ July 2005


August 2005
7. How do you output a line

September 2005
from PL/SQL?

October 2005
DBMS_OUTPUT.PUT_LINE

November 2005
('Hello.'); ❍

❍ December 2005
8. How do you get the current ❍ January 2006
date? ❍ February 2006
SELECT sysdate FROM dual; ❍ March 2006
SELECT systimestamp FROM ❍ April 2006
dual; ❍ May 2006
June 2006
9. What are some other syntax

July 2006
considerations? ❍

Commands must end with a ❍ August 2006


semi-colon; ❍ September 2006
Strings must be single-quoted ❍ October 2006
❍ November 2006
SQLPlus: ❍ December 2006
January 2007
10. How do you show the

February 2007
structure of a table?

March 2007
desc table

❍ April 2007
11. How do I re-execute the ❍ May 2007
most recent query/command? ❍ June 2007
/ ❍ October 2007

12. How do I see my most


recent query?
l (for "list")

13. How do I see the PL/SQL


procedure output?
SET SERVEROUTPUT ON;

14. How do I execute a SQL file?


@filename.sql

More Advanced:

15. How do I see who is


currently connected?
SELECT username, program

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (3 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

FROM v$session WHERE


username IS NOT NULL;

Or, courtesy of a colleague of


mine, something like this:

SELECT p.SPID "OS_PID", to_char


(s.SID,'999') SID, s.serial#,
SUBSTR(p.USERNAME,1,10)
"OS_USER", SUBSTR(s.
USERNAME,1,16)
"ORACLE_USER",
SUBSTR(TO_CHAR(s.logon_time,
'DD Month YY "at" HH:MI:
SS'),1,30) "LOGON TIME", s.
program, s.machine
FROM v$process p, v$session s
WHERE s.PADDR=p.ADDR
AND s.username IS NOT NULL
ORDER BY s.logon_time;

16. How do I find all invalid


objects?
Query dba_objects for status =
'INVALID', something like this:
SELECT owner, decode
(object_type,'PACKAGE
BODY','PACKAGE',object_type)
OBJECT_TYPE, count
(object_name)
FROM dba_objects WHERE
status = 'INVALID' GROUP BY
owner, object_type;

17. How do I recompile invalid


objects?
Must be logged in with
privileges, and use this:
@?/rdbms/admin/utlrp.sql

18. How do I compute table and


index statistics for a schema?
Answer from Steve Ensslen:
10g: Don't, it can be set up to

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (4 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

analyze itself.
Pre-10g: Must be logged in with
privileges:
execute DBMS_STATS.
GATHER_SCHEMA_STATS
('SCOTT');

19. How do I analyze the


performance of a query/
procedure (query plans, index
choice, etc)?
Many ways, one way is SQL
Trace with TKPROF, which I have
explained here:
http://thinkoracle.blogspot.
com/2005/09/analyzing-query-
performance.html

20. How do I tell which


database am I in?
select name from v$database;
or
select instance_name,
host_name from v$instance;
or
SELECT SYS_CONTEXT
(‘USERENV’,’DB_NAME’) FROM
DUAL;
http://thinkoracle.blogspot.
com/2005/07/which-instance-
am-i-in.html

Bonus:

21. How do I set up an Oracle


client?
http://thinkoracle.blogspot.
com/2005/06/oracle-client.
html

22. How do I get data into and


out of Oracle?
http://thinkoracle.blogspot.

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (5 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

com/2005/08/import-export.
html

// posted by Robert
Vollman @ Tuesday, December 20, 2005

Comments:
On #9 what is getdate()? Do you
mean sysdate?

On #18 shouldn't you use a


procedure from dbms_stats,
instead?
# posted by Mr. Ed : Tuesday, 20
December, 2005

I have to disagree with the


answer to question 18. "How do
I compute table and index
statistics for a schema?".

The first answer is that you


don't. In 10g the database
analyzes itself as needed in the
default install.

The second answer would


reference DBMS_STATS.
GATHER_SCHEMA_STATS which
has been the preferred
procedure to call since 8.1.7 .
# posted by Steven Ensslen :
Tuesday, 20 December, 2005

Thanks guys, I should have


proof-read! Edited original post.
# posted by Robert Vollman :
Tuesday, 20 December, 2005

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (6 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

"4. What are the key Oracle


files?"
had me puzzled. I was thinking
about data files, redo, control
files, that kind of thing. Turns
out TNS listener config files are
more important...

"5. How do you connect to the


database to execute queries?
sqlplus..."
also a bit of a trick question.
Who says SQL*Plus is the only
way to connect to Oracle?

"6. How do you see the errors


from your last query?"
Er, "show errors"? Your last
query?

"8. How do you show the


structure of a table? desc table"
seems like it should be in the
SQL*Plus section, since you
have one.

"9. How do you get the current


date? SELECT sysdate FROM
dual;"
Would I lose points for not
mentioning DUAL in my answer?
Or SYSDATE?

"12. How do I see my query/


command history? l (for 'list')"
Surely that only shows the most
recent command, not the whole
history.
# posted by William Robertson :
Tuesday, 20 December, 2005

Thanks William, I did another

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (7 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

round of editing to fix those


errors.

#4: I made a judgment that


those files are the first ones a
beginner is usually looking for.

#5: I chose SQL*Plus because in


my opinion it is the most
common and the most likely to
be available anywhere Oracle is
installed.

#6: Ack, I thought I had fixed


that. I had pulled that from a
question I got when someone
was building a view (aka stored
query).

#9: No bonus points, just


thought I'd show it that way.

#12: Good catch. In fact, I was


planning to blog on
workarounds to that.

Cheers
# posted by Robert Vollman :
Tuesday, 20 December, 2005

Question 1: whatever happened


to ORACLE_BASE?? Especially
when the installation
instructions for 10g tell you not
to bother setting
ORACLE_HOME? And I would
argue that PATH is pretty damn
important!

Question 2: In the first place,


"connect internal" was
deprecated back in version 8.0
(that's a zero!!). In the second

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (8 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

place, it has been impossible to


log on as SYS as an ordinary
user unless you tinker with init.
ora parameters since 9i Release
1, and therefore your second
example won't work. The
correct form of log on is
'sqlplus sys/password@instance
as sysdba'

Question 2: 20 question lists


are fun, but not if the answers
are over-simplified. The correct
way to shut down should be
'shutdown'. Or, you can start to
list 'shutdown normal|
transactional|immediate|abort'.
But just saying 'shutdown
immediate' is wrong.

Question 3: Your answer is


correct only if your listener has
been named 'Listener'. If it's
been called anything else, the
answer is 'lsnrctl name-of-
listener stop|start' -and that
revised answer would then be
true whatever name your
listener possesses.

Question 4: is meaningless.
What are the key files in MS
Office? Er, do you mean
winword.exe or very-important-
doc.doc, or a DLL or several??
"What are the key Oracle
Network Configuration files"
maybe, but the question as it
stands means nothing.

Question 5: "On a default


system you can use scott/
tiger"... not since about version
8.0 you can't. Scott is not

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (9 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

installed by default, even when


you select to install the 'sample
schemas' in recent versions.

Question 8: It could be argued


(and I would) that your answer,
whilst correct, is version 7 stuff.
The world has moved on since
then, and select systimestamp
from dual; is just as effective at
showing you the date, but
rather more useful in that it
shows you the current system
time, too.

Question 18: Steve Ensslen is


wrong. The 10g database
doesn't analyze anything itself.
There is a DBMS_SCHEDULER
job which *might* be created in
your database, but might not be
(if you didn't use DBCA, for
example, it won't be). If it has
been created, it might or might
not be enabled and thus might
or might not run. And if it runs,
your schema's tables and index
statistics might or might not be
locked from being re-
computed. Given all that lot,
just saying "the database does
it" is an over-simplification too
far.

Generally, a lot of your answers


are the sort of thing users in
version 7 or 8.0 would have
expected, and are therefore out-
of-date when it comes to
version 9i or 10g.

And whilst I'm all for a bit of


fun, bits of fun which over-
simplify or simply get things

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (10 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

wrong are bits of dangerous fun.


# posted by Howard J. Rogers :
Tuesday, 20 December, 2005

Enter: The Pedants.

Q16)

The question is "How do I find


all invalid objects?"

The "answer" query only counts


objects that are invalid by type.

Q7.)

How do you output a line from


PL/SQL?

DBMS_OUTPUT.PUT_LINE
("Hello.");

Those double quotes don't work


and also contradict your answer
to question 9?
# posted by Anonymous :
Wednesday, 21 December, 2005

Howard, thanks for the


corrections, I've made the fixes
and added a disclaimer.

Yes, you're quite astute - this


list came from my old notes
which did indeed cover version
7, 8 and sometimes 9. The
questions came from casual
users who didn't know Kyte
from byte.

#5: I have done default


installations of version 9 and

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (11 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

10, and scott/tiger was there in


both cases.

Cheers.
# posted by Robert Vollman :
Wednesday, 21 December, 2005

#8 In PL/SQL of course you'd


just set a variable with:
l_sysdate := sysdate;

Selecting it from dual would be


a waste of resources
# posted by David Aldridge :
Wednesday, 21 December, 2005

Hey, I got named in


ComputerWorld’s “Best IT Blogs
on the Net.” Granted, only in the
“buffer overflow” section, but
still – that’s pretty cool!

http://www.computerworld.
com/blogs/node/1466?
source=nlt_blg

I wonder if that is another


consequence of the Thomas
Kyte Effect?

http://thinkoracle.blogspot.
com/2005/12/thomas-kyte-
effect.html
# posted by Robert Vollman :
Wednesday, 21 December, 2005

I received my Oracle PL/SQL


certification from brainbench.
Can somebody tell me if this is
a well recognised certificatio.

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (12 of 13)1/9/2008 2:51:24 AM


OracleBlog: 20 Beginner Oracle Questions

# posted by Anonymous : Sunday,


28 May, 2006

it's helpful for a beginners like


me.. i need some more help
from you..
pls visit my blog and give ur
suggestios
my blog is
www.oracle9itraining.blogsppot.
com

here, i am trying to educate


oracle for a layman..
# posted by hari : Thursday, 01
November, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/12/20-beginner-oracle-questions.html (13 of 13)1/9/2008 2:51:24 AM


OracleBlog: Asking For Help

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, June 17, 2005


About Me
Asking For Help Name: Robert Vollman
There are a lot of people Location: Calgary, Alberta, Canada
who know Oracle. It makes
sense to leverage their
I was born and raised in Ottawa, and have
abilities when you're stuck.
lived in Calgary since 1991. I like playing
Why re-invent the wheel?
sports (hockey, soccer, ultimate, basketball, you name
First of all, often answers it) and military board games. I also enjoy reading,
are easy to come by walking, and playing with my 2 cats Lilly and Brutus.
yourself. For example, I'm a database application specialist, whatever that is.
here is Jeff Hunter's
suggestions on where to View my complete profile
find answers:

http://marist89.blogspot.
com/2005/06/where-can-
Best Links
● Ask Tom Kyte
i-find-help.html ● Oracle Docs
Dan Morgan and PSOUG
If you want to reach a

Steven Feuerstein
large body of Oracle ●

professionals, the best ● Jonathan Lewis


approach is to post it to a ● FAQ
popular newsgroup or ● Connor McDonald
forum. Here are a few of ● The Oak Table
my favourites. ● Cary Millsap and Hotsos
● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/06/asking-for-help.html (1 of 6)1/9/2008 2:51:27 AM


OracleBlog: Asking For Help

Oracle Technology ● Anjo Kolk and OraPerf


Network: ● Dizwell Oracle Wiki
http://forums.oracle.com/ ● My Personal Blog
forums/forum.jsp?
forum=75

comp.databases.oracle.
server:
Aggregators
Brian Duff's OraBlogs

http://groups-beta.google.
❍ Eddie Awad's OracleNA
com/group/comp. ❍ Pete Finnigan's Aggregator
databases.oracle.server ❍ Oracle's Bloglist
Oracle Base Aggregator
DBA-Support:

http://www.dbasupport.
com/forums/
Top Blogs
❍ Oracle's Ask Tom Kyte
Dizwell Forum: ❍ Oracle Guru Jonathan Lewis
http://www.phpbbserver. ❍ Blogger of the Year Eddie Awad
com/phpbb/viewforum. ❍ Data Warehouser David Aldridge
php? ❍ Oracle Geek Lewis Cunningham
f=2&mforum=dizwellforum ❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
It is tempting to contact ❍ Oracle Master Laurent Schneider
certain professionals ❍ Security Expert Pete Finnigan
directly. After all, there are ❍ Oracle Award Winner Mark Rittman
several of them that spend ❍ Doug Burns
seemingly hours Oracle ACE of the Year Dr. Tim Hall
answering questions in

UKOUG's Andrew (Arfur C.) Clarke


these forums, and putting

Newbie DBA Lisa Dobson


together web pages to

assist fellow Oracle ❍ Coffee-Drinking DBA Jon Emmons


professionals. ❍ Chris Foot
❍ The Pythian DBA Team Blog
But be aware that some of ❍ DBA Don Seiler
them do not have the time ❍ DBA Coskan Gundogar
(or sometimes the interest) ❍ Oracle WTF
in answering questions,
like Mark Rittman or
Duncan Mills.
ARCHIVES
❍ LIST ALL ARTICLES
http://www.rittman.net/ ❍ May 2005
archives/001276.html ❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2005/06/asking-for-help.html (2 of 6)1/9/2008 2:51:27 AM


OracleBlog: Asking For Help

http://www.groundside. ❍ August 2005


com/blog/content/ ❍ September 2005
DuncanMills/ ❍ October 2005
2005/06/16/ ❍ November 2005
Questions_Questions.html ❍ December 2005
❍ January 2006
And be aware that those ❍ February 2006
that do like to receive ❍ March 2006
questions may have a ❍ April 2006
specific method of
May 2006
submitting them, such as

June 2006
Tom Kyte and Steven

July 2006
Feuerstein:

❍ August 2006
http://asktom.oracle.com ❍ September 2006
http://www.oracle.com/ ❍ October 2006
technology/pub/columns/ ❍ November 2006
plsql/index.html ❍ December 2006
❍ January 2007
If you do ask someone a ❍ February 2007
question, it sounds like ❍ March 2007
these are the ground rules ❍ April 2007
to follow: ❍ May 2007
June 2007
1. Don't even bother

October 2007
submitting urgent

questions with time


deadlines.
2. Even if English isn't your
first language, try to make
the question as clear as
possible.
3. Try to keep the question
brief, but ...
4. Try to provide all
necessary information,
including examples and
error messages
5. Don't ask questions that
are obviously school
assignments
6. Include "why" you are
doing something.

http://thinkoracle.blogspot.com/2005/06/asking-for-help.html (3 of 6)1/9/2008 2:51:27 AM


OracleBlog: Asking For Help

http://tkyte.blogspot.
com/2005/05/why.html

But the most important


thing is:

Always try to find the


answer yourself first!

Loosely Related:
http://vollman.blogspot.
com/2005/04/roberts-
tips-on-asking-for-help-
1.html

// posted by Robert
Vollman @ Friday, June 17, 2005

Comments:
Robert,

I hope I didn't come across


as some grumpy old
bugger!

I guess what I was trying


to say was that I will
actually try and answer
many of the questions that
come through (with the
likelyhood being in direct
relation to how interesting
the question is), but
sometimes it's clear that
either the person asking
the question is a bit mad,
is being a bit lazy in not
reading the docs first, or is
being a bit unrealistic in
terms of how much time I

http://thinkoracle.blogspot.com/2005/06/asking-for-help.html (4 of 6)1/9/2008 2:51:27 AM


OracleBlog: Asking For Help

can spend answering


questions.

cheers!

Mark
# posted by Mark : Saturday,
18 June, 2005

This link is related to


Linux forums, and pretty
harsh, but a great guide
on asking for help:

http://www.catb.org/~esr/
faqs/smart-questions.html
# posted by Robert Vollman :
Monday, 20 June, 2005

I hadn't noticed that Tom


Kyte had written an
excellent article on this
weeks ago. Obviously "Ask
Tom" knows a lot about
how to ask! Check it out:

http://tkyte.blogspot.
com/2005/06/how-to-
ask-questions.html
# posted by Robert Vollman :
Friday, 24 June, 2005

Lisa Dobson has written a


blog on this recently.
There are some great tips
and links among the
comments, too.

http://newbiedba.
blogspot.com/2005/08/

http://thinkoracle.blogspot.com/2005/06/asking-for-help.html (5 of 6)1/9/2008 2:51:27 AM


OracleBlog: Asking For Help

how-to-be-good-newbie.
html
# posted by Robert Vollman :
Thursday, 18 August, 2005

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/06/asking-for-help.html (6 of 6)1/9/2008 2:51:27 AM


OracleBlog: Oracle Docs

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, July
About Me
14, 2005
Name: Robert Vollman
Oracle Docs Location: Calgary, Alberta, Canada
We have seen
articles on where I was born and raised in Ottawa, and have lived in
to go for help, Calgary since 1991. I like playing sports (hockey,
and how to ask soccer, ultimate, basketball, you name it) and military board
for help: games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever
http://thinkoracle.
that is.
blogspot.
com/2005/06/
View my complete profile
asking-for-help.
html

Recently Tom Kyte Best Links


wrote an article ● Ask Tom Kyte
on Reading the ● Oracle Docs
F'n Manual: ● Dan Morgan and PSOUG
● Steven Feuerstein
http://tkyte. ● Jonathan Lewis
blogspot. ● FAQ
com/2005/07/ ● Connor McDonald
rtfm.html ● The Oak Table
Cary Millsap and Hotsos
Which begs the

● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/07/oracle-docs.html (1 of 6)1/9/2008 2:51:31 AM


OracleBlog: Oracle Docs

F'n question. ● Anjo Kolk and OraPerf


Where are the F'n ● Dizwell Oracle Wiki
manuals? Which ● My Personal Blog
manuals should
you F'n read?

The first question


is easy, it's all
Aggregators
here: Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


http://www.oracle. ❍ Pete Finnigan's Aggregator
com/technology/ ❍ Oracle's Bloglist
documentation/ ❍ Oracle Base Aggregator

Top Blogs
index.html

Personally, I use ❍ Oracle's Ask Tom Kyte


Oracle9, so I have Oracle Guru Jonathan Lewis
this page

Blogger of the Year Eddie Awad


bookmarked:

❍ Data Warehouser David Aldridge


http://www.oracle. ❍ Oracle Geek Lewis Cunningham
com/technology/ ❍ Database Expert James Koopmann
documentation/ ❍ Dizwell's Howard Rogers
oracle9i.html ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
For the novice, ❍ Oracle Award Winner Mark Rittman
you want to go to ❍ Doug Burns
View Library and ❍ Oracle ACE of the Year Dr. Tim Hall
Getting Started ❍ UKOUG's Andrew (Arfur C.) Clarke
Newbie DBA Lisa Dobson
There you will

Coffee-Drinking DBA Jon Emmons


find links for the

Chris Foot
Installer, the

Administrator, ❍ The Pythian DBA Team Blog


and the ❍ DBA Don Seiler
Developer. These ❍ DBA Coskan Gundogar
links give you ❍ Oracle WTF

ARCHIVES
recommendations
for which F'n
manuals to read. ❍ LIST ALL ARTICLES
May 2005
Being an

June 2005
application ❍

❍ July 2005

http://thinkoracle.blogspot.com/2005/07/oracle-docs.html (2 of 6)1/9/2008 2:51:31 AM


OracleBlog: Oracle Docs

developer the key ❍ August 2005


F'n manual for ❍ September 2005
me, without ❍ October 2005
dispute, is: ❍ November 2005
December 2005
Oracle9i ❍

Application ❍ January 2006


Developer's Guide ❍ February 2006
- Fundamentals ❍ March 2006
http://download- ❍ April 2006
west.oracle.com/ ❍ May 2006
docs/cd/ ❍ June 2006
B10501_01/ ❍ July 2006
appdev.920/ ❍ August 2006
a96590.pdf ❍ September 2006
❍ October 2006
I won't include all ❍ November 2006
the links, because ❍ December 2006
a list of all F'n ❍ January 2007
manuals for ❍ February 2007
Oracle9i can be ❍ March 2007
found here: ❍ April 2007
May 2007
http://www.oracle. ❍

June 2007
com/pls/db92/

October 2007
db92.docindex?

remark=homepage

Here are the F'n


manuals that are
recommended for
Application
Developers:

Oracle9i Database
Concepts Guide
Oracle9i SQL
Reference
Oracle9i Data
Warehousing
Guide
PL/SQL User's
Guide and

http://thinkoracle.blogspot.com/2005/07/oracle-docs.html (3 of 6)1/9/2008 2:51:31 AM


OracleBlog: Oracle Docs

Reference
Oracle9i Supplied
PL/SQL Packages
and Types
Reference
Oracle9i Database
Performance
Tuning Guide and
Reference
Oracle9i Database
Error Messages

Beyond that, there


are also F'n
manuals for more
advanced
programming
(Java, C++, XML,
Object-Related).

Please feel free to


leave me some F'n
comments with
other F'n good
manuals and
books.

// posted by Robert
Vollman @ Thursday,

July 14, 2005

Comments:
The "F" is for
"Fine" of course.
# posted by
Thomas Kyte :
Thursday, 14 July,
2005

Thanks for
compiling it in

http://thinkoracle.blogspot.com/2005/07/oracle-docs.html (4 of 6)1/9/2008 2:51:31 AM


OracleBlog: Oracle Docs

one shot..These
link go right into
my bookmarks as
well
# posted by
Anonymous :
Thursday, 14 July,
2005

The mother of all


documentations
can be found at
http://tahiti.
oracle.com/
# posted by Eddie
Awad : Thursday, 14
July, 2005

As eddie stated
Oracle Paradise
http://tahiti.
oracle.com

You also forgot


one manual 9i
RAC Concepts
guide - Excellent
manual. It does
not exist for 10g.
# posted by
Anonymous :
Thursday, 14 July,
2005

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/07/oracle-docs.html (5 of 6)1/9/2008 2:51:31 AM


OracleBlog: Oracle Docs

http://thinkoracle.blogspot.com/2005/07/oracle-docs.html (6 of 6)1/9/2008 2:51:31 AM


OracleBlog: 3 Easy Ways to Improve Your PL/SQL

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, October 19,


About Me
2006
Name: Robert Vollman
3 Easy Ways to Location: Calgary, Alberta, Canada
Improve Your
PL/SQL I was born and raised in Ottawa, and have
Want to know what has lived in Calgary since 1991. I like playing
been calling the PL/SQL sports (hockey, soccer, ultimate, basketball, you name it)
Procedure you've written? and military board games. I also enjoy reading, walking,
Want to know how to tell and playing with my 2 cats Lilly and Brutus. I'm a
how far along your long- database application specialist, whatever that is.
running PL/SQL
Procedure is? View my complete profile
What to know how to

Best Links
write fast mass insert/
deletes like a pro?
Ask Tom Kyte
I have found you the

answer for all three, ● Oracle Docs


courtesy of my fine ● Dan Morgan and PSOUG
colleagues featured ● Steven Feuerstein
among my links. Allow ● Jonathan Lewis
me to guide you through ● FAQ
these three great articles. ● Connor McDonald
● The Oak Table
Who Is Calling Your Cary Millsap and Hotsos
Procedure?

● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/10/3-easy-ways-to-improve-your-plsql.html (1 of 9)1/9/2008 2:51:34 AM


OracleBlog: 3 Easy Ways to Improve Your PL/SQL

● Anjo Kolk and OraPerf


The answer to our first ● Dizwell Oracle Wiki
question comes courtesy ● My Personal Blog
of Oracle's Blogger of
the Year Eddie Awad.

Eddie won this award


not just by virtue of
Aggregators
being first in an Brian Duff's OraBlogs

alphabetical listing, but ❍ Eddie Awad's OracleNA


also by the sheer volume ❍ Pete Finnigan's Aggregator
of focused articles of ❍ Oracle's Bloglist
high interest, each one ❍ Oracle Base Aggregator

Top Blogs
backed up by references
and proven tests. His
article about OWA_UTIL. Oracle's Ask Tom Kyte
WHO_CALLED_ME is no

Oracle Guru Jonathan Lewis


exception. His article

Blogger of the Year Eddie Awad


includes:

Data Warehouser David Aldridge


1. A working example ❍

you can cut and paste, ❍ Oracle Geek Lewis Cunningham


2. A link to Oracle's ❍ Database Expert James Koopmann
documentation, and ❍ Dizwell's Howard Rogers
3. A link to Dan ❍ Oracle Master Laurent Schneider
Morgan's syntax ❍ Security Expert Pete Finnigan
reference ❍ Oracle Award Winner Mark Rittman
Doug Burns
Thanks to his diligence,

Oracle ACE of the Year Dr. Tim Hall


it literally took only

UKOUG's Andrew (Arfur C.) Clarke


minutes to add this type

Newbie DBA Lisa Dobson


of instrumentation to my ❍

existing code. When ❍ Coffee-Drinking DBA Jon Emmons


something goes wrong, I ❍ Chris Foot
know exactly who called ❍ The Pythian DBA Team Blog
my procedure, and ❍ DBA Don Seiler
where. This even works ❍ DBA Coskan Gundogar
if the calling code is ❍ Oracle WTF
wrapped. (Proof
forthcoming) ARCHIVES
LIST ALL ARTICLES
Given how easy it is, I

plan on testing the ❍ May 2005


overhead/performance ❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2006/10/3-easy-ways-to-improve-your-plsql.html (2 of 9)1/9/2008 2:51:34 AM


OracleBlog: 3 Easy Ways to Improve Your PL/SQL

to see how feasible it ❍ August 2005


would be to start using ❍ September 2005
this as a metric by ❍ October 2005
creating this table and November 2005
adding this line:

❍ December 2005
CREATE TABLE ❍ January 2006
MyProcCalls ❍ February 2006
(caller_name VARCHAR2 ❍ March 2006
(100), line_number ❍ April 2006
NUMBER(8)); ❍ May 2006
❍ June 2006
INSERT INTO ❍ July 2006
MyProcCalls
August 2006
(caller_name,

September 2006
line_number) VALUES

October 2006
(caller_name, ❍

line_number); ❍ November 2006


❍ December 2006
Then I'll start looking ❍ January 2007
like a pro already. ❍ February 2007
❍ March 2007
How Far Along Is My April 2007
Procedure?

❍ May 2007
This answer comes from ❍ June 2007
my newest featured ❍ October 2007
blogger Andy Campbell.
He has been an Oracle
DBA for 7 years and, like
me, started a blog to
record the things he
learns and doesn't want
to forget.

Let's take advantage of


Andy's experience on
how to instrument our
PL/SQL code further by
including calls to
DBMS_APPLICATION_INFO
to record our
procedure's on-going
progress.

http://thinkoracle.blogspot.com/2006/10/3-easy-ways-to-improve-your-plsql.html (3 of 9)1/9/2008 2:51:34 AM


OracleBlog: 3 Easy Ways to Improve Your PL/SQL

Andy explains, complete


with examples, how to
use this supplied
package (available as far
back as Oracle 7) to
have your procedure
write information into
session-tracking tables
using SET_MODULE and
then SET_ACTION.

Of course the big pay-


off comes at the end of
his article where he
executes his long-
running procedure and
then queries the session-
tracking tables like V
$SESSION to find out
how far along the
procedure is. Brilliant!

Let me supplement his


article with the following
three references:

1. Supplied Packages
References, Chapter 3:
DBMS_APPLICATION_INFO

2. Another one of my
favourite featured
bloggers, Oracle ACE of
the Year Tim Hall, is
reknowned for his great
articles. He also has a
write-up on how to use
DBMS_APPLICATION_INFO
and the V$SESSION
tables.

3. Finally, what list of

http://thinkoracle.blogspot.com/2006/10/3-easy-ways-to-improve-your-plsql.html (4 of 9)1/9/2008 2:51:34 AM


OracleBlog: 3 Easy Ways to Improve Your PL/SQL

mine would be complete


without including Dan
Morgan's reference?

Thanks to Andy's
working example, it
literally took me minutes
to further instrument my
PL/SQL code and fool
people into thinking
they were written by a
true Oracle pro.

How Do I Write Mass


Inserts/Deletes Like a
Pro?

If we're going to code


like a pro, we need to
take at least one page
out of Tom Kyte's
playbook. Tom Kyte's
work is beloved for its
passion, dedication,
completeness and
accuracy.

Tom's has a passionate


distaste for bad
practises, including
slow-by-slow
processing.
Programmers unused to
thinking in sets are at a
distinct disadvantage
when programming
database applications.
Why? Because they do
their inserts and deletes
one-by-one in a for
loop.

As database

http://thinkoracle.blogspot.com/2006/10/3-easy-ways-to-improve-your-plsql.html (5 of 9)1/9/2008 2:51:34 AM


OracleBlog: 3 Easy Ways to Improve Your PL/SQL

programmers know, this


approach is completely
unnecessary and
wasteful. They know
instead to look for a
solution that does some
kind of bulk processing
when doing inserts,
deletes or updates on a
large number of records.

Tom illustrates this


point with a specific
case where particularly
bad Oracle code had
been written.

The original requirement


was to prune down a list
of employees, removing
duplicate employees by
choosing the one with
the most recent hiring
date.

What did the original


programmer do? First,
created a big master
table of all employees,
then when through them
in a loop, each time
deleting employees that
produced more than one
record when grouped by
employee number.

Study how it was done


by the original
programmer. It might
not look like an
altogether unfamiliar
approach. But what do
you think about this
result?

http://thinkoracle.blogspot.com/2006/10/3-easy-ways-to-improve-your-plsql.html (6 of 9)1/9/2008 2:51:34 AM


OracleBlog: 3 Easy Ways to Improve Your PL/SQL

Well, you may find that


the result was not only
very slow because it
would loop as often as
your most common
duplicate, but potentially
logically incorrect
because it would remove
an employee entirely if it
had duplicate records
with the same hiring
date.

Instead look how a true


pro handles this
situation. Tom handles
this case in a single,
efficient SQL statement.

He breaks the problem


down to its simplest
form: we need a list of
each employee with its
data, with only a single
row per employee
representing the most
recent hiring date.

Therefore Tom
populates such a table
by first adding a column
signifying the most
recent hiring date for
each employee (using
PARTITION BY, a
technique we've
discussed many times
before), then by
selecting only the rows
where the hiring date
and this most recent
hiring date match.

http://thinkoracle.blogspot.com/2006/10/3-easy-ways-to-improve-your-plsql.html (7 of 9)1/9/2008 2:51:34 AM


OracleBlog: 3 Easy Ways to Improve Your PL/SQL

I admit this third tip is a


little harder to digest
than the first two,
because you have to
learn how to think like a
pro. Break a problem
down, and approach it
like a database would by
thinking in sets.

Summary

The true secret behind


these three tips is
actually to read. There
are a lot of Oracle
professionals just like
you, and we're fortunate
that so many of them
are generous with their
knowledge. Thanks!!!

Looking for more great


articles whenever I'm
quiet? Please bookmark
the links along the side
of the page. And visit
the articles in my
archives: you may have
especially missed some
of the early ones.

// posted by Robert
Vollman @ Thursday, October

19, 2006

Comments: Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/10/3-easy-ways-to-improve-your-plsql.html (8 of 9)1/9/2008 2:51:34 AM


OracleBlog: 3 Easy Ways to Improve Your PL/SQL

http://thinkoracle.blogspot.com/2006/10/3-easy-ways-to-improve-your-plsql.html (9 of 9)1/9/2008 2:51:34 AM


OracleBlog: 40 Tips From Tom

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, March 09, 2007


About Me
40 Tips From Name: Robert Vollman
Tom Location: Calgary, Alberta, Canada
Everybody learns their
lessons, and so will I was born and raised in Ottawa, and have
you. The only variable lived in Calgary since 1991. I like playing
is how expensive the sports (hockey, soccer, ultimate, basketball, you name it)
lesson is. While there is and military board games. I also enjoy reading, walking,
no substitute for direct, and playing with my 2 cats Lilly and Brutus. I'm a
first-hand experience, database application specialist, whatever that is.
the cheapest way to
learn a lesson is to View my complete profile
benefit from the
experience of others.

My favourite source of Best Links


cheap lessons is Ask ● Ask Tom Kyte
Tom. I've compiled a ● Oracle Docs
sample collection of ● Dan Morgan and PSOUG
Tom's Wisdom from ● Steven Feuerstein
just the articles ● Jonathan Lewis
updated in the past ● FAQ
week. Review this list ● Connor McDonald
and consider how many ● The Oak Table
free lessons are Cary Millsap and Hotsos
contained in the past 7

● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2007/03/40-tips-from-tom.html (1 of 10)1/9/2008 2:51:37 AM


OracleBlog: 40 Tips From Tom

years of archived ● Anjo Kolk and OraPerf


information! ● Dizwell Oracle Wiki
● My Personal Blog
The number next to
every tip has a
hyperlink to the
appropriate question. I
included this because I
Aggregators
remember that Tom's Brian Duff's OraBlogs

credo is "Trust, but ❍ Eddie Awad's OracleNA


Verify." Trust in Tom's ❍ Pete Finnigan's Aggregator
wisdom, but check the ❍ Oracle's Bloglist
context of his advice so ❍ Oracle Base Aggregator
you can see if it applies
to your situation, is still
valid today, and that it
Top Blogs
Oracle's Ask Tom Kyte
wasn't one of those

Oracle Guru Jonathan Lewis


rare cases where he got

Blogger of the Year Eddie Awad


it wrong. ❍

❍ Data Warehouser David Aldridge


As a bonus for those ❍ Oracle Geek Lewis Cunningham
who enjoyed my last ❍ Database Expert James Koopmann
post about Tom's more ❍ Dizwell's Howard Rogers
entertaining side, I've ❍ Oracle Master Laurent Schneider
included a bit more of ❍ Security Expert Pete Finnigan
his biting humour too. ❍ Oracle Award Winner Mark Rittman
Doug Burns
1. Row-level locking

Oracle ACE of the Year Dr. Tim Hall


has no overhead, not

UKOUG's Andrew (Arfur C.) Clarke


for 1 lock, not for 1

Newbie DBA Lisa Dobson


billion locks ❍

2. Reads are never ❍ Coffee-Drinking DBA Jon Emmons


blocked, and reads ❍ Chris Foot
don't block ❍ The Pythian DBA Team Blog
3. The best UI is a ❍ DBA Don Seiler
command line ❍ DBA Coskan Gundogar
4. Always use ❍ Oracle WTF
packages, for all good,
real, production code ARCHIVES
4a. Never use a ❍ LIST ALL ARTICLES
standalone procedure ❍ May 2005
except for demos, tests ❍ June 2005
and standalone utilities ❍ July 2005

http://thinkoracle.blogspot.com/2007/03/40-tips-from-tom.html (2 of 10)1/9/2008 2:51:37 AM


OracleBlog: 40 Tips From Tom

that call nothing and ❍ August 2005


are called by nothing. ❍ September 2005
4b. Packages break the ❍ October 2005
dependency chain, ❍ November 2005
support encapsulation, ❍ December 2005
increase namespace, January 2006
support overloading

February 2006
and session variables,

March 2006
and promote overall

good coding techniques ❍ April 2006


5. Use the same source ❍ May 2006
control techniques for ❍ June 2006
PL/SQL as you would ❍ July 2006
for any other language ❍ August 2006
(C, Java, VB) ❍ September 2006
6. Use dbms_stats ❍ October 2006
instead of Analyze ❍ November 2006
6a. Easier to automate, ❍ December 2006
the stated/preferred ❍ January 2007
way of collecting ❍ February 2007
statistics, can analyze ❍ March 2007
external tables, gathers ❍ April 2007
statistics need for CBO ❍ May 2007
(and nothing extra)
June 2007
7. Serializable does not

October 2007
imply serial ordering

8. To be useful, know
more than just the
technology, know the
business and the goals
of your organisation
9. Joins are not evil.
Databases were born to
join.
10. Never compare
strings to dates, and
dates to strings.
Compare dates to
dates, strings to
strings, numbers to
numbers and never any
other combination.

http://thinkoracle.blogspot.com/2007/03/40-tips-from-tom.html (3 of 10)1/9/2008 2:51:37 AM


OracleBlog: 40 Tips From Tom

11. Beware of implicit


conversions of dates
and numbers. Avoid
implicit like the plague,
explicit is good
12. Never TO_NUMBER
a number, never
TO_DATE a date
13. Stop using YY in
your date formatting,
now and forever
14. Autonomous
transactions as a
feature was a huge
mistake, they are rarely
used in a manner that
is safe.
15. Never copy online
redolog when your
database is in
archivelog mode
16. Never restore the
online redo log files
17. Rollback is not just
for modifications, this
is fundamental about
Oracle
18. Stop committing
until your transaction is
complete
19. Don't use a loop
when a single query will
do
19a. Use bulk
processing instead of
slow-by-slow
processing
20. For performance
reasons, call PL/SQL (or
worse, Java) from SQL if
and where there is
quite simply no other

http://thinkoracle.blogspot.com/2007/03/40-tips-from-tom.html (4 of 10)1/9/2008 2:51:37 AM


OracleBlog: 40 Tips From Tom

way
21. Large databases are
neither slow nor scary
22. Analytical functions
are for those who
crave, desire or just
sometimes NEED speed.
23. The way to
understand is to do
24. Soft parse
percentage? 99% and
above is good.
25. Select only the
columns you need, not *
26. When designing a
table, put the most
frequently access
columns first, those
most likely to be NULL
last, but don't
overnalyse it.
27. Disk is cheap. Data
integrity, priceless.
28. You cannot put CPU
in the bank and save it
for later. If you are at
99.99% utilization --
pat yourself on the
back, you've done well.
29. Analytics rock.
Analytics roll.
30. Don't use the
slower UNION when
UNION ALL will do
31. Never never never
do dynamically what
you can do statitically,
in PL/SQL.
32. You want to scale?
Use static SQL in PL/
SQL, all binds, all the
time.

http://thinkoracle.blogspot.com/2007/03/40-tips-from-tom.html (5 of 10)1/9/2008 2:51:37 AM


OracleBlog: 40 Tips From Tom

33. Triggers are evil.


34. Magic should be
avoided. Experience
tells me this.
35. Never create stuff
as "sys" or "sysdba",
thats a special magical
account not to be used
by you or me.
36. Be careful doing
anything non-
transactional in a
trigger. It won't
rollback when the
transaction rolls back.
36a. Be very careful
using any routine that
starts with UTL_ in a
trigger, they're
generally non-
transactional
37. Use
dbms_application_info
package to allow you to
show a procedure's
progress in v$session.
38. The sheer beauty of
PL/SQL is that your
concerns with other
languages, like "parse
once; execute many"
and using bind
variables are done
automatically and
transparently.
39. Cursor sharing is a
bad thing, if you don't
need it
40. Not binding is
actually harder to do
than binding (and less
secure)

http://thinkoracle.blogspot.com/2007/03/40-tips-from-tom.html (6 of 10)1/9/2008 2:51:37 AM


OracleBlog: 40 Tips From Tom

More Tom Humour!

Refresh on Materialized
View

Q: see oracle bug no


2088032
A: And then scratch
your head and ask "why
am I reading this bug
report which doesn't
have anything to do
with my problem?"

Update Statement
Not that I don't believe
you -- but -- I don't
believe you.

Oracle PL/SQL -
Performance Tuning -
Comments in Code
In response to someone
saying their code
review team told them
to remove comments
from the code for
performance reasons. I
just KNEW a good retort
was coming.

Oh my gosh.

I have never heard of


anything so - well, I
won't be that blunt, fill
in your favorite word.
...
get a new code review
team, one that actually
knows how to review
code
...

http://thinkoracle.blogspot.com/2007/03/40-tips-from-tom.html (7 of 10)1/9/2008 2:51:37 AM


OracleBlog: 40 Tips From Tom

umm, they are sort of


"not correct"

DBMS_JOB Package
This is one of Tom's
favourite comebacks to
someone saying "it
doesn't work."

My car won't start


either. why not?

Umm, define "does not


work"

String Concatenation
Q: Can you do the same
thing in Microsoft SQL
server 2000....
A: That would be a
good question for
askbill@ms.com....

Restoring a file stored


in a database
hahahahaha, ouch.
sorry I just fell out of
my chair.

Hmm, the bigger the


database, the slower it
is. Interesting.

But completely and


utterly wrong.

CPU Utilization
Q: How can I reduce
CPU utilization of
Oracle database?
A: shutdown abort
works well ;)

Refresh Complete and

http://thinkoracle.blogspot.com/2007/03/40-tips-from-tom.html (8 of 10)1/9/2008 2:51:37 AM


OracleBlog: 40 Tips From Tom

Rollback
Q: I have read/heard/
been told that
snapshots are a lot of
overhead.
A: I heard that business
travelers better not
goto bars cause there
are people that will
drug you and take out
your kidneys to sell on
the black market.

Rollback Segments
Q: insert /*+ append
nologging */ into t
select * from t_stging
where country_code =
'US'
A: That insert is just the
same as:
insert /*+ append hello
world!!!! how you
DOING? */ into t ......

// posted by Robert
Vollman @ Friday, March 09,

2007

Comments:
Great list!

I think you can make


the links a little more
specific. View source
when you are on Tom's
page, and you can
scroll up to the last
name statement, and
add that to the link with
a pound sign separator.

http://thinkoracle.blogspot.com/2007/03/40-tips-from-tom.html (9 of 10)1/9/2008 2:51:37 AM


OracleBlog: 40 Tips From Tom

For example:

This gives the top of


the page, while this
goes right to the
comment that is
answered with "magic."
The difference is I
appended
#140783200346467586
to the link, which I
found by viewing the
source, searching for
the word magic, then
scrolling up to find the
name statement just
above the beginning of
the question.

Though I can
understand you might
want to encourage
people to read the
whole thing!
# posted by Joel Garry :
Monday, 12 March, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2007/03/40-tips-from-tom.html (10 of 10)1/9/2008 2:51:37 AM


OracleBlog: Bind Variables in PL/SQL

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, June 14, 2005


About Me
Bind Variables in PL/SQL Name: Robert Vollman
If you learn nothing else from the Location: Calgary, Alberta,
Oracle experts out there but want to Canada
improve your Oracle application
development knowledge, then read up
I was born and raised in
on bind variables.
Ottawa, and have lived in Calgary since
Bind variables are already very well 1991. I like playing sports (hockey,
explained, here are my favourite links soccer, ultimate, basketball, you name it)
on the subject: and military board games. I also enjoy
reading, walking, and playing with my 2
Mark Rittman's Bind Variables cats Lilly and Brutus. I'm a database
Explained application specialist, whatever that is.
http://www.rittman.net/
archives/000832.html View my complete profile

Best Links
Tom Kyte is one of the champions of
using Bind Variables. Links to his
articles and books can be found at the
Ask Tom Kyte
bottom of Mark's article.

● Oracle Docs
After reading these articles, I ● Dan Morgan and PSOUG
understood that PL/SQL automatically ● Steven Feuerstein
binds variables, so you really don't ● Jonathan Lewis
have to worry. But I was still ● FAQ
concerned that I might be missing ● Connor McDonald

http://thinkoracle.blogspot.com/2005/06/bind-variables-in-plsql.html (1 of 4)1/9/2008 2:51:40 AM


OracleBlog: Bind Variables in PL/SQL

something. The Oak Table


● Cary Millsap and Hotsos


Tom has a query that you can run to ● Steve Adams and Ixora
determine if you are currently using ● Anjo Kolk and OraPerf
bind variables or not. Find it here
Dizwell Oracle Wiki
(Hint: select sql_test from v$sqlarea):

My Personal Blog
http://asktom.oracle.com/pls/ask/f?

p=4950:8:::::
F4950_P8_DISPLAYID:1163635055580.

I posted the following question to the


Aggregators
Dizwell forum, which is an excellent Brian Duff's OraBlogs

place to tap the minds of Oracle gurus ❍ Eddie Awad's OracleNA


directly. ❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
http://www.phpbbserver.com/phpbb/ ❍ Oracle Base Aggregator
viewtopic.php?
t=169&mforum=dizwellforum Top Blogs
Oracle's Ask Tom Kyte
Is there any possible way to NOT use

Oracle Guru Jonathan Lewis


bind variables in a PL/SQL stored

procedure WITHOUT using 'execute ❍ Blogger of the Year Eddie Awad


immediate' or DBMS_SQL package? ❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
I just want to make sure that there are ❍ Database Expert James Koopmann
only 2 situations I have to look out for ❍ Dizwell's Howard Rogers
in my PL/SQL code with regards to ❍ Oracle Master Laurent Schneider
bind variables. ❍ Security Expert Pete Finnigan
Oracle Award Winner Mark Rittman
A developer from Australia going by

"gamyers" responded with ref cursors: ❍ Doug Burns


❍ Oracle ACE of the Year Dr. Tim Hall
DECLARE ❍ UKOUG's Andrew (Arfur C.) Clarke
v_cur sys_refcursor; ❍ Newbie DBA Lisa Dobson
BEGIN ❍ Coffee-Drinking DBA Jon Emmons
OPEN v_cur FOR 'select 1 from dual ❍ Chris Foot
where 1=2'; ❍ The Pythian DBA Team Blog
CLOSE v_cur; DBA Don Seiler
END;

❍ DBA Coskan Gundogar


Also, you could code ❍ Oracle WTF
IF v_value =1 then
select ... where col_a = 1; ARCHIVES
ELSIF v_value = 2 then ❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/06/bind-variables-in-plsql.html (2 of 4)1/9/2008 2:51:40 AM


OracleBlog: Bind Variables in PL/SQL

select ... where col_a = 2; ❍ May 2005


.... ❍ June 2005
July 2005
But with that sort of code you are

August 2005
probably dealing with a very small set

September 2005
of SQL statements and are specifically ❍

wanting different plans etc. ❍ October 2005


❍ November 2005
And the champion himself, Tom Kyte, ❍ December 2005
had this reply and defined some new ❍ January 2006
terms: "Overbind" and "Underbind." ❍ February 2006
Using these terms I was asking ❍ March 2006
whether it was possible to ❍ April 2006
"Underbind" using PL/SQL.
❍ May 2006
The only way to improperly bind in PL/ ❍ June 2006
SQL is when you use dynamic sql. ❍ July 2006
❍ August 2006
Else, you can "overbind" -- bind when ❍ September 2006
you didn't need to, but you cannot ❍ October 2006
"underbind", not binding when you ❍ November 2006
should! ❍ December 2006
January 2007
eg:

❍ February 2007
for x in ( select * from all_objects ❍ March 2007
where object_type = 'TABLE' ) ❍ April 2007
loop ❍ May 2007
❍ June 2007
is perfectly ok, you do NOT need to: ❍ October 2007
declare
l_otype varchar2(25) := 'TABLE';
begin
for x in ( select * from all_objects
where object_type = l_otype )
loop

You do not need to bind 'TABLE' in


that query since no matter how many
times you run that query, it'll be
'TABLE' over and over.

But with static SQL, it's not possible to


"underbind"

http://thinkoracle.blogspot.com/2005/06/bind-variables-in-plsql.html (3 of 4)1/9/2008 2:51:40 AM


OracleBlog: Bind Variables in PL/SQL

As an aside, visit Jeff Hunter's Oracle


blog, which is fast becoming one of
my favourites. Here is his recent post
on where Oracle DBAs can get help:
http://marist89.blogspot.
com/2005/06/where-can-i-find-help.
html

// posted by Robert Vollman @ Tuesday, June

14, 2005

Comments: Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/06/bind-variables-in-plsql.html (4 of 4)1/9/2008 2:51:40 AM


OracleBlog: Gathering Requirements

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, January
About Me
24, 2006
Name: Robert Vollman
Gathering Location: Calgary, Alberta, Canada
Requirements
I wanted to briefly I was born and raised in Ottawa, and have lived
follow up on Tip #2 in Calgary since 1991. I like playing sports
on my recent post (hockey, soccer, ultimate, basketball, you name it) and
about PL/SQL military board games. I also enjoy reading, walking, and
Coding. playing with my 2 cats Lilly and Brutus. I'm a database
http://thinkoracle. application specialist, whatever that is.
blogspot.
com/2005/12/20- View my complete profile
plsql-coding-tips.
html

I am not intending
Best Links
● Ask Tom Kyte
to convince anyone
Oracle Docs
WHY they should

Dan Morgan and PSOUG


spend time

Steven Feuerstein
gathering ●

requirements, but ● Jonathan Lewis


rather simply HOW ● FAQ
to do it. However, let ● Connor McDonald
it be known that ● The Oak Table
there are people ● Cary Millsap and Hotsos
whose careers are ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/01/gathering-requirements.html (1 of 10)1/9/2008 2:51:42 AM


OracleBlog: Gathering Requirements

entirely based on ● Anjo Kolk and OraPerf


the requirements ● Dizwell Oracle Wiki
gathering process, ● My Personal Blog
that there are
volumes of books on
the subject, and
there exists
methods much more
Aggregators
Brian Duff's OraBlogs
sophisticated and

Eddie Awad's OracleNA


involved that what I ❍

am going to ❍ Pete Finnigan's Aggregator


describe here. ❍ Oracle's Bloglist
❍ Oracle Base Aggregator
This post is
understandably
technology-
Top Blogs
Oracle's Ask Tom Kyte
independent, which

Oracle Guru Jonathan Lewis


is good because it is

Blogger of the Year Eddie Awad


based on my ❍

experience along ❍ Data Warehouser David Aldridge


with some articles ❍ Oracle Geek Lewis Cunningham
I've read recently, ❍ Database Expert James Koopmann
which has involved a ❍ Dizwell's Howard Rogers
variety of industries ❍ Oracle Master Laurent Schneider
and technologies. ❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
Step 1: State Your
Doug Burns
Vision

❍ Oracle ACE of the Year Dr. Tim Hall


Before prattling off a ❍ UKOUG's Andrew (Arfur C.) Clarke
list of what the ❍ Newbie DBA Lisa Dobson
software must do, ❍ Coffee-Drinking DBA Jon Emmons
you should start by ❍ Chris Foot
naming some clear, ❍ The Pythian DBA Team Blog
concise key ❍ DBA Don Seiler
objectives. The basic ❍ DBA Coskan Gundogar
idea is that all the ❍ Oracle WTF
requirements you
are about to list
match these key
ARCHIVES
objectives. ❍ LIST ALL ARTICLES
❍ May 2005
Ideally I like to ❍ June 2005
mention in this brief ❍ July 2005

http://thinkoracle.blogspot.com/2006/01/gathering-requirements.html (2 of 10)1/9/2008 2:51:42 AM


OracleBlog: Gathering Requirements

opening statement ❍ August 2005


how the ❍ September 2005
stakeholder's needs ❍ October 2005
can be fulfilled, pain November 2005
reduced, and/or

December 2005
gain received.

❍ January 2006
What Are ❍ February 2006
Requirements? ❍ March 2006
❍ April 2006
A requirement is ❍ May 2006
based on a specific ❍ June 2006
business-driven ❍ July 2006
need that is
August 2006
necessary to

September 2006
accomplish the

October 2006
stated project vision. ❍

Each requirement ❍ November 2006


should be ❍ December 2006
enumerated (or ❍ January 2007
otherwise ❍ February 2007
identifiable), and ❍ March 2007
should only describe ❍ April 2007
WHAT should be ❍ May 2007
provided, not HOW, ❍ June 2007
and should thus not ❍ October 2007
necessarily discuss
implementation
details. A
requirement should
also be testable/
verifiable, and
mention how that is
planned to be done.

As I alluded to in Tip
#1, my conviction is
that the rationale
behind a
requirement is a
necessary step. By
explaining WHY
something is
necessary we can

http://thinkoracle.blogspot.com/2006/01/gathering-requirements.html (3 of 10)1/9/2008 2:51:42 AM


OracleBlog: Gathering Requirements

help keep the


requirements
complete, clear,
concise, consistent
and maybe some
other things that
start with c.

Depending on the
application,
requirements can be
related to the
functionality, the
business interaction
(with users), or the
technical
requirements (eg:
time, space,
performance,
scalability, security,
disaster recovery).

For example,
requirements can
include anything
from business rules,
the budget, the
interface (web-
based vs desktop),
reporting abilities,
performance
(number of
concurrent users),
completion date/
schedule, security
needs, hardware,
software, error/fault-
tolerance, user
technical level,
system maintenance
requirements, and
so on.

How to Gather

http://thinkoracle.blogspot.com/2006/01/gathering-requirements.html (4 of 10)1/9/2008 2:51:42 AM


OracleBlog: Gathering Requirements

Requirements

Is this a brand new


product, or is it
meant to either
replace or compete
with another
product? If the
latter, you should
evaluate what that
product does, and
how it can be
improved.

Identify all the


stakeholders, such
as users,
management and
the nerds (technical
folk). Talk to them
either one-on-one
or in groups.

Techniques

In my experience, I
simply write a
document. For more
sophisticated
approaches, you can
look into use-case
models, unified
modeling language
(UML), automatic
requirements
generation tools,
prototypes,
storyboard, agile
software
development or any
other host of
techniques.

One word about

http://thinkoracle.blogspot.com/2006/01/gathering-requirements.html (5 of 10)1/9/2008 2:51:42 AM


OracleBlog: Gathering Requirements

prototypes. Go
ahead and use
prototypes to help
users express their
needs. But when
you're done, throw
the prototype away.
Tell management
that a quality
product will take
time to develop, and
working with hastily-
thrown together
prototype code is
just going to wind
up with a real mess.
Trust me: Chuck it!

Common
Requirements Errors

Based on some
research articles, the
most common types
of errors when
writing requirements
are (in order):
1. Incorrect
assumptions
2. Omitted
requirements
3. Inconsistent
requirements
4. Ambiguous
requirements

What's Next?

Remember that
requirements
gathering is a
cyclical process.
Despite having a
single author

http://thinkoracle.blogspot.com/2006/01/gathering-requirements.html (6 of 10)1/9/2008 2:51:42 AM


OracleBlog: Gathering Requirements

responsible for this


document, there
should be several
stakeholders
conducting several
rounds of reviews
and inspections. In
fact, you should
have a way to track
the history of the
requirements
document, and it
should be possible
to revise it, even
after it is finalized
(this is the real
world, after all).

Prioritize your
requirements. You
may even want to
move some
requirements to a
"future release"
section.

In my requirements
document, I als like
to add the following
sections:
1. A list of all the
assumptions that
were made during
the requirements
gathering process,
and why.
2. A list of
constraints on either
the software, the
design, or the
development process
3. A reference to any
industry standards

http://thinkoracle.blogspot.com/2006/01/gathering-requirements.html (7 of 10)1/9/2008 2:51:42 AM


OracleBlog: Gathering Requirements

to which you want


the software to
conform (eg: ANSI
SQL), and why.
4. A summary of
how we expect the
system to be used:
how many
concurrent users,
transactions per day,
etc.
5. Project-specific
details, like the
manpower, time,
skill sets, deadlines,
licenses, equipment
that will be needed.
6. A project glossary
of terms used in this
application,
including acronyms.

Granted this was


just one man's very
basic look at
requirements
gathering, but for
many small to mid-
sized projects, that
should get us
started in the right
direction.

// posted by Robert
Vollman @ Tuesday,

January 24, 2006

Comments:
Robert Vollman
said....
A requirement is
based on a specific

http://thinkoracle.blogspot.com/2006/01/gathering-requirements.html (8 of 10)1/9/2008 2:51:42 AM


OracleBlog: Gathering Requirements

business-driven
need that is
necessary to
accomplish the
stated project vision.

Yup. Don't tell me


what you WANT, tell
me what you NEED.
I'll make sure you
get it, but only if you
TELL ME about it.
The other point you
made that I'd like to
re-iterate is making
sure to discuss
WHAT needs to be
accomplished, not
HOW it should be
accomplished.
Developers are
responsible for
figuring out the
most efficient
methods for getting
the task done - it's
the users'
responsibility to
make sure the
developer (or the
analyst) understands
the NEED. How the
need is met isn't (or
shouldn't be)
important to the
user as long as it fits
the specs.
# posted by Bill S. :
Wednesday, 25 January,
2006

Years ago, I was in

http://thinkoracle.blogspot.com/2006/01/gathering-requirements.html (9 of 10)1/9/2008 2:51:42 AM


OracleBlog: Gathering Requirements

an environment
where we used the
old Oracle
SQL*Forms to
develop rought
prototypes so we
could better
understand the
user's needs. But we
decided early on to
intentionally put
bugs in the
prototype so the
users (and especially
the user managers)
wouldn't think we
had a nearly-
finished product.
That tactic served us
well many times.
# posted by Harry :
Wednesday, 25 January,
2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/01/gathering-requirements.html (10 of 10)1/9/2008 2:51:42 AM


OracleBlog: Handling exceptions

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated,
but it is the most powerful tool when it comes to data. That's why when I think data, I think Oracle. I
also enjoy writing, so I use this format to organise my thoughts. Please feel free to discuss any
thoughts you may have on the same topics, even old ones (I will see and respond to such comments).
You may want to start with "LIST ALL ARTICLES" under Archives.

Wednesday, March 01, 2006


About Me
Handling exceptions Name: Robert
I've got a checklist of tasks I like to complete before Vollman
beginning a new project. One important item on my list Location: Calgary,
is to decide on how my exceptions are going to be Alberta, Canada
handled.
I was born and raised in Ottawa,
By deciding in advance, I can save time by implementing
and have lived in Calgary since
exception handling only once, and also have much more
1991. I like playing sports
consistent code. I also find that once I begin a project,
(hockey, soccer, ultimate,
I'm focusing on the logic and can easily miss handling
basketball, you name it) and
exceptions properly, so my code is much more robust
military board games. I also
thinking about it in advance.
enjoy reading, walking, and
So what is an exception? playing with my 2 cats Lilly and
Brutus. I'm a database
Well an exception is more about what it represents application specialist, whatever
rather than what it IS. The existence of an exception that is.
means that something unexpected has failed in the run-
time execution of your code. It also means that this View my complete profile
execution has stopped.

Actually, I am slightly oversimplying the case, because


you can actually create and raise an exception yourself
Best Links
without an unexpected failure, but generally you are only ● Ask Tom Kyte
going to do this if you have either found something ● Oracle Docs
wrong, or you want to infuriate whoever is maintaining ● Dan Morgan and PSOUG
your code. ● Steven Feuerstein
● Jonathan Lewis
Ok, so you've got an exception. Now what? ● FAQ
Connor McDonald
Good question. Your first choice is to do nothing. That

will cause your code block to fail, giving whatever ● The Oak Table
executed this block an opportunity to do something. If ● Cary Millsap and Hotsos
you executed the block from SQL*Plus, (edit) all the (non- ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (1 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

COMMITed) work in your block and all (non- ● Anjo Kolk and OraPerf
autonomous) sub-blocks will be rolled back by the ● Dizwell Oracle Wiki
database. ● My Personal Blog

Your other option is to do something. Your only


opportunity to do this is in the EXCEPTION section of
your block. In this section you can examine the type of
exception, and handle it however you please.
Aggregators
Brian Duff's OraBlogs

Briefly, it looks like this: ❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
EXCEPTION ❍ Oracle's Bloglist
WHEN ONE_KIND_OF_ERROR THEN ❍ Oracle Base Aggregator

Top Blogs
-- Do something here
WHEN OTHERS THEN
-- Handle all left over cases here
❍ Oracle's Ask Tom Kyte
END
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
Once you're in there, you can get information about your ❍ Oracle Geek Lewis Cunningham
error by looking at SQLCODE and SQLERRM, which ❍ Database Expert James Koopmann
contain the number and a text message for the latest ❍ Dizwell's Howard Rogers
exception. Oddly enough (here's a little "gotcha") you ❍ Oracle Master Laurent Schneider
can't just insert these values to a table, for reasons I ❍ Security Expert Pete Finnigan
discovered last July. ❍ Oracle Award Winner Mark
Rittman
Incidentally, here is what the "do nothing" (edit or "hide
Doug Burns
the error") option looks like:

❍ Oracle ACE of the Year Dr. Tim


EXCEPTION WHEN OTHERS THEN NULL; Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
Edit: Read Tom Kyte's comments to learn why some ❍ Newbie DBA Lisa Dobson
people will strangle you with their bare hands if you ever ❍ Coffee-Drinking DBA Jon Emmons
do this. ❍ Chris Foot
The Pythian DBA Team Blog
I want to do something. Uhh ... what should I do?

❍ DBA Don Seiler


That's an even better question, and one that not a lot of ❍ DBA Coskan Gundogar
books or articles actually focus on. That's because you ❍ Oracle WTF

ARCHIVES
have to figure out for yourself what you want to do when
something goes wrong. Do you want to write a message
to a table that you can query later? Are there some LIST ALL ARTICLES
business-specific steps you want to do? Do you want to

May 2005
email yourself? Do you want to write to a log? Do you

June 2005
want to send a text message to output?

❍ July 2005
Whatever you decide to do, don't forget to do any clean ❍ August 2005
up, because this is your only chance. Like I said, ❍ September 2005
execution of your code block is over, and there is no ❍ October 2005

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (2 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

avoiding that, so if you have something to do, do it now! ❍ November 2005


❍ December 2005
What if I don't want the execution to stop? ❍ January 2006
February 2006
Too bad! The only way around that is to decide what

March 2006
code falls into this category, and wrap it in its own, ❍

nested block. Let me explain (and demonstrate). ❍ April 2006


❍ May 2006
Let's say you have several tasks to perform, and ❍ June 2006
regardless of whether the first one succeeds or not, you ❍ July 2006
want to continue to do the other tasks. Since execution ❍ August 2006
stops the moment you get an exception, this is a case ❍ September 2006
where you should wrap the first task in its own block, ❍ October 2006
and handle the exception there. It doesn't even have to November 2006
be a separate function/procedure, you can just create an

December 2006
anonymous block right then and there, like this:

❍ January 2007
❍ February 2007
BEGIN
❍ March 2007
BEGIN
-- Do task one. ❍ April 2007
EXCEPTION ❍ May 2007
-- Handle it! ❍ June 2007
END ❍ October 2007
-- Do task two
-- Do task three ...
EXCEPTION
-- Handle exceptions from task two, three, ...
END

Don't forget to actually handle the exception in your


nested block! As I said before, unhandled exceptions
stop the execution of whatever called your block, too.

Incidentally, in some cases you actually want to stop the


execution of the calling block, but you still want to do
something right now in your current, failed block. But if
you handle it, then the exception is gone, and the calling
block will therefore just continue its execution. In that
case, you can re-raise the exception. The only caveat is
that whatever called your block will think that the
exception came from your exception handling code, not
the original point of failure. Keep that in mind.

Good stuff. So what do you do?

Personally, I like to define an exception package.

There I can do a few things. I like to define my own

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (3 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

exceptions (including number and text message) using


PRAGMA EXCEPTION_INIT. Then I can throw my custom
exceptions around.

But more importantly I can write a few different


procedures that can handle exceptions in standard ways,
and then all I have to do in my exception blocks is
choose which way I want to handle an error, and then
send the required information (usually SQLCODE and
SQLERRM) to these standard procedures.

Needless to say, I can put these packages together quite


quickly by re-using tested, trusted code from previous
projects.

A word on rollback

I mentioned previously that if you don't handle your


exceptions, SQL*Plus will rollback your work. It is
probably better for you if you decide what gets
committed, and what gets rolled back, and when.
Therefore you should be sure to include COMMIT
(preferably with SAVEPOINTs) and ROLLBACK
appropriately in your code. And while ROLLBACK is a
topic for another day, I should at least tell you to be
aware of autonomous transactions, which are special
blocks that will commit its work right away, regardless of
whether its calling block rolled back or not.

Whew, anything else?

Yeah, one more thing. Exceptions in the DECLARE block


can't be caught in the same block, but rather by the
calling block. Keep that in mind in your EXCEPTION block
when your block calls blocks with a DECLARE section.

In closing, it's important to note that this is a huge topic,


and I can't do it justice in one page. Fortunately Oracle
has a great write-up on handling PL/SQL Errors in the PL/
SQL User's Guide and Reference, see Chapter 7. It even
includes a list of pre-defined exceptions and what they
mean.

But the true master of PL/SQL Exception Handling is


doubtlessly Steven Feuerstein. I urge you to buy his book
on Oracle PL/SQL Programming, and check out Chapter 8
on exception handling. If at all possible, attend one of
his live presentations.

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (4 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

// posted by Robert Vollman @ Wednesday, March 01, 2006

Comments:
This post has been removed by a blog administrator.
# posted by Thomas Kyte : Thursday, 02 March, 2006

I wish we didn't have when others.

the use of when others is probably the single largest


cause of logic bugs in PLSQL.

"when others then null" is not the "do nothing" exception


- it is almost certainly a bug in the developed code.

A when others that is not followed by RAISE to re-raise


the exception is almost always a bug. You have just
HIDDEN THE ERROR from the caller - they have no clue
(don't even think about using return codes - people/
code ignore those too)

I hate when others. Think about it - you DON'T KNOW


WHAT the error was, you are not equipped to deal with it.

Also, you say:

SQL*Plus will rollback your work.

sqlplus doesn't do that, the database does. It makes all


calls to the database 'atomic', the statement (the call)
either succeeds or fails.

begin p; end;

that is the CALL to the database, if it fails, the work done


by P will be undone - but not other work!! for example:

ops$tkyte@ORA10GR2> create table t ( x int check


(x>0));
Table created.
ops$tkyte@ORA10GR2> create or replace procedure p
(p_x in number)
2 as
3 begin
4 insert into t values(100);
5 insert into t values(p_x);
6 end;
7/
Procedure created.

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (5 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

ops$tkyte@ORA10GR2> insert into t values (1);


1 row created.

ops$tkyte@ORA10GR2> exec p(-1);


BEGIN p(-1); END;
*
ERROR at line 1:
ORA-02290: check constraint (OPS$TKYTE.
SYS_C007585) violated
ORA-06512: at "OPS$TKYTE.P", line 5
ORA-06512: at line 1

ops$tkyte@ORA10GR2> select * from t;


X
----------
1

ops$tkyte@ORA10GR2> rollback;
Rollback complete.

See how the entire set of work done by P is undone


(there are implicit savepoints wrapped around the
procedure) but the work done before P was invoked IS
NOT undone. It (the database) did not rollback your
transaction -- it just makes your statements atomic.

Now, add that "when others" bug:

ops$tkyte@ORA10GR2> create or replace procedure p


(p_x in number)
2 as
3 begin
4 insert into t values(100);
5 insert into t values(p_x);
6 exception
7 when others
8 then
9 dbms_output.put_line( 'I have utterly failed' );
10 end;
11 /
Procedure created.

ops$tkyte@ORA10GR2> insert into t values (2);


1 row created.

ops$tkyte@ORA10GR2> exec p(-1);


I have utterly failed
PL/SQL procedure successfully completed.

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (6 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

ops$tkyte@ORA10GR2> select * from t;

X
----------
2
100

See how you totally changed the behavior - you have half
of P's work now - ugh.

I also wish plsql didn't have commit and rollback - only


the invoking client knows when the transaction is
complete. A simply piece of code doesn't.

Say you have an API to update an employee status and


an API to change their address.

Now, you need a transaction that does both. If those


API's had the audacity to commit (or rollback) - this
would not be possible - you'd have to write yet another
API to do it. Ugh.

So, WHEN OTHERS THEN NULL = bug

sqlplus doesn't rollback your work, the database doesn't


rollback your work, the database makes statements
atomic.

when coding plsql you should thing 1,000,000 times


before adding the words commit or rollback to your
routines.
# posted by Thomas Kyte : Thursday, 02 March, 2006

Tom said:

>> I also wish plsql didn't have commit and rollback -


only the invoking client
>> knows when the transaction is complete. A simply
piece of code doesn't.

Except that sometimes the invoking client _is_ PL/SQL,


programs invoked by dbms_job , cron or some other
automatic process. In those cases the PL/SQL has to be
able to issue a commit or rollback. Of course, the
proportion of PL/SQL that is at the top of the callstack
and so needs to manage transactions is usually a fairly
small slice of the total body of PL/SQL.
# posted by APC : Thursday, 02 March, 2006

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (7 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

Thanks Tom! Addressing your points:

1. Avoiding use of "WHEN OTHERS"

I agree that I generally like to explicitly list the


exceptions I consider possible. However, sometimes I
don't care! If anything went wrong, just log it. That's
when I'd use WHEN OTHERS. If I think I've anticipated
every possible exception, I might still have a WHEN
OTHERS so I can flag this new situation and I can go
update my code with this new possibility.

2. "the use of when others is probably the single largest


cause of logic bugs in PLSQL."

In my opinion, the single largest cause of logic bugs in


PL/SQL is probably misunderstanding what NULL is.

3. WHEN OTHERS THEN NULL = bug

You're right that you are merely hiding the errror. But
that's not necessarily a bug. If that is what you've
written, you are probably saying "exceptions aren't
relevant to this block." You don't care if it succeeds or
fails, and you don't want to bother any calling block. I'm
not saying that's advisable ...

4. WHEN OTHERS followed by a (re-)RAISE)

Standard practise for me (except, of course, if I don't


want to bother the calling block). The only problem is
that the calling block thinks the error came from the
exception area instead of the true source of the
exception. Therefore, I always like to at least write
something to a log before re-raising.

5. SQL*Plus doesn't roll back your work, the database


does

I originally thought this I was merely guilty of an


oversimplification - that SQL*Plus instructs the database
to roll back, but upon reflection it crossed the line into
falsehood. Plus I like your wording so much better, so
I'm revising the original.

6. Your first example

In fairness, when I said "rollback your work" I meant the


work within your block (and its non-autonomous sub-

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (8 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

blocks) - not any work performed by any other block. So


I'll replace "work" with "block" to make that clear.

7. Your second example

Of course the work won't be rolled back. You "handled"


the exception yourself. Of course, you handled it by
printing "I have utterly failed", but if that's how you
chose to handle it, that's your call. As far as the calling
block is concerned (in this case, it was right from
SQL*Plus) there IS NO EXCEPTION and therefore no
reason to rollback. If that's not the behaviour you want,
then re-RAISE the exception, or ROLLBACK yourself.

Sometimes that is your desired behaviour. Ask yourself


this, if you wanted the 100 INSERTed regardless of
whether or not the second insert failed, how would you
write that code? You could make the INSERT of 100 an
autonomous sub-block (BLECH!), you could issue an
immediate COMMIT (which you also poo-pood), or you
could make the second insert a sub-block that CAUGHT
ALL EXCEPTIONS. (Note: in this case, that second insert
was all that remained, so it wasn't necessary to put it in a
sub-block). Is there any other way to achieve your goal?

8. COMMIT and ROLLBACK within your code

This deserves a blog of its own, but I will grant you the
final word: "when coding plsql you should thing
1,000,000 times before adding the words commit or
rollback to your routines."
# posted by Robert Vollman : Thursday, 02 March, 2006

Robert --

if something goes wrong, feel free to log it but you


better re-raise it. It would be irresponsible to do
anything else. The TOP LEVEL caller needs to know.
Period. when others then null is almost certainly A BUG.

Look at it this way - if it is OK to ignore any error, then


basically it matters NOT if your routine runs or not -
therefore JUST DON'T RUN YOUR ROUTINE AT ALL, it
obviously does NOT MATTER.

If it doesn't matter if a block

a) runs all the way


b) not at all

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (9 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

c) partitally

then I would opt for NOT RUNNING IT AT ALL - it just


doesn't matter.

Don't replace work with block replace it with STATEMENT


as that is what gets rolled back - the failing STATEMENT
submitted by the caller of the database - that statement
might invoke hundreds of blocks (triggers, anonymous
blocks, whatever). It is statement level atomicity.

The reason I'm being so picky here is because....

This is a huge cause of bugs, and needs serious deep


attention to detail.

Showing the when others then null and calling it the null
exception - I actually think of that as "irresponsible".

This is a very hard topic to deal with in snippets, this is


important stuff. It doesn't seem like it is but it is very
very very much misunderstood.

when others then null; <<=== almost certainly a bug.


# posted by Thomas Kyte : Thursday, 02 March, 2006

Tom,

I hear what you're saying here:

"If it doesn't matter if a block

a) runs all the way


b) not at all
c) partitally

then I would opt for NOT RUNNING IT AT ALL - it just


doesn't matter."

But I have had situations where this was the case. Just
because something doesn't matter doesn't mean you
shouldn't do it.

For example, just because our email server is down and


someone can't get an informational message about an

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (10 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

update doesn't mean I want my whole nightly batch to


fail.

Tell you what - I'll update my article to say you've got


important thoughts about this, and link to your blog. Of
course I'm assuming you're about to put something on
your blog on this topic. :)

Oh, and what's the difference between a statement and a


block?

Rob
# posted by Robert Vollman : Thursday, 02 March, 2006

Can you post a real world example where you didn't care
if

a) it runs all of the way


b) not at all
c) partially

cause, if b is EVER true, then b can ALWAYS be true - no?

:)

A statement is something issued by a client to the


database.
# posted by Thomas Kyte : Friday, 03 March, 2006

That was a real-world example. There was a stored


procedure that ran every night and did certain business-
related modifications. One step involved sending an
informational email to one of the analysts. Sometimes
the mail server was down, in which case we merrily
continued our modifications. We certainly didn't want to
abort our tasks just because we couldn't send an email!
If the analyst didn't get an email, he'd check if the mail
server was down, and then he'd check the data.

Yes, we could forget about emailing the analyst


altogether, but that email spared him the time it would
take to check that certain steps were completed.

Don't get me wrong, I do see your point, but I still think


that "I don't care" is a legitimate case.
# posted by Robert Vollman : Sunday, 05 March, 2006

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (11 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

But the sending of the email would raise a set of KNOWN


exceptions that you could deal with. You did not need a
when others, what if the exception was "ora-4031", or
something else as serious.

continue? I think not.

And it seems the analyst would "sometimes get email,


sometimes not". Seems analyst should have been
provided with LINK they could click on to generate said
report at their leisure (so you could see if said analyst
actually READ the report, so the analyst could be
ASSURED of always getting the report if they wanted it)

The day that email didn't show up, what does that poor
analyst do?

That, and the email should have been scheduled via


DBMS_JOB - to make it transactional with regards to the
rest of the larger transaction. When you commit - the job
would be free to run and if it failed, the system would
keep trying until it did or the job broke and then the DBA
fixes the issue.

So, I would still say "when others = evil", even in this


rather simple example.

The analyst is hosed when the mail doesn't get sent.

You don't know what the error was further downstream


in your application (what if it had nothing to do with the
email - but an oracle error of a serious nature, you can
catch the SMTP related - documented exceptions)

The sending of the email should have been made


transactional via dbms_job anyway (meaning the SMTP
error would never happen as part of your transaction).

When others then null -> almost certainly a bug and I


would never simply write:

....
Incidentally, here is what the "do nothing" (edit or "hide
the error") option looks like:

EXCEPTION WHEN OTHERS THEN NULL;

.........

and leave it at that. Too many people read too much

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (12 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

stuff and pick up too many bad habits - this when


others, big big big bad habit.

Sorry, this "when others" stuff, along with abuse of


autonomous transactions coupled with lack of binds -
my TOP THREE PET PEEVES.

Add triggers to round out the top four, wish they did not
exist at this point in my life.
# posted by Thomas Kyte : Sunday, 05 March, 2006

Tom,

I use triggers all the time. Show me a better way to


enforce a business contraint that involves more than one
table, or something non-trivial, and I'll switch!

Use Constraints
Variables in Constraints

I'll make one final edit to add a word of warning on that


line you find particularly dangerous. We both agree its to
be avoided, we just disagree on the degree of
absolution.

I will tell you one of my pet peeves, though. When


something trivial fails, lets exceptions slip out, and I
have to abort and rollback non-dependent, important
work that otherwise would have succeeded.

If it failed because of something important, then it will


soon affect something important and can get handled
then.

That's why its legitimate to insist that certain blocks


include WHEN OTHERS. It is your way of saying "This is
not a deal-breaker, I do not want other stuff rolling back
or aborting because of it." Use it wisely (or, I can
concede, don't use it at all).

Rob
# posted by Robert Vollman : Sunday, 05 March, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (13 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling exceptions

http://thinkoracle.blogspot.com/2006/03/handling-exceptions.html (14 of 14)1/9/2008 2:51:47 AM


OracleBlog: Handling Performance Issues

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, March 10,


About Me
2006
Name: Robert Vollman
Handling Location: Calgary, Alberta, Canada
Performance
Issues I was born and raised in Ottawa, and have lived in
Typically Calgary since 1991. I like playing sports (hockey,
performance soccer, ultimate, basketball, you name it) and military board
issues are handled games. I also enjoy reading, walking, and playing with my 2
by looking for cats Lilly and Brutus. I'm a database application specialist,
common whatever that is.
symptoms and
trying common View my complete profile
solutions. Given a

Best Links
sufficient level of
experience, this is
successful quite Ask Tom Kyte
often with minimal

Oracle Docs
effort. But there

Dan Morgan and PSOUG


are times where

this does not work ● Steven Feuerstein


and you need a ● Jonathan Lewis
more systematic ● FAQ
approach. ● Connor McDonald
● The Oak Table
Let's take a look at ● Cary Millsap and Hotsos
one approach, ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (1 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

bearing in mind: ● Anjo Kolk and OraPerf


1. This is a rough, ● Dizwell Oracle Wiki
first, high-level ● My Personal Blog
pass
2. It is NOT Oracle
(or even database)
specific
3. I am not
Aggregators
Brian Duff's OraBlogs
including the

Eddie Awad's OracleNA


details on the HOW ❍

❍ Pete Finnigan's Aggregator


Also, some people ❍ Oracle's Bloglist
may notice Cary ❍ Oracle Base Aggregator

Top Blogs
Millsap's influence
in this approach.
Oracle's Ask Tom Kyte
1. Rank the most

Oracle Guru Jonathan Lewis


significant

Blogger of the Year Eddie Awad


performance

Data Warehouser David Aldridge


issues, by specific ❍

application, from ❍ Oracle Geek Lewis Cunningham


the business user's ❍ Database Expert James Koopmann
perspective. ❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
2. Carefully ❍ Security Expert Pete Finnigan
measure the total ❍ Oracle Award Winner Mark Rittman
time currently Doug Burns
taken for each of

Oracle ACE of the Year Dr. Tim Hall


these specific

UKOUG's Andrew (Arfur C.) Clarke


applications.

❍ Newbie DBA Lisa Dobson


3. Determine ❍ Coffee-Drinking DBA Jon Emmons
exactly how fast ❍ Chris Foot
the application ❍ The Pythian DBA Team Blog
would need to run ❍ DBA Don Seiler
in order to meet ❍ DBA Coskan Gundogar
the business user's ❍ Oracle WTF
needs.

Now, for each


ARCHIVES
business ❍ LIST ALL ARTICLES
application in ❍ May 2005
order of ❍ June 2005
importance, ❍ July 2005

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (2 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

perform steps ❍ August 2005


starting at 4-9: ❍ September 2005
October 2005
4. Break down the

November 2005
specific application

December 2005
into tasks. ❍

❍ January 2006
5. Carefully ❍ February 2006
measure how often ❍ March 2006
each task is ❍ April 2006
currently being ❍ May 2006
executed, how ❍ June 2006
long each ❍ July 2006
execution
August 2006
currently takes,

September 2006
and from that, how

October 2006
much total time it ❍

currenty takes and ❍ November 2006


what % of total ❍ December 2006
time each task ❍ January 2007
represents. ❍ February 2007
❍ March 2007
Now, for each ❍ April 2007
specific task in ❍ May 2007
order of total % of June 2007
time taken,

October 2007
perform steps 6-9:

6. If you
COMPLETELY
ELIMINATED the
time taken by this
task and all tasks
below it, would the
performance goal
be met?
YES: Continue,
with step 7-9
NO: Stop until the
situation changes.
Continue to the
next application,
steps 4-9.

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (3 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

7. Predict how to
reduce time spent
for this task, either
by:
a) Reducing the
number of times
this task is being
done
OR
b) Reducing the
time it takes to
execute a task once

Note: If required,
recursively
perform steps 4-9
by breaking the
task down further
into sub-tasks.

8. Perform a cost-
benefit analysis of
your plan in step
7. Is it worthwhile?
If so, do it.

9. Have you
reached the
performance goal
of this application?
YES: Proceed to the
next application
and perform steps
4-9.
NO: Proceed to the
next task and
repeat steps 6-9.

Notes:
1. By doing things
in order of
business
importance
a) the users are

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (4 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

most likely to
experience results
b) anything we
"harm" is, by
definition, less
important
2. By addressing
tasks in order of
time spent
a) we get the best
results first
b) adverse results
will only affect
tasks that take less
time
3. By defining
success up front,
and performing a
cost-benefit
analysis before
taking action, we
can avoid wasting
time by stopping
either
a) when the goal is
met
b) when the goal is
proven to be
impossible.

Since this is a
rough sketch, I
especially invite
people's thoughts.

// posted by Robert
Vollman @ Friday,

March 10, 2006

Comments:
I think this

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (5 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

methodology
misses some
important issues:

It presupposes
everything is close.
This may be
reasonable for a
10g installation,
may be way off for
an older one that
has never been
looked at. For
example, some
vendor slapped in
a generic db and
their app, not
doing any capacity
planning beyond
gross disk size,
then threw
physical memory
at it.

It presupposes the
business user's
perspective is
correct. Personally,
I've noted that a
person is brought
in to solve a
particular problem,
but the range of
problems that are
already there is
much larger. Users
have simply
accepted that is
how the system is
and don't see
problems. There
must be a
technical

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (6 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

evaluation
independent of the
business analysis
to see these things.

Not useable for


greenfield systems.

A system with a
broad range of
applications on it
may actually have
the worst
problems further
down the list as
made by the
business concerns.
One example I've
seen is the
batched report
that no one cares
takes 4 hours to
run - then putting
the relevant
objects in the
recycle pool brings
it down to minutes
and severely
increases
performance for
everything else.

That's why as an
experienced
person I take some
time to just poke
around and see
what strikes me as
"wrong" before
doing any formal
analysis. Usually
what happens is I
give some
recommendations,

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (7 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

people kind of go
"uh huh" and
ignore it, then I fix
the actual problem
they got me for,
then they realize I
actually do know
what I'm talking
about, then they
keep me around
for several years
after the 3 month
contract.

Perhaps the
difference is
between sites that
are sorta well run
and sites that
aren't. Easy
pickin's in the
latter.
# posted by Joel
Garry : Thursday, 16
March, 2006

The is very close to


the approach I try
to teach here.

Joel has a good


point, there is no
exact guide to
follow, just a list of
good practices and
procedures you
evolve per
application.

One thing I do
here, that is a
slight departure

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (8 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

from your
thoughts but Joel
pointed it out, is I
do a very detailed
technical analysis
of the database
and waits, slow
SQL and other
factors that impact
database
performance first.
Then I have a face
to face with the
users and try to
relate their
experience to the
technical end
issues. That
assumes you do
have a good
understanding of
the business
application, if you
do not, then it is a
large amount of
work, but you
learn the
application.
# posted by Herod
T : Wednesday, 22
March, 2006

Joel and Herod,

Thanks for your


comments. You
raise an important
point.

When I was
referring to the
"common

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (9 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

symptoms" you
should look for
and the "common
solutions" you
should attempt
first, I meant to
include efforts that
may include
looking at waits, or
slow SQL, etc. So
we're in agreement
there.

I also agree that


sometimes
reducing the
resources used by
something that no
one cares about
can actually speed
up tasks people do
care about. So it is
a good practise to
tune "unimportant"
things, but at the
same time, if it
ain't broke don't
fix it. Plus, to get
the best bang for
your buck, its
generally best to
focus on the
things that matter
most to the end
users.

Cheers,
Robert
# posted by Robert
Vollman : Wednesday,
22 March, 2006

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (10 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

Depends on your
definition of
"broke." :-)

Saw one of those


$800K custom
motorhomes on
the freeway today,
with something
flapping
underneath. I'm
sure the people
inside had no clue.
It wouldn't be
good for them to
get a clue when it
breaks off and
jams up the third
axle.

While I
acknowledge
Compulsive Tuning
Disorder, I don't
think that applies
to just looking at
everything that is
going on, because
you just can't tell
with any
methodology I've
seen all the things
that could go/are
going wrong.
Preventative
Maintenance is not
a bad thing. I think
it should be a
formalized DBA
duty.

Getting back to the


OP, Craig
Shallahammer has

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (11 of 12)1/9/2008 2:51:49 AM


OracleBlog: Handling Performance Issues

four interesting
points in his
Modern
Performance Myths
paper at orapub.
# posted by Joel
Garry : Thursday, 23
March, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/03/handling-performance-issues.html (12 of 12)1/9/2008 2:51:49 AM


OracleBlog: Keeping Tables Small

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday, August
About Me
17, 2005
Name: Robert Vollman
Keeping Location: Calgary, Alberta, Canada
Tables Small
David Aldridge I was born and raised in Ottawa, and have
recently put together lived in Calgary since 1991. I like playing
a list of ways to make sports (hockey, soccer, ultimate, basketball, you name it)
table scans faster: and military board games. I also enjoy reading, walking,
and playing with my 2 cats Lilly and Brutus. I'm a database
http://oraclesponge. application specialist, whatever that is.
blogspot.
com/2005/08/list- View my complete profile
ways-to-scan-table-

Best Links
faster.html

There is one really


Ask Tom Kyte
simple, effective but

Oracle Docs
often overlooked way ●

of decreasing the time ● Dan Morgan and PSOUG


it takes to scan a table ● Steven Feuerstein
that I want to ● Jonathan Lewis
elaborate on. It's ● FAQ
based on this simple ● Connor McDonald
premise: ● The Oak Table
● Cary Millsap and Hotsos
Fewer Rows = Faster ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (1 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

Scans. ● Anjo Kolk and OraPerf


● Dizwell Oracle Wiki
The time it takes to ● My Personal Blog
scan a table can be
roughly calculated like
so:
Number of Rows
TIMES Time to Process
Aggregators
One Row Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


Many people focus on ❍ Pete Finnigan's Aggregator
the second part of the ❍ Oracle's Bloglist
question (the time it ❍ Oracle Base Aggregator
takes to process a
single row), when
sometimes it is far
Top Blogs
Oracle's Ask Tom Kyte
more simple to ❍

decrease the number ❍ Oracle Guru Jonathan Lewis


of rows. ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
What that means is, ❍ Oracle Geek Lewis Cunningham
look at the table and ❍ Database Expert James Koopmann
determine if some of ❍ Dizwell's Howard Rogers
the data is used ❍ Oracle Master Laurent Schneider
infrequently enough
Security Expert Pete Finnigan
that it can be moved

Oracle Award Winner Mark Rittman


aside to an archived

Doug Burns
version of this table. ❍

❍ Oracle ACE of the Year Dr. Tim Hall


You may need to ❍ UKOUG's Andrew (Arfur C.) Clarke
modify your existing ❍ Newbie DBA Lisa Dobson
applications to ❍ Coffee-Drinking DBA Jon Emmons
account for cases ❍ Chris Foot
where you truly do ❍ The Pythian DBA Team Blog
need to look at all that ❍ DBA Don Seiler
data. In that case, you DBA Coskan Gundogar
might keep a view of

Oracle WTF
all data.

That is basically my ARCHIVES


point, so you can stop ❍ LIST ALL ARTICLES
reading there if you ❍ May 2005
wish. I have put ❍ June 2005
together an example, ❍ July 2005

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (2 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

where I elaborate on ❍ August 2005


this a little further. It ❍ September 2005
is meant only as a ❍ October 2005
demonstration of what November 2005
I mean, not any kind

December 2005
of compelling

January 2006
argument or proof.

❍ February 2006
First off, here is an ❍ March 2006
easy way to create a ❍ April 2006
nice, big test table. ❍ May 2006
❍ June 2006
CREATE TABLE ❍ July 2006
ReallyBigTable AS
August 2006
SELECT * FROM

September 2006
ALL_OBJECTS;

❍ October 2006
SELECT COUNT (*) ❍ November 2006
FROM ReallyBigTable; ❍ December 2006
❍ January 2007
40763 ❍ February 2007
March 2007
Now I'm going to

April 2007
create a query that

ought to really suffer, ❍ May 2007


performance-wise, the ❍ June 2007
larger the table is: ❍ October 2007

SELECT SUM(object_id)
FROM ReallyBigTable
WHERE object_id * 2
NOT IN
(SELECT object_id
FROM ReallyBigTable);

Time Elapsed:
00:11:42.09

Alright, now let's


create an archive and
active version of this
table. For argument's
sake, let's say that
anything with an

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (3 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

object_id below 40000


is used infrequently
enough that it is safe
to push aside for our
business-specific
purposes:

CREATE TABLE
ReallyBigTable_Archive
AS SELECT * FROM
ReallyBigTable
WHERE object_id <
40000;

SELECT COUNT (*)


FROM
ReallyBigTable_Archive;

38000

CREATE TABLE
ReallyBigTable_Active
AS SELECT * FROM
ReallyBigTable
WHERE object_id >=
40000;

SELECT COUNT (*)


FROM
ReallyBigTable_Active;

2763

I'm in a single-user
environment doing a
test, so I really don't
have to worry right
now about updates
taking place.
Otherwise we'd have
to more clever about
the creation of our
archive and active
tables. But I will say

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (4 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

that creating these


tables can be
lightning-fast!

Ok, now let's try our


query on our little
table:

SELECT SUM(object_id)
FROM
ReallyBigTable_Active
WHERE object_id * 2
NOT IN
(SELECT object_id
FROM
ReallyBigTable_Active);

Time Elapsed:
00:00:02.08

So it completed in
0.3% of the time.
Awesome!

"OK," you say, "but


you're cheating!" So
what if I am?
Sometimes in the real
world we CAN cheat.
Sometimes we don't
have to go through all
the data, every time,
every case. Don't get
mad at Oracle or your
DBA or your
application when it's
not fast enough, just
get creative. You don't
always have to apply
painful Kolkian
techniques or
Millsapian analysis to
get results.

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (5 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

Moving on, there may


still be some
applications that want
to query on the whole
dataset. No problem,
that is still possible
using UNION. But what
kind of price will we
pay? Let's see, in this
one example:

DROP TABLE
ReallyBigTable;

CREATE VIEW
ReallyBigTable AS
SELECT * FROM
ReallyBigTable_Archive
UNION ALL
SELECT * FROM
ReallyBigTable_Active;

Remember, a view is
just like a stored
query, but we can use
it like a table. Which
means our
applications don't
have to change their
queries.

http://thinkoracle.
blogspot.
com/2005/07/use-
views.html

One limitation of this


kind of view is that we
won't be able to insert
from our legacy
applications anymore:

INSERT INTO
ReallyBigTable

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (6 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

(object_id) VALUES
(NULL);

ORA-01732: data
manipulation
operation not legal on
this view

Let's see how much of


a performance penalty
we have in this case
by using a view
instead of the original
base table:

SELECT SUM(object_id)
FROM ReallyBigTable
WHERE object_id * 2
NOT IN
(SELECT object_id
FROM ReallyBigTable);

Time Elapsed:
00:08:18.02

What??? The use of a


view on two smaller
sub-tables took less
time than the original
table? It only took 70%
as much time.
Probably something to
do with having the
data in memory, or
statistics, or
something like that.
I'll get back to you in
another blog. The
main thing I wanted to
demonstrate was that
the performance
would be in the same
"order" as the original
query. That is, you're

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (7 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

not taking a huge


performance hit by
using a view.

Out of curiousity, let's


take a mixed sub-
example, where we
are using our new,
smaller table against
that big view.

SELECT SUM
(object_id) FROM
ReallyBigTable_Active
WHERE object_id * 2
NOT IN
(SELECT object_id
FROM ReallyBigTable);

Time Elapsed:
00:00:43.05

Nice.

One final point, if I


may. Notice I used
"UNION ALL" instead
of "UNION." I did this
because UNION
rearranges the order
of the table, and
removes duplicates.

http://thinkoracle.
blogspot.
com/2005/08/union-
all.html

I don't care about


duplicates and order,
and I didn't want the
performance hit, so I
used UNION ALL. Of
course, I am curious

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (8 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

to know how
significant the
performance hit is in
this case. Let's see.

CREATE OR REPLACE
VIEW ReallyBigTable AS
SELECT * FROM
ReallyBigTable_Archive
UNION
SELECT * FROM
ReallyBigTable_Active;

SELECT SUM(object_id)
FROM ReallyBigTable
WHERE object_id * 2
NOT IN
(SELECT object_id
FROM ReallyBigTable);

Time Elapsed:
00:13:20.02

So it took about 60%


longer than with
UNION ALL.

SELECT SUM
(object_id) FROM
ReallyBigTable_Active
WHERE object_id * 2
NOT IN
(SELECT object_id
FROM ReallyBigTable);

Time Elapsed:
00:00:54.05

And this one about


25% longer. So in this
case it was definitely
noticeable.

Wrap-up:

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (9 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

1. David Aldridge has


a great article on how
to make your table
scans go faster.
2. In addition to his
techniques, I
recommend "being
creative" (aka
"cheating") and trying
to split your data.
3. Use Views to
maintain applications
that SELECT from the
big, original table so
you don't have to
change code and can
still query the whole
set.
4. Using Views will not
have a big
performance hit. In
fact, in this
demonstration it was
faster (a topic for
another day's blog).
5. Use UNION ALL
instead of UNION in
this view to avoid the
noticeable
performance hit.

// posted by Robert
Vollman @ Wednesday,

August 17, 2005

Comments:
... and partitioning is
an even better way of
achieving the same
thing!

But it's an important

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (10 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

point you make. As


well as using wait
event information and
execution plans, I find
that the biggest
performance
improvements come
from rethinking what
it is you're trying to do
so that you perform
the smallest amount
of work to get there. I
find it's essential to
say to myself, what is
this app trying to do
and how is it
approaching the task
before I go anywhere
*near* detailed
statistics collection
and analysis. It's
amazing how often
the solution is
blindingly obvious
(which is a sad
comment on the
standard of a lot of
oracle-based apps, I
suppose ...)

Cheers,

Doug
# posted by Doug
Burns : Wednesday, 17
August, 2005

Closer to partitioning
than you might think,
Doug ... in fact this is
how partitioning was
implemented in Oracle

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (11 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

7 before partitioned
tables existed,
through partitioned
views (aka "manual
partitioning"). Here's
where they're
documented: http://
download-west.oracle.
com/docs/cd/
A57673_01/DOC/
server/doc/A48506/
partview.htm#238

You'll see some extra


comments in there
that show how
partition elimination
was implemented and
how you know
whether the optimizer
recognizes operations
against partitioned
views.

The technique is
deprecated now in
favour of the (much
more expensive and
efficient) partitioning
option, but may still
be viable for those on
a budget.
# posted by David
Aldridge : Thursday, 18
August, 2005

"Closer to partitioning
than you might think,
Doug ... in fact this is
how partitioning was
implemented in Oracle
7 before partitioned

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (12 of 13)1/9/2008 2:51:52 AM


OracleBlog: Keeping Tables Small

tables existed, "

I know ... used to use


them! But if you have
the cash for
partitioning, it's a
much better option,
no?

Cheers,

Doug
# posted by Doug
Burns : Thursday, 18
August, 2005

Yes, I wouldn't like to


be fiddling around like
that if I regularly could
use partitioning. For a
one-off event though
it probably wouldn't
be too bad.
# posted by David
Aldridge : Thursday, 18
August, 2005

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html (13 of 13)1/9/2008 2:51:52 AM


OracleBlog: Oracle Packages

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, October
About Me
31, 2005
Name: Robert Vollman
Oracle Location: Calgary, Alberta, Canada
Packages
What is a I was born and raised in Ottawa, and have lived in
"package"? Calgary since 1991. I like playing sports (hockey,
soccer, ultimate, basketball, you name it) and military board
According to the games. I also enjoy reading, walking, and playing with my 2
PL/SQL User's cats Lilly and Brutus. I'm a database application specialist,
Guide and whatever that is.
Reference, "A
package is a View my complete profile
schema object that
groups logically
related PL/SQL
types, items and Best Links
subprograms." ● Ask Tom Kyte
● Oracle Docs
But I believe a ● Dan Morgan and PSOUG
package is far Steven Feuerstein
more than just a

Jonathan Lewis
way of logically

FAQ
grouping objects

Connor McDonald
together. ●

● The Oak Table


Before I digress, ● Cary Millsap and Hotsos
let's very briefly ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/10/oracle-packages.html (1 of 10)1/9/2008 2:51:55 AM


OracleBlog: Oracle Packages

understand what a ● Anjo Kolk and OraPerf


package is. It's ● Dizwell Oracle Wiki
probably easiest if ● My Personal Blog
you take a look at
Oracle's
documentation,
which has a good
description of
Aggregators
Brian Duff's OraBlogs
packages and

Eddie Awad's OracleNA


some examples: ❍

❍ Pete Finnigan's Aggregator


PL/SQL User's ❍ Oracle's Bloglist
Guide and ❍ Oracle Base Aggregator
Reference, Chapter
9: PL/SQL
Packages:
Top Blogs
Oracle's Ask Tom Kyte
http://download-

Oracle Guru Jonathan Lewis


west.oracle.com/

Blogger of the Year Eddie Awad


docs/cd/

❍ Data Warehouser David Aldridge


B10501_01/
❍ Oracle Geek Lewis Cunningham
appdev.920/ ❍ Database Expert James Koopmann
a96624.pdf ❍ Dizwell's Howard Rogers
Oracle Master Laurent Schneider
Put simply,

Security Expert Pete Finnigan


packages have two

parts, the ❍ Oracle Award Winner Mark Rittman


specification and ❍ Doug Burns
the body. ❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
The specification ❍ Newbie DBA Lisa Dobson
is the interface ❍ Coffee-Drinking DBA Jon Emmons
into the package. ❍ Chris Foot
It describes all the The Pythian DBA Team Blog
types, variables,

DBA Don Seiler


procedures (etc)

DBA Coskan Gundogar


within the

Oracle WTF
package. Ideally ❍

the specification
does not change. ARCHIVES
❍ LIST ALL ARTICLES
The body has all ❍ May 2005
the June 2005
implementation.

❍ July 2005

http://thinkoracle.blogspot.com/2005/10/oracle-packages.html (2 of 10)1/9/2008 2:51:55 AM


OracleBlog: Oracle Packages

Inside the body ❍ August 2005


you would actually ❍ September 2005
write the ❍ October 2005
procedures, assign November 2005
the values, and

December 2005
have all the details

January 2006
and logic behind

February 2006
the package. Often ❍

(unless you are the ❍ March 2006


developer), you ❍ April 2006
can treat the body ❍ May 2006
as a "black box." ❍ June 2006
❍ July 2006
As always, I'll refer ❍ August 2006
you to Dan Morgan ❍ September 2006
to understand the
October 2006
syntax of Oracle

November 2006
PL/SQL Packages:

December 2006
http://www.psoug.

January 2007
org/reference/

February 2007
packages.html

❍ March 2007
Back to the story. ❍ April 2007
❍ May 2007
According to one ❍ June 2007
of my favourite PL/ ❍ October 2007
SQL Authors
Connor McDonald,
"The main reason
packages are not
more widely
adopted is that
users are unaware
of the benefits
they offer."

Beyond the known,


obvious advantage
of grouping
together related
items, which is
great for
organising your

http://thinkoracle.blogspot.com/2005/10/oracle-packages.html (3 of 10)1/9/2008 2:51:55 AM


OracleBlog: Oracle Packages

code and
"modularity", what
are these benefits
of which we are
speaking?

1. Objects don't
get invalidated
when you makes
changes to the
body. That saves a
lot of
recompilation and
makes changing
the
implementation
much more
painless. You will
still have to
recompile if you
change the
specification, but
that's not
something you
should be doing
very often.

2. You can
"overload"
subprograms
(procedures/
functions). You
can have several
subprograms with
the same name,
but with a
different number
of parameters, or
different types.
That is another
thing that makes
implementation
changes more

http://thinkoracle.blogspot.com/2005/10/oracle-packages.html (4 of 10)1/9/2008 2:51:55 AM


OracleBlog: Oracle Packages

painless because
you can keep
legacy code if you
like. You can also
see the extra
flexibility that
offers developers.

3. You can have


persistent
variables
throughout a
session without
storing anything in
a database table.
Packages can have
variables and
constants that are
initialised when
the packages is
first used within a
session, and then
they are available
for the remainder
of the session for
all future
references to
anything within
that package. That
comes in very
handy.

4. Speaking of
initialisation, being
able to call a
procedure
automatically the
first time a
package is used
within a session
can also come in
very handy.

5. You can take

http://thinkoracle.blogspot.com/2005/10/oracle-packages.html (5 of 10)1/9/2008 2:51:55 AM


OracleBlog: Oracle Packages

advantage of
"encapsulation." In
essence, you can
hide the
implementation
details from users
but still give them
all the information
they need to use
the package. Since
they aren't aware
of the details, that
means you can
change them with
minimal impact or
risk. Packages also
support private
subprograms and
variables which are
available only to
other
subprograms
within the
package, and
remain completely
hidden and
inaccessible to
anything outside
the package.

6. You may notice


some performance
improvement
when using
packages. When
you first use a
package, the
entire package
may be loaded into
memory, meaning
fewer disk I/Os as
you use the related
items within.

http://thinkoracle.blogspot.com/2005/10/oracle-packages.html (6 of 10)1/9/2008 2:51:55 AM


OracleBlog: Oracle Packages

I'm sure there are


other advantages,
but those are the
ones I've noticed.

Let me close with


links to my
favourite two
articles about
Packages, from
two of my
favourite PL/SQL
experts:
Connor
McDonald's
Chapter 2 from
Mastering Oracle
PL/SQL: Practical
Solutions
http://www.oracle.
com/technology/
books/pdfs/
sample2174ch2.
pdf

Steven Feuerstein's
article "Picking
Your Packages"
from May/June
2005 Oracle
Magazine
http://www.oracle.
com/technology/
oramag/oracle/05-
may/o35plsql.html

---
Addition:
By the way, to use
packages, just
prefix the package
name using dot

http://thinkoracle.blogspot.com/2005/10/oracle-packages.html (7 of 10)1/9/2008 2:51:55 AM


OracleBlog: Oracle Packages

notation

Check out PL/SQL


Supplied Packages
and Types
Reference
http://download-
west.oracle.com/
docs/cd/
B10501_01/
appdev.920/
a96612.pdf

It includes
UTL_HTTP and
DBMS_OUTPUT
http://thinkoracle.
blogspot.
com/2005/08/
utlhttp.html
http://thinkoracle.
blogspot.
com/2005/10/
dbmsoutputputline.
html

But also check out


UTL_FILE,
DBMS_PIPE,
DBMS_ALERT and
the DBMS_XML
stuff.

// posted by Robert
Vollman @ Monday,

October 31, 2005

Comments:
Hi...I have a

http://thinkoracle.blogspot.com/2005/10/oracle-packages.html (8 of 10)1/9/2008 2:51:55 AM


OracleBlog: Oracle Packages

question..Say if i
create a custom
package with
package name as
dbms_output and
still i wanted to
call the Oracle's
built in
dbms_output? Is
there a way out?

Mail me at
krishmah@gmail.
com
# posted by
Anonymous :
Monday, 22 May, 2006

no buddy u can't
create it if u know
do let me know at
fuchauhan@gmail.
com
# posted by
Anonymous :
Tuesday, 19
September, 2006

Dear Vollman,

I am a developer at
initial.I want aa
deep knowledge in
oracle features and
impotance of
packages. Please
send me some
usefull tutorial
regarding pl/sql. I
will be gratefull to
u.

http://thinkoracle.blogspot.com/2005/10/oracle-packages.html (9 of 10)1/9/2008 2:51:55 AM


OracleBlog: Oracle Packages

# posted by
Manish : Monday,
16 April, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/10/oracle-packages.html (10 of 10)1/9/2008 2:51:55 AM


OracleBlog: Specifying INSERT Columns

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, July 11,


About Me
2005
Name: Robert Vollman
Specifying Location: Calgary, Alberta, Canada
INSERT
Columns I was born and raised in Ottawa, and have lived in
Here is a quick one Calgary since 1991. I like playing sports (hockey,
that I touched on soccer, ultimate, basketball, you name it) and military board
briefly in one of my games. I also enjoy reading, walking, and playing with my 2
first blogs: cats Lilly and Brutus. I'm a database application specialist,
whatever that is.
http://thinkoracle.
blogspot. View my complete profile
com/2005/05/null-
vs-nothing.html
Best Links
It can be important ● Ask Tom Kyte
to specify which ● Oracle Docs
columns you plan Dan Morgan and PSOUG
on providing values

Steven Feuerstein
for in an INSERT

Jonathan Lewis
statement.

Repeating Dan ● FAQ


Morgan's quote: ● Connor McDonald
● The Oak Table
"By not specifying ● Cary Millsap and Hotsos
column names you ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/07/specifying-insert-columns.html (1 of 6)1/9/2008 2:51:58 AM


OracleBlog: Specifying INSERT Columns

are signifying that ● Anjo Kolk and OraPerf


you are providing ● Dizwell Oracle Wiki
values for ALL ● My Personal Blog
columns. This is
why it is a very bad
practice as doing an
ALTER TABLE ADD
immediately
Aggregators
Brian Duff's OraBlogs
invalidates all SQL

Eddie Awad's OracleNA


statements." ❍

❍ Pete Finnigan's Aggregator


Here is an example. ❍ Oracle's Bloglist
I created a table, ❍ Oracle Base Aggregator
and then wrote a
procedure that will
insert a row
Top Blogs
Oracle's Ask Tom Kyte
WITHOUT specifying

Oracle Guru Jonathan Lewis


the values. Works

Blogger of the Year Eddie Awad


fine if the table ❍

doesn't change: ❍ Data Warehouser David Aldridge


❍ Oracle Geek Lewis Cunningham
SET SERVEROUTPUT ❍ Database Expert James Koopmann
ON; ❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
CREATE TABLE
Security Expert Pete Finnigan
MyTable (MyInt

Oracle Award Winner Mark Rittman


NUMBER);

❍ Doug Burns
CREATE OR ❍ Oracle ACE of the Year Dr. Tim Hall
REPLACE ❍ UKOUG's Andrew (Arfur C.) Clarke
PROCEDURE ❍ Newbie DBA Lisa Dobson
InsertIntoMyTable ❍ Coffee-Drinking DBA Jon Emmons
(InValue IN NUMBER) ❍ Chris Foot
AS ❍ The Pythian DBA Team Blog
BEGIN ❍ DBA Don Seiler
DBMS_OUTPUT. DBA Coskan Gundogar
PUT_LINE('Inserting '

Oracle WTF
|| InValue || ' into

MyTable');
INSERT INTO ARCHIVES
MyTable VALUES ❍ LIST ALL ARTICLES
(InValue); ❍ May 2005
EXCEPTION ❍ June 2005
WHEN OTHERS ❍ July 2005

http://thinkoracle.blogspot.com/2005/07/specifying-insert-columns.html (2 of 6)1/9/2008 2:51:58 AM


OracleBlog: Specifying INSERT Columns

THEN ❍ August 2005


DBMS_OUTPUT. ❍ September 2005
PUT_LINE('SQLERRM: ❍ October 2005
' || SQLERRM); November 2005
DBMS_OUTPUT.

December 2005
PUT_LINE

January 2006
('SQLCODE: ' ||

February 2006
SQLCODE); ❍

❍ March 2006
END ❍ April 2006
InsertIntoMyTable; ❍ May 2006
/ ❍ June 2006
❍ July 2006
EXEC
August 2006
InsertIntoMyTable

September 2006
(1);

October 2006
Inserting 1 into ❍

MyTable ❍ November 2006


❍ December 2006
PL/SQL procedure ❍ January 2007
successfully ❍ February 2007
completed. ❍ March 2007
April 2007
So let's try

May 2007
modifying the table,

June 2007
and try again.

❍ October 2007
ALTER TABLE
MyTable ADD
(MyString VARCHAR2
(32));

EXEC
InsertIntoMyTable
(2);
BEGIN
InsertIntoMyTable
(2); END;

*
ERROR at line 1:
ORA-06550: line 1,
column 7:
PLS-00905: object

http://thinkoracle.blogspot.com/2005/07/specifying-insert-columns.html (3 of 6)1/9/2008 2:51:58 AM


OracleBlog: Specifying INSERT Columns

SCOTT.
INSERTINTOMYTABLE
is invalid
ORA-06550: line 1,
column 7:
PL/SQL: Statement
ignored

The procedure fails,


and can't recompile.
Perhaps you want
that behaviour,
because you want
to require all your
procedures to be
checked every time
a related table has
changed. But, then
again, maybe you
don't.

In that case, modify


the stored
procedure to specify
which value you are
inserting, and then
you're good to go.
Let's repeat this test
that way:

CREATE OR
REPLACE
PROCEDURE
InsertIntoMyTable
(InValue IN NUMBER)
AS
BEGIN
DBMS_OUTPUT.
PUT_LINE('Inserting '
|| InValue || ' into
MyTable');
INSERT INTO
MyTable (MyInt)
VALUES (InValue);

http://thinkoracle.blogspot.com/2005/07/specifying-insert-columns.html (4 of 6)1/9/2008 2:51:58 AM


OracleBlog: Specifying INSERT Columns

EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.
PUT_LINE('SQLERRM:
' || SQLERRM);
DBMS_OUTPUT.
PUT_LINE
('SQLCODE: ' ||
SQLCODE);

END
InsertIntoMyTable;
/

SQL> EXEC
InsertIntoMyTable
(2);
Inserting 2 into
MyTable

PL/SQL procedure
successfully
completed.

SQL> ALTER TABLE


MyTable ADD
(MyOtherInt
NUMBER);

Table altered.

SQL> EXEC
InsertIntoMyTable
(3);
Inserting 3 into
MyTable

PL/SQL procedure
successfully
completed.

// posted by Robert
Vollman @ Monday, July

http://thinkoracle.blogspot.com/2005/07/specifying-insert-columns.html (5 of 6)1/9/2008 2:51:58 AM


OracleBlog: Specifying INSERT Columns

11, 2005

Comments: Post
a Comment

<< Home

http://thinkoracle.blogspot.com/2005/07/specifying-insert-columns.html (6 of 6)1/9/2008 2:51:58 AM


OracleBlog: Steven Feuerstein on Refactoring

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday, May 18,


About Me
2005
Name: Robert Vollman
Steven Location: Calgary, Alberta, Canada
Feuerstein on
Refactoring I was born and raised in Ottawa, and have lived
Refactoring for PL/ in Calgary since 1991. I like playing sports
SQL Developers (hockey, soccer, ultimate, basketball, you name it) and
By Steven Feuerstein military board games. I also enjoy reading, walking, and
playing with my 2 cats Lilly and Brutus. I'm a database
From Oracle Magazine application specialist, whatever that is.
January/February 2005
View my complete profile
http://www.oracle.
com/technology/
oramag/oracle/05-
jan/o15plsql.html
Best Links
● Ask Tom Kyte
Oracle Docs
Steven Feuerstein is

Dan Morgan and PSOUG


one of my favourite

PL/SQL authors, ● Steven Feuerstein


especially when he ● Jonathan Lewis
lays off the socio- ● FAQ
political tangents. ● Connor McDonald
● The Oak Table
I especially enjoyed ● Cary Millsap and Hotsos
his article on ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (1 of 11)1/9/2008 2:52:00 AM


OracleBlog: Steven Feuerstein on Refactoring

refactoring PL/SQL ● Anjo Kolk and OraPerf


code. I had a few ● Dizwell Oracle Wiki
thoughts to add to it. ● My Personal Blog

My additional
thoughts on
Refactoring: Aggregators
1. One of the Brian Duff's OraBlogs

advantages that also ❍ Eddie Awad's OracleNA


bears note is that re- ❍ Pete Finnigan's Aggregator
factoring your code ❍ Oracle's Bloglist
can encourage code ❍ Oracle Base Aggregator
re-use. Clean,
modular, well-written
code is easy to re-
Top Blogs
Oracle's Ask Tom Kyte
use, reducing future ❍

programming efforts. ❍ Oracle Guru Jonathan Lewis


❍ Blogger of the Year Eddie Awad
2. However, one of ❍ Data Warehouser David Aldridge
the disadvantages of ❍ Oracle Geek Lewis Cunningham
code re-factoring is ❍ Database Expert James Koopmann
that you can introduce ❍ Dizwell's Howard Rogers
unknown factors to a ❍ Oracle Master Laurent Schneider
(presumably) working,
Security Expert Pete Finnigan
trusted procedure.

Oracle Award Winner Mark Rittman


There is an expense

Doug Burns
to re-testing and re- ❍

validating the ❍ Oracle ACE of the Year Dr. Tim Hall


modified code. Even if ❍ UKOUG's Andrew (Arfur C.) Clarke
you FIXED errors, ❍ Newbie DBA Lisa Dobson
some other ❍ Coffee-Drinking DBA Jon Emmons
procedures might ❍ Chris Foot
have been written in ❍ The Pythian DBA Team Blog
such a way that they ❍ DBA Don Seiler
depend on them, and ❍ DBA Coskan Gundogar
they will now fail. ❍ Oracle WTF

My additional
imperfections in the ARCHIVES
unfactored code ❍ LIST ALL ARTICLES
sample: ❍ May 2005
❍ June 2005
1. Inline ❍ July 2005

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (2 of 11)1/9/2008 2:52:00 AM


OracleBlog: Steven Feuerstein on Refactoring

documentation ❍ August 2005


September 2005
I think Steven failed to

October 2005
point out the most

November 2005
egregious

December 2005
transgression: lack of ❍

inline documentation! ❍ January 2006


I believe almost every ❍ February 2006
procedure needs it, at ❍ March 2006
LEAST a 'header' but ❍ April 2006
preferrably also some ❍ May 2006
comments that ❍ June 2006
explain in plain ❍ July 2006
language what was ❍ August 2006
intended by the code. ❍ September 2006
Steven did go ahead
October 2006
and add some in-line

November 2006
documentation, but

December 2006
didn't draw any

attention to that. ❍ January 2007


❍ February 2007
* Note: Perhaps due to ❍ March 2007
his friendly nature, I ❍ April 2007
am referring to him in ❍ May 2007
this post in the ❍ June 2007
familiar. Certainly no ❍ October 2007
disrespect is intended.

2. Bad variable names

If this article was to


be re-written, I would
change the initial
code sample to use
very bad variable
names and then re-
name them as part of
the "refactored"
version. I think that's
a very common
problem.

My comments on the
refactored version:

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (3 of 11)1/9/2008 2:52:00 AM


OracleBlog: Steven Feuerstein on Refactoring

1. utl_file_constants

Rather than define my


own file
utl_file_constants, I
would use something
that was already
defined and possibly
tied in. I mean, there's
a REASON that 32767
was used. You are
bound by a particular
(probably OS-level, or
DB-level) limitation
that is probably
defined in some
package or some
configuration value,
or right in UTL_FILE.

If you define your own


and then all of a
sudden the 32767
limitation is changed
at the OS or DB level,
you STILL have to go
change all your
private constant
packages. I mean
that's a bit better than
having to change
magic numbers in
your code, but we can
do a little better, I
think.

get_next_line_from_file
isn't even aware of
that limitation. How
would this program
fail if you set the
value to, say, '4'
instead of '32767' in

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (4 of 11)1/9/2008 2:52:00 AM


OracleBlog: Steven Feuerstein on Refactoring

utl_file_constants?

It appears like Steven


didn't even use his
utl_file_constant for
32767 in the final
version (Code Listing
7). Why not? The
answer is probably
that you can not
dynamically define the
length of a string.
That is, of course, a
PL/SQL restriction. I
suppose we should be
happy with whatever
magic numbers we
can remove.

2. compare_latest_read

I'm really not sure I


would have created
"compare_latest_read".
That seems like we
are overdoing it. I
mean this is not a big
procedure and its
entire point is to do
what is in that
procedure anyway.
Why introduce the
overhead of another
procedure (assuming
there is any overhead)?

Think of it this way,


you are passing in the
lines. Instead of that,
you could pass in the
files and
compare_latest_read
can call
get_next_line_from_file

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (5 of 11)1/9/2008 2:52:00 AM


OracleBlog: Steven Feuerstein on Refactoring

to get the lines. That


would be reasonable.
But now, all of a
sudden, the main
procedure is doing
nothing but
initialising and calling
a procedure. So
basically
"compare_latest_read"
is one reasonable
change away from
already doing all the
work.

So why is it even
necessary? It is only
done once ... How is
the purpose of this
internal procedure
significantly different
from the purpose of
the overall procedure?
I suppose this is just
an opinion, and a
matter of taste, but I
really think the extra
procedure is
unnecessary.

Other comments and


questions:

1. VARCHAR2 length

In the procedure
Steven uses
VARCHAR2 as a
variable-lengthed
string even though we
know the maximum
size (32767). Is there
any value in
specifying VARCHAR2

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (6 of 11)1/9/2008 2:52:00 AM


OracleBlog: Steven Feuerstein on Refactoring

(32767) instead of
VARCHAR2 in the final
version (as the IN or
OUT parameters)? Is
there any advantage
to that? Is it even
possible?

2. Procedures vs
Functions

Any reason why


Steven uses
procedures instead of
functions?

3. Cleanup: closing an
unopened file

In "cleanup", will there


be a problem if you
UTL_FILE.fclose a file
that hasn't been
opened? Because that
will happen if there is
an exception while
opening the first file
when cleanup closes
both.

4. Handling "WHEN
OTHERS"

WHEN OTHERS -
cleanup .... without
any error message
written to screen or
log?? For shame!
Steven said earlier in
the article you would
re-raise the
exception, but in the
end he didn't.

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (7 of 11)1/9/2008 2:52:00 AM


OracleBlog: Steven Feuerstein on Refactoring

Plus the problem with


re-raising an
exception is you are
actually getting a NEW
exception. If it is
checked later, the
error messages will
say the error was
created at this new
line number instead
of the original spot.
Might as well fully
handle the exception
right here when we
catch it.

Conclusion:

A sure sign of a good


article is that it gets
you thinking. Steven
Feuerstein rarely fails
to achieve that. I have
shared these thoughts
with him, and I'll
follow-up with any
answers or
clarification he
provides.

I noticed Harm
Vershuren had some
thoughts in his blog
as well:
http://technology.
amis.nl/blog/index.
php?p=317

// posted by Robert
Vollman @ Wednesday, May

18, 2005

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (8 of 11)1/9/2008 2:52:00 AM


OracleBlog: Steven Feuerstein on Refactoring

Comments:
Regarding your
question:

2. Procedures vs
Functions

Any reason why


Steven uses
procedures instead of
functions?

IMO, there are two


reasons for this: First
of all, he uses more
then just one OUT
parameter. With
functions he would
still need an out
parameter, which
would lead to even
more confusion
because return values
now come through
two different ways.

Secondly, in pl/sql I
find the readability is
much higher if you
use procedures:

declare
l_stepresult varchar2
(10) := 'GO';
begin
while l_stepresult !=
'STOP' loop
do_first_step (param1,
param2, param3,
l_stepresult);
do_next_step
(param3, param4,
param5, l_stepresult);

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (9 of 11)1/9/2008 2:52:00 AM


OracleBlog: Steven Feuerstein on Refactoring

. end loop;
.
.
end;

The line starts with


what you actually do.
Using functions I find
it somewhat less
obvious what
actually is going on.

declare
l_stepresult varchar2
(10) := 'GO';
begin
while l_stepresult !=
'STOP' loop
l_stepresult :=
do_first_step (param1,
param2, param3);
l_stepresult :=
do_next_step
((param3, param4,
param5, l_stepresult);
end loop;
.
.
end;

My 2 ct (euro)

Cheers,
Holger
# posted by
Anonymous : Thursday,
19 May, 2005

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (10 of 11)1/9/2008 2:52:00 AM


OracleBlog: Steven Feuerstein on Refactoring

http://thinkoracle.blogspot.com/2005/05/steven-feuerstein-on-refactoring.html (11 of 11)1/9/2008 2:52:00 AM


OracleBlog: Use Constraints

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, July 26, 2005


About Me
Use Constraints Name: Robert Vollman
I was ready to explain to you why Location: Calgary, Alberta,
you should take advantage of Canada
Oracle's ability to manage the
integrity of your data rather than
I was born and raised in Ottawa,
rely on your applications, but I
and have lived in Calgary since 1991. I like
found a much better explanation
playing sports (hockey, soccer, ultimate,
in the Oracle Data Warehousing
basketball, you name it) and military board
Guide. Read the section "Why
games. I also enjoy reading, walking, and
Integrity Constraints are Useful in
playing with my 2 cats Lilly and Brutus. I'm a
a Data Warehouse" in Chapter 7 on
database application specialist, whatever that
"Integrity Constraints."
is.
So instead, let me give you a just a
really quick primer from my own View my complete profile
experience, and a couple of treats.

There are many types of


constraints, including primary key,
Best Links
Ask Tom Kyte
unique, referential (foreign key)

and check constraints. I'll talk ● Oracle Docs


about check constraints. ● Dan Morgan and PSOUG
● Steven Feuerstein
There are basically three ways to ● Jonathan Lewis
set up your table constraint. Check ● FAQ
a reference (like Dan Morgan's ● Connor McDonald

http://thinkoracle.blogspot.com/2005/07/use-constraints.html (1 of 6)1/9/2008 2:52:03 AM


OracleBlog: Use Constraints

http://www.psoug.org/reference/ The Oak Table


constraints.html) for more detail, ● Cary Millsap and Hotsos


but I will review them here. ● Steve Adams and Ixora
● Anjo Kolk and OraPerf
1. On the Same Line ● Dizwell Oracle Wiki
My Personal Blog
CREATE TABLE ConstraintTable (

MyNumber NUMBER(1) CHECK


(MyNumber < 5)
);
Aggregators
Using this method (only), you can't Brian Duff's OraBlogs

reference other columns in the ❍ Eddie Awad's OracleNA


table in your check constraint. Try ❍ Pete Finnigan's Aggregator
it: ❍ Oracle's Bloglist
Oracle Base Aggregator
CREATE TABLE ConstraintTable (

MyNumber1 NUMBER(1),
MyNumber2 NUMBER(1) CHECK Top Blogs
(MyNumber2 > MyNumber1) ❍ Oracle's Ask Tom Kyte
); ❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
ORA-02438: Column check Data Warehouser David Aldridge
constraint cannot reference other

Oracle Geek Lewis Cunningham


columns

❍ Database Expert James Koopmann


It is also not obvious what name ❍ Dizwell's Howard Rogers
the constraint takes so it's more ❍ Oracle Master Laurent Schneider
difficult to alter it later. But here is ❍ Security Expert Pete Finnigan
how: ❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
SQL> SELECT constraint_name ❍ Oracle ACE of the Year Dr. Tim Hall
2 FROM user_constraints
UKOUG's Andrew (Arfur C.) Clarke
3 WHERE table_name =

Newbie DBA Lisa Dobson


'CONSTRAINTTABLE';

❍ Coffee-Drinking DBA Jon Emmons


CONSTRAINT_NAME ❍ Chris Foot
------------------------------ ❍ The Pythian DBA Team Blog
SYS_C007536 ❍ DBA Don Seiler
❍ DBA Coskan Gundogar
2. During table creation ❍ Oracle WTF
Example:
ARCHIVES
CREATE TABLE ConstraintTable ( ❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/07/use-constraints.html (2 of 6)1/9/2008 2:52:03 AM


OracleBlog: Use Constraints

MyNumber NUMBER(1) ❍ May 2005


CONSTRAINT c_my_number CHECK ❍ June 2005
(MyNumber < 5) ❍ July 2005
); ❍ August 2005
September 2005
Doing it this way allows you to ❍

reference other columns in the ❍ October 2005


table: ❍ November 2005
❍ December 2005
SQL> CREATE TABLE ❍ January 2006
ConstraintTable ( ❍ February 2006
2 MyNumber1 NUMBER(1), ❍ March 2006
3 MyNumber2 NUMBER(1), ❍ April 2006
4 CONSTRAINT c_my_number
May 2006
CHECK (MyNumber2 >

June 2006
MyNumber1)

July 2006
5 ); ❍

❍ August 2006
3. Alter table ❍ September 2006
❍ October 2006
You can create your table as ❍ November 2006
normal, and then add your ❍ December 2006
constraints separately. I don't January 2007
think there is any actual difference

February 2007
to Oracle between method #2 and

March 2007
#3.

❍ April 2007
CREATE TABLE ConstraintTable ❍ May 2007
(MyNumber Number(1)); ❍ June 2007
❍ October 2007
ALTER TABLE ConstraintTable ADD
CONSTRAINT c_my_number check
(MyNumber < 5);

There is actually a 4th way, kind


of. See, CHECK constraints can not
include sub-queries, and you can't
reference other tables in them.
You also can't use package-
defined constants or variables. All
you can basically do is simple
things, like <>=, and [not]
between/in/like/equals

http://thinkoracle.blogspot.com/2005/07/use-constraints.html (3 of 6)1/9/2008 2:52:03 AM


OracleBlog: Use Constraints

I get around all of this by using


triggers. I add a simple constraint
to the table (possibly a "NOT
NULL", if applicable) and then write
a trigger which will do my check -
referencing other tables, writing
subqueries and using package-
defined constants as I please -
and then deliberately set off the
simple constraint.

Of course, this may look silly to a


user, who gets an error on
inserting a row with a NULL value
when it clearly isn't NULL. So I
usually write something to a log,
or name my simple constraint, and
I certainly document the source
code. But that's a topic for another
day.

Here is an article where I describe


the concept in more detail, picking
especially on using variables in
constraints. But apply the same
logic for complex integrity
constraints when you want to
reference other tables.

http://thinkoracle.blogspot.
com/2005/06/variable-
constraints.html

Ok, let me wrap it up by saying


that one of the other advantages
of constraints is that you can
disable them when you need to:

SQL> INSERT INTO


ConstraintTable (MyNumber)
VALUES (6);

ORA-02290: check constraint (SYS.


SYS_C007536) violated

http://thinkoracle.blogspot.com/2005/07/use-constraints.html (4 of 6)1/9/2008 2:52:03 AM


OracleBlog: Use Constraints

(By the way, that's the other way to


find out the name of your
constraint: violate it!)

SQL> ALTER TABLE


ConstraintTable DISABLE
CONSTRAINT SYS_C007536;

SQL> INSERT INTO


ConstraintTable (MyNumber)
VALUES (6);

And you're ok! Of course, you


better make sure the data is ok by
the time you turn it back on, or
you'll get this error:

SQL> ALTER TABLE


ConstraintTable ENABLE
CONSTRAINT SYS_C007536;

ORA-02293: cannot validate (SYS.


SYS_C007536) - check constraint
violated

Which is a great segue into my


closing, which includes two of my
favourite discussions on disabling
and deferring constraints. Check
them out:

Jeff Hunter
http://marist89.blogspot.
com/2005/06/deferrable-
constraints_29.html

Doug Burns
http://doug.burns.tripod.com/
oracle/index.blog?
entry_id=1170846

// posted by Robert Vollman @ Tuesday,

http://thinkoracle.blogspot.com/2005/07/use-constraints.html (5 of 6)1/9/2008 2:52:03 AM


OracleBlog: Use Constraints

July 26, 2005

Comments:
Why don't you throw an exception
in the trigger rather than creating
a constraint and having the trigger
cause the constraint validation to
fail? If you throw your own
exception, you can control the
error message and error number,
so it'll be more obvious to the user
what the problem was. It also puts
the error throwing logic close to
where you find the problem, which
should make it easier for later
developers to follow.
# posted by Justin : Wednesday, 27 July,
2005

But if you give your check


constraint a name that is obvous
enough you will achieve the same
thing without coding out a trigger.

For simple checks I think the


solution of a check constraint is
quite elegant
# posted by Anonymous : Tuesday, 09
October, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/07/use-constraints.html (6 of 6)1/9/2008 2:52:03 AM


OracleBlog: Use Views

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, July 25, 2005


About Me
Use Views Name: Robert Vollman
Very often the solution to a problem Location: Calgary, Alberta,
involves using a view. Use Views! Canada
What is a View?
I was born and raised in
Most people think of a view either as Ottawa, and have lived in Calgary since
a stored, named query, or as a 1991. I like playing sports (hockey, soccer,
"virtual table." ultimate, basketball, you name it) and
military board games. I also enjoy reading,
Here are two definitions from Oracle, walking, and playing with my 2 cats Lilly
along with references to the key and Brutus. I'm a database application
documents on Views to review. specialist, whatever that is.

"A logical representation of a table or View my complete profile


combination of tables."
- Oracle Application Developer's
Guide, Section 2.11 (Views)
Best Links
"A view takes the output of a query ● Ask Tom Kyte
and presents it as a table." ● Oracle Docs
- Oracle Concepts Guide, Section ● Dan Morgan and PSOUG
10.16 (Views) ● Steven Feuerstein
Jonathan Lewis
How do you create a View?

● FAQ
Nothing could be easier. Here: ● Connor McDonald

http://thinkoracle.blogspot.com/2005/07/use-views.html (1 of 7)1/9/2008 2:52:05 AM


OracleBlog: Use Views

The Oak Table


CREATE OR REPLACE VIEW MyView AS ● Cary Millsap and Hotsos


(Insert Query Here!) ● Steve Adams and Ixora
Anjo Kolk and OraPerf
For more, you can always reference

Dizwell Oracle Wiki


Dan Morgan's library: ●

http://www.psoug.org/reference/ ● My Personal Blog


views.html

How do I use Views?


Aggregators
Treat it just like a table. You can Brian Duff's OraBlogs

query them, as well as insert, update ❍ Eddie Awad's OracleNA


and delete*. Bear in mind that these Pete Finnigan's Aggregator
actions will update the base table(s).

Oracle's Bloglist
Likewise, any changes to the base

Oracle Base Aggregator


table(s) will automatically update the

View*.
Top Blogs
*This is true in general. Some Views ❍ Oracle's Ask Tom Kyte
can't be updated, and you can make ❍ Oracle Guru Jonathan Lewis
a View READONLY. ❍ Blogger of the Year Eddie Awad
Data Warehouser David Aldridge
Here is how to tell what Views exist:

❍ Oracle Geek Lewis Cunningham


SELECT view_name FROM user_views; ❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
Here is how to tell what the View is: ❍ Oracle Master Laurent Schneider
Security Expert Pete Finnigan
SELECT text FROM user_views WHERE

Oracle Award Winner Mark Rittman


view_name = 'MyView';

❍ Doug Burns
Why are they useful? ❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
I use them for many reasons, here ❍ Newbie DBA Lisa Dobson
are the most common situations ❍ Coffee-Drinking DBA Jon Emmons
where I will advocate their use: ❍ Chris Foot
The Pythian DBA Team Blog
1. Denormalizing the database ❍

❍ DBA Don Seiler


Sometimes its nice to pull related ❍ DBA Coskan Gundogar
data from several tables into a single ❍ Oracle WTF
table. Using views allows you to
satisfy both the Fabian Pascalesque
relational database purist, and the
ARCHIVES
❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/07/use-views.html (2 of 7)1/9/2008 2:52:05 AM


OracleBlog: Use Views

pragmatic user. ❍ May 2005


June 2005
2. Making things look better

❍ July 2005
For example, you can use a view to ❍ August 2005
substitute a generic ID number with ❍ September 2005
the name of the individual. You can ❍ October 2005
leave out columns that are rarely ❍ November 2005
interesting. You can use a view to ❍ December 2005
add information that is derived from ❍ January 2006
other data, for example figure out ❍ February 2006
everyone's salary in Canadian dollars ❍ March 2006
in an international organisation. ❍ April 2006
May 2006
3. Complex queries/query ❍

simplification ❍ June 2006


❍ July 2006
You might have several queries that ❍ August 2006
have to perform similar logic. You ❍ September 2006
can just create a view for that logic, ❍ October 2006
and make the queries far simpler. ❍ November 2006
Also, when I can't figure out how to ❍ December 2006
write a really complex query, January 2007
sometimes I just create views as

February 2007
intermediate steps.

❍ March 2007
For example, say you have a table of ❍ April 2007
expenses, with "department", "type" ❍ May 2007
and "total", a revenue table with the ❍ June 2007
same columns, and a department ❍ October 2007
table. Now you have to put together
a query that shows each department,
and their total expenses and
revenues, regardless of type.

Rather than write a really complex


query, just write a view (or two) that
contains the sum of the expenses
and revenues, by department. Then
you can create a query to put them
all into a single row by (outer)
joining on those views. Simple!

4. Restrict access to a column or row

http://thinkoracle.blogspot.com/2005/07/use-views.html (3 of 7)1/9/2008 2:52:05 AM


OracleBlog: Use Views

Say you want a user to have access


to only part of a table (either by row
or column). Here's what you do:
restrict his access to the table
completely, then create a view that
contains the information the user is
allowed to access, and then grant
that user access to the view.

5. Rename a column

Create a view which is exactly like


the table, but with the column
renamed. That is really easy, and it
will save you from having to possibly
update lots of other tables or
applications because you left the
base table alone. No, you can't write
indexes on views, but queries get
optimized as normal, and it will use
the base table's indexes at that time.

6. Change schema, but still support


an old version

Just like renaming a column. You can


completely re-design your database
schema, but create views to support
legacy applications who still rely on
the structure and naming of the
original. That will save a lot of hassle.

I will close with a really interesting


aspect of Views.

SQL> CREATE TABLE BaseTable


(MyNumber NUMBER(1));

Table created.

SQL> INSERT INTO BaseTable


(MyNumber) VALUES (1);

1 row created.

http://thinkoracle.blogspot.com/2005/07/use-views.html (4 of 7)1/9/2008 2:52:05 AM


OracleBlog: Use Views

SQL> CREATE VIEW MyView AS


SELECT * FROM BaseTable;

View created.

SQL> ALTER TABLE BaseTable ADD


(MyString VARCHAR2(32));

Table altered.

SQL> INSERT INTO BaseTable


(MyNumber, MyString) VALUES (2,
'Hello');

1 row created.

SQL> SELECT * FROM MyView;

MYNUMBER
----------
1
2

SQL> SELECT * FROM BaseTable;

MYNUMBER MYSTRING
----------
--------------------------------
1
2 Hello

The View is NOT updated when the


BaseTable is, even when you SELECT
*. When you write SELECT * the view
chooses its columns then and there.

// posted by Robert Vollman @ Monday, July

25, 2005

Comments:
Nice write up, only thing you might
explore later is "are views generaly

http://thinkoracle.blogspot.com/2005/07/use-views.html (5 of 7)1/9/2008 2:52:05 AM


OracleBlog: Use Views

purpose" - or are they more like a


stored procedure, single minded.

I think of them as the latter from a


performance perspective.
Most people want them as the
former from a "we don't want too
many things" perspective.
# posted by Thomas Kyte : Monday, 25
July, 2005

change generaly to general in the


above :)
# posted by Thomas Kyte : Monday, 25
July, 2005

Robert, good write up.

How about expanding on the fact


that a CREATE VIEW xxx AS SELECT *
FROM yyy is parsed by Oracle as
CREATE VIEW xxx AS SELECT col1,
col2, ... FROM yyy? That's why when
you add another column, the view
definition is still valid but if you drop
an existing column (referred to by
the view), the view definition is
invalidated.
# posted by Peter K : Wednesday, 27 July,
2005

why we use view on single table?we


can use select query istead of view.
# posted by Anonymous : Wednesday, 03
May, 2006

Anonymous,

I don't understand your question.

http://thinkoracle.blogspot.com/2005/07/use-views.html (6 of 7)1/9/2008 2:52:05 AM


OracleBlog: Use Views

What difference does it make if the


view is on a single table? You can
always use a query instead of a view,
no matter how many tables are
involved in the view.

All of my points above (except #1)


are relevant to a view on either one,
or many tables.

Robert
# posted by Robert Vollman : Tuesday, 09
May, 2006

This is one of the ways to restrict


viewing in columns to users that
aren't allowed to see certain
columns. Have one group of users
see one view, and have another
group of users see another view. And
grant them rights to these views
accordingly. I see a very good use for
views.
# posted by Anonymous : Wednesday, 10
May, 2006

Like point #4 above? :)


# posted by Robert Vollman : Wednesday,
10 May, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/07/use-views.html (7 of 7)1/9/2008 2:52:05 AM


OracleBlog: Using Numerical Fields

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday,
About Me
September 12,
Name: Robert Vollman
2006
Location: Calgary, Alberta, Canada
Using
Numerical I was born and raised in Ottawa, and have lived in
Fields Calgary since 1991. I like playing sports (hockey,
soccer, ultimate, basketball, you name it) and military board games.
What is a
I also enjoy reading, walking, and playing with my 2 cats Lilly and
number? The
Brutus. I'm a database application specialist, whatever that is.
definition is
one of the
longest I've View my complete profile
seen, but
generally it
refers to a Best Links
quantity (or ● Ask Tom Kyte
sum, total, ● Oracle Docs
count) of units. Dan Morgan and PSOUG
Quantities can

Steven Feuerstein
be subjected to

Jonathan Lewis
all sorts of

calculations, ● FAQ
such as ● Connor McDonald
addition, ● The Oak Table
subtraction, ● Cary Millsap and Hotsos
multiplication ● Steve Adams and Ixora
and division. ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (1 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

● Dizwell Oracle Wiki


Sometimes ● My Personal Blog
numbers are
used for
ordering, as
well. So it
makes sense
Aggregators
to compare Brian Duff's OraBlogs

one number to ❍ Eddie Awad's OracleNA


another, not ❍ Pete Finnigan's Aggregator
only as being ❍ Oracle's Bloglist
greater or ❍ Oracle Base Aggregator

Top Blogs
lesser than
another, but
also by what Oracle's Ask Tom Kyte
number of

Oracle Guru Jonathan Lewis


units it is

Blogger of the Year Eddie Awad


greater.

❍ Data Warehouser David Aldridge


Which brings ❍ Oracle Geek Lewis Cunningham
me to my ❍ Database Expert James Koopmann
point. I've been ❍ Dizwell's Howard Rogers
asked on more ❍ Oracle Master Laurent Schneider
than one ❍ Security Expert Pete Finnigan
occasion why I ❍ Oracle Award Winner Mark Rittman
sometimes ❍ Doug Burns
favour the use
Oracle ACE of the Year Dr. Tim Hall
of VARCHAR2

UKOUG's Andrew (Arfur C.) Clarke


in situations

Newbie DBA Lisa Dobson


where others ❍

are using ❍ Coffee-Drinking DBA Jon Emmons


NUMBER. Take, ❍ Chris Foot
for example, ❍ The Pythian DBA Team Blog
my earlier post ❍ DBA Don Seiler
on creating an ❍ DBA Coskan Gundogar
appropriate ❍ Oracle WTF
Boolean type.

Some
ARCHIVES
LIST ALL ARTICLES
developers

think I should ❍ May 2005


have used ❍ June 2005
NUMBER(1) as ❍ July 2005
the type, ❍ August 2005

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (2 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

denote True as ❍ September 2005


1, False as 0, ❍ October 2005
and have a ❍ November 2005
check to make ❍ December 2005
sure the value ❍ January 2006
is either 0 or 1. ❍ February 2006
March 2006
That solution ❍

also works. But ❍ April 2006


there is a ❍ May 2006
reason I don't ❍ June 2006
use it. ❍ July 2006
❍ August 2006
It is true that ❍ September 2006
this method ❍ October 2006
has its
November 2006
advantages,

December 2006
not the least of

January 2007
which is

comfort to ❍ February 2007


programmers ❍ March 2007
who are used ❍ April 2007
to that (most ❍ May 2007
programming ❍ June 2007
languages ❍ October 2007
make that
conversion
implicitly).
They also claim
that you can
use
multiplication
for AND
operations,
and addition
for OR
operations.

Or can you?
True * False =
False, so ok,
multiplication
seems to work

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (3 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

fine. But
addition? True
+ True = 2. 2
is not a valid
value. And
what about
subtraction
and division?
"Oh those
don't apply"
Then it's not
an appropriate
use of
NUMBER, in my
mind. What
about square
root? What is
True to the
exponent
False? And so
on.

I don't mean to
pick on this
one example.
I've seen cases
where NUMBER
is used for all
sorts of things:
dates, credit
card numbers,
social
insurance/
security
numbers,
street address
house
numbers, zip
codes, and so
on. In some of
these cases
(though not
necessarily all),

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (4 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

it would have
been more
appropriate to
create a type: a
VARCHAR2
restricted to
numerical
characters, and
then use that
one type for all
such instances.

No, this is not


a critical point.
NUMBER will
work just fine,
and I have no
stories about
how people
got into
trouble by
using NUMBER
for something
that wasn't. But
consider the
importance of
having
precision and
accuracy in
your data.
Shouldn't we
be equally
precise in your
description of
the data?

That is why I
generally
prefer using
NUMBER only
in cases where
the field
actually is by

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (5 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

definition a
number, a
quantity of
units, and
eligible for all
numerical
operations. I'd
love to hear
your thoughts
on this matter
too.

// posted by
Robert
Vollman @ Tuesday,
September 12,

2006

Comments:
To simulate a
Boolean
datatype in
SQL, I usually
use 0 for false
and 1 for true.
It does not
matter to me
whether I store
the 0 or the 1
in a number or
a varchar2
datatype, but
since 0 and 1
are "numbers" I
usually use the
number
datatype.

I prefer 0/1
over y/n and
true/false just
to avoid

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (6 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

questions like
is it Y or y?, No
or no?, yes or
YES? true or
TRUE...
# posted by
Eddie Awad :
Tuesday, 12
September, 2006

I completely
agree with you.
How hard
could it
possibly be to
add a boolean
data type to
the database?

I also agree
with only using
numbers when
it's actually a
number. One
of the
problems with
storing
account
numbers is
when they
have leading
zeroes.

00000123 =
123 and that's
fine.

But when I
print 123 on a
check because
Oracle got rid
of the zeroes,
that's a

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (7 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

problem. If the
account
number was
stored as a
varchar2, that
wouldn't be a
problem.

Good post,

LewisC
# posted by
LewisC :
Tuesday, 12
September, 2006

A vendor-
specific
language I use
keeps the
values of yes
and no in a
parameter
table. This
way, you can
code
VARCHAR2(1)
yes and no
variables in the
user's
language, and
not be stuck
with Y and N in
a place that
uses Asian
languages and
French, or
whatever.

The language
also separates
out storage
from display,

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (8 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

so the
0000123 can
be kept in a
numeric field.
Formatting and
storage should
be separate
and in the db
(with
formatting as a
dictionary
attribute),
don't you think?
# posted by
Joel Garry :
Wednesday, 13
September, 2006

Thanks,
Robert. I put
this in Log
Buffer #10.

Cheers,
Dave.
Log Buffer
# posted by
Dave Edwards :
Friday, 15
September, 2006

To Joel,

I would prefer
a true boolean,
i.e. TRUE/
FALSE. I don't
want to say
IF var = 1 THEN
or
IF UPPER(var)

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (9 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

IN ('Y', 'YES',
'TRUE') THEN

I want to say
IF var THEN

And I don't
think the
format of a
varchar2 field
should be
removed from
the data unless
there is a
reason for it.
Should we
remove all the
white space
from a text
field? How
about
punctuation? I
want the data
in my database
to accurately
represent what
the data is and
what it means.
If there was a
GOOD reason
to remove the
formatting, I
would agree.
Just because
putting a
varchar in a
numeric does, I
wouldn't say
that's a good
practice.

Thanks,

LewisC

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (10 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

# posted by
LewisC : Friday,
15 September,
2006

Regarding TRUE
+TRUE=2, the
suggested
course would
simply to
check if the
results is 0 or
not 0. A lot of
languages do
this in their
conditional
structures, any
non-zero value
evaluates to
true.
# posted by
Don Seiler :
Tuesday, 26
September, 2006

Ok Don, but
then you have
the case where
TRUE does not
equal TRUE.
Check it out.

a=1
b=2
a and b are
both TRUE, but
they aren't
equal!

Instead of
if (a = b)

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (11 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

you have to
write
if (a = b OR (a
<> FALSE and
b <> FALSE)).
BAH!

TRUE+TRUE=2
just doesn't
make sense.
# posted by
Robert
Vollman : Tuesday,
26 September,
2006

Hi,
I use number
(1) to store
boolean values
(it's like bit
value for me).

so in my case
true + true is
eqvivalent to
bitwise
addition: 1 or
1=1
true * false is
eqvivalent to
bitwise
multiplication:
1 and 0 = 0

I ofen use sys.


diutil package
to convert
between int
and boolean..
http://psoug.
org/reference/
diutil.html

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (12 of 13)1/9/2008 2:52:08 AM


OracleBlog: Using Numerical Fields

Boolean is
internally
represented by
number in
every language
I know. So
that's another
reason why I
think that
number is
more
appropriate.
# posted by
Radoslav :
Sunday, 09
December, 2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/09/using-numerical-fields.html (13 of 13)1/9/2008 2:52:08 AM


OracleBlog: DBMS_OUTPUT.PUT_LINE

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated,
but it is the most powerful tool when it comes to data. That's why when I think data, I think Oracle. I
also enjoy writing, so I use this format to organise my thoughts. Please feel free to discuss any
thoughts you may have on the same topics, even old ones (I will see and respond to such
comments). You may want to start with "LIST ALL ARTICLES" under Archives.

Wednesday, October 12, 2005


DBMS_OUTPUT.PUT_LINE
DBMS_OUTPUT.PUT_LINE allows you to write information to a buffer throughout the
execution of a trigger/procedure. That information is available to be read by a
trigger/procedure (using GET_LINE(S)), or dumped to SQL*Plus upon completion of
execution.

One of the most common misconceptions is that PUT_LINE writes data immediately to
SQL*Plus. That is not true. PUT_LINE only puts it in the buffer. You will not see it
before the block has executed. I can prove that with this example (note: you must
load the user_lock package for this):

scott@Robert> BEGIN
2 DBMS_OUTPUT.PUT_LINE('Going to sleep for 10 seconds...');
3 USER_LOCK.SLEEP(1000);
4 DBMS_OUTPUT.PUT_LINE('Woke up after 10 seconds.');
5 END;
6/
Going to sleep for 10 seconds...
Woke up after 10 seconds.

You will have seen both messages come out after 10 seconds as opposed to one
before and one after.

Despite the fact that it doesn't write messages throughout its progress, PUT_LINE can
still make a useful debugging tool. I like the way that the messages can be kept but
easily disabled by using DBMS_OUTPUT.DISABLE. Any PUT_LINE messages are silently
ignored if you have DISABLEd DBMS_OUTPUT (or failed to ENABLE).

To see the messages, you need to call DBMS_OUTPUT.ENABLE. The only parameter is
buffer_size, which, if NULL, will default to 20000. The buffer size can be anywhere
from 2000 to 1000000.

scott@Robert> BEGIN

http://thinkoracle.blogspot.com/2005/10/dbmsoutputputline.html (1 of 7)1/9/2008 2:52:11 AM


OracleBlog: DBMS_OUTPUT.PUT_LINE

2 DBMS_OUTPUT.DISABLE;
3 DBMS_OUTPUT.PUT_LINE('Disabled');
4 DBMS_OUTPUT.ENABLE;
5 DBMS_OUTPUT.PUT_LINE('Enabled');
6 END;
7/
Enabled

PL/SQL procedure successfully completed.

Incidentally, SQL*Plus's SET SERVEROUTPUT ON will call DBMS_OUTPUT.ENABLE. You


can even use SIZE with that command. SET SERVEROUTPUT also includes formatting
options, such as FORMAT WRAPPED, WORD_WRAPPED and TRUNCATE (along with a
SET LINESIZE) to get the output the way you want it. [EDIT: Fixed Typo]

There are two common errors related to DBMS_OUTPUT.PUT_LINE. The first one is
trying to put more than 255 characters per line.

scott@Robert> DECLARE
2 l_string VARCHAR2(300);
3 BEGIN
4 l_string := '1234567890';
5 l_string := l_string || l_string || l_string || l_string || l_string;
6 l_string := l_string || l_string || l_string || l_string || l_string || l_string;
7 DBMS_OUTPUT.PUT_LINE(l_string);
8 END;
9/
DECLARE
*
ERROR at line 1:
ORA-20000: ORU-10028: line length overflow, limit of 255 chars per line
ORA-06512: at "SYS.DBMS_OUTPUT", line 35
ORA-06512: at "SYS.DBMS_OUTPUT", line 133
ORA-06512: at line 7

The solution here is to use DBMS_OUTPUT.NEW_LINE to split it up into lines. 255 is a


hard limit, if you really want to print a line with more than that, you can write your
own package that does the same thing as DBMS_OUTPUT. That is actually a very
common thing to do. Tom Kyte's has a handy one in Appendix A of "Expert One-on-
One Oracle."

The second common error is overfilling your buffer.

scott@Robert> BEGIN
2 DBMS_OUTPUT.ENABLE(2000);
3 FOR i IN 1..1000 LOOP
4 DBMS_OUTPUT.PUT_LINE('This is line ' || i);
5 END LOOP;
6 END;
7/

http://thinkoracle.blogspot.com/2005/10/dbmsoutputputline.html (2 of 7)1/9/2008 2:52:11 AM


OracleBlog: DBMS_OUTPUT.PUT_LINE

This is line 1

This is line 105


BEGIN
*
ERROR at line 1:
ORA-20000: ORU-10027: buffer overflow, limit of 2000 bytes
ORA-06512: at "SYS.DBMS_OUTPUT", line 35
ORA-06512: at "SYS.DBMS_OUTPUT", line 198
ORA-06512: at "SYS.DBMS_OUTPUT", line 139
ORA-06512: at line 4

The solution here is increase the size of your buffer, using ENABLE. The maximum
size is 1000000 and that is a hard limit. Once again, you can write your own package
as a workaround.

This example also illustrated that even if you have an exception, the contents of the
buffer until that point is still available.

The alternative to writing your own package is to write your messages to a table.
Then you can query the table at any time to see your debug messages. DBMS_PIPE is
another option to consider.

I will close with two more interesting "gotchas" for DBMS_OUTPUT.PUT_LINE.

scott@Robert> BEGIN
2 DBMS_OUTPUT.PUT_LINE(' What happened to my leading spaces?');
3 END;
4 /
What happened to my leading spaces?

This is an SQL*Plus Gotcha. Just be sure to use FORMAT WRAPPED, like so:

scott@Robert> SET SERVEROUTPUT ON FORMAT WRAPPED


scott@Robert> BEGIN
2 DBMS_OUTPUT.PUT_LINE(' There they are!');
3 END;
4 /
There they are!

Here is the second gotcha.

scott@Robert> DECLARE
2 l_bool BOOLEAN;
3 BEGIN
4 l_bool := TRUE;

http://thinkoracle.blogspot.com/2005/10/dbmsoutputputline.html (3 of 7)1/9/2008 2:52:11 AM


OracleBlog: DBMS_OUTPUT.PUT_LINE

5 DBMS_OUTPUT.PUT_LINE(l_bool);
6 END;
7/
DBMS_OUTPUT.PUT_LINE(l_bool);
*
ERROR at line 5:
ORA-06550: line 5, column 1:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
ORA-06550: line 5, column 1:
PL/SQL: Statement ignored

DBMS_OUTPUT.PUT_LINE is not overloaded for Booleans. The solution is to either to


write your own package (as mentioned above), or convert from Boolean type to
something else for the PUT_LINE call.

For more information, this package is described in (among other places) Oracle's
Supplied PL/SQL Packages Reference Guide, Chapter 43:
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612.pdf

And here is Dan Morgan's Quick Reference:


http://www.psoug.org/reference/dbms_output.html

// posted by Robert Vollman @ Wednesday, October 12, 2005

Comments:
I think those hard limits have gone in 10gR2

http://www.oracle.com/technology/oramag/oracle/05-sep/o55asktom.html

Cheers,

Doug
# posted by Doug Burns : Wednesday, 12 October, 2005

...SQL*Plus's SHOW SERVEROUTPUT ON will call...

I believe you meant SET SERVEROUTPUT ON.

And a follow-up to Doug's comment, here is a quote from the Oracle 10gR2
documentation:

PL/SQL programmers frequently use DBMS_OUTPUT and, in Oracle Database 10g


Release 1 and earlier, were constrained by the 255 byte limit. When using SQL*Plus,
most programmers are regularly caught by the small default overall limit and
sometimes by the current 1,000,000 maximum overall limit. In Release 2, the line
length limit is increased to 32,767 bytes and the overall limit is removed altogether.
# posted by Eddie Awad : Wednesday, 12 October, 2005

http://thinkoracle.blogspot.com/2005/10/dbmsoutputputline.html (4 of 7)1/9/2008 2:52:11 AM


OracleBlog: DBMS_OUTPUT.PUT_LINE

is there any place we can set SET SERVEROUT ON make it permanent


# posted by anand : Monday, 29 May, 2006

Yes, anand. To do this automatically in SQL*Plus, you are thinking of the glogin.sql
file, which can be found in your sqlplus/admin directory.

You can learn more about the glogin.sql file by checking the SQL*Plus User's Guide
and Reference.

http://oracleheva1.oracle.com/docs/cd/B10501_01/server.920/a90842.pdf
# posted by Robert Vollman : Monday, 29 May, 2006

How to truncate a variable in Oracle


# posted by Anonymous : Thursday, 28 June, 2007

what do you mean by truncating a variable... is it a variable in pl/sql block or


somewhat else..
# posted by valentine : Tuesday, 14 August, 2007

Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I like playing
sports (hockey, soccer, ultimate, basketball, you name it) and military board
games. I also enjoy reading, walking, and playing with my 2 cats Lilly and Brutus. I'm a
database application specialist, whatever that is.

View my complete profile

Best Links
http://thinkoracle.blogspot.com/2005/10/dbmsoutputputline.html (5 of 7)1/9/2008 2:52:11 AM
OracleBlog: DBMS_OUTPUT.PUT_LINE

● Ask Tom Kyte


● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

http://thinkoracle.blogspot.com/2005/10/dbmsoutputputline.html (6 of 7)1/9/2008 2:52:11 AM


OracleBlog: DBMS_OUTPUT.PUT_LINE

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/10/dbmsoutputputline.html (7 of 7)1/9/2008 2:52:11 AM


OracleBlog: DBMS_PIPE

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics, even
old ones (I will see and respond to such comments). You may want to start with "LIST ALL
ARTICLES" under Archives.

Thursday, November 24, 2005


DBMS_PIPE
You would like to communicate with a 3rd-party application from your PL/
SQL program, for example you want to run a UNIX command. Or perhaps
you'd like to communicate directly with another Oracle session. Whatever
your specific communication needs are, DBMS_PIPE is your solution.

What is DBMS_PIPE?

DBMS_PIPE is a package provided by Oracle that allows two or more sessions


in the same instance to communicate.

If you know anything about UNIX pipes, its a similar concept in Oracle. It is
called a pipe because it connects two (or more) sessions, and messages are
queued up inside, just like a pipe. Each session can take the next received
item out of a pipe, or insert the next item to send. Anybody (with access)
can insert or remove something from the pipe, in any order. Messages can
only be removed and read once - two people can't remove the same
message from a pipe.

In more real terms, these pipes are buffers in the system global area (the
SGA). Messages are prepared for loading using PACK_MESSAGE, loaded into
a pipe using SEND_MESSAGE, and read similarly (RECEIVE_MESSAGE then
UNPACK_MESSAGE).

There are basically 3 different types of pipes. Briefly:


Implicit Public Pipe: Automatically created when first accessed, disappears
when it is emptym, available to entire schema

http://thinkoracle.blogspot.com/2005/11/dbmspipe.html (1 of 7)1/9/2008 2:52:13 AM


OracleBlog: DBMS_PIPE

Explicit Public Pipe: Created with CREATE_PIPE, freed with REMOVE_PIPE,


available to entire schema
Explicit Private Pipe: Created with CREATE_PIPE and private=true, freed with
REMOVE_PIPE, available only to that userid privileges, or SYSDBA.

Check chapter 45 of the PL/SQL Supplied Packages and Types Reference.


http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612.
pdf

Example:

For this test, open up two sessions as the SAME user on the SAME instance.
Make sure your user has access to the DBMS_PIPE package.

We are going to have the first instance create the pipe, send in an SQL
command, and have the second instance retrieve that message and execute
it. That should accomplish two things: show the basic usage of DBMS_PIPE,
and give Pete Finnigan a heart attack.

I have largely left out error-checking and handling, for brevity's sake. At
many points throughout the "ORA-23322" error is possible, which is for
insufficient privileges to access that pipe.

Session #1:

DECLARE
l_status NUMBER(2);
BEGIN
-- Create the pipe. 0 is success.
-- Possible error: name in use.
l_status := DBMS_PIPE.CREATE_PIPE (pipename => 'TEST_PIPE',
maxpipesize => 8192, private => TRUE);

-- Let's pack an instruction for another session.


-- Possible error: buffer overflow (4093 bytes of data)
DBMS_PIPE.PACK_MESSAGE(item => 'SELECT SYSDATE FROM DUAL;');

-- Let's stuff it into the pipe


-- We'll use defaults for maxpipesize and timeout
-- Returns 0 on success, 1 for timeout, 3 for interrupt
l_status := DBMS_PIPE.SEND_MESSAGE(pipename => 'TEST_PIPE');

-- Ok we're done, we should get 0 for success


l_status := DBMS_PIPE.REMOVE_PIPE (pipename => 'TEST_PIPE');
EXCEPTION

http://thinkoracle.blogspot.com/2005/11/dbmspipe.html (2 of 7)1/9/2008 2:52:13 AM


OracleBlog: DBMS_PIPE

WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE('SQLCODE: ' || SQLCODE);
END;

Session #2:

DECLARE
l_received_message VARCHAR2(128);
l_message_type NUMBER(2);
l_status NUMBER(2);
BEGIN
-- Receive the message, use default timeout
-- If the pipe doesn't exist, Oracle will create it,
-- and wait for a message.
-- Returns 0 on success, 1 on a timeout, 3 for an interrupt
l_status := DBMS_PIPE.RECEIVE_MESSAGE(pipename => 'TEST_PIPE');
-- Ok, so what type are we extracting?
-- 0 nothing, 6 number, 9 varchar2, 11 ROWID, 12 DATE, 23 RAW
l_message_type := DBMS_PIPE.NEXT_ITEM_TYPE;

-- Open up the message, we can get ORA-06556 or ORA-06559


-- if its the wrong time, or nothing is left.
IF (l_message_type = 9) THEN
DBMS_PIPE.UNPACK_MESSAGE(item => l_received_message);
EXECUTE IMMEDIATE(l_received_message);
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE('SQLCODE: ' || SQLCODE);
END;

By the way, I realise that I have removed the pipe in the first session before
accessing that message in the second session. But because there is still a
message in there, the pipe will stick around. To destroy it immediately I
would have to purge it first.

http://thinkoracle.blogspot.com/2005/11/dbmspipe.html (3 of 7)1/9/2008 2:52:13 AM


OracleBlog: DBMS_PIPE

More Examples:

The aforementioned guide has an example on how to use DBMS_PIPE for


debugging. There is also a great example on communication with the shell
to execute UNIX commands (like listing the contents of a directory). These
are complete, excellent examples.

I'll close with some other little notes about DBMS_PIPES:


- There is a constant called maxwait which determines how long the pipe
will wait for a message to be picked up.
- The two major errors with DBMS_PIPE are ORA-23321 (bad pipename) or
ORA-23322 (insufficient privileges).
- You can use PURGE to empty out a pipe, and RESET_BUFFER for the local
packing buffer
- You can use UNIQUE_SESSION_NAME to help distinguish between sessions
if there are several accessing the pipe.

// posted by Robert Vollman @ Thursday, November 24, 2005

Comments:
Heard a lot about DBMS_PIPES. Now I know what it is all about. :) Thanks.
# posted by Ram : Tuesday, 29 November, 2005

Robert: sorry that this is so off topic, but I see you have a link direct to my
old Blog. If, instead, you link to http://www.dizwell.com/oracle/articles/
the_dizwell_blog.html, that is guaranteed always to redirect you to the new
one, wherever it happens to be!
# posted by Howard J. Rogers : Wednesday, 30 November, 2005

Post a Comment

<< Home

About Me
Name: Robert Vollman

http://thinkoracle.blogspot.com/2005/11/dbmspipe.html (4 of 7)1/9/2008 2:52:13 AM


OracleBlog: DBMS_PIPE

Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it) and
military board games. I also enjoy reading, walking, and playing with my 2 cats Lilly
and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham

http://thinkoracle.blogspot.com/2005/11/dbmspipe.html (5 of 7)1/9/2008 2:52:13 AM


OracleBlog: DBMS_PIPE

❍ Database Expert James Koopmann


❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007

http://thinkoracle.blogspot.com/2005/11/dbmspipe.html (6 of 7)1/9/2008 2:52:13 AM


OracleBlog: DBMS_PIPE

❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/11/dbmspipe.html (7 of 7)1/9/2008 2:52:13 AM


OracleBlog: UTL_HTTP

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Sunday, August 14, 2005


About Me
UTL_HTTP Name: Robert Vollman
Let's say you want to pull some real- Location: Calgary, Alberta,
time information off the Internet Canada
and put it in your database. For
example:
I was born and raised in
- Stock Market Quotes
Ottawa, and have lived in Calgary since
- Temperature
1991. I like playing sports (hockey, soccer,
- Sports scores
ultimate, basketball, you name it) and
No need to write a separate military board games. I also enjoy reading,
application in Java or whatever, you walking, and playing with my 2 cats Lilly
can do it all directly in Oracle. and Brutus. I'm a database application
specialist, whatever that is.
Your solution will involve using one
of the many handy Oracle built-in View my complete profile
utilities: UTL_HTTP.

For reference, flip open Chapter 78


of the 'Supplied PL/SQL Packages
Best Links
and Types Reference'. ● Ask Tom Kyte
● Oracle Docs
Tom Kyte also had a discussion in ● Dan Morgan and PSOUG
the Appendix of "Expert One-on- ● Steven Feuerstein
One Oracle", and also on Ask Tom: ● Jonathan Lewis
http://asktom.oracle.com/pls/ask/f? ● FAQ
p=4950:8::::: ● Connor McDonald

http://thinkoracle.blogspot.com/2005/08/utlhttp.html (1 of 6)1/9/2008 2:52:16 AM


OracleBlog: UTL_HTTP

F4950_P8_DISPLAYID:285215954607 The Oak Table


● Cary Millsap and Hotsos


Let's look at a simple example, ● Steve Adams and Ixora
grabbing a market quotation. ● Anjo Kolk and OraPerf
Dizwell Oracle Wiki
You can get the latest quotes from

My Personal Blog
Yahoo Finance. Using UTL_HTTP.

REQUEST, you can get the content of


that page, and then search within
for the data you want.
Aggregators
SELECT UTL_HTTP.REQUEST('http:// Brian Duff's OraBlogs

finance.yahoo.com/q?s=KMP') FROM ❍ Eddie Awad's OracleNA


DUAL; ❍ Pete Finnigan's Aggregator
Oracle's Bloglist
If you're behind a firewall, include

the IP or name of your proxy server ❍ Oracle Base Aggregator


as the second parameter.
Top Blogs
For simplicity, I'm not including the ❍ Oracle's Ask Tom Kyte
output here, but you can see that we ❍ Oracle Guru Jonathan Lewis
don't have our quote in there. That's Blogger of the Year Eddie Awad
because we only got the first 2000

Data Warehouser David Aldridge


bytes of the web page. If we want

Oracle Geek Lewis Cunningham


more, we need to use

REQUEST_PIECES. ❍ Database Expert James Koopmann


❍ Dizwell's Howard Rogers
Down below I have included a ❍ Oracle Master Laurent Schneider
working example. It's roughly ❍ Security Expert Pete Finnigan
thrown together, but it does ❍ Oracle Award Winner Mark Rittman
illustrate the point: you can use ❍ Doug Burns
UTL_HTTP to retrieve information ❍ Oracle ACE of the Year Dr. Tim Hall
from the Internet that you can put in UKOUG's Andrew (Arfur C.) Clarke
the database.

❍ Newbie DBA Lisa Dobson


As an aside, talk to some lawyers to ❍ Coffee-Drinking DBA Jon Emmons
make sure the data you are mining ❍ Chris Foot
is not violating any copyrights. ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
After you write stored procedures to ❍ DBA Coskan Gundogar
retrieve web pages, and to extract ❍ Oracle WTF
information from within and insert
them into the database, you can
automate the updates by calling the
ARCHIVES
❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/08/utlhttp.html (2 of 6)1/9/2008 2:52:16 AM


OracleBlog: UTL_HTTP

stored procedures using DBMS_JOB ❍ May 2005


(a topic for another day!). ❍ June 2005
July 2005
SET SERVEROUTPUT ON

❍ August 2005
DECLARE ❍ September 2005
l_pieces UTL_HTTP.HTML_PIECES; ❍ October 2005
-- We'll look at two 2000-byte ❍ November 2005
pages at a time ❍ December 2005
l_two_pages VARCHAR2(4000); ❍ January 2006
l_start_read NUMBER; ❍ February 2006
l_end_read NUMBER; ❍ March 2006
l_quote VARCHAR2(12); ❍ April 2006
BEGIN
May 2006
-- Grab up to a maxium of 32 2000-

June 2006
byte pages, and then go through

July 2006
them, ❍

-- looking at 2 pages at a time in ❍ August 2006


case the data we are looking for ❍ September 2006
-- overlaps a page boundary ❍ October 2006
l_pieces := UTL_HTTP. ❍ November 2006
REQUEST_PIECES('http://finance. ❍ December 2006
yahoo.com/q?s=KMP', 32); ❍ January 2007
FOR i IN 1 .. l_pieces.COUNT LOOP ❍ February 2007
l_two_pages := l_two_pages || ❍ March 2007
l_pieces(i); ❍ April 2007
-- Look for a string preceding the May 2007
information we want

June 2007
-- If we find it, add 52 (magic,

October 2007
Yahoo-specific number)

-- to find the point where the quote


will begin
SELECT INSTR(l_two_pages, 'Last
Trade', 1, 1) INTO l_start_read FROM
dual;
IF (l_start_read > 0) THEN
l_start_read := l_start_read + 52;
IF (l_start_read < 3950) THEN
SELECT INSTR(l_two_pages, '<',
l_start_read, 1) INTO l_end_read
FROM dual;
IF (l_end_read > 0) THEN
IF ((l_end_read - l_start_read) < 12)

http://thinkoracle.blogspot.com/2005/08/utlhttp.html (3 of 6)1/9/2008 2:52:16 AM


OracleBlog: UTL_HTTP

THEN
SELECT SUBSTR(l_two_pages,
l_start_read, l_end_read -
l_start_read) INTO l_quote FROM
dual;
DBMS_OUTPUT.PUT_LINE(l_quote);
ELSE
DBMS_OUTPUT.PUT_LINE('Error
(Quote more than 12 chars)');
END IF;
EXIT;
END IF;
END IF;
END IF;
l_two_pages := l_pieces(i);
END LOOP;
END;

// posted by Robert Vollman @ Sunday,

August 14, 2005

Comments:
Good write up and easy to
understand example. I will be
checking out the UTL_HTTP
packages. Just wanted to note that
Pete Finnigan also talked about your
entry on his blog and has a simple
caveat

Remember that this package can


also be used in the opposite
direction and data can be extracted
from the database. Also it can be
used to load and run hacker SQL or
PL/SQL scripts that are stored on an
external web site. Beware of default
privileges and useful functionality.
# posted by Peter K : Monday, 15 August,
2005

http://thinkoracle.blogspot.com/2005/08/utlhttp.html (4 of 6)1/9/2008 2:52:16 AM


OracleBlog: UTL_HTTP

Thanks! Link to Pete Finnigan's


article is here:
http://www.petefinnigan.com/
weblog/archives/00000512.htm

On the coaxing of the guys at work,


I quickly put together a stored
procedure that will automatically fill
out our office hockey pool using
this technique. Anyone who wants
this small, rough demo can send me
an email for a copy.
# posted by Robert Vollman : Monday, 15
August, 2005

In response to some people who


have asked me privately, yes, taking
advantage of Regular Expressions in
Oracle 10 is an excellent way to
avoid the "magic number" kluge I
used here. Finding (or writing) a
good HTML/XML parser (including
what Oracle has built-in) is a great
idea, too.
# posted by Robert Vollman : Wednesday,
24 August, 2005

Interesting blog. I have a java xml


blog.
# posted by Steve Austin : Sunday, 02
October, 2005

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/08/utlhttp.html (5 of 6)1/9/2008 2:52:16 AM


OracleBlog: UTL_HTTP

http://thinkoracle.blogspot.com/2005/08/utlhttp.html (6 of 6)1/9/2008 2:52:16 AM


OracleBlog: Oracle DO NOTs

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Sunday, January 15, 2006


About Me
Oracle DO NOTs Name: Robert Vollman
Here is another interesting discussion Location: Calgary, Alberta,
taking place on AskTom about Oracle Canada
DO NOTs:

http://asktom.oracle.com/pls/ask/f? I was born and raised in


Ottawa, and have lived in Calgary since
p=4950:8:::::
1991. I like playing sports (hockey,
F4950_P8_DISPLAYID:53901314988148 soccer, ultimate, basketball, you name
it) and military board games. I also enjoy
After Tom responded, a lot of people
reading, walking, and playing with my 2
got into it. I had some ideas myself,
cats Lilly and Brutus. I'm a database
but decided not to make one of my
application specialist, whatever that is.
famous Top 20 Lists after all, since it
wound up similar to this one:
View my complete profile
http://thinkoracle.blogspot.
com/2005/12/20-plsql-coding-tips.
html Best Links
● Ask Tom Kyte
For those of you who are curious, here ● Oracle Docs
is more or less what was covered by ● Dan Morgan and PSOUG
Tom or his guests: ● Steven Feuerstein
Tom: ● Jonathan Lewis
1. Don't accept string literals from end ● FAQ
users and concatenate them into your ● Connor McDonald

http://thinkoracle.blogspot.com/2006/01/oracle-do-nots.html (1 of 4)1/9/2008 2:52:19 AM


OracleBlog: Oracle DO NOTs

SQL. In other words, use binds. This The Oak Table


isn't just for efficiency, its more to ● Cary Millsap and Hotsos
prevent execution of malicious code. ● Steve Adams and Ixora
Yes, I know I did this one when ● Anjo Kolk and OraPerf
demonstrating DBMS_PIPE.http:// ● Dizwell Oracle Wiki
thinkoracle.blogspot.com/2005/11/ ● My Personal Blog
dbmspipe.html

2. Don't test on an empty or near-


empty database (you need real
volumes)
Aggregators
Brian Duff's OraBlogs

3. Don't test with a single user (you'll ❍ Eddie Awad's OracleNA


miss scalability issues) ❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
4. Don't forget to use a source control ❍ Oracle Base Aggregator
system.

5. Don't wing it as you go along,


Top Blogs
design in advance. ❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
One responded (our buddy Bill) that ❍ Blogger of the Year Eddie Awad
you shouldn't do anything without a ❍ Data Warehouser David Aldridge
spec. ❍ Oracle Geek Lewis Cunningham
Database Expert James Koopmann
6. Don't take advice from experts

without testing to see if it applies to ❍ Dizwell's Howard Rogers


you. ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
7. Don't optimize by hypothesize. Test! ❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
From Others: ❍ Oracle ACE of the Year Dr. Tim Hall
8. Don't reinvent the wheel, use built- ❍ UKOUG's Andrew (Arfur C.) Clarke
in packages ❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
9. Don't ignore the Oracle ❍ Chris Foot
documentation, there is a wealth of ❍ The Pythian DBA Team Blog
information there. ❍ DBA Don Seiler
DBA Coskan Gundogar
10. Don't use technologies because

Oracle WTF
they are cool.

11. Don't hesitate to throw away bad ARCHIVES


code, rewriting can be better than ❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2006/01/oracle-do-nots.html (2 of 4)1/9/2008 2:52:19 AM


OracleBlog: Oracle DO NOTs

refactoring. ❍ May 2005


June 2005
This actually resulted in some debate.

July 2005
Sometimes you want to let sleeping

August 2005
dogs lie. That is, if the code works,

September 2005
don't spend days re-factoring it unless ❍

you need to. ❍ October 2005


❍ November 2005
12. Don't write code without ❍ December 2005
documentation/comments ❍ January 2006
❍ February 2006
Here is a great language-neutral link:
March 2006
http://tlug.up.ac.za/old/htwuc/

April 2006
unmain.html

❍ May 2006
June 2006
13. Don't name variables arbitrarily. ❍

❍ July 2006
14. Don't skip your unit-testing ❍ August 2006
❍ September 2006
15. Don't comment your SQL to ❍ October 2006
override the optimizer plan unless you ❍ November 2006
are sure.
❍ December 2006
16. Don't forget to update comments ❍ January 2007
when you update code. ❍ February 2007
❍ March 2007
17. Don't forget to instrument your ❍ April 2007
code. ❍ May 2007
June 2007
What is instrumentation? Well, read

October 2007
Mogens Norgaard, or start with this

link:
http://tkyte.blogspot.com/2005/06/
instrumentation.html

18. Don't forget to mention


dependencies when commenting code.

19. Don't expect the same database on


two different hosts to work exactly the
same.

20. Don't modify init.ora parameters


without documenting the originals.

http://thinkoracle.blogspot.com/2006/01/oracle-do-nots.html (3 of 4)1/9/2008 2:52:19 AM


OracleBlog: Oracle DO NOTs

21. Don't neglect to collect histogram


data when you run stats.

Well this may have turned into a Top


20 (well, 21) list, but none of these are
my own. If you find this interesting,
the link to the discussion is at the top.

// posted by Robert Vollman @ Sunday, January

15, 2006

Comments: Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/01/oracle-do-nots.html (4 of 4)1/9/2008 2:52:19 AM


OracleBlog: 20 Oracle Lessons

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday,
About Me
September 12,
Name: Robert Vollman
2005
Location: Calgary, Alberta, Canada
20 Oracle
Lessons I was born and raised in Ottawa, and have lived in
I started using Calgary since 1991. I like playing sports (hockey,
Oracle with soccer, ultimate, basketball, you name it) and military board
version 8 in games. I also enjoy reading, walking, and playing with my 2 cats
1999. After a Lilly and Brutus. I'm a database application specialist, whatever
few years I that is.
changed
companies to a View my complete profile
Sybase/SQL-
Server shop. But
the past year has
found me back
Best Links
working with ● Ask Tom Kyte
Oracle, this time ● Oracle Docs
version 8, and 9. ● Dan Morgan and PSOUG
● Steven Feuerstein
It has been an ● Jonathan Lewis
interesting time ● FAQ
getting myself Connor McDonald
back into "game

The Oak Table


shape" with

Cary Millsap and Hotsos


Oracle, and

digging into ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (1 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

version 9. If ● Anjo Kolk and OraPerf


you've been ● Dizwell Oracle Wiki
reading this ● My Personal Blog
blog, you've
been able to

Aggregators
follow along with
me in my
adventures.
Brian Duff's OraBlogs

I decided this ❍ Eddie Awad's OracleNA


was as good a ❍ Pete Finnigan's Aggregator
time as any to ❍ Oracle's Bloglist
pause and reflect ❍ Oracle Base Aggregator

Top Blogs
on some of the
lessons I've
learned in this ❍ Oracle's Ask Tom Kyte
past year. ❍ Oracle Guru Jonathan Lewis
Oracle: ❍ Blogger of the Year Eddie Awad
1. Oracle is very ❍ Data Warehouser David Aldridge
complex. ❍ Oracle Geek Lewis Cunningham
I always thought ❍ Database Expert James Koopmann
"a database is a ❍ Dizwell's Howard Rogers
database" but ❍ Oracle Master Laurent Schneider
Oracle is about 4 ❍ Security Expert Pete Finnigan
times as ❍ Oracle Award Winner Mark Rittman
complex as ❍ Doug Burns
Sybase/MS-SQL. ❍ Oracle ACE of the Year Dr. Tim Hall
2. Fortunately ❍ UKOUG's Andrew (Arfur C.) Clarke
Oracle is well- ❍ Newbie DBA Lisa Dobson
documented. ❍ Coffee-Drinking DBA Jon Emmons
I have fallen in ❍ Chris Foot
love with Oracle ❍ The Pythian DBA Team Blog
documentation. ❍ DBA Don Seiler
Clear, well- ❍ DBA Coskan Gundogar
written, ❍ Oracle WTF
comprehensive
and lots of
examples.
ARCHIVES
❍ LIST ALL ARTICLES
http:// ❍ May 2005
thinkoracle. ❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (2 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

blogspot. ❍ August 2005


com/2005/07/ ❍ September 2005
oracle-docs.html ❍ October 2005
❍ November 2005
3. There are ❍ December 2005
many on-line ❍ January 2006
Oracle sites and February 2006
forums to find

March 2006
help.

April 2006
The primary

benefit of a ❍ May 2006


popular product ❍ June 2006
is that whatever ❍ July 2006
your mistake is, ❍ August 2006
you're probably ❍ September 2006
not the first ❍ October 2006
person to ❍ November 2006
experience it. ❍ December 2006
There is a huge ❍ January 2007
on-line Oracle February 2007
community, and

March 2007
so many places

April 2007
to search for

help. My ❍ May 2007


favourite links ❍ June 2007
and blogs are ❍ October 2007
kept current on
this site.

Testing:
4. It's quick, free
and very easy to
set up a personal
Oracle database
on your Windows
PC for testing
purposes.

5. Build proper
test cases, and
test everything
you read before
your implement.

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (3 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

This is part of
my personal
style that I apply
to all my work,
regardless of
technology. But I
feel it is
especially true of
a database as
complex as
Oracle. Especially
with all the
different
versions out
there.

6. Burleson
Consulting
makes a lot of
mistakes.
So test those
even more
carefully. But
remember, even
the stellar Tom
Kyte makes
mistakes.

http://
thinkoracle.
blogspot.
com/2005/06/
expert-one-on-
one.html

Coding/
Modelling
Practises:
7. Document
your code.
It makes it easier
to reuse good
code, and fix

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (4 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

bad code. Again,


this is my
personal style
that I apply to all
project,
regardless of
technology. Do
the best I can,
and explain what
I'm doing.

8. Specify
column/
parameter
names when
writing queries
or making stored
procedure calls.

http://
thinkoracle.
blogspot.
com/2005/07/
specifying-
insert-columns.
html

9. NULLs are
very special
This is one of my
favourite topics.
Casual database
programmers
might not be
aware of all the
special cases
related to NULLs,
making them a
common cause
of honest (but
costly) mistakes.

http://

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (5 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

thinkoracle.
blogspot.
com/2005/05/
null-vs-nothing.
html
http://
thinkoracle.
blogspot.
com/2005/06/
nulls-in-oracle.
html
http://
thinkoracle.
blogspot.
com/2005/09/
nulls-in-count.
html

10. Data
integrity is best
accomplished in
the database
layer (as
opposed to
procedure or
application
layers).
Why use a
sophisticated
database like
Oracle if you're
just going to use
it as a data
store? Use
Oracle's ability to
protect your
data's integrity,
and then you can
fear badly
written
applications a

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (6 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

little bit less.

11. Triggers can


be used as a
form of
"advanced
constraint" for
data integrity.

http://
thinkoracle.
blogspot.
com/2005/07/
use-constraints.
html

12. Views are


very useful in
solving complex
queries without
affecting your
data model
(among many
other uses!)

http://
thinkoracle.
blogspot.
com/2005/07/
use-views.html

13. A great way


to improve
performance is
to archive/
partition data.

http://
thinkoracle.
blogspot.
com/2005/08/
keeping-tables-

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (7 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

small.html

14. You can


often achieve
common table
types and
procedure
parameters by
defining user
types, using %
TYPE and
referencing
foreign keys.
Otherwise, use
an advanced SQL
modeller to
develop your PL/
SQL.

http://
thinkoracle.
blogspot.
com/2005/06/
common-table-
column-types.
html

15. Choose
carefully
between using
natural and
synthetic keys
when designing
your tables.

http://
thinkoracle.
blogspot.
com/2005/06/
natural-vs-
synthetic-keys.
html

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (8 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

Useful Oracle
(other than
REGEXP, in
Version 10):

16. DECODE is
incredibly useful
(CASE WHEN can
also be used).
I am a huge fan
of DECODE, I
can't imagine
working without
it. It is perhaps
poorly named.

http://
thinkoracle.
blogspot.
com/2005/06/
decode.html

17. CONNECT BY
is useful when
you need
hierarchical,
string
aggregation
(stragg).

http://
thinkoracle.
blogspot.
com/2005/06/
connect-by.html

18. GROUP BY
has a lot of
relatives to help
write queries for
complex analytic
functions: RANK,

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (9 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

GROUPING SETS,
GROUPING_ID,
ROLLUP

http://
thinkoracle.
blogspot.
com/2005/08/
compute.html

19. PL/SQL
supports OOP
(Object-Oriented
Programming)

http://
thinkoracle.
blogspot.
com/2005/06/
oop-in-plsql-
yep.html

20. Oracle has a


lot of handy
toolkits
For example
UTL_HTTP can be
used to achieve
very simple
screen-scraping
(among other
things)

http://
thinkoracle.
blogspot.
com/2005/08/
utlhttp.html

One more thing


that didn't make
the list (because

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (10 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

it would push
the total from an
even 20 to an
odd 21):
When you're
having trouble
writing a very
clever query or
procedure, take
a step back and
look at your data
model. It might
be inappropriate
for how you're
using it.

Thanks for
joining me on
this stroll down
memory lane!

// posted by Robert
Vollman @ Monday,
September 12, 2005

Comments:
21st point is the
best one!
# posted by
Anonymous :
Monday, 12
September, 2005

Sometimes
Oracle
doucmentation
is clear and
useful.
But how much
use are these

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (11 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

flow charts of
the SQL syntax,
which IMO are
fairly typical of
Oracle docs?

http://download-
west.oracle.com/
docs/cd/
B10501_01/
server.920/
a96540/
statements_103a.
htm#SQLRF01702

Personally I feel
that the terse
and partially (or
non-publically)
documented
nature of Oracle
makes for an
entire range of
publications
which would not
otherwise be
there.
# posted by
Anonymous :
Tuesday, 13
September, 2005

... to another
anonymous who
wrote on
timestampt 13
September 2005

But how much


use are these
flow charts of
the SQL syntax,
which IMO are

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (12 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

fairly typical of
Oracle docs?

I find them very


useful. If you
happen to have a
vague
knowledge of the
syntax,
it really helps to
get the little bits
right, like what is
the correct order
of the syntactical
elements or
which part is
optional etc.

On the
downside, if
you're about to
enter a new field
like e.g. XML DB,
I frequently
find it very hard
to gather all the
necessary bits
that get you
started and
let you
understand the
interaction of the
components
involved.

Regards,
Holger
# posted by
Anonymous :
Wednesday, 14
September, 2005

Hey, you have a

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (13 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 Oracle Lessons

great blog here!


I'm definitely
going to
bookmark you!
Cool Links:
Custom Web Site
Design by
BlueBizz
MCSE
Certification
training
Custom Web Site
Design by
BlueBizz
Data Conversion
Services
Web Hosting
Providers
Come and check
it out if you get
time.. Thanks.
# posted by
custom web
design : Saturday, 26
November, 2005

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/09/20-oracle-lessons.html (14 of 14)1/9/2008 2:52:21 AM


OracleBlog: 20 PL/SQL Coding Tips

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, December 19, 2005


About Me
20 PL/SQL Coding Tips Name: Robert Vollman
Gary pointed me to a recent AskTom Location: Calgary, Alberta,
thread that contained a list of PL/SQL Canada
Coding Practises. The ensuing
discussion added a few more, and I'd
I was born and raised in
like to throw in a few of my own as
Ottawa, and have lived in Calgary since
well. I also think most of these tips
1991. I like playing sports (hockey,
are useful for other languages, but
soccer, ultimate, basketball, you name it)
this is first and foremost an Oracle
and military board games. I also enjoy
developer's blog.
reading, walking, and playing with my 2
Here they are, with the order and cats Lilly and Brutus. I'm a database
wording slightly revised in some application specialist, whatever that is.
cases (removed the biblical
undertones for politically correct View my complete profile
reasons), and my comments after

Best Links
each one. Each of these could be a
separate blog on their own, but I
restrained myself to only brief Ask Tom Kyte
comments.

● Oracle Docs
Design (Pre-Coding): ● Dan Morgan and PSOUG
● Steven Feuerstein
1. Ask Why ● Jonathan Lewis
● FAQ
A popular philosophy in the Oracle Connor McDonald
blogging community, and

http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html (1 of 9)1/9/2008 2:52:32 AM


OracleBlog: 20 PL/SQL Coding Tips

championed by Tom Kyte, is the The Oak Table


notion of asking why. Why is this ● Cary Millsap and Hotsos


code being written, why is it being ● Steve Adams and Ixora
done the way that it is, etc. ● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
From Tom Kyte's Blog: http://tkyte. ● My Personal Blog
blogspot.com/2005/05/why.html

2. Gather requirements thoroughly

Based on the experiences of many, Aggregators


gather all the requirements and do Brian Duff's OraBlogs

not begin anything until all parties ❍ Eddie Awad's OracleNA


have agreed on what the end result ❍ Pete Finnigan's Aggregator
will have to be in order to be ❍ Oracle's Bloglist
considered successful. ❍ Oracle Base Aggregator

3. Design, including for scalability


and security, first.
Top Blogs
❍ Oracle's Ask Tom Kyte
With the exception of quasi- ❍ Oracle Guru Jonathan Lewis
prototypes and small proofs of ❍ Blogger of the Year Eddie Awad
concept, no coding should begin until ❍ Data Warehouser David Aldridge
it has been designed. This is the time ❍ Oracle Geek Lewis Cunningham
to think about scalability and Database Expert James Koopmann
security. Those aren't issues to tackle

Dizwell's Howard Rogers


after the fact.

❍ Oracle Master Laurent Schneider


4. Set up proper testing/ ❍ Security Expert Pete Finnigan
development/debugging environment ❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
I find that developers are far more ❍ Oracle ACE of the Year Dr. Tim Hall
effective if they have a reliable, ❍ UKOUG's Andrew (Arfur C.) Clarke
accurate and convenient environment Newbie DBA Lisa Dobson
for testing and debugging. Also, it is

Coffee-Drinking DBA Jon Emmons


usually better to set that up first,

Chris Foot
rather than patching something

The Pythian DBA Team Blog


together on the fly. ❍

❍ DBA Don Seiler


5. Use source control ❍ DBA Coskan Gundogar
❍ Oracle WTF
"Consider source control non-
optional, and a factor on which your
job depends." - a former director of
ARCHIVES
❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html (2 of 9)1/9/2008 2:52:32 AM


OracleBlog: 20 PL/SQL Coding Tips

mine. That simplifies your decision, ❍ May 2005


doesn't it? ❍ June 2005
July 2005
6. Choose the right tools

❍ August 2005
Notepad and SQL*Plus might work for ❍ September 2005
you now, but for a larger project you ❍ October 2005
might want to consider a different ❍ November 2005
IDE. You'll also want to look at source ❍ December 2005
control systems, and code libraries. ❍ January 2006
❍ February 2006
7. Write test cases before coding
❍ March 2006
It seems like many people agree on ❍ April 2006
this rule, but consider it a fantasy ❍ May 2006
because how often do you see this ❍ June 2006
done in practise? Ideally you would ❍ July 2006
do this right after #2 (gather ❍ August 2006
requirements thoroughly). That way ❍ September 2006
you can say "when these tests pass, ❍ October 2006
you are done." ❍ November 2006
December 2006
Coding:

❍ January 2007
8. Check and handle errors ❍ February 2007
❍ March 2007
Up front, decide a common way of ❍ April 2007
handling errors in the EXCEPTIONS ❍ May 2007
block. You can figure out what works ❍ June 2007
best, customer error types, an error October 2007
table, an error file, whatever works as

long as you are checking and


handling all errors.

For starters, check Chapter 7 of the


PL/SQL User's Guide and Reference:
Handling PL/SQL Errors:
http://download-west.oracle.com/
docs/cd/B10501_01/appdev.920/
a96624.pdf

9. Comment your code

This one resulted in a lot of debate

http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html (3 of 9)1/9/2008 2:52:32 AM


OracleBlog: 20 PL/SQL Coding Tips

on the thread. No, commenting your


code is not a substitute for making
your code readable, but then again,
neither is making your code readable
a substitute for commenting. Indeed,
I agree with the one suggestion that
you should write your comments
BEFORE you write the code!

10. Use proper indexes

11. Maximise SQL and minimise PL/


SQL

There are books written on the


efficiency gain of preferring SQL over
PL/SQL.

12. Instrument your code for


debugging

Choose your favourite method: debug


statements judiciously places
throughout your code, or perhaps
using DBMS_PROFILE (that is
definitely a topic I'll do soon), or
something else entirely. As long as
you have a way to troubleshoot bugs
and performance issues later on.

13. Make use of bulk processing

14. Minimise client code and


maximise server code.

Generally servers are more powerful


and built for this type of work. You
also want to minimise trips back and
forth to the server.

15. Use bind variables, not


concatenation

Not just for performance reasons, but


also for security (thwart SQL

http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html (4 of 9)1/9/2008 2:52:32 AM


OracleBlog: 20 PL/SQL Coding Tips

injection). I think Tom Kyte made his


living off this topic for awhile.

I blogged about bind variables once:


http://thinkoracle.blogspot.
com/2005/06/bind-variables-in-
plsql.html

16. Think in sets.

17. Use procedures/functions to


name and modularize your code for
reuse

Don't just create one big massive


function that does many, specific
things. Best to break it out into
specific tasks, which can be
optimized and reused. Also makes
you think more about your detailed
design.

18. Use unique and meaningful names

Unique names can be found easier in


the code with "Find". Meaningful
names make your code easier to
understand. If you can't think of a
meaningful name for a procedure/
variable, maybe you don't have a
clear idea on its purpose and you
need to re-think your design.

Coding and Afterwards:

19. Stress test your code with


significant data, and benchmark it

Doesn't matter how much time you


spent thinking about performance
and bottlenecks during the design
and implementation, you might still
have missed a few things.

http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html (5 of 9)1/9/2008 2:52:32 AM


OracleBlog: 20 PL/SQL Coding Tips

20. Perform a code review with your


peers.

Code reviews are good to find


mistakes, but also for knowledge
transfer. I also think you take more
pride in your work when you have the
opportunity to share it, rather than
just hide in a cubicle as an
anonymous coder.

Comments are welcome, but I also


encourage you to visit the thread and
follow up to the wider audience there:
http://asktom.oracle.com/pls/ask/f?
p=4950:8:18231831513891656743::
NO::F4950_P8_DISPLAYID,
F4950_P8_CRITERIA:51960184066540

Steven Feuerstein is also one of my


favourite champions on good PL/SQL
programming. Here is a previous blog
on one of his articles on refactoring
(the link to which is within):
http://thinkoracle.blogspot.
com/2005/05/steven-feuerstein-on-
refactoring.html

// posted by Robert Vollman @ Monday,

December 19, 2005

Comments:
Rob,

This blog is quite timely for me


because if the developers of the
application I'm working on had read
this, they might have followed tips 13
and 14 and avoided some of the
problems we're running into.

http://oracledoug.blogspot.

http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html (6 of 9)1/9/2008 2:52:32 AM


OracleBlog: 20 PL/SQL Coding Tips

com/2005/12/another-10046-
success.html

Cheers,

Doug
# posted by Doug Burns : Monday, 19
December, 2005

Hi,
to 17. Use procedures/functions to
name and modularize your code for
reuse
i would say - don not use singel
functions/procedures at all but use
Packages instead to
organize as set of function/
Procedures and types to a design
aspect.

Further i would like to say - the data


dicitonary is a repository. Out of an
repository
you can generate code for db objects
as Triggers/Views/Tale API's,
Packages .. with PL/SQL;

An important pont doing a database


oriented project is the dployment of
the db objects.
The Use of PL/SQL helps to automate
something better then a pure
SQL*PLUs SQL-Script

Very important too is a PL/SQL code


beautifier - helping better to
understand the logic behind.

Regards
Karl
# posted by Karl r. : Tuesday, 20 December,
2005

http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html (7 of 9)1/9/2008 2:52:32 AM


OracleBlog: 20 PL/SQL Coding Tips

Karl,

Excellent points! I will definitely


incorporate those into a revised
version next week.

I can't believe I overlooked using


packages, after all, I blogged on this
recently:
http://thinkoracle.blogspot.
com/2005/10/oracle-packages.html

Doug:

I think you posted your comment


before my blog was even posted!
That's fast!
# posted by Robert Vollman : Tuesday, 20
December, 2005

Rob, great expansion on the


original :-)
Cosmin
# posted by oracos : Thursday, 12 January,
2006

This post has been removed by a


blog administrator.
# posted by Tito Maury : Wednesday, 08
February, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html (8 of 9)1/9/2008 2:52:32 AM


OracleBlog: 20 PL/SQL Coding Tips

http://thinkoracle.blogspot.com/2005/12/20-plsql-coding-tips.html (9 of 9)1/9/2008 2:52:32 AM


OracleBlog: Software Vendor Customer Support

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday,
About Me
October 17,
Name: Robert Vollman
2006
Location: Calgary, Alberta, Canada
Software
Vendor I was born and raised in Ottawa, and have lived in
Customer Calgary since 1991. I like playing sports (hockey,
soccer, ultimate, basketball, you name it) and military board games.
Support I also enjoy reading, walking, and playing with my 2 cats Lilly and
Having worked Brutus. I'm a database application specialist, whatever that is.
in technical
support for View my complete profile
software
vendors for 4
years, I know a
few strategies Best Links
that can help ● Ask Tom Kyte
customers get ● Oracle Docs
the best ● Dan Morgan and PSOUG
response. ● Steven Feuerstein
Jonathan Lewis
1. Get training

FAQ
Rely on the

Connor McDonald
assistance of ●

the software ● The Oak Table


vendor for as ● Cary Millsap and Hotsos
little as ● Steve Adams and Ixora
possible. ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (1 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

Invest in ● Dizwell Oracle Wiki


training your ● My Personal Blog
own people by
signing them

Aggregators
up for courses
and, more
importantly,
Brian Duff's OraBlogs
giving them

Eddie Awad's OracleNA


the time to

Pete Finnigan's Aggregator


learn the ❍

product and ❍ Oracle's Bloglist


how your ❍ Oracle Base Aggregator
company uses
it. Once Top Blogs
knowledgeable, Oracle's Ask Tom Kyte

your expert ❍ Oracle Guru Jonathan Lewis


can get the Blogger of the Year Eddie Awad
best results

Data Warehouser David Aldridge


from the

Oracle Geek Lewis Cunningham


vendor.

❍ Database Expert James Koopmann


2. Avoid ❍ Dizwell's Howard Rogers
customizations ❍ Oracle Master Laurent Schneider
No product is ❍ Security Expert Pete Finnigan
going to fit ❍ Oracle Award Winner Mark Rittman
your needs ❍ Doug Burns
exactly, and ❍ Oracle ACE of the Year Dr. Tim Hall
it's tempting ❍ UKOUG's Andrew (Arfur C.) Clarke
just to make
Newbie DBA Lisa Dobson
little fixes here

Coffee-Drinking DBA Jon Emmons


and there, but

Chris Foot
resist the urge. ❍

Just because ❍ The Pythian DBA Team Blog


you can do ❍ DBA Don Seiler
something, it ❍ DBA Coskan Gundogar
does not ❍ Oracle WTF

ARCHIVES
necessarily
follow that you
should. ❍ LIST ALL ARTICLES
Consider May 2005
leaving the

June 2005
software as-is

July 2005
and just

❍ August 2005

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (2 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

changing your ❍ September 2005


process. ❍ October 2005
Customizations ❍ November 2005
can cause December 2005
problems,

January 2006
become

February 2006
(legitimate or

March 2006
not) obstacles ❍

preventing the ❍ April 2006


vendor from ❍ May 2006
providing you ❍ June 2006
assistance, and ❍ July 2006
make upgrades ❍ August 2006
more ❍ September 2006
problematic. ❍ October 2006
November 2006
3. Stay current,

December 2006
but not too

January 2007
current

Generally the ❍ February 2007


vendor offers ❍ March 2007
the best ❍ April 2007
support for ❍ May 2007
versions ❍ June 2007
immediately ❍ October 2007
before the
latest version.
If your version
is too old, they
may have
fewer people
that know it
and they may
stop
supporting it
altogether. You
don't want to
stay too
current - let
the other
customers find
the bugs in the
latest releases.

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (3 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

Of course, if
you need the
functionality in
the latest
version and the
vendor is
prepared to
give you extra
support for
being a guinea
pig, go for it.

4. Allow for
remote access
Generally you
should never
allow the
vendors on to
your system,
but sometimes
it will be
necessary, so
be set up to
make that as
easy as
possible.

5. Wait until
you have time
There is no
point opening
a ticket with
them until your
resources have
the time to act
on whatever
they suggest.
Take too long
to respond and
your item will
be
downgraded,
perhaps

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (4 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

permanently. If
something is
low priority
and you just
want it "on the
record", then
make sure you
say so.

6. Assign the
right priority
Every software
vendor will
have standard
definitions
where you
define the
severity/
priority/impact
of a problem.
It is tempting
to assign a
higher priority,
but once
you're
downgraded
you may be
given a lower
priority than
items that
were opened
correctly at
this new
downgraded
level. You can
also get a
reputation that
may cause
truly important
items to get
downgraded in
the future. Any
way you slice

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (5 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

it, clearly
explain the
business
impact of your
problem,
regardless of
priority, to
avoid any
problems.

7. Answer the
standard
questions in
advance
Don't wait for
them to ask
you the usual
questions:
When did this
start, what
changed, etc.
Anticipate their
questions and
answer them
up front. Look
back at the
questions they
usually ask as
a clue.

8. Provide a
complete,
independent
test case
Doing a little
work
beforehand
can save a lot
of time later.
Eliminate
distractions
and narrow the
problem down

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (6 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

to a simple,
reproducible
step-by-step
description
that will work
anywhere. Try
to use default
data wherever
possible. A test
case is worth a
thousand
words, so this
will save you
days or weeks
of back-and-
forth
explanations.

9. Provide all
logs,
configuration
files
Don't wait for
them to ask,
go ahead and
attach all
relevant
configuration
files and logs.
Tell them what
you've already
tried (from
standard
troubleshooting
techniques in
the manual)
and what the
results were
for those tests.

10. Make it as
easy as
possible

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (7 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

Try to make
your case look
as simple and
clear as
possible. Some
vendors
measure their
service
representatives
by how many
items they
close to the
customer's
satisfaction. So
they like to
pick off the
low hanging
fruit. If your
case looks
hard, it may
get neglected,
or assigned to
someone not
new or skilled
enough to
dodge the
tough ones.

11. Open
separate tickets
Try not to
lump
everything into
one ticket, or
you risk having
your problem
only partially
solved. Why
not open a
separate item,
and have them
work on your
issues in

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (8 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

parallel? If
they're
somewhat
related, you
can always say
so in your
description.
Worse case
scenario,
solving one
solves the
other and you
can just close
both.

12. Escalate
when you're
stuck
If you're not
getting
anywhere, ask
for the issue to
be escalated to
the manager. S/
he will make
sure the right
people are
working on it,
that there is a
resolution
plan, and
communicate
that
information to
you. Keep
going up if you
have to,
managers have
managers too.

13. If you need


extra, pay for
it.

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (9 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

If, for whatever


reason, you
can't do certain
things for
yourself, or
you need some
extra help
from the
software
vendor, offer
to pay. Money
talks! You will
get results far
faster and
more reliably
than if you just
try to threaten
or cajole them
into it.

14. Make sure


the solution is
permanent
Try to keep the
focus on
identifying and
solving the
root cause, not
the
consequence.
It is almost
always
advisable to
end a
resolution with
a
documentation
enhancement
or a new item
in their
solutions
knowledge
base.

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (10 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

Volunteer to
proof read it.

Note: I
originally
wrote this
article in April,
but it was on
my personal
blog. It occurs
to me that the
Oracle
professionals
that read this
blog might be
supporting
3rd-party
Oracle-based
applications,
or perhaps
dealing with
Oracle support
directly, and
therefore
would enjoy
this article too.

Also, given my
lack of material
lately, this is
the best way to
confirm I am
still alive. :)

// posted by
Robert
Vollman @ Tuesday,
October 17, 2006

Comments:
Really

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (11 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

excellent
advice. ALong
the lines of "so
obvious
everybody
knows it, and
nobody does
it".
# posted by
Harry :
Thursday, 19
October, 2006

Good list, but


#2, good luck!

For #7-#9,
Oracle has
pretty good
docs like
Working
Effectively With
Support
which every
3rd party
vendor should
try to emulate
to help
customers help
themselves.

Also regarding
#7, most
vendors these
days seem to
use fairly
standard web
packages for
support, they
need to
remember to
configure them

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (12 of 13)1/9/2008 2:52:35 AM


OracleBlog: Software Vendor Customer Support

properly to ask
the proper
questions (and
allow the
possible
answers!), and
get the
analysts to
read them.
# posted by
Joel Garry :
Friday, 20 October,
2006

This post has


been removed
by a blog
administrator.
# posted by
Ayisha :
Monday, 13
August, 2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/10/software-vendor-customer-support.html (13 of 13)1/9/2008 2:52:35 AM


OracleBlog: Expert One-on-One

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday, June
About Me
22, 2005
Name: Robert Vollman
Expert One- Location: Calgary, Alberta, Canada
on-One
The general I was born and raised in Ottawa, and have lived in
consensus is that Calgary since 1991. I like playing sports (hockey,
Tom Kyte's "Expert soccer, ultimate, basketball, you name it) and military board
One-on-One games. I also enjoy reading, walking, and playing with my 2
Oracle" is the best cats Lilly and Brutus. I'm a database application specialist,
Oracle book whatever that is.
available, and most
Oracle View my complete profile
professionals have
a copy on their
shelves.
Best Links
In Chapter 1 of the ● Ask Tom Kyte
first edition, you'll ● Oracle Docs
see a scheduling ● Dan Morgan and PSOUG
algorithm that is ● Steven Feuerstein
supposed to avoid ● Jonathan Lewis
double-bookings. ● FAQ
Here is an example
Connor McDonald
of how to double-

The Oak Table


book a room:

● Cary Millsap and Hotsos


CREATE TABLE ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/06/expert-one-on-one.html (1 of 8)1/9/2008 2:52:38 AM


OracleBlog: Expert One-on-One

resources ● Anjo Kolk and OraPerf


(resource_name ● Dizwell Oracle Wiki
VARCHAR2(25) ● My Personal Blog
primary key);
CREATE TABLE
schedules
(resource_name
VARCHAR2(25)
Aggregators
Brian Duff's OraBlogs
references

Eddie Awad's OracleNA


resources, ❍

start_time DATE, ❍ Pete Finnigan's Aggregator


end_time DATE); ❍ Oracle's Bloglist
❍ Oracle Base Aggregator
INSERT INTO
resources
(resource_name)
Top Blogs
Oracle's Ask Tom Kyte
VALUES ('Room A');

Oracle Guru Jonathan Lewis


INSERT INTO

Blogger of the Year Eddie Awad


schedules ❍

(resource_name, ❍ Data Warehouser David Aldridge


start_time, ❍ Oracle Geek Lewis Cunningham
end_time) VALUES ❍ Database Expert James Koopmann
('Room A', '01-Jan- ❍ Dizwell's Howard Rogers
04', '04-Jan-04'); ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
VARIABLE ❍ Oracle Award Winner Mark Rittman
new_start_time
Doug Burns
VARCHAR2(32)

Oracle ACE of the Year Dr. Tim Hall


EXEC :

UKOUG's Andrew (Arfur C.) Clarke


new_start_time := ❍

'02-Jan-04' ❍ Newbie DBA Lisa Dobson


❍ Coffee-Drinking DBA Jon Emmons
VARIABLE ❍ Chris Foot
new_end_time ❍ The Pythian DBA Team Blog
VARCHAR2(32) ❍ DBA Don Seiler
EXEC : ❍ DBA Coskan Gundogar
new_end_time := ❍ Oracle WTF
'03-Jan-04'

VARIABLE ARCHIVES
room_name ❍ LIST ALL ARTICLES
VARCHAR2(25) ❍ May 2005
EXEC :room_name : ❍ June 2005
= 'Room A' ❍ July 2005

http://thinkoracle.blogspot.com/2005/06/expert-one-on-one.html (2 of 8)1/9/2008 2:52:38 AM


OracleBlog: Expert One-on-One

❍ August 2005
-- If the count September 2005
comes back 0, the

October 2005
room is yours

November 2005
SELECT COUNT (*)

December 2005
FROM schedules ❍

WHERE ❍ January 2006


resource_name = : ❍ February 2006
room_name ❍ March 2006
AND (start_time ❍ April 2006
BETWEEN : ❍ May 2006
new_start_time ❍ June 2006
AND :new_end_time ❍ July 2006
OR ❍ August 2006
end_time BETWEEN : ❍ September 2006
new_start_time
October 2006
AND :

November 2006
new_end_time);

❍ December 2006
This returns 0, ❍ January 2007
which means the ❍ February 2007
room is double- ❍ March 2007
booked!! ❍ April 2007
❍ May 2007
Here is the fixed June 2007
version from the

October 2007
2nd edition:

ops
$tkyte@ORA10GR1>
select count(*)
2 from schedules
3 where
resource_name = :
room_name
4 and (start_time
<= :new_end_time)
5 and (end_time
>= :
new_start_time);

According to Tom,
"the only [other]
notable fix is with

http://thinkoracle.blogspot.com/2005/06/expert-one-on-one.html (3 of 8)1/9/2008 2:52:38 AM


OracleBlog: Expert One-on-One

regards to function
based indexes
where I said
erroneously that
the to_date()
function was
"broken" with
respect to the YYYY
format - it is not
(can you see why :)"

Here it is:

CREATE TABLE t (y
VARCHAR2(32));

CREATE INDEX t2
ON t(to_date
(y,'yyyy'));
ORA-01743: only
pure functions can
be indexed.

As a workaround in
the book, Tom
created his own
"to_date" function.
But there is a far
simpler reason why
this doesn't work
(and a far simpler
solution). Even
though it was
staring us all in the
very same pages,
not very many
people could figure
out why this
function-based
index was
disallowed:

"My conclusion in
the book is wrong

http://thinkoracle.blogspot.com/2005/06/expert-one-on-one.html (4 of 8)1/9/2008 2:52:38 AM


OracleBlog: Expert One-on-One

because to_date
with the 'yyyy'
format is not
deterministic."

That means that for


the same input, you
can get a different
output. But how
can that be?

ops
$tkyte@ORA10GR1>
select to_date
( '2005', 'yyyy' )
from dual;

TO_DATE('
---------
01-JUN-05

"Today, in june,
to_date(2005)
returns 01-jun, last
month, same
function, same
inputs - would
return 01-may"

Wow. Never would


have guessed
to_date(year) would
be non-
deterministic.

Tom also clarified


that the following
function would be
deterministic and
therefore eligible
for a function-
based index:

create index t2 on t

http://thinkoracle.blogspot.com/2005/06/expert-one-on-one.html (5 of 8)1/9/2008 2:52:38 AM


OracleBlog: Expert One-on-One

( to_date( '01'||y,
'mmyyyy') );

That, of course,
would force it to
choose January no
matter what time of
year you called the
function.

To me, it is very
funny that to_date:
1. IS deterministic if
you leave out the
day (it will always
choose the 1st day)
2. IS NOT
deterministic if you
leave out the
month (it will not
choose the 1st
month, but rather
the current month).

Often in Oracle
there is method
behind the
madness, but I do
now know why
there is this
difference.

So I guess this
issue is just
another interesting
footnote in some
nerd's blog...

// posted by Robert
Vollman @ Wednesday,

June 22, 2005

Comments:

http://thinkoracle.blogspot.com/2005/06/expert-one-on-one.html (6 of 8)1/9/2008 2:52:38 AM


OracleBlog: Expert One-on-One

6 entries found for


nerd.
nerd also nurd
Audio
pronunciation of
"nerd" ( P )
Pronunciation Key
(nûrd)
n. Slang

1. A foolish, inept,
or unattractive
person.
2. A person who is
single-minded or
accomplished in
scientific or
technical pursuits
but is felt to be
socially inept.

So, which one are


you :)

I think we need a
#3 there....
(personally)
# posted by Thomas
Kyte : Thursday, 23 June,
2005

This post has been


removed by a blog
administrator.
# posted by Robert
Vollman : Friday, 24
June, 2005

Post a Comment

http://thinkoracle.blogspot.com/2005/06/expert-one-on-one.html (7 of 8)1/9/2008 2:52:38 AM


OracleBlog: Expert One-on-One

<< Home

http://thinkoracle.blogspot.com/2005/06/expert-one-on-one.html (8 of 8)1/9/2008 2:52:38 AM


OracleBlog: Optimizing Oracle Performance (Millsap, Holt)

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, May 16, 2005


About Me
Optimizing Name: Robert Vollman
Oracle Location: Calgary, Alberta, Canada
Performance
I was born and raised in Ottawa, and have
(Millsap, Holt) lived in Calgary since 1991. I like playing
There are certain "camps" sports (hockey, soccer, ultimate, basketball, you name
in the worldwide Oracle it) and military board games. I also enjoy reading,
community. For example, walking, and playing with my 2 cats Lilly and Brutus.
there is the "Oak Table I'm a database application specialist, whatever that is.
Network" of "Oracle
scientists" who seek
View my complete profile
thorough understandings
of issues backed up by
details, tests and proofs.
Contrasting is the "Silver Best Links
Bullet" family of field- ● Ask Tom Kyte
tested generals who ● Oracle Docs
prefer rules of thumb and ● Dan Morgan and PSOUG
quick fixes even it means ● Steven Feuerstein
some false Jonathan Lewis
understandings and

FAQ
occasionally being wrong.

Connor McDonald
Cary Millsap (of the Oak

Table Network) stands as ● The Oak Table


someone respected by ● Cary Millsap and Hotsos
both sides. ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/05/optimizing-oracle-performance-millsap.html (1 of 7)1/9/2008 2:52:40 AM


OracleBlog: Optimizing Oracle Performance (Millsap, Holt)

● Anjo Kolk and OraPerf


Cary Millsap worked at ● Dizwell Oracle Wiki
Oracle for 10 years on ● My Personal Blog
system performance
before co-founding
Hotsos in 1999 (http://
www.hotsos.com -
register for free). He is
Aggregators
Brian Duff's OraBlogs
one of the most trusted

Eddie Awad's OracleNA


sources on matters of

Oracle system ❍ Pete Finnigan's Aggregator


performance, and ❍ Oracle's Bloglist
"Optimizing Oracle ❍ Oracle Base Aggregator
Performance" is
considered his finest work Top Blogs
(4.5 out of 5 stars on Oracle's Ask Tom Kyte

Amazon). The best way to ❍ Oracle Guru Jonathan Lewis


learn more about him is to Blogger of the Year Eddie Awad
see for yourself. Here are

Data Warehouser David Aldridge


some of his most popular

Oracle Geek Lewis Cunningham


articles:

❍ Database Expert James Koopmann


"Diagnosing Performance ❍ Dizwell's Howard Rogers
Problems" from Oracle ❍ Oracle Master Laurent Schneider
Magazine. A brief ❍ Security Expert Pete Finnigan
summary of what is ❍ Oracle Award Winner Mark Rittman
covered in this book: ❍ Doug Burns
http://www.oracle.com/ ❍ Oracle ACE of the Year Dr. Tim Hall
technology/oramag/ ❍ UKOUG's Andrew (Arfur C.) Clarke
oracle/04-jan/ ❍ Newbie DBA Lisa Dobson
o14tech_perf.html ❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
"Introduction", the first The Pythian DBA Team Blog
chapter from "Optimizing

DBA Don Seiler


Oracle

DBA Coskan Gundogar


Performance."Chapter 1:

Oracle WTF
http://www.oreilly.com/ ❍

catalog/optoraclep/
chapter/ch01.pdf
ARCHIVES
❍ LIST ALL ARTICLES
"Case Study", the 12th ❍ May 2005
chapter from "Optimizing ❍ June 2005
Oracle ❍ July 2005

http://thinkoracle.blogspot.com/2005/05/optimizing-oracle-performance-millsap.html (2 of 7)1/9/2008 2:52:40 AM


OracleBlog: Optimizing Oracle Performance (Millsap, Holt)

Performance."Chapter 12 ❍ August 2005


(Case Study): http://www. ❍ September 2005
oreillynet.com/pub/a/ ❍ October 2005
network/excerpt/ ❍ November 2005
optimizing_oracle_chap12/ ❍ December 2005
index.html ❍ January 2006
❍ February 2006
"Performance ❍ March 2006
Management: Myths and ❍ April 2006
Facts." One of his most
May 2006
popular articles.https://

June 2006
secure.hotsos.com/

❍ July 2006
downloads/
❍ August 2006
visitor/00000024.pdf ❍ September 2006
October 2006
"Why a 99%+ Database

November 2006
Buffer Cache Hit Ratio is ❍

Not Ok." Another of his ❍ December 2006


more popular articles. ❍ January 2007
http://www.oradream. ❍ February 2007
com/pdf/Why%20a%2099% ❍ March 2007
20Cahe%20Hit%20Ratio% ❍ April 2007
20is%20Not%20OK.pdf ❍ May 2007
❍ June 2007
While everyone will have ❍ October 2007
their own favourite parts
of the book, I think most
readers would agree that
getting a good taste of
the author's performance
tuning philosophy is one
of the highlights. "Method
R", not to be confused
with "System R" (ie. SQL),
is not about looking at
STATSPACK, cache hit
ratios, or V$ tables and
guessing. The author
wanted to devise a system
to identify and resolve the
top performance concerns
of an organisation with

http://thinkoracle.blogspot.com/2005/05/optimizing-oracle-performance-millsap.html (3 of 7)1/9/2008 2:52:40 AM


OracleBlog: Optimizing Oracle Performance (Millsap, Holt)

reliable, predictable
results. The first few
chapters put this method
in writing in perhaps the
best way since the
introduction of
"YAPP" (Anjo Kolk).

"The performance
enhancement possible
with a given improvement
is limited by the fraction
of the execution time that
the improved feature is
used." - Amdahl's Law

After several years of


research, the author
discovered that Extended
SQL Trace Data was at the
centre of "Method R".
Some of the articles
should give you a good
taste of what Extended
SQL Trace data is, if you
didn't know already. By
the time you finish
reading this book you will
know exactly how to
collect and interpret all
the little "ela=17101
p1=10 p2=2213 p3=1 ..."
within into something
meaningful. For some,
that justifies the price tag
right there.

So in essence I would have


re-named this book
"Method R: Optimizing
Oracle Performance Using
Extended SQL Trace Data,"
because that is basically
what this book is about.

http://thinkoracle.blogspot.com/2005/05/optimizing-oracle-performance-millsap.html (4 of 7)1/9/2008 2:52:40 AM


OracleBlog: Optimizing Oracle Performance (Millsap, Holt)

There are some


reasonably "stand-alone"
chapters on other topics,
for instance on the Oracle
Fixed View tables (Chapter
8) and on Queueing
Theory (Chapter 9), but
that is not the primary
focus of the book.

Those that are expecting


a more broad treatment of
the subject of
performance tuning may
be justifiably disappointed
that it basically covers
only this narrow aspect.
However, it is covered
very well, and it isn't really
covered anywhere else.
The author makes no
apologies for this,
claiming that extended
SQL trace data is the only
resource you will ever
need for diagnosing and
solving performance
problems.

"You cannot extrapolate


detail from an aggregate."
- Cary Millsap's
preference of SQL
extended trace data over
fixed views (system-wide
average performance
characteristics)

Indeed, some people


might contend that the
author spends a little too
much time stating his
beliefs, defending them,
and patting himself on the

http://thinkoracle.blogspot.com/2005/05/optimizing-oracle-performance-millsap.html (5 of 7)1/9/2008 2:52:40 AM


OracleBlog: Optimizing Oracle Performance (Millsap, Holt)

back. But I think it adds a


certain flavour to the
book, and I respect an
author who backs up his
statements.

"Proving that V$ data are


superior to extended SQL
trace data because of the
'missing time' issue is
analagous to proving that
its safer to be in a room
with a hungry bear if
you'll just close your
eyes." - Cary Millsap

The book can be a tough


read in the sense that the
author goes very deep
into the material, and
generally each subject is
treated thoroughly.
Chapter 9 on Queueing
Theory can be a
particularly overwhelming
chapter. But the material
is served in bite-size
pieces, and broken up
with tips, tricks, stories,
diagrams and code
(sometimes 3+ pages
worth at a time,
embedded directly in the
middle of a chapter).
There are even worthwhile
exercises at the end of
each chapter.

In the end, I enjoyed this


book and I'm glad I got it.
I don't consider it a "must
have" for your Oracle
collection, but I definitely
feel it is quite worthwhile.

http://thinkoracle.blogspot.com/2005/05/optimizing-oracle-performance-millsap.html (6 of 7)1/9/2008 2:52:40 AM


OracleBlog: Optimizing Oracle Performance (Millsap, Holt)

I recommend it especially
to those who read his
articles and were very
comfortable with his
writing style and
philosophy, and also to
those that need a book on
extended SQL trace data
(because this is basically
the only one). But even
those in the "Silver Bullet"
camp will be glad to add
another tool to their belt.

Thumbs up.

http://www.coug.ab.ca/
Resources/BookReviews/
MillsapsOOPByRVollman.
htm

// posted by Robert
Vollman @ Monday, May 16,

2005

Comments: Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/05/optimizing-oracle-performance-millsap.html (7 of 7)1/9/2008 2:52:40 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday,
About Me
November 02,
Name: Robert Vollman
2005
Location: Calgary, Alberta, Canada
Oracle
Insights: I was born and raised in Ottawa, and have lived in
Tales of Calgary since 1991. I like playing sports (hockey,
soccer, ultimate, basketball, you name it) and military board
the Oak games. I also enjoy reading, walking, and playing with my 2 cats
Table Lilly and Brutus. I'm a database application specialist, whatever
A recent book that is.
review of "Oracle
Insights: Tales of View my complete profile
the Oak Table" by
Doug Burns,
combined with
the introduction
Best Links
Ask Tom Kyte
of Mogens

Norgaard's new ● Oracle Docs


blog motivated ● Dan Morgan and PSOUG
me to finally ● Steven Feuerstein
finish my own ● Jonathan Lewis
review of his ● FAQ
book, which has ● Connor McDonald
sat incomplete ● The Oak Table
since I first read ● Cary Millsap and Hotsos
it 6 months ago. ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (1 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

● Anjo Kolk and OraPerf


Doug Burns' Book ● Dizwell Oracle Wiki
Review of "Oracle ● My Personal Blog
Insights:"
http://
oracledoug.
blogspot.
com/2005/10/
Aggregators
Brian Duff's OraBlogs

book-review- ❍ Eddie Awad's OracleNA


oracle-insights- ❍ Pete Finnigan's Aggregator
tales-of.html ❍ Oracle's Bloglist
Oracle Base Aggregator
Mogens

Norgaard's new
blog:
Top Blogs
http:// Oracle's Ask Tom Kyte

wedonotuse. ❍ Oracle Guru Jonathan Lewis


blogspot.com/ ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
Oracle Insights is ❍ Oracle Geek Lewis Cunningham
a series of essays ❍ Database Expert James Koopmann
from a variety of ❍ Dizwell's Howard Rogers
relatively like- ❍ Oracle Master Laurent Schneider
minded authors ❍ Security Expert Pete Finnigan
that together ❍ Oracle Award Winner Mark Rittman
comprise the Oak Doug Burns
Table Network.

Oracle ACE of the Year Dr. Tim Hall


This network

UKOUG's Andrew (Arfur C.) Clarke


includes some of

my favourite ❍ Newbie DBA Lisa Dobson


authors, a group ❍ Coffee-Drinking DBA Jon Emmons
of individuals ❍ Chris Foot
who are very ❍ The Pythian DBA Team Blog
excited about ❍ DBA Don Seiler
their experiences ❍ DBA Coskan Gundogar
with Oracle and ❍ Oracle WTF
are eager to both
share their
insights, and
ARCHIVES
LIST ALL ARTICLES
gain even more.

❍ May 2005
For more about ❍ June 2005
the Oak Table ❍ July 2005

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (2 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

Network, visit ❍ August 2005


their web site: ❍ September 2005
http://www. ❍ October 2005
oaktable.net/ ❍ November 2005
main.jsp ❍ December 2005
❍ January 2006
Oracle Insights is ❍ February 2006
a wonderful
March 2006
collection of

April 2006
essays from a

May 2006
very talented and ❍

enthusiastic ❍ June 2006


bunch of Oracle ❍ July 2006
experts. It starts ❍ August 2006
with a great ❍ September 2006
history of Oracle, ❍ October 2006
and then is ❍ November 2006
followed by 10 ❍ December 2006
chapters, ❍ January 2007
basically split ❍ February 2007
evenly between March 2007
the topics of

April 2007
performance/

May 2007
tuning and

collections of war ❍ June 2007


stories of Oracle ❍ October 2007
projects gone
bad.

Being a collection
of essays, each
chapter is stand-
alone, linked
together only by
Mogens
Norgaard's
prefaces. In fact,
I really enjoyed
the prefaces
because they
were very casual
and personal.
Normally I skip

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (3 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

prefaces because
they're carefully
scripted, bland
advertisements
for a book you're
already reading,
but Mogens were
short, and served
to put a human
face to each of
the authors.

Because of the
nature of this
book, I will
briefly review
each of the
essays before
going into my
overall
impression of the
book. First, you
may want to visit
Jonathan Lewis'
site, where he
has a synopsis on
each chapter as
well as some
anonymous
reviews (with his
responses):
http://www.
jlcomp.demon.co.
uk/book_rev_2.
html

Chapter 1: A Brief
History of Oracle,
by Dave Ensor

Without question,
this is the
highlight of the

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (4 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

book. It is much
longer than the
other essays
(maybe he should
drop "Brief" from
the title), and he
does tend to go
on from time to
time, but this is
still the hardest
chapter to put
down. It is
admittedly not a
complete history,
but it touches on
the evolution of
Oracle from Ted
Codd's original
paper of
Relational
Databases to
what Oracle is
today. It
organises
Oracle's
responses to
Codd's 12 Rules,
and then some of
the other related
hot topics over
the years that
shaped Oracle
into what it is
today: e.g.
Transactional
Integrity,
Isolation Levels,
Privileges, Rule
Based
Optimizers. It
then covers
Oracle version-
by-version

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (5 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

discussing the
new features,
their motivations,
and their
consequences,
right up to and
including version
10.

I've heard it said


that this chapter
alone is worth
the price of the
book, and its
hard to disagree.

Chapter 2: You
Probably Don't
Tune Right, by
Mogens Norgaard

There are at least


5 chapters that
focus on
performance and
tuning, this being
the first and
probably the
weakest. Let me
qualify that. First
of all, I mean that
more out of
praise to the
other essays than
an indictment of
this one. Indeed,
this essay is (at
least in part) a
summary (or
high-level view)
of the others.

Secondly, this
chapter's

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (6 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

strength is not in
"tuning" but
rather on the
topic of
Instrumentation.
I think that would
have made a
better essay, and
that's what
makes it worth
reading.

One word on the


style. This
chapter is more
like a narrative,
or a conversation
that the author is
having with you.
I'll be honest,
that's not really
my style
(although its
great for
prefaces). For
example,
sometimes it
gets repetitive.
("the Oracle
database is by far
the best database
around,
technically
speaking", next
page: "Oracle is
technically the
best database
around.")

Chapter 3: Waste
Not, Want Not, by
Connor McDonald

Connor

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (7 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

McDonald is
perhaps the most
talented writer in
the crowd, and
that's saying a
lot. His essay
includes
examples of
inefficient (or
"wasteful")
applications, SQL
statements and
PL/SQL blocks.
Even in this short
essay, he
describes how he
found these
wasteful cases,
why they were
wasteful, and
how to correct
them. Those that
learn from
example will
particularly enjoy
his lessons.

Chapter 4: Why I
Invented YAPP,
by Anjo Kolk

The shortest
chapter, and now
the third on
performance.
This chapter is
only of interest
to those that
have already read
(and enjoyed)
Anjo Kolk's
famous (and
awesome) paper

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (8 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

on Yet Another
Performance
Profiling Method.
Here is the link
to that paper
(after a free
registration):
http://www.
oraperf.com/
logon.html?
rpage=download.
php/
yapp_anjo_kolk.
pdf

Chapter 5:
Extended SQL
Trace Data by
Cary Millsap

This one, you can


judge for
yourself, because
this chapter is
available on-line
right here:
http://www.
oracle.com/
technology/
books/pdfs/
oaktable_ch5.pdf

If you want to
hear a little bit
more about this
chapter, I found
that it was
consistent with
Cary Millsap's
other work,
about which you
can find a review

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (9 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

of mine here:
http://
thinkoracle.
blogspot.
com/2005/05/
optimizing-
oracle-
performance-
millsap.html

Chapter 6: Direct
Memory Access,
by Kyle Hailey

Because of the
developer in me,
this was one of
my favourite
chapters. Kyle
Hailey relays a
story about
having met and
worked with an
Oracle master
named Roger
Sanders and his
"m2" application,
which could
access the
memory Oracle
was using
directly. Having
opened our
minds to the
possibilities, his
story leads into a
discussion on
Oracle's SGA
(Shared memory)
and DMA, leaving
you thirsting for
more. A very
memorable

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (10 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

chapter for fans


of the nuts and
bolts, and yet is
not that heavy a
read.

Chapter 7:
Compulsive
Tuning Disorder,
by Gaja Krishna
Vaidyanatha

It is time not only


for yet another
chapter on
performance and
tuning, but also
for a comedy
break. Don't get
me wrong, there
is just as much
substance as the
other chapters,
especially for
fans of the Oracle
Wait Interface.

The most
valuable
contribution of
this chapter is
the so-called
"Cure for CTD". It
is a 2-pronged
methodology that
focuses both on
the OWI and the
OS. It is very
clearly
summarized on
page 235:
photocopy it and
pass it around to

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (11 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

your team. After


explaining the
system in very
clear and specific
terms, the
chapter closes
with 2
appropriate
examples. Even
your junior DBAs
can now look like
pros.

If they had
decided there
were far too
many chapters
on performance
and tuning
(which there are),
and decided to
only keep one,
this chapter
would have my
vote.

Chapter 8: New
Releases and Big
Projects, by
James Morle

This essay deals


with one
particular Oracle
project gone bad.
It starts where
the author joined
in, describing the
mess his
predecessors had
gotten
themselves into,
and then all the
problems they

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (12 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

had to contend
with along the
way. A fun read.

Chapter 9:
Testing and Risk
Management, by
David Ruthven

"Poor
engineering
practises remain
the root cause of
application
failures and there
is usually very
little in the way
of contingency
planning to avoid
and minimise the
impact of such
failures." - David
Ruthven.

In this chapter,
David Ruthven
breaks a
database
application
project down,
dividing it into
types and levels,
and identifies
where they often
go wrong. He
includes
something for
everyone, for
example I
enjoyed his
summary on the
ingredients to an
effective
development

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (13 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

environment. He
even helps
quench the thirst
for more on
Instrumentation
that was first
whetted in
Chapter 2.

The second half


of his chapter
focuses on
testing. He
touches on
functionality
tests, white box
and black box
tests, regression
tests, automated
tests, scalability
tests - everything
you wish your
manager had
read about.

Chapter 10:
Design Disasters,
by Jonathan Lewis

More war stories,


for fans of
Chapter 8! "Now
prepare yourself
to read all about
'The World's
Worst Oracle
Project.'" -
Jonathan Lewis.

This chapter
describes some
of the most
common
mistakes in

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (14 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

development
Oracle database
applications.
You'll certainly
recognise some
of them, because
so many people
stubbornly cling
to certain beliefs.
I know I like to
bring up several
of his points
when I get into
common
arguments like
these:
1. We want our
application to be
"Database
Independent."
2. We will check
data integrity at
the application
level instead of
taking advantage
of Oracle's
constraint
checking abilities.
3. We want to use
sequences for
our primary keys.

I won't give away


too much of this
chapter, but its
definitely food
for thought for
anyone who has
ever been (or
plans to be)
involved in a
database
application

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (15 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

development
project.

Chapter 11: Bad


CaRMa, by Tim
Gorman

The book closes


with another war
story. We get a
look at Vision, a
custom-built
order-entry and
customer-service
application (a
CRM). "This story
is about such an
IT project, the
most spectacular
failure I have ever
experienced." -
Time Gorman.
(Why do we enjoy
the chapters
about failures so
much?)

Appendix: Join
the BAARF Party,
by James Morle
and Mogens
Norgaard

This is a rant
against Raid-5.
Check out their
web site for more:
http://www.baarf.
com/

Overall
Impression:
This book has
been fairly widely

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (16 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

praised
throughout the
Oracle
community. It
received 4.5 out
of 5 stars on
Amazon.com and
even PSOUG's
Dan Morgan gave
it a very high
recommendation:
http://www.
psoug.org/
bookrev.html

Personally I
would love to see
many more
books like these.
I certainly hope
there is a sequel
coming up with
even more essays
from the most
gifted and
enthusiastic
authors in the
Oracle
community. I
would even love
to see more of
these essays
expanded into
books. This book
is a very fun
read, and I
guarantee every
Oracle specialist
will find several
essays within
that they will
enjoy. High
recommendation.

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (17 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

// posted by Robert
Vollman @ Wednesday,
November 02, 2005

Comments:
"Chapter 10: by
Jonathan Lewis
3. We want to use
sequences for
our primary keys."

Maybe I missed
something here,
what is wrong
about using
sequences for
pk???
# posted by
Anonymous :
Friday, 04 November,
2005

There is a
tendency in
Oracle projects to
implement
sequences
incorrectly.
You're right,
that's not a good
enough reason to
avoid the practise
entirely, but it is
a decision to take
seriously.
# posted by
Robert Vollman :
Friday, 04 November,
2005

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (18 of 19)1/9/2008 2:52:43 AM


OracleBlog: Oracle Insights: Tales of the Oak Table

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/11/oracle-insights-tales-of-oak-table.html (19 of 19)1/9/2008 2:52:43 AM


OracleBlog: PL/SQL Books

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, June
About Me
23, 2005
Name: Robert Vollman
PL/SQL Location: Calgary, Alberta, Canada
Books
There are 3 PL/ I was born and raised in Ottawa, and have lived in
SQL books Calgary since 1991. I like playing sports (hockey,
considered soccer, ultimate, basketball, you name it) and military board
above the pack. games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever
I settled on that is.
Scott Urman's
book, but that's View my complete profile
only because I
got a deal on it
when Nexus
Computer Best Links
Books in ● Ask Tom Kyte
Calgary went ● Oracle Docs
out of business. ● Dan Morgan and PSOUG
I like it, and it is ● Steven Feuerstein
ranked #1 ● Jonathan Lewis
among PL/SQL ● FAQ
books on
Connor McDonald
Amazon.com.

● The Oak Table


Oracle9i PL/SQL ● Cary Millsap and Hotsos
Programming ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/06/plsql-books.html (1 of 4)1/9/2008 2:52:45 AM


OracleBlog: PL/SQL Books

Scott Urman ● Anjo Kolk and OraPerf


32.99 ● Dizwell Oracle Wiki
664 Pages ● My Personal Blog
4 on 7 reviews
Rank in sales:
#5460

I really like
Aggregators
Steven Brian Duff's OraBlogs

Feuerstein's ❍ Eddie Awad's OracleNA


work, most of ❍ Pete Finnigan's Aggregator
which can be ❍ Oracle's Bloglist
found on the ❍ Oracle Base Aggregator
web. He's got
Q&A, Puzzlers,
and regular
Top Blogs
Oracle's Ask Tom Kyte
articles on

Oracle Guru Jonathan Lewis


Oracle's site.

Blogger of the Year Eddie Awad


You can find ❍

sample ❍ Data Warehouser David Aldridge


chapters on- ❍ Oracle Geek Lewis Cunningham
line. Despite ❍ Database Expert James Koopmann
the fact that I ❍ Dizwell's Howard Rogers
already have a ❍ Oracle Master Laurent Schneider
good PL/SQL ❍ Security Expert Pete Finnigan
book, I might ❍ Oracle Award Winner Mark Rittman
get this one, ❍ Doug Burns
too. He also has ❍ Oracle ACE of the Year Dr. Tim Hall
a "Best
UKOUG's Andrew (Arfur C.) Clarke
Practises" book.

❍ Newbie DBA Lisa Dobson


Oracle PL/SQL ❍ Coffee-Drinking DBA Jon Emmons
Programming, ❍ Chris Foot
Third Edition ❍ The Pythian DBA Team Blog
Steven ❍ DBA Don Seiler
Feuerstein ❍ DBA Coskan Gundogar
34.62 ❍ Oracle WTF
1018 Pages
4 on 66 reviews
Rank in sales:
ARCHIVES
LIST ALL ARTICLES
#17659

❍ May 2005
Connor ❍ June 2005
McDonald of ❍ July 2005

http://thinkoracle.blogspot.com/2005/06/plsql-books.html (2 of 4)1/9/2008 2:52:45 AM


OracleBlog: PL/SQL Books

the Oak Table ❍ August 2005


Network has a ❍ September 2005
highly rated PL/ ❍ October 2005
SQL book as ❍ November 2005
well. He also December 2005
has an Internet

January 2006
presense. His

February 2006
site is

awesome, he's ❍ March 2006


got some great ❍ April 2006
stuff, so his ❍ May 2006
book ought to ❍ June 2006
be great, too. I ❍ July 2006
wouldn't mind ❍ August 2006
picking this up. ❍ September 2006
October 2006
Mastering

November 2006
Oracle PL/SQL:

December 2006
Practical

January 2007
Solutions ❍

Connor ❍ February 2007


McDonald ❍ March 2007
32.99 ❍ April 2007
648 Pages ❍ May 2007
4.5 on 5 reviews ❍ June 2007
Rank in sales: ❍ October 2007
#106559

There are other


PL/SQL books
out there, but
any of these 3
is probably your
best bet. Leave
some
comments if
you have a
preference for
the 3, or know
of any other
really great PL/
SQL books to
consider.

http://thinkoracle.blogspot.com/2005/06/plsql-books.html (3 of 4)1/9/2008 2:52:45 AM


OracleBlog: PL/SQL Books

// posted by Robert
Vollman @ Thursday,

June 23, 2005

Comments:
Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/06/plsql-books.html (4 of 4)1/9/2008 2:52:45 AM


OracleBlog: OOP in PL/SQL? Yep

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, June 30,


About Me
2005
Name: Robert Vollman
OOP in PL/ Location: Calgary, Alberta, Canada
SQL? Yep
I was recently speaking I was born and raised in Ottawa, and have
with someone who was lived in Calgary since 1991. I like playing
stunned to find out that sports (hockey, soccer, ultimate, basketball, you name it)
object-oriented and military board games. I also enjoy reading, walking,
programming is and playing with my 2 cats Lilly and Brutus. I'm a
available in PL/SQL (as database application specialist, whatever that is.
of version 9, basically).
View my complete profile
I guess I was stunned
he didn't know this, but
then again, I guess
there isn't much fanfare Best Links
about it. ● Ask Tom Kyte
● Oracle Docs
Inheritance? Yep. ● Dan Morgan and PSOUG
Polymorphism? Yep. Steven Feuerstein
Encapsulation? Yep.

● Jonathan Lewis
I gave him this basic, ● FAQ
bare-bones template. It ● Connor McDonald
isn't much, but it can ● The Oak Table
get someone started. ● Cary Millsap and Hotsos
● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html (1 of 8)1/9/2008 2:52:48 AM


OracleBlog: OOP in PL/SQL? Yep

CREATE OR REPLACE ● Anjo Kolk and OraPerf


TYPE some_object AS ● Dizwell Oracle Wiki
OBJECT ( ● My Personal Blog

some_variable NUMBER
(10),

MEMBER FUNCTION
Aggregators
member_function Brian Duff's OraBlogs

RETURN NUMBER, ❍ Eddie Awad's OracleNA


MEMBER FUNCTION ❍ Pete Finnigan's Aggregator
member_function ❍ Oracle's Bloglist
(l_overloading IN ❍ Oracle Base Aggregator
NUMBER) RETURN
NUMBER,
MEMBER PROCEDURE
Top Blogs
Oracle's Ask Tom Kyte
member_procedure, ❍

❍ Oracle Guru Jonathan Lewis


-- Static functions can ❍ Blogger of the Year Eddie Awad
be used with an ❍ Data Warehouser David Aldridge
instance of the object ❍ Oracle Geek Lewis Cunningham
-- They can NOT ❍ Database Expert James Koopmann
reference any other ❍ Dizwell's Howard Rogers
non-static member ❍ Oracle Master Laurent Schneider
functions or variables
Security Expert Pete Finnigan
STATIC FUNCTION

Oracle Award Winner Mark Rittman


static_function (l_value

Doug Burns
IN NUMBER DEFAULT 1) ❍

RETURN NUMBER, ❍ Oracle ACE of the Year Dr. Tim Hall


❍ UKOUG's Andrew (Arfur C.) Clarke
-- Constructors must ❍ Newbie DBA Lisa Dobson
return self. ❍ Coffee-Drinking DBA Jon Emmons
Constructors are ❍ Chris Foot
optional ❍ The Pythian DBA Team Blog
CONSTRUCTOR ❍ DBA Don Seiler
FUNCTION some_object DBA Coskan Gundogar
(some_variable

Oracle WTF
NUMBER) RETURN SELF

AS RESULT,
ARCHIVES
-- Used for comparison ❍ LIST ALL ARTICLES
purposes: GROUP BY, ❍ May 2005
ORDER BY, DISTINCT ❍ June 2005
-- No parameters ❍ July 2005

http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html (2 of 8)1/9/2008 2:52:48 AM


OracleBlog: OOP in PL/SQL? Yep

allowed, returns ❍ August 2005


NUMBER, DATE, ❍ September 2005
VARCHAR2, CHAR or ❍ October 2005
REAL November 2005
MAP MEMBER

December 2005
FUNCTION

January 2006
map_member_function

February 2006
RETURN NUMBER ❍

❍ March 2006
-- ORDER takes one ❍ April 2006
parameter of same ❍ May 2006
type, and returns ❍ June 2006
NUMBER ❍ July 2006
-- You may only have ❍ August 2006
EITHER MAP OR ORDER ❍ September 2006
-- ORDER MEMBER
October 2006
FUNCTION

November 2006
order_member_function

December 2006
(some_other_object IN

some_object) RETURN ❍ January 2007


NUMBER ❍ February 2007
❍ March 2007
) ❍ April 2007
INSTANTIABLE -- Or ❍ May 2007
"NOT INSTANTIABLE" if ❍ June 2007
this is a base class only ❍ October 2007
NOT FINAL -- Or
"FINAL" if this class will
NOT have a sub-class
;

CREATE OR REPLACE
TYPE
composition_object AS
OBJECT (

composed_object
some_object

);

CREATE OR REPLACE
TYPE derived_object
UNDER some_object (

http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html (3 of 8)1/9/2008 2:52:48 AM


OracleBlog: OOP in PL/SQL? Yep

OVERRIDING MEMBER
PROCEDURE
member_procedure

);

CREATE OR REPLACE
TYPE BODY
some_object AS

MEMBER FUNCTION
member_function
RETURN NUMBER
IS
BEGIN
-- The "SELF" isn't
necessary, but is always
available by default in
member functions
RETURN SELF.
some_variable;
END member_function;

MEMBER FUNCTION
member_function
(l_overloading IN
NUMBER) RETURN
NUMBER
IS
BEGIN
RETURN l_overloading;
END member_function;

MEMBER PROCEDURE
member_procedure
IS
BEGIN
NULL;
END
member_procedure;

-- Note: Unlike with


packages, no private

http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html (4 of 8)1/9/2008 2:52:48 AM


OracleBlog: OOP in PL/SQL? Yep

functions or
declarations are
allowed.
-- MEMBER FUNCTION
hidden_proc RETURN
NUMBER ...

-- Remember, static
functions can't access
SELF variables
STATIC FUNCTION
static_function (l_value
IN NUMBER DEFAULT 1)
RETURN NUMBER
IS
BEGIN
RETURN l_value;
END static_function;

CONSTRUCTOR
FUNCTION some_object
(some_variable
NUMBER) RETURN SELF
AS RESULT
AS
BEGIN
SELF.some_variable :=
some_variable;

-- It will automatically
return self, don't even
try to return anything
else
RETURN;

END some_object;

MAP MEMBER
FUNCTION
map_member_function
RETURN NUMBER IS
BEGIN
RETURN SELF.
some_variable;

http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html (5 of 8)1/9/2008 2:52:48 AM


OracleBlog: OOP in PL/SQL? Yep

END
map_member_function;

-- ORDER MEMBER
FUNCTION
order_member_function
(some_other_object IN
some_object) RETURN
NUMBER IS
-- BEGIN
-- IF
some_other_object.
some_variable < SELF.
some_variable THEN
RETURN 1;
-- ELSIF
some_other_object.
some_variable > SELF.
some_variable THEN
RETURN -1;
-- ELSE RETURN 0;
-- END IF;
-- END
order_member_function;

END;

CREATE OR REPLACE
TYPE BODY
derived_object AS

OVERRIDING MEMBER
PROCEDURE
member_procedure
IS
BEGIN
NULL;
END
member_procedure;

END;

-- Test!

http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html (6 of 8)1/9/2008 2:52:48 AM


OracleBlog: OOP in PL/SQL? Yep

DECLARE
-- You MUST
instantiate it to use it.
A NULL object is hard
to use.
my_some_object
some_object :=
some_object(0);
my_composition_object
composition_object :=
composition_object
(my_some_object);
my_number NUMBER;
BEGIN
my_number :=
my_composition_object.
composed_object.
member_function;
my_number :=
some_object.
static_function
(my_number);
END;

// posted by Robert
Vollman @ Thursday, June 30,

2005

Comments:
This post has been
removed by a blog
administrator.
# posted by cc Infopage :
Tuesday, 11 October, 2005

This post has been


removed by a blog
administrator.
# posted by Tito Maury :
Wednesday, 08 February,

http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html (7 of 8)1/9/2008 2:52:48 AM


OracleBlog: OOP in PL/SQL? Yep

2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html (8 of 8)1/9/2008 2:52:48 AM


OracleBlog: Stored Procedure template

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday, July 13, 2005


About Me
Stored Procedure Name: Robert Vollman
template Location: Calgary, Alberta, Canada
Since there was some
interest in the "object" I was born and raised in Ottawa, and
template, have lived in Calgary since 1991. I like
playing sports (hockey, soccer, ultimate, basketball,
http://thinkoracle.blogspot. you name it) and military board games. I also enjoy
com/2005/06/oop-in-plsql- reading, walking, and playing with my 2 cats Lilly
yep.html and Brutus. I'm a database application specialist,
whatever that is.
and since I've been dry on
ideas lately because I haven't View my complete profile
been working on non-Oracle
things the last week or two, I
decided to share another one
of my templates. This time:
Best Links
stored procedures. Enjoy! ● Ask Tom Kyte
● Oracle Docs
SET SERVEROUTPUT ON; ● Dan Morgan and PSOUG
Steven Feuerstein
-- 'NOCOPY' makes it a

Jonathan Lewis
pointer (pass by reference) -

FAQ
faster.

-- 'DETERMINISTIC' means ● Connor McDonald


the output is the same for ● The Oak Table
every input - allows caching ● Cary Millsap and Hotsos

http://thinkoracle.blogspot.com/2005/07/stored-procedure-template.html (1 of 5)1/9/2008 2:52:50 AM


OracleBlog: Stored Procedure template

(for return type tables) ● Steve Adams and Ixora


-- CREATE OR REPLACE ● Anjo Kolk and OraPerf
FUNCTION MyFunc ● Dizwell Oracle Wiki
(p_something IN OUT ● My Personal Blog
NOCOPY Transactions.
number%TYPE)
-- RETURN BOOLEAN
DETERMINISTIC
-- 'DEFAULT' is the same as ':
Aggregators
Brian Duff's OraBlogs
=' for both here and DECLARE ❍

CREATE OR REPLACE ❍ Eddie Awad's OracleNA


PROCEDURE MyProc ❍ Pete Finnigan's Aggregator
(p_something IN ❍ Oracle's Bloglist
Transactions.number%TYPE ❍ Oracle Base Aggregator

Top Blogs
DEFAULT 1)
-- The following says it is
independent of anything Oracle's Ask Tom Kyte
calling it (eg: rollbacks, etc)

Oracle Guru Jonathan Lewis


-- IS PRAGMA

Blogger of the Year Eddie Awad


AUTONOMOUS_TRANSACTION

Data Warehouser David Aldridge


AS ❍

[[BlockName]] ❍ Oracle Geek Lewis Cunningham


-- If its an anonymous block: ❍ Database Expert James Koopmann
-- DECLARE ❍ Dizwell's Howard Rogers
v_datetime TIMESTAMP; ❍ Oracle Master Laurent Schneider
v_transaction Transactions. ❍ Security Expert Pete Finnigan
number%TYPE := 0; ❍ Oracle Award Winner Mark Rittman
v_the_date_is CONSTANT ❍ Doug Burns
VARCHAR2(12) := 'The date ❍ Oracle ACE of the Year Dr. Tim Hall
is '; ❍ UKOUG's Andrew (Arfur C.) Clarke
Newbie DBA Lisa Dobson
-- Create an exception, the ❍

pragma is optional ❍ Coffee-Drinking DBA Jon Emmons


v_my_exception EXCEPTION; ❍ Chris Foot
PRAGMA EXCEPTION_INIT ❍ The Pythian DBA Team Blog
(v_my_exception, 100); ❍ DBA Don Seiler
❍ DBA Coskan Gundogar
-- subprograms (functions) ❍ Oracle WTF
MUST be declared last
PROCEDURE NothingReally IS
BEGIN NULL; END
ARCHIVES
NothingReally; ❍ LIST ALL ARTICLES
BEGIN ❍ May 2005
❍ June 2005

http://thinkoracle.blogspot.com/2005/07/stored-procedure-template.html (2 of 5)1/9/2008 2:52:50 AM


OracleBlog: Stored Procedure template

-- SET TRANSACTION READ ❍ July 2005


ONLY; -- Use consistent ❍ August 2005
snapshot of the database ❍ September 2005
-- SET TRANSACTION READ October 2005
WRITE; -- The default. Turns

November 2005
"off" the Read Only

December 2005
-- SET TRANSACTION

January 2006
ISOLATION LEVEL READ ❍

COMMITTED ❍ February 2006


-- SET TRANSACTION ❍ March 2006
ISOLATION LEVEL ❍ April 2006
SERIALIZABLE ❍ May 2006
-- SET TRANSACTION USE ❍ June 2006
ROLLBACK SEGMENT ❍ July 2006
❍ August 2006
-- This is a comment
September 2006
SELECT systime INTO

October 2006
BlockName.v_datetime FROM

November 2006
dual;

DBMS_OUTPUT.PUT_LINE ❍ December 2006


(v_the_date_is || v_datetime); ❍ January 2007
❍ February 2007
[[LoopName]] ❍ March 2007
IF 1=1 ❍ April 2007
THEN NULL; ❍ May 2007
ELSIF 1=2 ❍ June 2007
THEN RAISE October 2007
NO_DATA_FOUND;

ELSE
THEN NothingReally;
END IF;

CASE
WHEN 1=1 THEN NULL;
-- Application Errors have to
be -20000 to -20999
inclusive and can't be caught
specifically
WHEN 1=2 THEN
RAISE_APPLICATION_ERROR(-
20000, 'Error: '||
v_the_date_is||' BAH');
ELSE NULL;
END CASE;

http://thinkoracle.blogspot.com/2005/07/stored-procedure-template.html (3 of 5)1/9/2008 2:52:50 AM


OracleBlog: Stored Procedure template

LOOP
EXIT WHEN 1=1;
END LOOP;

FOR v_transaction IN 0 .. 10
LOOP
NULL;
END LOOP;

WHILE 1=2
LOOP
RAISE v_my_exception;
END LOOP;

COMMIT;
EXCEPTION
-- This only covers errors
raised after BEGIN (but NOT
in 'DECLARE'!)
-- You can "OR" exceptions.
-- An exception can't be in
more than 1 block
WHEN v_my_exception
THEN NULL;
-- This is optional but good
practice.
-- Unhandled exceptions fall
through to the next block or
statement
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE
('SQLERRM: ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE
('SQLCODE: ' || SQLCODE);
END MyProc;
/

// posted by Robert
Vollman @ Wednesday, July 13, 2005

http://thinkoracle.blogspot.com/2005/07/stored-procedure-template.html (4 of 5)1/9/2008 2:52:50 AM


OracleBlog: Stored Procedure template

Comments: Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/07/stored-procedure-template.html (5 of 5)1/9/2008 2:52:50 AM


OracleBlog: Natural vs Synthetic keys

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I think data,
I think Oracle. I also enjoy writing, so I use this format to organise my thoughts. Please feel free
to discuss any thoughts you may have on the same topics, even old ones (I will see and respond
to such comments). You may want to start with "LIST ALL ARTICLES" under Archives.

Tuesday, June 21, 2005


Natural vs Synthetic keys
Primary keys should be:
1. Unique
2. Never changed (or very infrequently)

This is because they are used in other tables to reference a single row.

(Definitions from www.orafaq.com)


Natural Key: A key made from existing attributes.
Surrogate Key: A system generated key with no business value. Usually
implemented with database generated sequences.

This topic has been discussed at great length many times. We recently re-hashed it
on the Dizwell Forum.

Disadvantages:

EDIT: Please note: There are some potentially important corrections and
clarifications to the below. Please see Howard's comments and follow the links to
his blog or the forum discussion.

Natural keys:
- May require the concatentation of many columns, so it gets very long
- Sometimes a natural key can be hard to find (in example: names can change)
- In a sense, you are duplicating data
- Can lead to future conflicts when the database expands beyond original
requirements
- Care must be taken to avoid block-splitting
- Care must be taken to avoid index range scans
- Tend to change, albeit infrequently

"You nearly always end up having to append a number to guarantee both

http://thinkoracle.blogspot.com/2005/06/natural-vs-synthetic-keys.html (1 of 8)1/9/2008 2:52:53 AM


OracleBlog: Natural vs Synthetic keys

uniqueness and existence. If I always have to append a guaranteed unique existing


number to ensure I meet my requirements, why not make it the key itself."
- Niall Litchfield

Synthetic/Surrogate keys:
- Meaningless by itself (ie. no relationship to the data to which it is assigned)
- Implementation is database-dependent
- Care must be taken to avoid contention (monotically increasing and smaller
indexes)
- Similar rows would not have similar keys

Gauss suggested considering using a GUID for the surrogate key. No trigger is
required, uniqueness is guaranteed over space and time, but it is 16 bytes.

SQL> CREATE TABLE atable (pk RAW(16) DEFAULT SYS_GUID() PRIMARY KEY,
2 a_str VARCHAR2(32));
Table created.
SQL> INSERT INTO atable (a_str) VALUES ('One');
1 row created.
SQL> INSERT INTO atable (a_str) VALUES ('Two');
1 row created.
SQL> SELECT * FROM atable;
PK A_STR
-------------------------------- --------------------------------
5C3BCF77D55B41E78DE4016DFBE25FFA One
D3B959F3010745D3854F8FC2B09A18F3 Two

// posted by Robert Vollman @ Tuesday, June 21, 2005

Comments:
Howard Rogers responded to this discussion on his blog, mostly to assert that
there is legitimacy to the "natural keys" opinion (some people felt there wasn't).

http://www.dizwell.com/2005/06/natural-or-synthetic-primary-keys.html
# posted by Robert Vollman : Thursday, 23 June, 2005

The item "Care must be taken to avoid index range scans" is wrong. The point is
that if you use a synthetic key, you will tend to have a 'right-hand index', for which
the "usual" cure is to rebuild the index as a reverse-key index.

But if you then issue a query against the contents of that index (unlikely, if the
synthetic key is a meaningless sequence number, but it has been done), the
reversing of the index means that what ought to have been a quick range scan
turns into a full scan on the index... though the optimiser at that point likely gives

http://thinkoracle.blogspot.com/2005/06/natural-vs-synthetic-keys.html (2 of 8)1/9/2008 2:52:53 AM


OracleBlog: Natural vs Synthetic keys

up and just scans the table instead.

A range scan on a natural selection of data is *not* a problem at all, of course.

So, you need to remove that item from your 'disadvantages with natural keys'
selection, and add it to the disadvantages of synthetic keys. (A section which,
unaccountably, seems to be missing from your summation!)

Similarly, the block-splitting item is not a legitimate entry. The issue there was
that a reversed synthetic index will block split, whereas a non-reversed synthetic
index will not. It is an issue with synthetic keys that you "must carefully decide
whether to reverse them or not", because block splitting is either a non-event or
an issue depending on your decision.

It is never an issue with natural keys, because they inevitably and intrinsically
block-split anyway, assuming only that data arrives at your table in a fairly random
order. There is no "will it/won't it" dilemma, therefore, with natural keys. The
answer is "It will". Sure, you then have to set a PCTFREE to deal with that. But a
natural key-er knows that. The concern is that a synthetic key-er might not know,
or realise that it's important to care, that the decision to reverse or not has major
implications for the setting of PCTFREE.

I also disagree with your "You are duplicating data" statement. That is again a
disadvantage of synthetic keys, not natural ones. Synthetic keys require the
introduction of an ID column into the table which wasn't "naturally" there. Extra
data in the table for a start. Then there's an index on that column because it's the
primary key. Extra data storage requirement Number 2. And *then* you probably
have to put a unique constraint on the natural columns, because otherwise there's
no protection against duplication. So now you have a new index containing large
amounts of data. That's two indexes to both provide a primary key and protect
against duplication of natural data.

In a natural key setting, you don't have a spurious ID column for starters. There's
no index on that extra column, therefore. And the natural primary key intrinsically
indexes the natural columns and protects them from data duplication. There is one
table, one index.

So which scenario requires more storage?

I'm not seeking to re-open the debate in the pages of your blog, just trying to
point out areas of the Forum debate which I think have been misunderstood, or
mischaracterised.
# posted by Howard J. Rogers : Thursday, 23 June, 2005

Thanks for the corrections, Howard, Your clarifications are very welcome.

Rather than try to explain them myself, I will add a note to the blog pointing
people to your comments, and your related blog (there is already a pointer to the

http://thinkoracle.blogspot.com/2005/06/natural-vs-synthetic-keys.html (3 of 8)1/9/2008 2:52:53 AM


OracleBlog: Natural vs Synthetic keys

forum discussion).

There is already a summation of the disadvantages of synthetic/surrogate keys


immediately following Niall's quote. You probably got too hot to read that far. :)

This is what I meant by duplication of data:

Last_name: Gretzky
First_name: Wayne
DOB: 26-Jan-61
ID: Gretzky_Wayne_260161

The ID just duplicated 3 columns worth of data.


# posted by Robert Vollman : Thursday, 23 June, 2005

I really opened the pickle jar this time!

David Aldridge has a contrasting viewpoint to Howard's. Here is his blog article:

http://oraclesponge.blogspot.com/2005/06/natural-and-synthetic-keys.html
# posted by Robert Vollman : Monday, 27 June, 2005

I think that the topics of the size of the required index and the rate of block splits
are related, are they not? Whether the index is built on a natural key or on a
synthetic key (RKI there for the purpose of this, of course) you increase the
chances of block splits by increasing the amount of free space per index block,
either by reducing the size of the indexed values or by spreading them over more
blocks (hence the index itself is larger).

Or have I been thinking about this too hard?


# posted by David Aldridge : Monday, 27 June, 2005

Here is Pete's take on the topic, and look in the comments for a link to Tom Kyte's.

http://pjs-random.blogspot.com/2005/06/surrogate-keys.html
# posted by Robert Vollman : Monday, 04 July, 2005

One disadvantage of synthetic keys I don't see mentioned here: In many cases they
require an extra join. Suppose, for example, I have a table of U.S. states, where a
natural key would be two-letter state abbreviation. I have another table of tax
rates with a foreign key that ties it back to the state. If I want a query that gives
information about each tax rate including the state it applies to, but I don't care
about any other information from the state table, with a natural key I would just
display the key because it is already a human-comprehensible identification of the

http://thinkoracle.blogspot.com/2005/06/natural-vs-synthetic-keys.html (4 of 8)1/9/2008 2:52:53 AM


OracleBlog: Natural vs Synthetic keys

state. With a synthetic key I would have to join on the state table to find the state
abbreviation. For production queries this can be a major performance hit. For ad
hoc queries it can be a big hassle to have to construct more complex queries and
make sure they're correct.

Another advantage of natural keys is that they make it much easier to resolve
database corruption problems. Suppose in the above example I used a synthetic
key, and we find that due to database corruption state records 17, 19, and 24 have
been lost. When we try to repair the problem, we can't just add back in those three
records in any order. We have to study the records with the state-id posted as a
foreign key to figure out which state was #17, which was #19, and which was #24,
so that we can keep everything pointed to the correct record. It may not be at all
obvious looking at the tax rate table what state any given record should apply to.
But if we use a natural key, this would be zero problem.

And I must object to the unfairness of your "Gretzky_Wayne_260161" example. If


this was a political debate I think I'd be screaming "propaganda tactics". If the
question is, "Do database designers who prefer natural keys sometimes do things
that are totally stupid and pointless in a vain attempt to avoid having to create a
synthetic key in situations when there is no natural key available?" then okay, this
is an example that proves that the answer is "yes". But the fact that some people
attempt to apply a principle in an incompetent way doesn't mean the principle is
flawed. I think every introductory database design book ever written points out
that a name is not a suitable primary key because we cannot be sure it is unique:
we might well have many people named "Jim Smith" in our database. And about
90% of them point out that concatenating multiple fields in order to create some
combination that is unlikely to be duplicated is inadequate, because "unlikely" isn't
good enough in database design. Even if we were talking about a set of fields that
would make a suitable key, duplicating data by concatenating several fields into
one is just ... why would you want to do this? If your answer is, "So I have a single
key field rather than having to mess with multiple fields", then I think you failed
the class on data normalization. I tend to prefer natural keys, but I readily
recognize that there are cases where there is no natural key, or where the only
available natural key is impractical to use (like, it requires six fields totalling 500
bytes) and so the only practical choice is a synthetic key.
# posted by Anonymous : Tuesday, 13 March, 2007

Isn't the two-letter abbreviation for a state a synthetic key?

Isn't it, too, a quasi-duplication of data since it is based on the state's name (which
would be a natural key)?
# posted by Robert Vollman : Tuesday, 13 March, 2007

"Isn't the two-letter abbreviation for a state a synthetic key?"

No, not in this context. A natural key isn't necessarily all that natural: it's a value in

http://thinkoracle.blogspot.com/2005/06/natural-vs-synthetic-keys.html (5 of 8)1/9/2008 2:52:53 AM


OracleBlog: Natural vs Synthetic keys

a domain defined and controlled outside the boundaries of the system we are
designing.
# posted by Jim Gawn : Thursday, 14 June, 2007

Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I like
playing sports (hockey, soccer, ultimate, basketball, you name it) and military
board games. I also enjoy reading, walking, and playing with my 2 cats Lilly and Brutus. I'm a
database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
http://thinkoracle.blogspot.com/2005/06/natural-vs-synthetic-keys.html (6 of 8)1/9/2008 2:52:53 AM
OracleBlog: Natural vs Synthetic keys

Brian Duff's OraBlogs


❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006

http://thinkoracle.blogspot.com/2005/06/natural-vs-synthetic-keys.html (7 of 8)1/9/2008 2:52:53 AM


OracleBlog: Natural vs Synthetic keys

❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/06/natural-vs-synthetic-keys.html (8 of 8)1/9/2008 2:52:53 AM


OracleBlog: Optimizer

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday,
About Me
March 29, 2006
Name: Robert Vollman
Optimizer Location: Calgary, Alberta, Canada
There is a great
debate in the I was born and raised in Ottawa, and have lived in
database Calgary since 1991. I like playing sports (hockey,
application soccer, ultimate, basketball, you name it) and military board
development games. I also enjoy reading, walking, and playing with my 2 cats
community. I Lilly and Brutus. I'm a database application specialist, whatever
have encountered that is.
many developers
who prefer View my complete profile
putting all their
business logic in
the application
code and using Best Links
the database only ● Ask Tom Kyte
as a glorified file ● Oracle Docs
system. ● Dan Morgan and PSOUG
● Steven Feuerstein
You pick your
Jonathan Lewis
battles carefully

FAQ
with these

Connor McDonald
developers. I

always thought ● The Oak Table


the "line of last ● Cary Millsap and Hotsos
defense" was ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/03/optimizer.html (1 of 9)1/9/2008 2:52:56 AM


OracleBlog: Optimizer

data integrity ● Anjo Kolk and OraPerf


rules. When I ● Dizwell Oracle Wiki
encountered a ● My Personal Blog
particularly
stubborn
developer, I
decided that I
would focus on
Aggregators
Brian Duff's OraBlogs
convincing him

Eddie Awad's OracleNA


to, at the very ❍

least, use his ❍ Pete Finnigan's Aggregator


expensive RDBMS ❍ Oracle's Bloglist
to protect his ❍ Oracle Base Aggregator

Top Blogs
data's integrity
(through use of
constraints and ❍ Oracle's Ask Tom Kyte
keys). ❍ Oracle Guru Jonathan Lewis
Blogger of the Year Eddie Awad
However, I have ❍

learned that ❍ Data Warehouser David Aldridge


there is actually a ❍ Oracle Geek Lewis Cunningham
whole other ❍ Database Expert James Koopmann
battlefield to my ❍ Dizwell's Howard Rogers
rear. I just came ❍ Oracle Master Laurent Schneider
across a ❍ Security Expert Pete Finnigan
database ❍ Oracle Award Winner Mark Rittman
application that ❍ Doug Burns
overrides the ❍ Oracle ACE of the Year Dr. Tim Hall
optimizer. Every
UKOUG's Andrew (Arfur C.) Clarke
database query

Newbie DBA Lisa Dobson


this application

Coffee-Drinking DBA Jon Emmons


ever executes ❍

includes a forced ❍ Chris Foot


index. ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
What do I mean? ❍ DBA Coskan Gundogar
Why does that ❍ Oracle WTF
bother me? Let
me take a short
step back to
ARCHIVES
LIST ALL ARTICLES
explain what I

mean. ❍ May 2005


❍ June 2005
Think about ❍ July 2005

http://thinkoracle.blogspot.com/2006/03/optimizer.html (2 of 9)1/9/2008 2:52:56 AM


OracleBlog: Optimizer

when you ❍ August 2005


execute a query ❍ September 2005
to access some ❍ October 2005
data. That data ❍ November 2005
you are December 2005
requesting could

January 2006
be from several

February 2006
tables, spread all

over the disk. ❍ March 2006


The optimizer ❍ April 2006
does many ❍ May 2006
things, among ❍ June 2006
them to choose ❍ July 2006
how every query ❍ August 2006
is executed. That ❍ September 2006
means, for ❍ October 2006
instance, it ❍ November 2006
selects in which December 2006
order the tables

January 2007
will be joined,

February 2007
and which

March 2007
indexes will be ❍

used to access ❍ April 2007


the data. ❍ May 2007
❍ June 2007
In the past, ❍ October 2007
presumably when
this application
was written,
Oracle used a
rule-based
optimizer (RBO),
which used a set
of rules to
determine how to
access the data.
The RBO did not
always make
ideal choices.
Neither did the
early versions of
the cost-based
optimizer (CBO).

http://thinkoracle.blogspot.com/2006/03/optimizer.html (3 of 9)1/9/2008 2:52:56 AM


OracleBlog: Optimizer

That is why many


developers took
advantage of
their ability to
override the
optimizers and
tell it (for
example) which
join order or
indexes to use.

But that's the


past. Let's talk
about the present.

For several years


now, I've never
experienced a
legitimate need
to override the
optimizer.
Usually re-
generating my
DBMS_STATS is
all I need to do in
order to
guarantee good
choices.

As Jonathan
Lewis describes
in his latest book
Cost-Based
Oracle
Fundamentals,
the CBO has
come a long way.
You are doing
yourself a great
disservice when
you aren't
updating your
applications to

http://thinkoracle.blogspot.com/2006/03/optimizer.html (4 of 9)1/9/2008 2:52:56 AM


OracleBlog: Optimizer

take advantage
of it.

Both his book,


and Oracle's
Database
Performance and
Tuning Guide
describe the
optimizer in
more detail, and
present the
various ways you
can leverage its
power. I really
can't think of any
reason why we
still need to fight
these battles with
even the most
stubborn of
developers.

// posted by Robert
Vollman @ Wednesday,

March 29, 2006

Comments:
Try this for size:
forget tables,
indexes, primary
keys, foreign
keys (don't even
mention that
optimiser word)
and all that other
old fashioned
nonsense. Why
on earth would
developers need

http://thinkoracle.blogspot.com/2006/03/optimizer.html (5 of 9)1/9/2008 2:52:56 AM


OracleBlog: Optimizer

to know about all


that stuff? It's
just boring and
tedious having to
get to know
about it.

Instead just
redirect your
development
effort into
building
applications that
hold all the logic
and link back to
denormalised
"tables". Let's call
it a "query layer"
approach. This
way you can save
on trivial things
like database
training and
concentrate on
all the important
stuff like xml and
agile
programming... it
will be ok won't
it?!

I don't agree with


the approach
described
above... where
did I leave my
spreadsheet?

the word
verification
seems sort of
ironic: uiokj (or
am I just
paranoid?)

http://thinkoracle.blogspot.com/2006/03/optimizer.html (6 of 9)1/9/2008 2:52:56 AM


OracleBlog: Optimizer

# posted by Peter
Lewis : Wednesday,
29 March, 2006

I've fought this


battle too. It gets
frustrating after a
while. At least
half the time
after arguing to
put all the
business logic in
the application,
they come back
later and ask for
it in the database
anyway becuase
they can't do
something or
some other
application needs
the same
functionality.
Argh!

c'est la vie, I
guess.

LewisC
# posted by
LewisC :
Wednesday, 29
March, 2006

At least ours are


consistent. If
they choose to
implement some
functionality in
the app layer,
and then need it

http://thinkoracle.blogspot.com/2006/03/optimizer.html (7 of 9)1/9/2008 2:52:56 AM


OracleBlog: Optimizer

for another app


they will put that
functionality in
the second app
as well. Not the
same code
obviously it will
be rewritten...
# posted by Niall :
Wednesday, 29
March, 2006

This post has


been removed by
a blog
administrator.
# posted by
Phantom
Nitpicker : Thursday,
30 March, 2006

I think you mean


'last line of
defense'. Perhaps
you are thinking
of 'path of least
resistance'.
# posted by
Phantom
Nitpicker : Thursday,
30 March, 2006

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/03/optimizer.html (8 of 9)1/9/2008 2:52:56 AM


OracleBlog: Optimizer

http://thinkoracle.blogspot.com/2006/03/optimizer.html (9 of 9)1/9/2008 2:52:56 AM


OracleBlog: PL/SQL Code Storage: Files vs In-DB Packages

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, September 19, 2005


About Me
PL/SQL Code Storage: Name: Robert Vollman
Files vs In-DB Location: Calgary, Alberta,
Packages Canada
I read this interesting exchange on
Steven Feuerstein's Q&A: I was born and raised in
Ottawa, and have lived in Calgary since
http://htmldb.oracle.com/pls/otn/ 1991. I like playing sports (hockey, soccer,
f? ultimate, basketball, you name it) and
p=2853:4:1727923121986559057:: military board games. I also enjoy reading,
walking, and playing with my 2 cats Lilly
NO::P4_QA_ID:246
and Brutus. I'm a database application
specialist, whatever that is.
Essentially the question is where to
stored your PL/SQL stored
procedures. H. Sheehan, Gary View my complete profile
Myers, William Robertson, Pete
Scott, Scott Swank, A. Nadrian and I
discussed this on the Dizwell Best Links
Forum. ● Ask Tom Kyte
Oracle Docs
http://www.phpbbserver.com/

Dan Morgan and PSOUG


phpbb/viewtopic.php?

Steven Feuerstein
t=458&mforum=dizwellforum

● Jonathan Lewis
To sum up their positions: ● FAQ
● Connor McDonald

http://thinkoracle.blogspot.com/2005/09/plsql-code-storage-files-vs-in-db.html (1 of 4)1/9/2008 2:52:58 AM


OracleBlog: PL/SQL Code Storage: Files vs In-DB Packages

Option 1: In organized, packaged The Oak Table


files on your DB server ● Cary Millsap and Hotsos


- Fewer security holes ● Steve Adams and Ixora
- Handles failover situations better ● Anjo Kolk and OraPerf
- Easier to use version-control ● Dizwell Oracle Wiki
system ● My Personal Blog
- Available for a greater number of
nice PL/SQL editors
- Harder to inadvertantly overwrite
source code, leads to greater
confidence
Aggregators
Brian Duff's OraBlogs

Option 2: In-the-db packages ❍ Eddie Awad's OracleNA


- Greater efficiency (pre-loaded) ❍ Pete Finnigan's Aggregator
- Greater code integrity (shows ❍ Oracle's Bloglist
invalidation) ❍ Oracle Base Aggregator
- Search code in USER_SOURCE
table
- Use some PL/SQL tools easier
Top Blogs
(Note: there are IDEs that integrate Oracle's Ask Tom Kyte

with source control and compile ❍ Oracle Guru Jonathan Lewis


directly into the database) ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
It seems like the leading camp is ❍ Oracle Geek Lewis Cunningham
Option 2. The advantages of having ❍ Database Expert James Koopmann
your packages pre-loaded into the ❍ Dizwell's Howard Rogers
database are just so significant,
Oracle Master Laurent Schneider
especially since you should be able

Security Expert Pete Finnigan


to find an IDE that integrates

Oracle Award Winner Mark Rittman


directly with source control and can ❍

compile directly into the database. ❍ Doug Burns


Scott Swank provided this ❍ Oracle ACE of the Year Dr. Tim Hall
suggestion: ❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
http://www.oracle.com/technology/ ❍ Coffee-Drinking DBA Jon Emmons
products/jdev/101/ ❍ Chris Foot
howtos/extools/subversion.html ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
One general consensus, however, is ❍ DBA Coskan Gundogar
this: Oracle WTF
- Code should be contained in

packages
- These packages should be
ARCHIVES
❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/09/plsql-code-storage-files-vs-in-db.html (2 of 4)1/9/2008 2:52:58 AM


OracleBlog: PL/SQL Code Storage: Files vs In-DB Packages

wrapped. ❍ May 2005


❍ June 2005
// posted by Robert Vollman @ Monday, ❍ July 2005
September 19, 2005 ❍ August 2005
❍ September 2005
❍ October 2005
Comments: ❍ November 2005
It seems to me that the answer to ❍ December 2005
this is one that comes down to ❍ January 2006
mere personal preference. Both February 2006
camps include the statement that

March 2006
no matter what you do, the trusted

April 2006
version of the source code is in

May 2006
version control and you always ❍

deploy from there. ❍ June 2006


❍ July 2006
I'd say that message is the ❍ August 2006
important one. ❍ September 2006
# posted by Rob Baillie : Tuesday, 20 ❍ October 2006
September, 2005 ❍ November 2006
❍ December 2006
❍ January 2007
I think the original answer missed ❍ February 2007
the point of the question. ❍ March 2007
April 2007
The alleged DBA seems to me to be ❍

arguing against using PL/SQL ❍ May 2007


packages AT ALL, but the answer ❍ June 2007
and many of the following ❍ October 2007
comments seem to assume he/she
could not have been that stupid
and must have been referring to the
best place to keep master copies of
the source code.

>> My DBA friend argued that code


stored in the database does not
handle failover well and that storing
code in the database creates
security holes.

This is a non sequitur. It is


SQL*Plus scripting that does not

http://thinkoracle.blogspot.com/2005/09/plsql-code-storage-files-vs-in-db.html (3 of 4)1/9/2008 2:52:58 AM


OracleBlog: PL/SQL Code Storage: Files vs In-DB Packages

handle failover well and creates


security holes, and pretty bizarre to
argue the opposite. This goes for
all the other points claimed as
advantages too. I really don't see
what is being argued.
# posted by William Robertson : Tuesday,
20 September, 2005

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/09/plsql-code-storage-files-vs-in-db.html (4 of 4)1/9/2008 2:52:58 AM


OracleBlog: PL/SQL vs J2EE

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday,
About Me
January 18, 2006
Name: Robert Vollman
PL/SQL vs Location: Calgary, Alberta, Canada
J2EE
Let's say you're I was born and raised in Ottawa, and have lived in
designing an Calgary since 1991. I like playing sports (hockey,
enterprise-wide soccer, ultimate, basketball, you name it) and military board
OLTP Web games. I also enjoy reading, walking, and playing with my 2 cats
Application with Lilly and Brutus. I'm a database application specialist, whatever
Data that is.
Warehousing,
Reporting and View my complete profile
multiple
interfaces to
various external
systems for large
Best Links
volumes of data. ● Ask Tom Kyte
Where do you put ● Oracle Docs
your business ● Dan Morgan and PSOUG
logic? Do you ● Steven Feuerstein
embed your SQL ● Jonathan Lewis
into your Java ● FAQ
code, or do you ● Connor McDonald
keep your SQL in ● The Oak Table
the database,
Cary Millsap and Hotsos
and write stored

● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (1 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

procedures? ● Anjo Kolk and OraPerf


● Dizwell Oracle Wiki
Regardless of ● My Personal Blog
your answer, you
are wandering
into one of the
older and more
heated
Aggregators
arguments in this Brian Duff's OraBlogs

community. ❍ Eddie Awad's OracleNA


(Classic examples ❍ Pete Finnigan's Aggregator
of one: here and ❍ Oracle's Bloglist
here) I don't ❍ Oracle Base Aggregator
mean to re-ignite
it, but I do want Top Blogs
to understand it. ❍ Oracle's Ask Tom Kyte
Oracle Guru Jonathan Lewis
"It is a religious

Blogger of the Year Eddie Awad


war though, they

cannot be won by ❍ Data Warehouser David Aldridge


reason or ❍ Oracle Geek Lewis Cunningham
objectivity." - ❍ Database Expert James Koopmann
Tom Kyte ❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
It would appear ❍ Security Expert Pete Finnigan
like Java ❍ Oracle Award Winner Mark Rittman
programmers Doug Burns
hate stored

Oracle ACE of the Year Dr. Tim Hall


procedures. They

UKOUG's Andrew (Arfur C.) Clarke


are viewed as

Newbie DBA Lisa Dobson


hard to maintain, ❍

and not scalable. ❍ Coffee-Drinking DBA Jon Emmons


To them, ❍ Chris Foot
scalability means ❍ The Pythian DBA Team Blog
spreading out the ❍ DBA Don Seiler
workload, ❍ DBA Coskan Gundogar
running on ❍ Oracle WTF
several small
machines. ARCHIVES
Some don't even ❍ LIST ALL ARTICLES
like to write the ❍ May 2005
SQL themselves, ❍ June 2005
instead ❍ July 2005

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (2 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

preferring to use ❍ August 2005


a framework like ❍ September 2005
Hybernate or ❍ October 2005
TopLink do it, ❍ November 2005
and then rest ❍ December 2005
their heads on January 2006
their pillows at

February 2006
night dreaming

March 2006
of fewer errors/

portability issues ❍ April 2006


and better ❍ May 2006
performance. But ❍ June 2006
even if they can't ❍ July 2006
achieve the ❍ August 2006
better ❍ September 2006
performance the ❍ October 2006
database guys ❍ November 2006
keep bragging ❍ December 2006
about, they're January 2007
more than happy

February 2007
to accept greater

March 2007
ease of

April 2007
development and ❍

maintainability in ❍ May 2007


exchange. ❍ June 2007
❍ October 2007
Plus, Java
programmers
love choices. Lots
of tools, unit
testing packages,
libraries - all
open source -
not to mention a
huge community.
They wouldn't
want to get
attached to any
database vendor,
especially one
that is expensive
and proprietary.

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (3 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

"If you want


portability keep
logic out of SQL."
- Martin Fowler

At the other end


of the spectrum
are the database
specialists. They
walk around with
print-outs of all
the horrible SQL
statements Java
programmers
have written that
are choking the
database, with
serialization and
loads of parsing.
"Leave the SQL to
us!" they plead in
vain, "it's too
hard for you,
especially with
this crappy
database design!"
They may
secretly admire
the Java
progammers
ability to write
procedural or
object-oriented
code, but they
believe that they
lack the key to
unlocking
database
performance:
"set-based"
mentality.

They look at a

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (4 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

Java application
and all they can
see if multiple
database trips
where the SQL
could have been
combined into a
single stored
procedure
making one trip.
They examine
their EJB
containers and
then lecture the
programmers on
recognising and
understanding
the difference
between read-
write and read-
only situations.

The database
specialist isn't as
impressed by the
Java
programmer's
triumphant
removal from
database
dependence, for
if you aren't tying
yourself to a
database you are
losing out on all
its power.

Where does that


leave us?

The fundamental
question is where
the business
logic should be.

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (5 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

The Java
programmer,
who sometimes
refers to it as
domain logic,
wants business
logic out of the
database, often
in the name of
database
independence.
Even without this
argument, they
see live or non-
relational data, in
different formats,
much of it
transient and
with complex
rules ... why write
piles of
unmaintainable
PL/SQL for that?
They may
concede that
some validation
constraints are
OK, but even that
isn't for sure.

Here is an
argument on
avoiding putting
your Domain
Logic into SQL,
from none other
than Martin
Fowler:
http://www.
martinfowler.
com/articles/
dblogic.html

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (6 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

"Do not use


stored
procedures to
implement
business logic.
This should be
done in Java
business
objects." - Rod
Johnson

The database
specialist views
business rules as
data rules and
thus belongs
close to the data.
If there are some
business rules or
business
relationships
between various
entities, well that
should be
enforced in the
same place
where the data is
stored: the
database. You've
bought
expensive,
sophisticated
software capable
of managing your
data in a fast,
reliable,
scaleable way:
use it!

Consider a very
simple argument
put forward by
database

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (7 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

specialist Tony
Andrews about
putting the
business logic in
the database:
http://
tonyandrews.
blogspot.
com/2005/04/
business-logic-
apis.html

Here is an article
about a database-
centric approach
to J2EE
application
development:
http://www.
oracle.com/
technology/pub/
articles/
odtug_award.pdf

A Final Plea

I don't think
there really is a
right answer and
a wrong answer
in general terms.
But armed with
an awareness of
the debate, its
basic framework
and a few
starting points,
we can make the
decisions that
make sense on a
project-by-
project basis.

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (8 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

Note: This is one


of the first times
I've put up a non-
technical post, so
I'll be curious if
there is any
demand for more.

// posted by Robert
Vollman @ Wednesday,

January 18, 2006

Comments:
Rob,

Although I also
like your
technical guides,
I really enjoyed
this blog. It's well
worth the effort,
to get the subject
on the table for
those who might
not be aware of it.

Cheers,

Doug
# posted by Doug
Burns : Wednesday,
18 January, 2006

I enjoy everything
you write Rob.
# posted by Eddie
Awad : Wednesday,
18 January, 2006

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (9 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

I agree. It does
not matter if it is
technical or not,
it gives people
ideas and views.
# posted by yas :
Thursday, 19 January,
2006

every case and


his solution.
there is no global
answer for that.
each
oragnization
should do his
own thinking.
# posted by
Anonymous :
Thursday, 19 January,
2006

love these
discussion posts.
I started to write
a comment, but
it got to big, so I
wrote a whole
post here:

http://oracle-
base.blogspot.
com/2006/01/
plsql-vs-j2ee-
some-comments.
html

Cheers

Tim...
# posted by

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (10 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

Tim... : Thursday,
19 January, 2006

Nice Post.

Having over 12
years of
developing
database
applications, I
learned long ago
that the database
is hands down
the best place to
store the
business logic.
It's been said
before, but front
end applications
come and go, but
the database
(and your data)
live on.

Most J2EE
developers that
advocate putting
the business
logic in the
application are
writing rinky-
dink applications
where it's
possible to get
away with being
"database
independent".
Most aren't
writting
enterprise level
applications
where scalability

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (11 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

is a real issue, so
they haven't had
to learn the
mistake in their
approach the
hard way.

I believe too, that


a lot of J2EE
developers look
at having the
business logic in
the application
layer as a type of
job security. By
keeping the logic
in the
application, it is
more difficult to
switch to a new
development
platform when
something better
comes along.

Unfortunately, it
is a religious war
and no amount
of discussion
seems to change
the mindset of
the J2EE heretics.
# posted by
Anonymous :
Thursday, 19 January,
2006

I ended up
making my reply
on my blog, after
it got longer than
I intended:

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (12 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

http://www.
kudzufiles.com/
archives/000749.
html

And yes, on more


non-technical
posts. Not every
issue we face is
technical!
# posted by
Harry : Thursday,
19 January, 2006

Once you've got


past the technical
fallacies on
scalability issues
etc, the
arguments for
removing
business logic
from databases
crystalize into a
case for
commercial
expediency --
that it's easier to
shift the software
product if it
works on
multiple
database
platforms.

This, IMHO, is
why so many
commercial off-
the-shelf (COTS)
solutions
perform so
poorly. They are

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (13 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

database
independent and
lowest-common-
denominator
methodologies
that are not
technically
efficient
predominate.
Thus a lower
development cost
for the software
developer
translates into a
higher hardware
cost for the
purchaser.

Again IMHO, if
proper software
design
methodologies
are used then the
actual fingers-
on-keyboard
coding of the
business logic (as
distinct from the
GUI) is a
surprisingly low
proportion of the
development
effort. So it ought
to be
commercially
viable to support
business logic
embedded in
Oracle, SQL
Server, My SQL
and DB2 without
a prohibitively
expensive

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (14 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

premium, when
life-cycle costs
and performance
are considered.
# posted by David
Aldridge : Thursday,
19 January, 2006

I was never smart


enough to be a
developer or
even a real
DBA ;-), so I
ended up as a
business systems
implementor and
MIS manager.
Based on 12
years of that
work, I can only
beg, plead, and
beg some more
that architects
and developers
take the Tom
Kyte approach:
everything where
it makes sense to
do so goes in the
database. And it
makes sense for
a very very large
percentage of
most business
applications! I
can't rehash
Tom's arguments
1/10th as
eloquently as he
makes them and
won't try, but I
can report that

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (15 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

out here at the


sharp end the
database is the
most reliable and
managable piece
of the whole
puzzle. Often it
is the _only_
thing we can rely
one.

Well, off to vist


97 workstations
to update
Microsoft
Registry keys for
one of our apps.
Yeah, that is
productive.
Luckily that
means I don't
have time to give
you my views on
Java designers/
programmers....

sPh
# posted by
Anonymous :
Friday, 20 January,
2006

I wander how this


simplest 3 table
join was called
"complex query".
Dunno...wow!
Give him a real
complex query
with analytics,
query rewrite
capabilities and
let's see how this

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (16 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

"generic java
code approach"
would (*NOT*)
perform.
# posted by Qua
d r o : Sunday, 22
January, 2006

It's "Hibernate",
not "Hybernate"!
# posted by
Anonymous :
Monday, 06 February,
2006

well I come to the


blog rather late...
but I thought I'd
still say I liked
the post.

What I'd love to


do is mix java
and pl/sql Now is
there some
secure way to
pass asecure
connection from
java to pl/sql?
This would solve
so many
problems for me,
but making users
log in twice isn't
really an option
for me
# posted by Emu :
Monday, 04
September, 2006

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (17 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

It is not only a
technical, but
even more so a
cultural problem.
In the J2EE (and
increasingly .net)
world, DBAs are
seen as the ones
who have
cultivated the art
of non-
movement to
perfection.
Some may even
break out in
violent insults
when they hear
that there may be
something that
can be done
outside the
database.
Sometimes they
look misearable,
and I assume
that it is due to
the fact that they
have to expain
the obvious truth
again and again
to young and
stupid people.
No wonder that
application
developers try to
avoid contact!
There are
situations when I
would love to call
a stored
procedure, but I
know that when I
ask my DBA to

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (18 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

provide one,
endless
discussions will
take place,
including that the
whole project is
crappy because
stored
procedures
should have been
used all the time.
Now I imagine
that I want the
DBA to change
something in
"his" procedure...
I end this post
with qoute from
Douglas Adams:

Many were
increasingly of
the opinion that
they'd all made a
big mistake in
coming down
from the trees in
the first place.
And some said
that even the
trees had been a
bad move, and
that no one
should ever have
left the oceans.
# posted by
Anonymous :
Saturday, 02
December, 2006

As the writer of
the article,

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (19 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

towards the end,


has said it
correctly "There
is no right or
wrong answer". I
think it really
does not matter
in which
language you
code the
business logic as
long as it is easy
to understand,
easy to maintain,
works great and
most importantly
cost less to do
anything with it.
At an enterprise
level, tell me why
would some one
change their
database, it is a
huge effort as
well as costs too
much. Also how
much choice we
have left with ,
just 3 - Oracle/
SQL Server/DB2,
that's all. So if
some one codes
it in database,
fine, as long as
there are enough
people available
in the market to
maintain it.

Lastly,I feel there


are better tools
to debug/test/
enhance Java

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (20 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

code than PL/SQL


code, I might be
wrong, but
certainly it looks
that way.
# posted by
Prasanna :
Thursday, 10 May,
2007

There's definitely
a question of
general
preference here.
After all, you can
definitely get a
working
application either
way. I don't think
it would be
possible to prove
that one
approach is
fundamentally
better than the
other in all cases.
My personal
preference tends
to be in favour of
making the
application logic
reasonably
separate from
the data
representation.
To me it's a
question of
separating
concerns, not a
religious
question of app
vs. dbms. If I

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (21 of 22)1/9/2008 2:53:02 AM


OracleBlog: PL/SQL vs J2EE

were writing a
program that
didn't use a
dbms, I would do
the same. If I
were writing code
inside of a dmbs
with pl/sql or t-
sql or what have
you, I would still
try to do the
same.
# posted by
Vladimir Levin :
Wednesday, 16 May,
2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/01/plsql-vs-j2ee.html (22 of 22)1/9/2008 2:53:02 AM


OracleBlog: NULLs in COUNT

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, September 09, 2005


About Me
NULLs in COUNT Name: Robert Vollman
Quick, easy one, but it trips up Location: Calgary, Alberta,
beginners. Something of which to Canada
be mindful. Observe:
I was born and raised in Ottawa,
SELECT COUNT (*) FROM EMP; and have lived in Calgary since 1991. I like
COUNT(*) playing sports (hockey, soccer, ultimate,
---------- basketball, you name it) and military board
14 games. I also enjoy reading, walking, and
SELECT COUNT (COMM) FROM EMP; playing with my 2 cats Lilly and Brutus. I'm a
COUNT(COMM) database application specialist, whatever that
----------- is.
4
View my complete profile

Note: 4 instead of 14. But if we do


this: Best Links
● Ask Tom Kyte
SELECT COMM FROM EMP; ● Oracle Docs
● Dan Morgan and PSOUG
COMM
● Steven Feuerstein
----------
● Jonathan Lewis
300
500 ● FAQ
1400 ● Connor McDonald

http://thinkoracle.blogspot.com/2005/09/nulls-in-count.html (1 of 3)1/9/2008 2:53:04 AM


OracleBlog: NULLs in COUNT

0 The Oak Table


14 rows selected. ● Cary Millsap and Hotsos


● Steve Adams and Ixora
● Anjo Kolk and OraPerf
Dizwell Oracle Wiki
We get all 14.

● My Personal Blog
This is expected behaviour. From
the Oracle SQL Reference: "If you
specify 'expr' then COUNT returns
the number of rows where 'expr' is Aggregators
not null." Brian Duff's OraBlogs

Eddie Awad's OracleNA


http://download-west.oracle.com/

Pete Finnigan's Aggregator


docs/cd/B10501_01/server.920/

❍ Oracle's Bloglist
a96540.pdf ❍ Oracle Base Aggregator

COUNT can take virtually any


parameter, including 1, *, or a Top Blogs
column. But be aware that if you're ❍ Oracle's Ask Tom Kyte
counting a particular column, ❍ Oracle Guru Jonathan Lewis
NULLs won't be counted. ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
Additional reading material: ❍ Oracle Geek Lewis Cunningham
Database Expert James Koopmann
Everyone knows NULL is one of my ❍

favourite topics: ❍ Dizwell's Howard Rogers


http://thinkoracle.blogspot. ❍ Oracle Master Laurent Schneider
com/2005/05/null-vs-nothing. ❍ Security Expert Pete Finnigan
html ❍ Oracle Award Winner Mark Rittman
http://thinkoracle.blogspot. ❍ Doug Burns
Oracle ACE of the Year Dr. Tim Hall
com/2005/06/nulls-in-oracle.html ❍

❍ UKOUG's Andrew (Arfur C.) Clarke


Eddie Awad on the difference ❍ Newbie DBA Lisa Dobson
between COUNT(*) and COUNT(1) ❍ Coffee-Drinking DBA Jon Emmons
http://awads.net/wp/2005/07/06/ ❍ Chris Foot
count-vs-count1/ ❍ The Pythian DBA Team Blog
(Note: see the links in the ❍ DBA Don Seiler
comments for more information) ❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
// posted by Robert Vollman @ Friday,

September 09, 2005


❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/09/nulls-in-count.html (2 of 3)1/9/2008 2:53:04 AM


OracleBlog: NULLs in COUNT

❍ May 2005
Comments: ❍ June 2005
Worthwhile pointing out the ❍ July 2005
following quote for user-defined ❍ August 2005
aggregates.
❍ September 2005
"This routine ❍ October 2005
[ODCIAggregateIterate] is invoked ❍ November 2005
for every non-NULL value in the ❍ December 2005
underlying group. (NULL values are ❍ January 2006
ignored during aggregation and ❍ February 2006
are not passed to the routine.)" ❍ March 2006
❍ April 2006
http://download-west.oracle.com/ May 2006
docs/cd/B10501_01/appdev.920/

June 2006
a96595/dci11agg.htm#1004615

❍ July 2006
# posted by Gary Myers : Sunday, 11
❍ August 2006
September, 2005
❍ September 2006
❍ October 2006
I love this - apparently you can ❍ November 2006
exploit this fact and, combined ❍ December 2006
with the use of DECODE, write ❍ January 2007
some statements more efficiently. ❍ February 2007
❍ March 2007
http://www.akadia.com/services/ ❍ April 2007
ora_decode.html ❍ May 2007
# posted by Robert Vollman : Tuesday, ❍ June 2007
04 October, 2005 ❍ October 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/09/nulls-in-count.html (3 of 3)1/9/2008 2:53:04 AM


OracleBlog: NULLs in Oracle

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, June 10, 2005


About Me
NULLs in Oracle Name: Robert Vollman
If you read only one sentence per Location: Calgary, Alberta,
posting, read this: Canada
NULLs may not behave as you'd
expect in Oracle, and as a result, I was born and raised in
NULLs are the cause of many Ottawa, and have lived in Calgary since
application errors. 1991. I like playing sports (hockey,
soccer, ultimate, basketball, you name it)
I got a fair bit of private feedback on and military board games. I also enjoy
my recent article on the differences reading, walking, and playing with my 2
between "NULL" and nothing. Here is cats Lilly and Brutus. I'm a database
the link to the original article, and application specialist, whatever that is.
check out Howard Rogers' comments.
View my complete profile
http://thinkoracle.blogspot.
com/2005/05/null-vs-nothing.html

Let's start with an example to


Best Links
demonstrate a simple property of ● Ask Tom Kyte
NULL: that NULL is not equal to ● Oracle Docs
anything, including NULL itself. ● Dan Morgan and PSOUG
● Steven Feuerstein
SELECT * FROM dual WHERE NULL = ● Jonathan Lewis
NULL; ● FAQ
Connor McDonald
No rows selected.

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html (1 of 10)1/9/2008 2:53:07 AM


OracleBlog: NULLs in Oracle

The Oak Table


SELECT * FROM dual WHERE NULL <> ● Cary Millsap and Hotsos
NULL; ● Steve Adams and Ixora
Anjo Kolk and OraPerf
No rows selected.

● Dizwell Oracle Wiki


What happened here? How can ● My Personal Blog
something be both not equal and not
not equal to something else at the
same time? That probably doesn't
make much sense, does it? Aggregators
Brian Duff's OraBlogs
Essentially NULL means you don't

Eddie Awad's OracleNA


know the value. Basically, you can't

Pete Finnigan's Aggregator


say whether its equal or not equal to

anything else. You need to abandon ❍ Oracle's Bloglist


the binary logic you learned in first- ❍ Oracle Base Aggregator
year math and embrace tri-value
logic. Top Blogs
❍ Oracle's Ask Tom Kyte
That was also a clear demonstration Oracle Guru Jonathan Lewis
of how you should be careful using

Blogger of the Year Eddie Awad


equals or not equals when dealing

Data Warehouser David Aldridge


with NULLs. Instead, use "IS". Observe:

❍ Oracle Geek Lewis Cunningham


SELECT * FROM dual WHERE NULL IS ❍ Database Expert James Koopmann
NULL; ❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
D ❍ Security Expert Pete Finnigan
- Oracle Award Winner Mark Rittman
X

❍ Doug Burns
As an aside, you may be wondering ❍ Oracle ACE of the Year Dr. Tim Hall
what the heck "dual" is. And what do ❍ UKOUG's Andrew (Arfur C.) Clarke
we do when we have a question? We ❍ Newbie DBA Lisa Dobson
ask Tom! ❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
http://asktom.oracle.com/pls/ask/f? ❍ The Pythian DBA Team Blog
p=4950:8::::: ❍ DBA Don Seiler
F4950_P8_DISPLAYID:1562813956388 ❍ DBA Coskan Gundogar
❍ Oracle WTF
In my mind, dual is simply a table
with a single row that is guaranteed
to be there. And when you use it, it
ARCHIVES
❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html (2 of 10)1/9/2008 2:53:07 AM


OracleBlog: NULLs in Oracle

makes you look clever because that's ❍ May 2005


what the experts use. :) ❍ June 2005
July 2005
While I'm blowing your mind with the

August 2005
behaviour of NULL, check out this

September 2005
other case, kindly provided by Tom ❍

Kyte: ❍ October 2005


❍ November 2005
IF (x = 'A') THEN something ❍ December 2005
ELSE something else ❍ January 2006
END IF; ❍ February 2006
March 2006
IF NOT(x = 'A') THEN something else

April 2006
ELSE something

May 2006
END IF; ❍

❍ June 2006
Do these two pieces of pseudo-code ❍ July 2006
look the same to you? In many ❍ August 2006
languages, yes. But not in PL/SQL. ❍ September 2006
Why? ❍ October 2006
November 2006
Consider the case that x is NULL. In

December 2006
the first case it will do "something

January 2007
else" because it is not equal to 'A'. In

the second case it will do "something" ❍ February 2007


because it is also not not equal to 'A'. ❍ March 2007
❍ April 2007
Tom knows I never believe anything ❍ May 2007
without proof, so he provided me ❍ June 2007
with one: ❍ October 2007

ops$tkyte@ORA9IR2> declare
2 x varchar2(1);
3 begin
4 if ( x = 'A' )
5 then
6 dbms_output.put_line( 'X=A' );
7 else
8 dbms_output.put_line( 'NOT X=A' );
9 end if;
10
11 if NOT( x = 'A' )
12 then
13 dbms_output.put_line( 'NOT

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html (3 of 10)1/9/2008 2:53:07 AM


OracleBlog: NULLs in Oracle

X=A' );
14 else
15 dbms_output.put_line( 'X=A' );
16 end if;
17 end;
18 /
NOT X=A
X=A

PL/SQL procedure successfully


completed.

Pretty bizarre, eh? Starting to


understand the behaviour of NULL?
Starting to see why misunderstanding
NULL can lead to application errors?

While we are discussing NULLs, here


a few more useful things.

First, you can use the "set null"


command to change how NULL will
appear in SQLPLUS. This will not
change anything in the database, or
equality, it will just change the
appearance.

create table atable (last_name varchar


(12));
insert into atable (last_name) values
('Smith');
insert into atable (last_name) values
(NULL);

select * from atable;

LAST_NAME
------------
Smith

2 rows selected.

set null [NULL];

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html (4 of 10)1/9/2008 2:53:07 AM


OracleBlog: NULLs in Oracle

select * from atable;

LAST_NAME
------------
Smith
[NULL]

2 rows selected.

Also, you can use these two


functions, nvl and nvl2:

nvl(expr_1, expr_2)
Returns expr_2 if expr_1 is null and
expr_1 otherwise.

nvl2(expr_1, expr_2, expr_3)


Returns expr_3 if expr_1 is null and
expr_2 otherwise.

select nvl(last_name, '[NONE]') as


last_name from atable;
LAST_NAME
------------
Smith
[NONE]

2 rows selected.

select nvl2(last_name, 'Y: ' ||


last_name,'N') as last_name from
atable;

LAST_NAME
---------------
Y: Smith
N

2 rows selected.

Those of you who, like me, work on


many different databases have
hopefully seen by now that NULLs are
handled differently in Oracle. As a
final demonstration, consider how

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html (5 of 10)1/9/2008 2:53:07 AM


OracleBlog: NULLs in Oracle

NULLs are handled in Sybase ASE.

In Sybase ASE (and MS SQL), there is a


configuration parameter that tells the
database whether to treat NULLs as
they are defined in the ANSI SQL
standard, or whether to "bend the
rules" a bit, and allow "NULL = NULL"
to be true. Furthermore, the
behaviour changes depending on
whether you're in a join clause or a
search clause.

http://sybasease.blogspot.
com/2005/05/nulls-in-sybase-ase.
html

That is not the case in Oracle. As


confusing as NULLs may be at first,
they are consistent. They will behave
the same logically everywhere no
matter how and where you use them.

So what should we do?


1. Understand that "NULL = NULL"
and "NULL <> NULL" are both false
because NULL means "I don't know"
2. Use "IS NULL" instead of "= NULL"
if you are checking for NULLness.
3. Use "nvl" and "nvl2" if you want to
eliminate the possibility of a NULL in
a statement by assigning it a
(temporary) value.

For future reference, consult Dan


Morgan's page on NULL:
http://www.psoug.org/reference/null.
html

This is definitely not the last article


you'll see on NULL given how often it
is misunderstood. I encourage you to
include your own experiences of your
favourite NULLisms in the

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html (6 of 10)1/9/2008 2:53:07 AM


OracleBlog: NULLs in Oracle

"comments" section. And, naturally, I


appreciate corrections and
clarifications.

And as a final thanks to Tom, here


are some pictures from when he
visited us in Calgary this past March.
http://www.coug.ab.ca/events/05-
mar.htm

// posted by Robert Vollman @ Friday, June 10,

2005

Comments:
My favorite is the line in Chapter 2 of
Oracle's SQL Reference

"(Oracle
currently treats a character value with
a length of zero as null. However, this
may
not continue to be true in future
releases, and Oracle recommends
that you do not
treat empty strings the same as
nulls.)"
# posted by Anonymous : Thursday, 16
June, 2005

I have two questions that are only


loosely related to your post...

1. Can I get an RSS feed of Steven


Feuerstein's Oracle articles the same
way I can now get Ask Tom?

There is a RSS feed on Best Practice


PL/SQL with Steven Feuerstein - Most
Recent on this link

OTN RSS Feed

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html (7 of 10)1/9/2008 2:53:07 AM


OracleBlog: NULLs in Oracle

Hope that Helps


# posted by Amar : Friday, 17 June, 2005

Found a good link that talks about


NULL and "NOT IN" on AskTom:

http://asktom.oracle.com/pls/ask/f?
p=4950:8:9119946321000023065::
NO::F4950_P8_DISPLAYID,
F4950_P8_CRITERIA:442029737684
# posted by Robert Vollman : Wednesday,
22 June, 2005

This post has been removed by a


blog administrator.
# posted by Robert Vollman : Wednesday,
22 June, 2005

Note: Connor McDonald has pointed


out that there is a performance
overhead to using NVL over just
checking "is null". Here is the link:

http://www.oracledba.co.uk/tips/
plsql_nvl_costs.htm

I wonder if the same penalty exists


using decode? Probably. A good
future test.
# posted by Robert Vollman : Wednesday,
22 June, 2005

From Amis' Blog: http://technology.


amis.nl/blog/index.php?p=646

The july/august edition of Oracle


Magazine has a very interesting
article by Lex de Haan and Jonathan

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html (8 of 10)1/9/2008 2:53:07 AM


OracleBlog: NULLs in Oracle

Gennick about Nulls (‘nothing to


worry about’) in the database.

http://www.oracle.com/technology/
oramag/oracle/05-jul/o45sql.html
# posted by Robert Vollman : Monday, 27
June, 2005

Connor's article (linked above) is


being discussed on the Dizwell
Forum:

http://www.phpbbserver.com/phpbb/
viewtopic.php?
t=220&mforum=dizwellforum
# posted by Robert Vollman : Wednesday,
29 June, 2005

The way I had the first point in your


summary explained to me is that
when you
compare NULL with any value, using
anything other than IS NULL or IS
NOT NULL, the result is NULL.

The resulting NULL does not then


equate to either TRUE or FALSE.

That way we can clearly deduce that

IF NULL = NULL THEN


something
ELSEIF NOT( NULL = NULL )
something else
END IF;

reduces to

IF NULL THEN
something
ELSEIF NULL
something else

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html (9 of 10)1/9/2008 2:53:07 AM


OracleBlog: NULLs in Oracle

END IF;

and so will never do anything.

1. Understand that NULL compared


with any value results in NULL, no
matter what the comparison is (other
than IS NULL or IS NOT NULL).
# posted by Rob Baillie : Tuesday, 09
August, 2005

I have got a problem with some older


version of Oracle because when I run
some select statement with
value=DECODE('','',value,'') condition
on one instance it works without
problem but on another one it
doesn't work.

I have tried to execute the query on


the instance where it doesn't work:
select Decode ('','',value,'') from dual.

And it works. Where can be the


problem? My email is: marcin.
firla@apriso.com.pl
# posted by Anonymous : Saturday, 16
December, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html (10 of 10)1/9/2008 2:53:07 AM


OracleBlog: NULL vs Nothing

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, May 17, 2005


About Me
NULL vs Nothing Name: Robert Vollman
In Oracle, there is a difference Location: Calgary, Alberta,
between 'null' and nothing at all. Canada
Here is my story.

I discovered this when playing with I was born and raised in


default values. First, I created a table Ottawa, and have lived in Calgary since
that had a default value for one 1991. I like playing sports (hockey, soccer,
column. Then I tried to insert a row ultimate, basketball, you name it) and
that had nothing at all, and it military board games. I also enjoy reading,
wouldn't use the default value. So I walking, and playing with my 2 cats Lilly
tried inserting a row with null, and it and Brutus. I'm a database application
didn't assign the default value. specialist, whatever that is.
Observe.
View my complete profile
SQL> create table atable (
2 last_name varchar2(32) not null,
3 first_name varchar2(32) not null,
4 rating smallint default 0);
Best Links
● Ask Tom Kyte
Table created. ● Oracle Docs
● Dan Morgan and PSOUG
SQL> insert into atable values ● Steven Feuerstein
('Smith', 'John', null); ● Jonathan Lewis
FAQ
1 row created.

● Connor McDonald

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (1 of 11)1/9/2008 2:53:10 AM


OracleBlog: NULL vs Nothing

SQL> select * from atable; The Oak Table


● Cary Millsap and Hotsos


LAST_NAME FIRST_NAME RATING ● Steve Adams and Ixora
-------------------------------- ● Anjo Kolk and OraPerf
--------------------------------
Dizwell Oracle Wiki
----------

My Personal Blog
Smith John

Notice it inserted NULL, and not the


default value.
Aggregators
SQL> insert into atable values Brian Duff's OraBlogs

('Smith', 'John'); Eddie Awad's OracleNA
insert into atable values ('Smith',

Pete Finnigan's Aggregator


'John')

Oracle's Bloglist
*

Oracle Base Aggregator


ERROR at line 1: ❍

ORA-00947: not enough values


Top Blogs
Why doesn't this work? You may ❍ Oracle's Ask Tom Kyte
know this already, but in the words ❍ Oracle Guru Jonathan Lewis
of Dan Morgan: "By not specifying Blogger of the Year Eddie Awad
column names you are signifying

Data Warehouser David Aldridge


that you are providing values for ALL

Oracle Geek Lewis Cunningham


columns. This is why it is a very bad

Database Expert James Koopmann


practice as doing an ALTER TABLE ❍

ADD immediately invalidates all SQL ❍ Dizwell's Howard Rogers


statements." ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
So let's do it the proper way and see ❍ Oracle Award Winner Mark Rittman
if there is a difference. ❍ Doug Burns
Oracle ACE of the Year Dr. Tim Hall
SQL> insert into atable (last_name,

UKOUG's Andrew (Arfur C.) Clarke


first_name) values ('Smith', 'John');

❍ Newbie DBA Lisa Dobson


1 row created. ❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
SQL> select * from atable; ❍ The Pythian DBA Team Blog
DBA Don Seiler
LAST_NAME FIRST_NAME RATING

DBA Coskan Gundogar


--------------------------------

Oracle WTF
--------------------------------

----------
Smith John ARCHIVES
Smith John 0 ❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (2 of 11)1/9/2008 2:53:10 AM


OracleBlog: NULL vs Nothing

❍ May 2005
And there is a difference. Excellent. ❍ June 2005
Out of curiousity between the two July 2005
ways of inserting rows, I tried this:

❍ August 2005
SQL> insert into atable (last_name, ❍ September 2005
first_name, rating) values ('Smith', ❍ October 2005
'John', null); ❍ November 2005
❍ December 2005
1 row created. ❍ January 2006
February 2006
SQL> select * from atable;

❍ March 2006
LAST_NAME FIRST_NAME RATING ❍ April 2006
-------------------------------- ❍ May 2006
-------------------------------- ❍ June 2006
---------- ❍ July 2006
Smith John ❍ August 2006
Smith John 0 ❍ September 2006
Smith John ❍ October 2006
November 2006
So I was thinking, why isn't this null

December 2006
being replaced with the default ❍

value? Isn't the default value there ❍ January 2007


for instances to replace null? If you're ❍ February 2007
as skeptical as I am, it will make ❍ March 2007
sense after this second test, where I ❍ April 2007
add the "NOT NULL" constraint. ❍ May 2007
❍ June 2007
drop table atable; ❍ October 2007
create table atable (
last_name varchar2(32) not null,
first_name varchar2(32) not null,
rating smallint default 0 NOT NULL);

SQL> insert into atable (last_name,


first_name, rating) values ('Smith',
'John', null)
*
ERROR at line 1:
ORA-01400: cannot insert NULL into
("ROBERT"."ATABLE"."RATING")

That's when I figured out where I was

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (3 of 11)1/9/2008 2:53:10 AM


OracleBlog: NULL vs Nothing

confused. There are 3 things you can


assign to a column when doing an
insert:
1. a value (eg: 0)
2. null
3. nothing at all

See, there is a difference between #2


(null) and #3 (nothing at all). To wit:
1. Using null (#2) is 'ok' if you are
inserting without specifying
columns. Nothing at all (#3) is not.
2. Null (#2) will not be replaced by a
default value when inserting,
whereas nothing at all (#3) will.

When I started looking at stored


procedures, I found even more
difference between NULL and
nothing. My second story starts off
as an investigation of passing NULL
to stored procedures.

There is no such thing as "NOT


NULL" for stored procedure
parameters.

I noticed that the "NOT NULL"


keyword can't be used in procedure
parameters (nor can NULL).
Apparently that is for creating tables
only. You can not force input
parameters to a procedure to be non-
null. All you can do is start your
procedure by verifying the input
parameters.

SQL> create or replace procedure


MyProc1 (some_value IN number
NOT NULL)
2 AS
3 BEGIN
4 NULL;
5 END;

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (4 of 11)1/9/2008 2:53:10 AM


OracleBlog: NULL vs Nothing

6/

Warning: Procedure created with


compilation errors.

Nor can you allow it to be NULL.

SQL> create or replace procedure


MyProc2 (some_value IN number
NULL)
2 AS
3 BEGIN
4 NULL;
5 END;
6/

Warning: Procedure created with


compilation errors.

You can, however, assign default


values. However, note the difference
between assigning "NULL" and
assigning nothing at all.

SQL> create or replace procedure


MyProc3 (some_value IN number := 0)
2 AS
3 BEGIN
4 DBMS_OUTPUT.PUT_LINE
(some_value);
5 NULL;
6 END;
7/

Procedure created.

SQL> exec MyProc3();


0

PL/SQL procedure successfully


completed.

SQL> exec MyProc3(NULL);

PL/SQL procedure successfully

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (5 of 11)1/9/2008 2:53:10 AM


OracleBlog: NULL vs Nothing

completed.

SQL> exec MyProc3(1);


1

PL/SQL procedure successfully


completed.

Bottom line, there is a difference


NULL and nothing at all for both
tables and stored procedures. So
what is a guy to do?
1. Understand there is a difference
between NULL and nothing
2. For tables, use "NOT NULL" and
for stored procedures, verify the
input manually
3. Use default values for both tables
and stored procedures when passing
nothing at all.

// posted by Robert Vollman @ Tuesday, May

17, 2005

Comments:
NULL means "Not Known". Not
knowing something is very different
from knowing that something is
nothing (for which the empty string ''
is provided)!

When you insert a row that explicitly


includes a NULL, you are explicitly
stating you don't know what value
should be included for that column.
That is again very different from just
missing it out. The one is a
deliberate action and
acknowledgement of the limits to
knowledge. The other could be just a
mere oversight.

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (6 of 11)1/9/2008 2:53:10 AM


OracleBlog: NULL vs Nothing

This is why I cannot agree with your


advice 'For tables, use NOT NULL'.
That is a constraint, and constraints
should describe business rules. So
*if* your business rule states that for
a column you must always know a
value, then sure: use NOT NULL. It's
what it's there for. But it is frequently
the case that things will be unknown
at the time of data entry, and if so, a
not null constraint is entirely
inappropriate, and the explicit
assignment of NULL to a value is (in
my view) better practice than just
remaining silent on the matter.

Incidentally, because NULL means 'I


don't know', you can never equate
anything to NULL... even itself. Two
unknowns are two unknowns, not
two bits of the same unknown... for
to be able to say that would require
knowing something about them!!
Thus:

SQL> select count(*) from emp


where 1=1;

COUNT(*)
----------
14

SQL> select count(*) from emp


where null=null;

COUNT(*)
----------
0

Whilst 1=1 evaluates to 'aways true',


and hence every row in EMP gets
counted, NULL=NULL is never true,
and hence no rows are selected or
counted.

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (7 of 11)1/9/2008 2:53:10 AM


OracleBlog: NULL vs Nothing

Regards
HJR
# posted by Howard J. Rogers : Wednesday,
18 May, 2005

Thanks Howard for the correction


and further explanation. "NULL" is a
fascinating topic and sure to be the
focus of another upcoming post.

In response to the May 19th article


on Dynamically assigning size of
varchar2, Tom Kyte commented on a
way to force parameters to a stored
procedure to be NOT NULL without
having to validate inputs yourself
explicitly.

http://thinkoracle.blogspot.
com/2005/05/dynamically-
assigning-size-of-varchar2.html

"you can use subtypes (trick that


works with the NULLS from your
other blog too -- if you want
parameters that are NOT NULL, you
can create a subtype which is NOT
NULL and use that type...)"

create or replace package types as


subtype not_null_type is varchar2
(32) NOT NULL;
end;

create or replace procedure MyProc4


(some_value IN types.not_null_type :
= 0)
as
begin
dbms_output.put_line(some_value);
end;

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (8 of 11)1/9/2008 2:53:10 AM


OracleBlog: NULL vs Nothing

SQL> exec MyProc4();


0

PL/SQL procedure successfully


completed.

SQL> exec MyProc4(NULL);


BEGIN MyProc4(NULL); END;

*
ERROR at line 1:
ORA-06550: line 1, column 15:
PLS-00567: cannot pass NULL to a
NOT NULL constrained formal
parameter
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

However, note that this does NOT


work for tables!

create or replace procedure MyProc4


(some_value IN atable.last_name%
TYPE := 0)
as
begin
dbms_output.put_line(some_value);
end;

SQL> exec MyProc4(NULL);

PL/SQL procedure successfully


completed.

So what is a guy to do?


1. Validate the input of a stored
procedure yourself, or
2. Create a "not null" type in a
package as Tom described, and let
Oracle do your validation, but
3. Do NOT use the %TYPE of a
column in a table, because the NOT
NULL property will be ignored.
# posted by Robert Vollman : Friday, 20

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (9 of 11)1/9/2008 2:53:10 AM


OracleBlog: NULL vs Nothing

May, 2005

I received the following from Tom in


email:

You can use constrained subtypes in


PLSQL to do the NOT NULL'ness

ops$tkyte@ORA9IR2> create or
replace package foo
2 as
3 subtype mytype is number NOT
NULL;
4
5 procedure bar( x in mytype );
6 end;
7/
Package created.

ops$tkyte@ORA9IR2> create or
replace package body foo
2 as
3 procedure bar( x in mytype )
4 as
5 begin
6 dbms_output.put_line( 'x = ' || x );
7 end;
8 end;
9/
Package body created.

ops$tkyte@ORA9IR2> exec foo.bar


( null );
BEGIN foo.bar( null ); END;

*
ERROR at line 1:
ORA-06550: line 1, column 16:
PLS-00567: cannot pass NULL to a
NOT NULL constrained formal
parameter
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (10 of 11)1/9/2008 2:53:10 AM


OracleBlog: NULL vs Nothing

# posted by Robert Vollman : Friday, 10


June, 2005

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html (11 of 11)1/9/2008 2:53:10 AM


OracleBlog: Blank Lines and SQLPlus

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, June
About Me
13, 2005
Name: Robert Vollman
Blank Location: Calgary, Alberta, Canada
Lines
and I was born and raised in Ottawa, and have lived in
Calgary since 1991. I like playing sports (hockey,
SQLPlus soccer, ultimate, basketball, you name it) and military board games.
Try creating I also enjoy reading, walking, and playing with my 2 cats Lilly and
the following Brutus. I'm a database application specialist, whatever that is.
table using
SQLPlus View my complete profile
Worksheet.

create table
atable ( Best Links
● Ask Tom Kyte
aint integer
● Oracle Docs
); ● Dan Morgan and PSOUG
● Steven Feuerstein
You will get ● Jonathan Lewis
this error: ● FAQ
● Connor McDonald
SP2-0734: The Oak Table
unknown

Cary Millsap and Hotsos


command

Steve Adams and Ixora


beginning

● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2005/06/blank-lines-and-sqlplus.html (1 of 5)1/9/2008 2:53:12 AM


OracleBlog: Blank Lines and SQLPlus

"aint integ..." - ● Dizwell Oracle Wiki


rest of line ● My Personal Blog
ignored.

It thinks "aint
integer" is a
new
Aggregators
command. Brian Duff's OraBlogs

What is the ❍ Eddie Awad's OracleNA


problem? ❍ Pete Finnigan's Aggregator
Repeat this ❍ Oracle's Bloglist
test using ❍ Oracle Base Aggregator

Top Blogs
SQLPlus at a
prompt:
Oracle's Ask Tom Kyte
SQL> create

Oracle Guru Jonathan Lewis


table atable ❍

2( ❍ Blogger of the Year Eddie Awad


3 ❍ Data Warehouser David Aldridge
SQL> ❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
The blank line ❍ Dizwell's Howard Rogers
stops the ❍ Oracle Master Laurent Schneider
statement. ❍ Security Expert Pete Finnigan
Oracle Award Winner Mark Rittman
This doesn't ❍

apply to all ❍ Doug Burns


statements, ❍ Oracle ACE of the Year Dr. Tim Hall
but it does ❍ UKOUG's Andrew (Arfur C.) Clarke
apply to select/ ❍ Newbie DBA Lisa Dobson
insert/update/ ❍ Coffee-Drinking DBA Jon Emmons
delete queries. ❍ Chris Foot
It doesn't ❍ The Pythian DBA Team Blog
apply to ❍ DBA Don Seiler
creating ❍ DBA Coskan Gundogar
procedures: ❍ Oracle WTF
SQL> CREATE
OR REPLACE ARCHIVES
PROCEDURE ❍ LIST ALL ARTICLES
MyProc ❍ May 2005
2 ❍ June 2005
3 AS ❍ July 2005
4 ❍ August 2005

http://thinkoracle.blogspot.com/2005/06/blank-lines-and-sqlplus.html (2 of 5)1/9/2008 2:53:12 AM


OracleBlog: Blank Lines and SQLPlus

5 BEGIN ❍ September 2005


6 ❍ October 2005
7 NULL; ❍ November 2005
8 December 2005
9 END;

January 2006
10 /

❍ February 2006
Procedure ❍ March 2006
created. ❍ April 2006
❍ May 2006
At first I just ❍ June 2006
made the ❍ July 2006
blank lines a ❍ August 2006
comment:
❍ September 2006
create table ❍ October 2006
atable ( ❍ November 2006
-- ❍ December 2006
aint integer ❍ January 2007
-- ❍ February 2007
); ❍ March 2007
❍ April 2007
Table created. ❍ May 2007
But eventually ❍ June 2007
I took a closer ❍ October 2007
look and
arrived at the
correct
solution. Here
it is.

set
sqlblanklines
on;

SQL> create
table atable
2(
3
4 aint integer
5
6 );

http://thinkoracle.blogspot.com/2005/06/blank-lines-and-sqlplus.html (3 of 5)1/9/2008 2:53:12 AM


OracleBlog: Blank Lines and SQLPlus

Table created.

Its just a little


SQLPlus foible.

If you see
something
similar and
you aren't
using blank
lines, see if
you're using
any special
symbols and
look at "set
sqlprefix"
instead.

So what
should we do?
1. Put in
comments to
avoid the
blank lines.
2. Use
something
other than
sqlplus.
3. Explicitly
set blanklines
on at the top
of your
statement.

// posted by
Robert
Vollman @ Monday,

June 13, 2005

Comments:
Thank you for

http://thinkoracle.blogspot.com/2005/06/blank-lines-and-sqlplus.html (4 of 5)1/9/2008 2:53:12 AM


OracleBlog: Blank Lines and SQLPlus

the tip ... had


1361 lines
long query
failing ...
strange tool
this sqlplus.
# posted by
Branislav :
Wednesday, 30
May, 2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/06/blank-lines-and-sqlplus.html (5 of 5)1/9/2008 2:53:12 AM


OracleBlog: Multiple Foreign Keys on the Same ID

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, May 20,


About Me
2005
Name: Robert Vollman
Multiple Location: Calgary, Alberta, Canada
Foreign
Keys on I was born and raised in Ottawa, and have lived in
Calgary since 1991. I like playing sports (hockey,
the Same soccer, ultimate, basketball, you name it) and military board
ID games. I also enjoy reading, walking, and playing with my 2 cats
You can't set Lilly and Brutus. I'm a database application specialist, whatever
the same that is.
foreign key for
two different View my complete profile
columns with
the same
constraint: Best Links
create table ● Ask Tom Kyte
atable ( ● Oracle Docs
id varchar2(65) ● Dan Morgan and PSOUG
primary key); ● Steven Feuerstein
● Jonathan Lewis
create table FAQ
btable (

Connor McDonald
a_id1 varchar2

The Oak Table


(65),

Cary Millsap and Hotsos


a_id2 varchar2 ●

(65)); ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/05/multiple-foreign-keys-on-same-id.html (1 of 4)1/9/2008 2:53:15 AM


OracleBlog: Multiple Foreign Keys on the Same ID

● Anjo Kolk and OraPerf


ALTER TABLE ● Dizwell Oracle Wiki
btable ● My Personal Blog
ADD
CONSTRAINT
btable_fkey_both
FOREIGN KEY
(a_id1, a_id2)
Aggregators
REFERENCES Brian Duff's OraBlogs

atable(id, id) ❍ Eddie Awad's OracleNA


ON DELETE SET ❍ Pete Finnigan's Aggregator
NULL; ❍ Oracle's Bloglist
❍ Oracle Base Aggregator
ERROR at line 1:
ORA-00957:
duplicate
Top Blogs
Oracle's Ask Tom Kyte
column name

❍ Oracle Guru Jonathan Lewis


ALTER TABLE ❍ Blogger of the Year Eddie Awad
btable ❍ Data Warehouser David Aldridge
ADD ❍ Oracle Geek Lewis Cunningham
CONSTRAINT ❍ Database Expert James Koopmann
btable_fkey_both ❍ Dizwell's Howard Rogers
FOREIGN KEY ❍ Oracle Master Laurent Schneider
(a_id1, a_id2) Security Expert Pete Finnigan
REFERENCES

Oracle Award Winner Mark Rittman


atable(id)

Doug Burns
ON DELETE SET

Oracle ACE of the Year Dr. Tim Hall


NULL; ❍

❍ UKOUG's Andrew (Arfur C.) Clarke


ERROR at line 1: ❍ Newbie DBA Lisa Dobson
ORA-02256: ❍ Coffee-Drinking DBA Jon Emmons
number of ❍ Chris Foot
referencing ❍ The Pythian DBA Team Blog
columns must ❍ DBA Don Seiler
match DBA Coskan Gundogar
referenced

Oracle WTF
columns

But you can do ARCHIVES


it if you break it ❍ LIST ALL ARTICLES
up into separate ❍ May 2005
constraints: ❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2005/05/multiple-foreign-keys-on-same-id.html (2 of 4)1/9/2008 2:53:15 AM


OracleBlog: Multiple Foreign Keys on the Same ID

ALTER TABLE ❍ August 2005


btable ❍ September 2005
ADD ❍ October 2005
CONSTRAINT November 2005
btable_fkey1

December 2005
FOREIGN KEY

January 2006
(a_id1)

February 2006
REFERENCES ❍

atable (id) ❍ March 2006


ON DELETE SET ❍ April 2006
NULL; ❍ May 2006
❍ June 2006
Table altered. ❍ July 2006
August 2006
ALTER TABLE

September 2006
btable

October 2006
ADD ❍

CONSTRAINT ❍ November 2006


btable_fkey2 ❍ December 2006
FOREIGN KEY ❍ January 2007
(a_id2) ❍ February 2007
REFERENCES ❍ March 2007
atable (id) ❍ April 2007
ON DELETE SET ❍ May 2007
NULL; ❍ June 2007
October 2007
Table altered.

Note: Monday is
a holiday in
Canada, no
update until
Tuesday.

// posted by Robert
Vollman @ Friday,

May 20, 2005

Comments:
Post a
Comment

http://thinkoracle.blogspot.com/2005/05/multiple-foreign-keys-on-same-id.html (3 of 4)1/9/2008 2:53:15 AM


OracleBlog: Multiple Foreign Keys on the Same ID

<< Home

http://thinkoracle.blogspot.com/2005/05/multiple-foreign-keys-on-same-id.html (4 of 4)1/9/2008 2:53:15 AM


OracleBlog: SQLCODE and SQLERRM in INSERTs

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, July 04,


About Me
2005
Name: Robert Vollman
SQLCODE Location: Calgary, Alberta, Canada
and
SQLERRM in I was born and raised in Ottawa, and have lived
in Calgary since 1991. I like playing sports
INSERTs (hockey, soccer, ultimate, basketball, you name it) and
Here is an interesting military board games. I also enjoy reading, walking, and
foible. Normally you playing with my 2 cats Lilly and Brutus. I'm a database
can build strings on application specialist, whatever that is.
the fly from functions
and insert them into View my complete profile
a table. Like so:

CREATE TABLE
LogTable (logString Best Links
VARCHAR2(128)); ● Ask Tom Kyte
Oracle Docs
CREATE OR REPLACE

Dan Morgan and PSOUG


FUNCTION MyFunc

Steven Feuerstein
RETURN VARCHAR2 ●

AS ● Jonathan Lewis
BEGIN ● FAQ
RETURN 'Hello'; ● Connor McDonald
END; ● The Oak Table
● Cary Millsap and Hotsos
CREATE OR REPLACE ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/07/sqlcode-and-sqlerrm-in-inserts.html (1 of 5)1/9/2008 2:53:17 AM


OracleBlog: SQLCODE and SQLERRM in INSERTs

PROCEDURE MyProc ● Anjo Kolk and OraPerf


AS ● Dizwell Oracle Wiki
BEGIN ● My Personal Blog
NULL;
EXCEPTION
WHEN OTHERS
THEN
INSERT INTO
Aggregators
Brian Duff's OraBlogs
LogTable (logString)

Eddie Awad's OracleNA


VALUES (MyFunc || ' ' ❍

|| MyFunc); ❍ Pete Finnigan's Aggregator


END; ❍ Oracle's Bloglist
❍ Oracle Base Aggregator
But you can't do this
with SQLCODE and
SQLERRM.
Top Blogs
Oracle's Ask Tom Kyte

CREATE OR REPLACE ❍ Oracle Guru Jonathan Lewis


PROCEDURE MyProc ❍ Blogger of the Year Eddie Awad
AS ❍ Data Warehouser David Aldridge
BEGIN ❍ Oracle Geek Lewis Cunningham
NULL; ❍ Database Expert James Koopmann
EXCEPTION ❍ Dizwell's Howard Rogers
WHEN OTHERS ❍ Oracle Master Laurent Schneider
THEN ❍ Security Expert Pete Finnigan
INSERT INTO ❍ Oracle Award Winner Mark Rittman
LogTable (logString)
Doug Burns
VALUES (SQLCODE || '

Oracle ACE of the Year Dr. Tim Hall


' || SQLERRM);

UKOUG's Andrew (Arfur C.) Clarke


END; ❍

❍ Newbie DBA Lisa Dobson


PL/SQL: ORA-00984: ❍ Coffee-Drinking DBA Jon Emmons
column not allowed ❍ Chris Foot
here ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
You can always put DBA Coskan Gundogar
the values in a string

Oracle WTF
for a workaround.

CREATE OR REPLACE ARCHIVES


PROCEDURE MyProc ❍ LIST ALL ARTICLES
AS ❍ May 2005
errString LogTable. ❍ June 2005
logString%TYPE; ❍ July 2005

http://thinkoracle.blogspot.com/2005/07/sqlcode-and-sqlerrm-in-inserts.html (2 of 5)1/9/2008 2:53:17 AM


OracleBlog: SQLCODE and SQLERRM in INSERTs

BEGIN ❍ August 2005


NULL; ❍ September 2005
EXCEPTION ❍ October 2005
WHEN OTHERS November 2005
THEN

December 2005
errString := SQLCODE

January 2006
|| ' ' || SQLERRM;

February 2006
INSERT INTO ❍

LogTable (logString) ❍ March 2006


VALUES (errString); ❍ April 2006
END; ❍ May 2006
❍ June 2006
Procedure created. ❍ July 2006
August 2006
For reference, look

September 2006
up SQLCODE and

October 2006
SQLERRM in the PL/ ❍

SQL User's Guide and ❍ November 2006


Reference. ❍ December 2006
❍ January 2007
Bonus. I found the ❍ February 2007
following blog while ❍ March 2007
reviewing OraBlogs: ❍ April 2007
http://blog.niftypaint. ❍ May 2007
nl/ ❍ June 2007
October 2007
Which pointed me to

Eddie Awad's great


blog:
http://awads.net/wp/

Enjoy!

// posted by Robert
Vollman @ Monday, July

04, 2005

Comments:
Same for update's
too.

So as usual has to

http://thinkoracle.blogspot.com/2005/07/sqlcode-and-sqlerrm-in-inserts.html (3 of 5)1/9/2008 2:53:17 AM


OracleBlog: SQLCODE and SQLERRM in INSERTs

code like below

l_error_status :=
SQLERRM;

UPDATE
temp_tanmoy_271799
SET update_status =
'N',
error_status =
l_error_status
WHERE ee# = my ee;
# posted by Tanmoy :
Monday, 11 July, 2005

good work, and


thank you to google
for helping me find
stuff like this
# posted by
Anonymous : Sunday,
24 July, 2005

This post has been


removed by a blog
administrator.
# posted by cc
Infopage : Tuesday, 11
October, 2005

And, for those of you


who want to keep the
error code in a
numeric format, try
to multiply it by one,
or add zero to it ;-)
ie (in an exception
block):

declare

http://thinkoracle.blogspot.com/2005/07/sqlcode-and-sqlerrm-in-inserts.html (4 of 5)1/9/2008 2:53:17 AM


OracleBlog: SQLCODE and SQLERRM in INSERTs

le_errcode number :=
0;
begin
le_errcode := sqlcode
* 1;
insert into err_log
(le_errcode,
dbms_utility.
format_error_stack);
commit;
end;
# posted by adsm :
Tuesday, 22 November,
2005

this article is really a


good one AND ITS A
EXPERIMENTAL
RESULT.
I WANT SOME NOTE
ON THESE TWO
FUNCTIONS.WIIL U
HELP?
# posted by my ambit :
Monday, 10 September,
2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/07/sqlcode-and-sqlerrm-in-inserts.html (5 of 5)1/9/2008 2:53:17 AM


OracleBlog: Analyzing Query Performance

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday, September 14, 2005


Analyzing Query Performance
Alternate title: Keeping Tables Small, Revisited

In an earlier article I spoke about how removing old data can help speed
up table scans:

http://thinkoracle.blogspot.com/2005/08/keeping-tables-small.html

During a test in that article, I seemed to detect that querying a view


composed of the 90/10 split of a large table was much faster than
querying that table directly.

I was only trying to demonstrate that it wouldn't be much slower, I did


not expect for it to be faster. I didn't pursue it at the time, but
reproduced those results in 2 separate tests later on.

Incidentally, David Aldridge, who inspired my original article, has a


theory on this:
http://oraclesponge.blogspot.com/2005/08/more-on-partition-not-
quite-pruning.html

So the greater question was:


"How do you determine why a query is faster (or slower) than you
expected?"

The first step is to use SQL Trace and TKProf:


http://download-west.oracle.com/

http://thinkoracle.blogspot.com/2005/09/analyzing-query-performance.html (1 of 7)1/9/2008 2:53:20 AM


OracleBlog: Analyzing Query Performance

docs/cd/B10501_01/server.920/a96533/sqltrace.htm#1018

Note: there are MANY sources of information on this. Apart from the
Oracle documentation, I also used articled by Tom Kyte, as well as his
book "Expert One-on-One Oracle."

Here was my test.

1. Set some variables:

ALTER SESSION SET TIMED_STATISTICS=true;


ALTER SYSTEM SET MAX_DUMP_FILE_SIZE=1000;
ALTER SYSTEM SET USER_DUMP_DEST="C:/temp/trace";

2. Create the ReallyBigTable

CREATE TABLE ReallyBigTable AS SELECT * FROM ALL_OBJECTS;

3. Turn on tracing

ALTER SESSION SET SQL_TRACE = TRUE;

4. Run the query

SELECT SUM(object_id) FROM ReallyBigTable


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable);

Note: 00:44:50.07

5. Turn off tracing

ALTER SESSION SET SQL_TRACE = FALSE;

6. Run TKPROF (separate window)

TKPROF robert_ora_3236.trc robert_ora_3236.prf explain='sys/********


as sysdba'
- Save that file somewhere (it will be overwritten later)

7. Create Archive and Active tables.

CREATE TABLE ReallyBigTable_Archive AS SELECT * FROM ReallyBigTable


WHERE object_id < 40000;

CREATE TABLE ReallyBigTable_Active AS SELECT * FROM ReallyBigTable

http://thinkoracle.blogspot.com/2005/09/analyzing-query-performance.html (2 of 7)1/9/2008 2:53:20 AM


OracleBlog: Analyzing Query Performance

WHERE object_id >= 40000;

8. Drop ReallyBigTable

DROP TABLE ReallyBigTable;

9. Create the view

CREATE VIEW ReallyBigTable AS


SELECT * FROM ReallyBigTable_Archive
UNION ALL
SELECT * FROM ReallyBigTable_Active;

10. Turn on Tracing

ALTER SESSION SET SQL_TRACE = TRUE;

11. Run the query again

SELECT SUM(object_id) FROM ReallyBigTable


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable);

Elapsed: 00:45:21.04

12. Turn off tracing

ALTER SESSION SET SQL_TRACE = FALSE;

13. Run TKPROF (separate window)

TKPROF robert_ora_3236.trc robert_ora_3236.prf explain='sys/********


as sysdba'

Conclusion:

I repeated the test 3 times with tracing on, and each time I could not
reproduce the results. I saw virtually no difference in time elapsed
between querying a big table, and querying a big table

So I guess we're left in the dark as to why querying the view was so much
faster during my earlier tests. Perhaps we can apply Occam's Razor and
the safest conclusion was simply that I goofed.

Either way, it made for an interesting article of how to generate


performance data and query plans. I will leave you with an excerpt from

http://thinkoracle.blogspot.com/2005/09/analyzing-query-performance.html (3 of 7)1/9/2008 2:53:20 AM


OracleBlog: Analyzing Query Performance

the TKPROF output:

SELECT SUM(object_id) FROM ReallyBigTable


WHERE object_id * 2 NOT IN
(SELECT object_id FROM ReallyBigTable)
call count cpu elapsed disk query
------- ------ -------- ---------- ---------- ----------
Parse 1 0.01 0.00 0 0
Execute 1 0.00 0.00 0 0
Fetch 2 612.03 2690.60 16168915 17030020
------- ------ -------- ---------- ---------- ----------
total 4 612.04 2690.60 16168915 17030020
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: SYS
Rows Row Source Operation
------- ---------------------------------------------------
1 SORT AGGREGATE
20495 FILTER
40764 TABLE ACCESS FULL REALLYBIGTABLE
20269 TABLE ACCESS FULL REALLYBIGTABLE
Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: CHOOSE
1 SORT (AGGREGATE)
20495 FILTER
40764 TABLE ACCESS (FULL) OF 'REALLYBIGTABLE'
20269 TABLE ACCESS (FULL) OF 'REALLYBIGTABLE'

// posted by Robert Vollman @ Wednesday, September 14, 2005

Comments:
max_dump_file_size seems a little "conservative" there Robert ;)

I'm enjoying using:

alter session set tracefile_identifier='some_string_or_other';

... at the moment. It seems that you could also wrap up this series of
commands in a neat little procedure also.

http://thinkoracle.blogspot.com/2005/09/analyzing-query-performance.html (4 of 7)1/9/2008 2:53:20 AM


OracleBlog: Analyzing Query Performance

# posted by David Aldridge : Thursday, 15 September, 2005

The part about not being able to SQL trace a raw password value is not
exactly true:

PARSING IN CURSOR #1 len=73 dep=0 uid=39 oct=47 lid=39


tim=444650244946 hv=2365598651 ad='8b806280'
begin
execute immediate 'create user feeby identified by mypass';
end;
END OF STMT
PARSE #1:c=10000,e=6157,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,
tim=444650244935
BINDS #1:
XCTEND rlbk=0, rd_only=1

Caveat emptor.
# posted by Anonymous : Monday, 13 November, 2006

Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

http://thinkoracle.blogspot.com/2005/09/analyzing-query-performance.html (5 of 7)1/9/2008 2:53:20 AM


OracleBlog: Analyzing Query Performance

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke

http://thinkoracle.blogspot.com/2005/09/analyzing-query-performance.html (6 of 7)1/9/2008 2:53:20 AM


OracleBlog: Analyzing Query Performance

❍ Newbie DBA Lisa Dobson


❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/09/analyzing-query-performance.html (7 of 7)1/9/2008 2:53:20 AM


OracleBlog: ANSI Joins

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, May 04,


About Me
2007
Name: Robert Vollman
ANSI Location: Calgary, Alberta, Canada
Joins
Like most of I was born and raised in Ottawa, and have lived in
us, I still join Calgary since 1991. I like playing sports (hockey,
tables in my soccer, ultimate, basketball, you name it) and military board
SQL queries the games. I also enjoy reading, walking, and playing with my 2 cats
old-school Lilly and Brutus. I'm a database application specialist, whatever that
way. Simply is.
put:
View my complete profile
SELECT
whatever
FROM table1
t1, table2 t2 Best Links
WHERE t1.id = ● Ask Tom Kyte
t2.id ● Oracle Docs
AND t1.value > ● Dan Morgan and PSOUG
10; ● Steven Feuerstein
Jonathan Lewis
But

FAQ
increasingly

Connor McDonald
often I run into ●

people who use ● The Oak Table


ANSI joins ● Cary Millsap and Hotsos
instead. They ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (1 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

were either ● Anjo Kolk and OraPerf


introduced to ● Dizwell Oracle Wiki
SQL with ● My Personal Blog
Oracle 9 (or
Sybase 12, etc),
and were
taught to use
the SQL
Aggregators
Brian Duff's OraBlogs
standard way,

Eddie Awad's OracleNA


or else they ❍

made the ❍ Pete Finnigan's Aggregator


conversion at ❍ Oracle's Bloglist
some point in ❍ Oracle Base Aggregator

Top Blogs
the past few
years. They
would instead ❍ Oracle's Ask Tom Kyte
write that Oracle Guru Jonathan Lewis
query like this:

❍ Blogger of the Year Eddie Awad


SELECT ❍ Data Warehouser David Aldridge
whatever ❍ Oracle Geek Lewis Cunningham
FROM table1 t1 ❍ Database Expert James Koopmann
JOIN table2 t2 ❍ Dizwell's Howard Rogers
USING (id) ❍ Oracle Master Laurent Schneider
WHERE t1.value ❍ Security Expert Pete Finnigan
> 10; ❍ Oracle Award Winner Mark Rittman
Doug Burns
Then they look

Oracle ACE of the Year Dr. Tim Hall


at me all

UKOUG's Andrew (Arfur C.) Clarke


smug ... "Look ❍

how I have ❍ Newbie DBA Lisa Dobson


separated the ❍ Coffee-Drinking DBA Jon Emmons
JOIN clauses ❍ Chris Foot
from the ❍ The Pythian DBA Team Blog
WHERE clauses. ❍ DBA Don Seiler
Isn't that ❍ DBA Coskan Gundogar
infinitely more ❍ Oracle WTF
readable? Now
go back to
your cave."
ARCHIVES
❍ LIST ALL ARTICLES
I confess, I do ❍ May 2005
like the ❍ June 2005
elegance of ❍ July 2005

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (2 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

separating ❍ August 2005


those clauses. ❍ September 2005
Our business ❍ October 2005
analysts find ❍ November 2005
that format December 2005
much more

January 2006
readable, too,

February 2006
as do those

who use ❍ March 2006


several ❍ April 2006
different ❍ May 2006
databases. ❍ June 2006
Every time they ❍ July 2006
see one of my ❍ August 2006
queries, ❍ September 2006
especially a full ❍ October 2006
outer join or a ❍ November 2006
(+) in it, their December 2006
nose starts to

January 2007
bleed.

❍ February 2007
Incidentally, if ❍ March 2007
the columns ❍ April 2007
are named ❍ May 2007
differently, ❍ June 2007
you'd use this ❍ October 2007
syntax instead
(which is less
of a leap for
old school SQL
lovers):

SELECT
whatever
FROM table1 t1
JOIN table2 t2
ON (t1.id1 = t2.
id2)
WHERE t1.value
> 10;

And, of course,
you can have
multiple joins,

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (3 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

and can even


nest one join
inside another.
You can use all
the different
types of joins,
like INNER,
OUTER, LEFT,
RIGHT, UPSIDE-
DOWN, INSIDE-
OUT, whatever.
Ok, not those
last two. Tim
Hall has some
examples.

I started using
ANSI joins for
the first time
recently. There
certainly
doesn't seem
to be any
performance
hit. Of course, I
wasn't
expecting one,
because you'd
think Oracle
would be smart
enough to do
both things the
exact same
way. I can't say
for certain if
one is better
than the other,
I guess you
have to look at
it case-by-case
with your
profiling tools.
But I certainly

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (4 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

haven't seen
any difference.

The one thing


I'm not crazy
about is the
NATURAL JOIN.
In the example
above, if id was
the only
column that
those two
tables had in
common, they
could specify is
as a NATURAL
JOIN and leave
off the USING.
To wit:

SELECT
whatever
FROM table1 t1
NATURAL JOIN
table2 t2
WHERE t1.value
> 10;

What a
NATURAL JOIN
actually does,
is join the two
tables on all
columns that
exist in both
tables. It does
mean your
query will still
work if the
structure of the
table changes,
but is that
really what you
want? Call me a

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (5 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

caveman, but I
like to
explicitly state
exactly what I
want a query to
do, and that
includes
exactly on
which columns
I want to join.

If you think I'm


being too
harsh, you
should Ask
Tom for his
opinion:
"Natural joins
-- a bug
waiting to
happen.",
"I strongly,
vehemently
strongly,
discourage the
use of this
feature called
natural joins.",
"To join tables
by their
column names
-- how
patently just a
bad idea",
"Never never
never use this
feature."

I don't intend
to use this one
criticism to
denounce ANSI
joins

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (6 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

altogether, far
from it.
Traditional
joins
(especially full
outer joins) can
look messy,
especially the
aforementioned
group of new
graduates,
business
analysts and
multi-database
SQL
programmers.

Not everyone
has really
enjoyed
moving from
the traditional
join syntax to
ANSI syntax,
including Doug
Burns and Jeff
Moss.

As you can see


from the dates
on those, I'm
not the first
one to write
about this (but
hopefully the
last). I thought
Mark Rittman
was the first to
expound on
this, over 3
years ago, but
he links to Jim
Czuprynski,

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (7 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

who appears to
be truly the
earliest
crusader for
the USE of ANSI
joins, over 4
years ago. But,
reminiscent of
Wrath of Khan,
it was actually
Eddie Awad
who first put
the bug of
ANSI joins into
my ear. He's
got a crash
course on the
different types
of ANSI joins,
but of course,
that type of
information
you can find
almost
anywhere.

I'm not going


to endorse that
you
immediately
switch to ANSI
joins,
especially since
if you haven't
by now, you
probably have
no such
intention
anyway. But I
think it makes
a lot of sense
for my fellow
cavemen to at

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (8 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

least be aware
of it, and know
how to use it.

// posted by
Robert
Vollman @ Friday,

May 04, 2007

Comments:
I couldn't agree
more. Eddie
Awad has a
great series on
all the join
types, and he
uses ANSI
syntax in all his
demonstrations.
I'm making the
switch!
# posted by
Don : Friday, 04
May, 2007

Poking about
in the bug
database for
ansi join is
always a bit of
fun. I
particularly
liked the one
where ansi
worked and +
didn't.

Think I'd wait


for 11g
anywho, there

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (9 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

seem to be
enough things
that aren't
fixed 'til then.

I work with a
4GL which
automagically
does this
natural join
thing (it calls it
"implicit
domains" or
you can define
them explicitly)
which every so
often really
trips people
up. Especially
when it has to
resolve an
ambiguity, and
does it...
alphabetically.
# posted by Joel
Garry : Friday, 04
May, 2007

I made the
switch to ANSI
a few years ago
and can't
understand
why anybody
would continue
to use the old
style.
I guess old
habits die hard.
# posted by
Michael :
Saturday, 05 May,

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (10 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

2007

In the Oracle
database, v.
9.2.0.6.0, that I
have access to,
three table
joins with ANSI
syntax
consistently
takes twice as
long as three
table joins with
the old style
(+) syntax. I do
not understand
why this is but
hopefully
Oracle is
improving their
optimizer with
the recent
versions.
# posted by
Scott
Nightlinger :
Monday, 06
August, 2007

The DBA
showed me a
few things with
this situation
and I am
following up
with an
explanation of
the causes.

1) The Oracle
optimizer
engine

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (11 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

evaluates the
two styles of
joining tables
slightly
differently.
This can be
seen by a few
differences in
the "Explain
Plan" that is
available by
selecting the
F5 button in PL/
SQL Developer.
This Explain
Plan function
evaluates the
complexity of
the query.

2) The Oracle
optimizer
engine gets
confused due
to the
complexity of
multiple view
accesses.

3) The Oracle
optimizer
thought the
query would
run faster by
putting a
predicate from
the WHERE
clause inside
one of the
subqueries
within the
FROM clause.
The actual

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (12 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

result of this
action was to
dramatically
increase the
query run time
from 15
seconds to 5
minutes. When
the optimizer
hint /*+
no_push_pred
*/ was used,
the query run
time dropped
down to 15
seconds.

The need for


use of the /*+
no_push_pred
*/ optimizer
hint can be
seen in the
Explain Plan if
the description
states, "VIEW
PUSHED
PREDICATE".

All of this
shows the poor
performance
from my
example was
only partially
caused, in an
undetermined
small amount,
by the ANSI
syntax.
# posted by
Scott
Nightlinger :
Wednesday, 08

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (13 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

August, 2007

This post has


been removed
by a blog
administrator.
# posted by
Anonymous :
Sunday, 30
September, 2007

hi....

Can i insert
record in the
middle of the
table?

for example i
have a table
called Emp and
it contains 10
rows. I want to
insert a record
after 8th
record.
Is it possible to
insert? if yes
can u tell the
query please?.
# posted by
meera :
Monday, 31
December, 2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (14 of 15)1/9/2008 2:53:23 AM


OracleBlog: ANSI Joins

http://thinkoracle.blogspot.com/2007/05/ansi-joins.html (15 of 15)1/9/2008 2:53:23 AM


OracleBlog: Bulk Binding: FORALL

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, January 17, 2006


Bulk Binding: FORALL
When writing your PL/SQL stored procedure bear in mind that SQL
statements are still sent to the SQL Engine as opposed to the PL/SQL
Engine. Therefore in cases where you are executing several SQL
statements in a loop, the resulting context switches could cause a
noticeable performance problem.

One solution to this performance solution is the use of "bulk


binding." What is that? Well first, you may recall that binding
variables allows you to tie the current value of a variable into an SQL
statement.
http://thinkoracle.blogspot.com/2005/06/bind-variables-in-plsql.
html

"Bulk Binding" refers to a process whereby you can tie the current
values of all the elements in an entire collection into a single
operation. By using bulk binds, only one context switch is made
between the PL/SQL and SQL Engines, to pass the entire collection,
thus avoiding those performance issues.

So how is this done? In this case, using FORALL.

Let's look at an example from the Oracle documentation of how you


might do something without any knowledge of bulk binding:

DECLARE

http://thinkoracle.blogspot.com/2006/01/bulk-binding-forall.html (1 of 7)1/9/2008 2:53:26 AM


OracleBlog: Bulk Binding: FORALL

TYPE NumList IS VARRAY(20) OF NUMBER;


depts NumList := NumList(10,30,70);
BEGIN
FOR i IN depts.FIRST..depts.LAST LOOP
UPDATE emp SET sal = sal + 100 WHERE deptno = depts(i);
END LOOP;
END;

Using timing techniques I've explained before, here is what I came up


with:
http://thinkoracle.blogspot.com/2005/09/analyzing-query-
performance.html

call count cpu elapsed disk query


------- ------ -------- ---------- ---------- ----------
Parse 1 0.00 0.00 0
0
Execute 3 0.01 0.00 0
9
Fetch 0 0.00 0.00 0
0
------- ------ -------- ---------- ----------
----------
total 4 0.01 0.00 0
9

Instead, we can use FORALL like this:

DECLARE
TYPE NumList IS VARRAY(20) OF NUMBER;
depts NumList := NumList(10,30,70);
BEGIN
FORALL i IN depts.FIRST..depts.LAST
UPDATE emp SET sal = sal + 100 WHERE deptno = depts(i);
END;

And get this:

call count cpu elapsed disk query


------- ------ -------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0

http://thinkoracle.blogspot.com/2006/01/bulk-binding-forall.html (2 of 7)1/9/2008 2:53:26 AM


OracleBlog: Bulk Binding: FORALL

Execute 1 0.00 0.01 0 9


Fetch 0 0.00 0.00 0 0
------- ------ -------- ---------- ---------- ----------
total 2 0.00 0.01 0 9

Notice 1 execute instead of 3. Of course we won't see any


performance difference on a small sample size, but here I am just
illustrating the point.

You may notice the absense of the keyword "LOOP" in the FORALL
example. That is because despite its similar appearances and syntax
in this example, FORALL is not a loop. It takes a single SQL
statement, and the index i can be used only as an index into the
collection.

You can find more information about FORALL in the PL/SQL User's
Guide and Reference: http://download-west.oracle.com/docs/cd/
B10501_01/appdev.920/a96624.pdf

Another useful trick is the use of SQL%BULK_ROWCOUNT (SQL is the


implicit cursor used by the SQL engine for DML operations). It can be
indexed the same way as the collection.

DECLARE
TYPE NumList IS VARRAY(20) OF NUMBER;
depts NumList := NumList(10,30,70);
BEGIN
FORALL i IN depts.FIRST..depts.LAST
UPDATE emp SET sal = sal + 100 WHERE deptno = depts(i);

FOR i IN depts.FIRST..depts.LAST LOOP


DBMS_OUTPUT.PUT_LINE('Affected Rows for ' || depts(i) || ' is ' || SQL%
BULK_ROWCOUNT(i));
END LOOP;
END;

Affected Rows for 10 is 3


Affected Rows for 30 is 6
Affected Rows for 70 is 0

The only error I can foresee getting with FORALL is this one:
ORA-22160: element at index does not exist

http://thinkoracle.blogspot.com/2006/01/bulk-binding-forall.html (3 of 7)1/9/2008 2:53:26 AM


OracleBlog: Bulk Binding: FORALL

And you will only get that if you are somehow binding to an index
that does not exist.

You may also get complaints if you use the index in an expression,
which is not supported:
PLS-00430: FORALL iteration variable i is not allowed in this context

Now that I've spoken about avoiding unnecessary context switches


executing SQL statements, what about unnecessary context switches
in getting information FROM the SQL engine? Are those avoidable?
Yes, using BULK COLLECT. I'll write more about that shortly.

Links:
Dan Morgan has more than just a reference on this topic, he has lots
of really good examples: http://www.psoug.org/reference/
bulk_collect.html

There is also a short but good write-up on bulk binding in the


Application Developer's Guide: Fundamentals, look under Chapter 9:
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/
a96590.pdf

Dr. Tim Hall has some several good write-ups with good examples:
http://www.oracle-base.com/articles/8i/BulkBinds8i.php

// posted by Robert Vollman @ Tuesday, January 17, 2006

Comments:
One of my previous posts was about the bulk collect clause. You can
check it out also.
# posted by yas : Wednesday, 18 January, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/01/bulk-binding-forall.html (4 of 7)1/9/2008 2:53:26 AM


OracleBlog: Bulk Binding: FORALL

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
❍ Brian Duff's OraBlogs
❍ Eddie Awad's OracleNA
❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
http://thinkoracle.blogspot.com/2006/01/bulk-binding-forall.html (5 of 7)1/9/2008 2:53:26 AM
OracleBlog: Bulk Binding: FORALL

❍ Oracle's Ask Tom Kyte


❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006

http://thinkoracle.blogspot.com/2006/01/bulk-binding-forall.html (6 of 7)1/9/2008 2:53:26 AM


OracleBlog: Bulk Binding: FORALL

❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2006/01/bulk-binding-forall.html (7 of 7)1/9/2008 2:53:26 AM


OracleBlog: Column Name as a Variable

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, September 22,


About Me
2005
Name: Robert Vollman
Column Name as a Location: Calgary, Alberta, Canada
Variable
Consider the situation where I was born and raised in Ottawa, and
you are writing a stored have lived in Calgary since 1991. I like
procedure that takes a playing sports (hockey, soccer, ultimate,
column name as a variable, basketball, you name it) and military board games.
and then does some work I also enjoy reading, walking, and playing with my
based on a query that uses 2 cats Lilly and Brutus. I'm a database application
that column name. How specialist, whatever that is.
would you do it?
View my complete profile
Let's consider a hypothetical
situation. Say you have a
table with all your
employees. Some of the Best Links
columns are responsible for ● Ask Tom Kyte
their pay. Employees can get ● Oracle Docs
paid in different ways, for ● Dan Morgan and PSOUG
example: base salary, hourly ● Steven Feuerstein
wage, bonus, dividend, etc. ● Jonathan Lewis
You have made each one of ● FAQ
these a separate column in
Connor McDonald
the table. (Note: all these

The Oak Table


columns are of the same

Cary Millsap and Hotsos


type). ●

http://thinkoracle.blogspot.com/2005/09/column-name-as-variable.html (1 of 7)1/9/2008 2:53:34 AM


OracleBlog: Column Name as a Variable

● Steve Adams and Ixora


You have a number of stored ● Anjo Kolk and OraPerf
procedures that access these ● Dizwell Oracle Wiki
tables. They all share some ● My Personal Blog
things in common, so you
have decided to make some
common "helper" procedures
for all the "master"
procedures to use.
Aggregators
Brian Duff's OraBlogs

Your "helper" procedure ❍ Eddie Awad's OracleNA


would have to take the ❍ Pete Finnigan's Aggregator
column name from the ❍ Oracle's Bloglist
"master" procedure, and then ❍ Oracle Base Aggregator
perform the common queries
and data manipulations for
that given column.
Top Blogs
❍ Oracle's Ask Tom Kyte
1. Dynamic SQL ❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
One way of doing that is with ❍ Data Warehouser David Aldridge
dynamic SQL. Observe: ❍ Oracle Geek Lewis Cunningham
Database Expert James Koopmann
CREATE OR REPLACE

Dizwell's Howard Rogers


PROCEDURE HelperProc ( ❍

in_col_name IN VARCHAR2, ❍ Oracle Master Laurent Schneider


out_val OUT NUMBER) ❍ Security Expert Pete Finnigan
IS ❍ Oracle Award Winner Mark Rittman
BEGIN ❍ Doug Burns
EXECUTE IMMEDIATE 'SELECT ❍ Oracle ACE of the Year Dr. Tim Hall
MAX(' || in_col_name || ') ❍ UKOUG's Andrew (Arfur C.) Clarke
FROM EMP' INTO out_val; ❍ Newbie DBA Lisa Dobson
END; ❍ Coffee-Drinking DBA Jon Emmons
Chris Foot
SET SERVEROUTPUT ON;

❍ The Pythian DBA Team Blog


DECLARE ❍ DBA Don Seiler
out_val NUMBER; ❍ DBA Coskan Gundogar
BEGIN ❍ Oracle WTF
HelperProc('EMPNO', out_val);
DBMS_OUTPUT.PUT_LINE
(out_val);
ARCHIVES
LIST ALL ARTICLES
END;

❍ May 2005
❍ June 2005

http://thinkoracle.blogspot.com/2005/09/column-name-as-variable.html (2 of 7)1/9/2008 2:53:34 AM


OracleBlog: Column Name as a Variable

It works very well: ❍ July 2005


- It's a single line, no matter ❍ August 2005
how many possible columns ❍ September 2005
are used October 2005
- You don't need to know the

November 2005
column names in advance

December 2005
- You don't need to change it

January 2006
after a DDL change ❍

❍ February 2006
However, there are ❍ March 2006
drawbacks to Dynamic SQL. ❍ April 2006
Among others, there is extra ❍ May 2006
parsing and (most seriously) ❍ June 2006
vulnerabilities to SQL ❍ July 2006
injection. I won't go into ❍ August 2006
more detail on Dynamic SQL,
September 2006
but I promise to blog on it

October 2006
soon.

❍ November 2006
2. Static SQL ❍ December 2006
❍ January 2007
The obvious recourse is to ❍ February 2007
use something like IF or CASE ❍ March 2007
or (my favourite) DECODE. ❍ April 2007
May 2007
CREATE OR REPLACE

PROCEDURE HelperProc ( ❍ June 2007


in_col_name IN VARCHAR2, ❍ October 2007
out_val OUT NUMBER)
IS
BEGIN
SELECT MAX(DECODE
(in_col_name, 'EMPNO',
EMPNO, 'MGR', MGR, 'SAL',
SAL, 'COMM', COMM,
'DEPTNO', DEPTNO, NULL))
INTO out_val
FROM EMP;
END;

Essentially this is like looking


at the column name, and
doing something different
depending on what it is.

http://thinkoracle.blogspot.com/2005/09/column-name-as-variable.html (3 of 7)1/9/2008 2:53:34 AM


OracleBlog: Column Name as a Variable

That's practically all you can


do with static SQL, by
definition. This almost
defeats the purpose of
having a common "helper"
procedure, but there are still
two reasons it would still
make sense:
1. Modularity (and
abstraction) is generally a
good thing
2. Any extra work done on
out_val will justify the
"helper" procedure.

3. Revised Data Model

There is an even more


important consideration.
Whenever you are struggling
to do something clever, take
a step back and consider
your data model. It could be
ill-suited for your needs.

In this case, what could we


do?

We could break this


information into separate
tables. For example:
EmpBaseSalary, EmpHoury,
EmpBonus, etc. Then we
could join them to the Emp
table by employee id. Of
course, that just makes the
table name variable instead
of the column, so that
doesn't really help us, so
instead:

We could elongate the


employee table, making
something like this:

http://thinkoracle.blogspot.com/2005/09/column-name-as-variable.html (4 of 7)1/9/2008 2:53:34 AM


OracleBlog: Column Name as a Variable

ID;...;SALARY;HOURLY;BONUS;
DIVIDEND
1;...;60;NULL;NULL;NULL
2;...;100;NULL;NULL;20

into a separate table mapped


by ID:

ID;VALUE;TYPE
1;60;'SALARY'
2;100;'SALARY'
2;20;'DIVIDEND'

That would effectively move


the "column name" into the
WHERE clause. That would
certainly make the task
easier. That is sort of a
"reverse pivot."

Also, that opens the door to


add extra columns for
effective start and end dates.
We could even do this with
views if we wanted to leave
the data model alone.

http://thinkoracle.blogspot.
com/2005/07/use-views.
html
http://thinkoracle.blogspot.
com/2005/09/pivot-and-
crosstab-queries.html

That is just one example, but


it shows how you need to
take a step back and
consider the real-world
application.

Here is a link to the Dizwell


discussion forum where we
discussed this, and where

http://thinkoracle.blogspot.com/2005/09/column-name-as-variable.html (5 of 7)1/9/2008 2:53:34 AM


OracleBlog: Column Name as a Variable

most of this came from:


http://www.phpbbserver.
com/phpbb/viewtopic.php?
t=450&mforum=dizwellforum

// posted by Robert
Vollman @ Thursday, September 22,

2005

Comments:
Rob,

"The obvious recourse is to


use something like IF or CASE
or (my favourite) DECODE."

Why do you say that? It's just


I'm writing a version of the
DECODE paper that covers
CASE instead and I'm
wondering what you see as
the benefits.

Cheers,

Doug
# posted by Doug Burns : Friday,
23 September, 2005

If you're using static SQL,


that means that you need to
know the columns and what
you're going to do with them
at compile-time. In essence,
as you write the procedure
you need to specify the
different options and what to
do in each case. That is one
of the jobs that commands
like IF, CASE and DECODE
where designed for. I don't

http://thinkoracle.blogspot.com/2005/09/column-name-as-variable.html (6 of 7)1/9/2008 2:53:34 AM


OracleBlog: Column Name as a Variable

really see any other options


for static SQL against which
to compare the benefits.

If instead you are asking me


about why DECODE is my
favourite among the 3 it's
simply because I'm
comfortable with it, and I can
use it regardless of my
Oracle version.
# posted by Robert Vollman :
Friday, 23 September, 2005

It was the latter and I can see


what you're saying. The extra
functionality of CASE isn't
always neccessary.

Cheers,

Doug
# posted by Doug Burns : Friday,
23 September, 2005

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/09/column-name-as-variable.html (7 of 7)1/9/2008 2:53:34 AM


OracleBlog: Common Table Column Types

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, June 16, 2005


About Me
Common Table Column Name: Robert Vollman
Types Location: Calgary, Alberta,
I have two tables which are created in an Canada
SQL file, and I want to have a column in
common in both. I was born and raised in
Ottawa, and have lived in Calgary since
CREATE TABLE atable (atable_id 1991. I like playing sports (hockey,
VARCHAR2(32), atable_value NUMBER); soccer, ultimate, basketball, you name
CREATE TABLE btable (btable_id it) and military board games. I also
VARCHAR2(32), btable_name VARCHAR2 enjoy reading, walking, and playing
(32)); with my 2 cats Lilly and Brutus. I'm a
database application specialist,
However, I don't want to have to rely on whatever that is.
manual verification to make sure they
are the same type. And if I want to
View my complete profile
change them for a future version, I'd
rather only change it in one place.

I can't do this (abbreviated example): Best Links


Ask Tom Kyte
CREATE TABLE atable (atable_id

Oracle Docs
VARCHAR2(32));

SQL> CREATE TABLE btable (btable_id ● Dan Morgan and PSOUG


atable.atable_id%TYPE); ● Steven Feuerstein
CREATE TABLE btable (btable_id atable. ● Jonathan Lewis
atable_id%TYPE) ● FAQ

http://thinkoracle.blogspot.com/2005/06/common-table-column-types.html (1 of 4)1/9/2008 2:53:36 AM


OracleBlog: Common Table Column Types

* Connor McDonald

ERROR at line 1: ● The Oak Table


ORA-00911: invalid character ● Cary Millsap and Hotsos
● Steve Adams and Ixora
And I can't do this:
● Anjo Kolk and OraPerf
CREATE OR REPLACE PACKAGE ● Dizwell Oracle Wiki
table_types ● My Personal Blog
AS
SUBTYPE table_id IS VARCHAR2(32);
END;

SQL> CREATE TABLE atable (atable_id


Aggregators
Brian Duff's OraBlogs
table_types.table_id);

Eddie Awad's OracleNA


CREATE TABLE atable (atable_id

Pete Finnigan's Aggregator


table_types.table_id)

Oracle's Bloglist
* ❍

ERROR at line 1: ❍ Oracle Base Aggregator


ORA-00902: invalid datatype
Top Blogs
So what should we do? Oracle's Ask Tom Kyte

Oracle Guru Jonathan Lewis


If there is a logical link between these

Blogger of the Year Eddie Awad


two fields, we can use referential ❍

integrity constraints (thanks "hsheehan"): ❍ Data Warehouser David Aldridge


❍ Oracle Geek Lewis Cunningham
SQL>CREATE TABLE atable(atable_id ❍ Database Expert James Koopmann
VARCHAR2(32), atable_value NUMBER); ❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
Table created.
❍ Security Expert Pete Finnigan
SQL>ALTER TABLE atable ADD UNIQUE ❍ Oracle Award Winner Mark Rittman
(atable_id); ❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
Table altered. ❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
SQL>CREATE TABLE btable(btable_id Coffee-Drinking DBA Jon Emmons
REFERENCES atable(atable_id),

Chris Foot
btable_name VARCHAR2(32));

❍ The Pythian DBA Team Blog


Table created. ❍ DBA Don Seiler
❍ DBA Coskan Gundogar
However, this will require that every ❍ Oracle WTF
atable.atable_id be unique (ORA-
02270), and it will also require that ARCHIVES
http://thinkoracle.blogspot.com/2005/06/common-table-column-types.html (2 of 4)1/9/2008 2:53:36 AM
OracleBlog: Common Table Column Types

every btable.btable_id exists in atable. ❍ LIST ALL ARTICLES


atable_id (ORA-02291) ❍ May 2005
June 2005
This may not always be appropriate,

July 2005
because sometimes there is no such

August 2005
relationships between columns. You may ❍

simply want all columns in a database ❍ September 2005


that are somehow similar (example: ❍ October 2005
people's names) to be the same type. ❍ November 2005
You may be doing this for convenience ❍ December 2005
or because you have common functions ❍ January 2006
on these columns. ❍ February 2006
❍ March 2006
In that case, you may need to resort to a
April 2006
3rd-party schema modeller. After all,

May 2006
that's what they're for.

❍ June 2006
Otherwise, you can create a file of tags, ❍ July 2006
use these tags in a "pre-SQL" file, then ❍ August 2006
write a Perl script to do text ❍ September 2006
substitutions to generate the SQL file. ❍ October 2006
For example: ❍ November 2006
December 2006
Tags.txt:

January 2007
ID_TYPE VARCHAR2(32)

February 2007
CreateTable.pre:

CREATE TABLE ATABLE (atable_id ❍ March 2007


ID_TYPE, atable_value NUMBER); ❍ April 2007
CREATE TABLE BTABLE (btable_id ❍ May 2007
ID_TYPE, btable_name VARCHAR2(32)); ❍ June 2007
Execute your Perl script here ❍ October 2007
CreateTable.sql:
CREATE TABLE ATABLE (atable_id
VARCHAR2(32), atable_value NUMBER);
CREATE TABLE BTABLE (btable_id
VARCHAR2(32), atable_name VARCHAR2
(32));

Thanks to the folks at the Dizwell Forum


for helping me think this one through.
http://www.phpbbserver.com/phpbb/
viewtopic.php?
t=179&mforum=dizwellforum&sid=6802

http://thinkoracle.blogspot.com/2005/06/common-table-column-types.html (3 of 4)1/9/2008 2:53:36 AM


OracleBlog: Common Table Column Types

Here are some loosely related previous


blogs on this:
http://thinkoracle.blogspot.
com/2005/05/dynamically-assigning-
size-of-varchar2.html
http://thinkoracle.blogspot.
com/2005/05/null-vs-nothing.html

// posted by Robert Vollman @ Thursday, June 16,

2005

Comments: Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/06/common-table-column-types.html (4 of 4)1/9/2008 2:53:36 AM


OracleBlog: COMPUTE

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated, but it
is the most powerful tool when it comes to data. That's why when I think data, I think Oracle. I also enjoy
writing, so I use this format to organise my thoughts. Please feel free to discuss any thoughts you may
have on the same topics, even old ones (I will see and respond to such comments). You may want to
start with "LIST ALL ARTICLES" under Archives.

Wednesday, August 24, 2005


About Me
COMPUTE Name: Robert
Let's say you wanted to write a query that contained an Vollman
aggregate (eg: sum, min, max, count). No problem, you can Location: Calgary,
use 'GROUP BY'. Alberta, Canada
But suppose you wanted to write a query that was a report
containing both the aggregate and the detail. That makes it I was born and raised in Ottawa,
trickier. and have lived in Calgary since
1991. I like playing sports
You may even know how to do it in other databases: (hockey, soccer, ultimate,
basketball, you name it) and
http://sybasease.blogspot.com/2005/08/compute.html military board games. I also
enjoy reading, walking, and
There is a simple way of accomplishing this in SQL*Plus. playing with my 2 cats Lilly and
SQL*Plus includes a function of the same name (COMPUTE) Brutus. I'm a database
that will do the formatting for you. application specialist, whatever
that is.
In order to use it, you also have to use 'BREAK'. Let's take a
very brief look at it. BREAK, like COMPUTE, is an SQL*Plus View my complete profile
command that you would issue at any time prior to your
query. For example, the following BREAK command will
remove all values in DEPTNO if they are the same as the
preceding value, and skip 1 line after each grouping. Best Links
● Ask Tom Kyte
scott@Robert> BREAK ON deptno SKIP 1 NODUPLICATES ● Oracle Docs
scott@Robert> SELECT ename, sal, deptno ● Dan Morgan and PSOUG
2 FROM emp ● Steven Feuerstein
3 ORDER BY deptno; ● Jonathan Lewis
ENAME SAL DEPTNO ● FAQ
---------- ---------- ---------- ● Connor McDonald
CLARK 2450 10 ● The Oak Table
VOLLMAN 5000 ● Cary Millsap and Hotsos
MILLER 1300
● Steve Adams and Ixora
SMITH 800 20
● Anjo Kolk and OraPerf
ADAMS 1100

http://thinkoracle.blogspot.com/2005/08/compute.html (1 of 6)1/9/2008 2:53:39 AM


OracleBlog: COMPUTE

FORD 3000 ● Dizwell Oracle Wiki


SCOTT 3000 ● My Personal Blog
JONES 2975
ALLEN 1600 30

Aggregators
BLAKE 2850
MARTIN 1250
JAMES 950
Brian Duff's OraBlogs

TURNER 1500
❍ Eddie Awad's OracleNA
WARD 1250
❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator
Now let's add our COMPUTE command. This one will
calculate the subtotal of salary, just like it would using
GROUP BY. The advantage here is that its in the same table.
Top Blogs
❍ Oracle's Ask Tom Kyte
scott@Robert> COMPUTE SUM LABEL subtotal OF sal ON ❍ Oracle Guru Jonathan Lewis
deptno ❍ Blogger of the Year Eddie Awad
scott@Robert> SELECT ename, sal, deptno FROM emp ❍ Data Warehouser David Aldridge
ORDER BY deptno; ❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
ENAME SAL DEPTNO ❍ Dizwell's Howard Rogers
---------- ---------- ---------- ❍ Oracle Master Laurent Schneider
CLARK 2450 10 ❍ Security Expert Pete Finnigan
VOLLMAN 5000 ❍ Oracle Award Winner Mark
MILLER 1300 Rittman
---------- ********** ❍ Doug Burns
8750 subtotal ❍ Oracle ACE of the Year Dr. Tim
SMITH 800 20 Hall
ADAMS 1100
❍ UKOUG's Andrew (Arfur C.) Clarke
FORD 3000
❍ Newbie DBA Lisa Dobson
SCOTT 3000
❍ Coffee-Drinking DBA Jon Emmons
JONES 2975
---------- ********** ❍ Chris Foot
10875 subtotal ❍ The Pythian DBA Team Blog
ALLEN 1600 30 ❍ DBA Don Seiler
BLAKE 2850 ❍ DBA Coskan Gundogar
MARTIN 1250 ❍ Oracle WTF

ARCHIVES
JAMES 950
TURNER 1500
WARD 1250 ❍ LIST ALL ARTICLES
---------- **********
❍ May 2005
9400 subtotal
❍ June 2005
❍ July 2005
❍ August 2005
Naturally, this also works with other aggregate functions ❍ September 2005
like SUM, MIN, MAX, AVG, STD, VARIANCE, COUNT, ❍ October 2005
NUMBER. ❍ November 2005
December 2005
For reference, check out the SQL*Plus User's Guide:

❍ January 2006

http://thinkoracle.blogspot.com/2005/08/compute.html (2 of 6)1/9/2008 2:53:39 AM


OracleBlog: COMPUTE

http://download-west.oracle.com/docs/cd/B10501_01/ ❍ February 2006


server.920/a90842.pdf ❍ March 2006
❍ April 2006
You want chapters 7 and 13: ❍ May 2006
7 Formatting SQL*Plus Reports ❍ June 2006
13 SQL*Plus Command Reference
❍ July 2006
UPDATE: Actually there's a simple way without SQL*Plus, by ❍ August 2006
using GROUPING, see Tom Kyte's Comment. Here is his ❍ September 2006
example of my Oracle9 environment. ❍ October 2006
❍ November 2006
scott@Robert> SELECT DECODE(GROUPING_ID(ename), 1, ❍ December 2006
'Subtotal' ) tag ❍ January 2007
2 ename, deptno, SUM(sal) ❍ February 2007
3 FROM emp March 2007
4 GROUP BY GROUPING SETS( (ename,deptno), (deptno) );

❍ April 2007
❍ May 2007
TAG ENAME DEPTNO SUM(SAL)
❍ June 2007
-------- ---------- ---------- ----------
❍ October 2007
CLARK 10 2450
MILLER 10 1300
VOLLMAN 10 5000
Subtotal 10 8750
FORD 20 3000
ADAMS 20 1100
JONES 20 2975
SCOTT 20 3000
SMITH 20 800
Subtotal 20 10875
WARD 30 1250
ALLEN 30 1600
BLAKE 30 2850
JAMES 30 950
MARTIN 30 1250
TURNER 30 1500
Subtotal 30 9400

Read about GROUPING, GROUPING_ID and GROUPING SETS


in SQL Reference:
http://download-west.oracle.com/docs/cd/B10501_01/
server.920/a96540.pdf

// posted by Robert Vollman @ Wednesday, August 24, 2005

Comments:
scott@ORA10GR1> select decode( grouping_id(ename), 1,
'Subtotal' ) tag,

http://thinkoracle.blogspot.com/2005/08/compute.html (3 of 6)1/9/2008 2:53:39 AM


OracleBlog: COMPUTE

2 ename, deptno, sum(sal)


3 from emp
4 group by grouping sets( (ename,deptno), (deptno) )
5 /

TAG ENAME DEPTNO SUM(SAL)


-------- ---------- ---------- ----------
king 10 5000
clark 10 2450
miller 10 1300
Subtotal 10 8750
ford 20 3000
adams 20 1100
jones 20 2975
scott 20 3000
smith 20 800
Subtotal 20 10875
ward 30 1250
allen 30 1600
blake 30 2850
james 30 950
martin 30 1250
turner 30 1500
Subtotal 30 9400

17 rows selected.
# posted by Thomas Kyte : Wednesday, 24 August, 2005

Darn fast, Tom! Was going to have a crack at it as well with


the DW extensions but you beat me to it.
One of the least explored areas of Oracle but worth its
weight in gold.
# posted by Noons : Wednesday, 24 August, 2005

I didn't look at Tom's answer (honest!) but my reply


consists of simply GROUPING functions and ROLLUP. Are
these now deprecated in place of GROUPING_ID and GROUP
SETS??

select decode(grouping(ename),1,'',ename) as ename,


sum(sal) as sal,
decode(grouping(ename),1,'Sub total',deptno) as deptno
from emp
group by rollup(ename), deptno;

ENAME SAL DEPTNO


-------------------- ----------
----------------------------------------
CLARK 2450 10

http://thinkoracle.blogspot.com/2005/08/compute.html (4 of 6)1/9/2008 2:53:39 AM


OracleBlog: COMPUTE

MILLER 1300 10
VOLLMAN 5000 10
8750 Sub total
FORD 3000 20
ADAMS 1100 20
JONES 2975 20
SCOTT 3000 20
SMITH 800 20
10875 Sub total
WARD 1250 30
ALLEN 1600 30
BLAKE 2850 30
JAMES 950 30
MARTIN 1250 30
TURNER 1500 30
9400 Sub total

BTW mine looks more like Robert's SQL*Plus output :)


# posted by Anonymous : Wednesday, 24 August, 2005

I was wondering when someone would mention ROLLUP. :)

I love the way you even changed your emp table to make
me the President, too!!

I think the grand moral of the story is to consider


GROUPING, ROLLUP, GROUPING_ID, and GROUP SETS for
situations where you need details with aggregates.
# posted by Robert Vollman : Thursday, 25 August, 2005

No love for group by cube. In 8i, without grouping sets and


grouping id, group by cube and a having clause present an
option.
# posted by Justis Durkee : Friday, 26 August, 2005

Hi there!
I just answered a similar question on otn a few minutes ago:
Re: Display Grand Total on the same line.See output

without group by, without subquery, I used decode and


analytics.

Kindest regards
# posted by Laurent Schneider : Wednesday, 31 August, 2005

Post a Comment

http://thinkoracle.blogspot.com/2005/08/compute.html (5 of 6)1/9/2008 2:53:39 AM


OracleBlog: COMPUTE

<< Home

http://thinkoracle.blogspot.com/2005/08/compute.html (6 of 6)1/9/2008 2:53:39 AM


OracleBlog: Connect By

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics, even
old ones (I will see and respond to such comments). You may want to start with "LIST ALL
ARTICLES" under Archives.

Saturday, June 18, 2005


About Me
Connect By Name: Robert
I couldn't resist sharing this one, which I found Vollman
on DBA-Support recently: Location: Calgary,
Alberta, Canada
http://www.dbasupport.com/forums/
showthread.php?t=47760
I was born and raised in Ottawa,
and have lived in Calgary since
The question was how to create a column as
1991. I like playing sports
the concatentation of many rows into one,
(hockey, soccer, ultimate,
without using PL/SQL: just a single query.
basketball, you name it) and
Here is the example given: military board games. I also
enjoy reading, walking, and
CREATE TABLE t1 (col1 VARCHAR2(1)); playing with my 2 cats Lilly and
INSERT INTO t1 VALUES ('a'); Brutus. I'm a database
INSERT INTO t1 VALUES ('b'); application specialist, whatever
INSERT INTO t1 VALUES ('c'); that is.
INSERT INTO t1 VALUES ('d');
INSERT INTO t1 VALUES ('e'); View my complete profile

Desired result of an SQL statement on test:

abcde Best Links


● Ask Tom Kyte
The answer came from Tamil Selvan: ● Oracle Docs
Dan Morgan and PSOUG
1 SELECT REPLACE(col1, ' ')

http://thinkoracle.blogspot.com/2005/06/connect-by.html (1 of 4)1/9/2008 2:53:42 AM


OracleBlog: Connect By

2 FROM (SELECT SYS_CONNECT_BY_PATH ● Steven Feuerstein


(col1,' ') col1, level ● Jonathan Lewis
3 FROM t1 ● FAQ
4 START WITH col1 = (select min(col1) from ● Connor McDonald
t1) -- 'a' ● The Oak Table
5 CONNECT BY PRIOR col1 < col1 ● Cary Millsap and Hotsos
6 ORDER BY level DESC)
Steve Adams and Ixora
7* WHERE rownum = 1

Anjo Kolk and OraPerf


SQL> /

● Dizwell Oracle Wiki


REPLACE(COL1,'') ● My Personal Blog
----------------------------------------
abcde

Here are the things that may be new to


someone new to Oracle (especially Oracle 9 or
Aggregators
Brian Duff's OraBlogs
10):

Eddie Awad's OracleNA


- SYS_CONNECT_BY_PATH

Pete Finnigan's Aggregator


- CONNECT BY ❍

❍ Oracle's Bloglist
This is an interesting example, but it is just ❍ Oracle Base Aggregator

Top Blogs
one use of these features.

Here is a link to Dan Morgan's reference on


Oracle's Ask Tom Kyte
CONNECT BY

Oracle Guru Jonathan Lewis


http://www.psoug.org/reference/connectby. ❍

Blogger of the Year Eddie Awad


html

❍ Data Warehouser David Aldridge


And here is an Ask Tom article. ❍ Oracle Geek Lewis Cunningham
http://www.oracle.com/technology/oramag/ ❍ Database Expert James Koopmann
oracle/05-may/o35asktom.html ❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
// posted by Robert Vollman @ Saturday, June 18, 2005 ❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark
Rittman
❍ Doug Burns
Comments: ❍ Oracle ACE of the Year Dr. Tim
Quiz time Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
name the version of Oracle that introduced ❍ Newbie DBA Lisa Dobson
connect by. ❍ Coffee-Drinking DBA Jon Emmons
Chris Foot
You will likely be surprised by the answer.

❍ The Pythian DBA Team Blog

http://thinkoracle.blogspot.com/2005/06/connect-by.html (2 of 4)1/9/2008 2:53:42 AM


OracleBlog: Connect By

# posted by Thomas Kyte : Saturday, 18 June, 2005


DBA Don Seiler

❍ DBA Coskan Gundogar


❍ Oracle WTF

ARCHIVES
I started Oracle with version 8, which didn't
have SYS_CONNECT_BY_PATH or many of
these fancy CONNECT_BY_WHATEVER, but it ❍ LIST ALL ARTICLES
did have simple START WITH and CONNECT
May 2005
BY. Although I didn't know many people who

June 2005
bothered to use it. So my guess is Oracle 8 or

July 2005
earlier. ❍

❍ August 2005
Here is the answer (from Jonathan Lewis' site) ❍ September 2005
for cheaters like me: ❍ October 2005
http://www.jlcomp.demon.co.uk/faq/ ❍ November 2005
connectby.html ❍ December 2005
# posted by Robert Vollman : Saturday, 18 June, 2005 ❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
The FAQ needs to be updated... ❍ May 2006
June 2006
Keep guessing. ❍

❍ July 2006
# posted by Thomas Kyte : Sunday, 19 June, 2005
❍ August 2006
❍ September 2006
Here is a great article on string aggregation by ❍ October 2006
Tim Hall: ❍ November 2006
❍ December 2006
http://www.oracle-base.com/articles/10g/ ❍ January 2007
StringAggregationTechniques.php ❍ February 2007
# posted by Robert Vollman : Tuesday, 21 June, 2005 ❍ March 2007
❍ April 2007
❍ May 2007
Hi Robert. June 2007
is very short the result string.

October 2007
what is the max long???

# posted by Anonymous : Wednesday, 22 November,


2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/06/connect-by.html (3 of 4)1/9/2008 2:53:42 AM


OracleBlog: Connect By

http://thinkoracle.blogspot.com/2005/06/connect-by.html (4 of 4)1/9/2008 2:53:42 AM


OracleBlog: Decode

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, June 20, 2005


About Me
Decode Name: Robert Vollman
Here is another handy Oracle-only Location: Calgary, Alberta,
SQL tool: DECODE. Canada
Decode allows you to do if/elseif/else
logic within an SQL query, similar to a I was born and raised in
CASE WHEN statement in a PL/SQL Ottawa, and have lived in Calgary since
procedure. 1991. I like playing sports (hockey,
soccer, ultimate, basketball, you name it)
DECODE (expression, and military board games. I also enjoy
if_equal_to_this_1, give_me_this_1, reading, walking, and playing with my 2
else_if_equal_to_this_2, cats Lilly and Brutus. I'm a database
give_me_this_2, ..., default) application specialist, whatever that is.

Dan Morgan's Reference on DECODE: View my complete profile


http://www.psoug.org/reference/
decode_case.html

The default value is optional, if it is


Best Links
left out, it defaults to NULL. And the ● Ask Tom Kyte
maximum number of comparisons is ● Oracle Docs
255. ● Dan Morgan and PSOUG
● Steven Feuerstein
It works very much like a CASE WHEN ● Jonathan Lewis
statement, so you can already think ● FAQ
of uses, especially if you nest your ● Connor McDonald

http://thinkoracle.blogspot.com/2005/06/decode.html (1 of 4)1/9/2008 2:53:44 AM


OracleBlog: Decode

DECODEs. The Oak Table


● Cary Millsap and Hotsos


Remember the article I wrote on NULL ● Steve Adams and Ixora
vs Nothing and on NULLs in general? ● Anjo Kolk and OraPerf
Dizwell Oracle Wiki
http://thinkoracle.blogspot. ●

My Personal Blog
com/2005/05/null-vs-nothing.html

http://thinkoracle.blogspot.
com/2005/06/nulls-in-oracle.html

Well, you can actually use DECODE


Aggregators
like NVL. Don't believe me? I don't Brian Duff's OraBlogs

blame you, because I told you that ❍ Eddie Awad's OracleNA


NULL is not equal to NULL. But here is ❍ Pete Finnigan's Aggregator
a quote right from the Oracle 9i SQL ❍ Oracle's Bloglist
Reference: ❍ Oracle Base Aggregator

"In a DECODE function, Oracle


considers two nulls to be equivalent.
Top Blogs
If expr is null, then Oracle returns the ❍ Oracle's Ask Tom Kyte
result of the first search that is also ❍ Oracle Guru Jonathan Lewis
null." ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
And here is the example because like ❍ Oracle Geek Lewis Cunningham
me you don't believe anything ❍ Database Expert James Koopmann
without proof: ❍ Dizwell's Howard Rogers
Oracle Master Laurent Schneider
SQL> CREATE TABLE atable (avalue ❍

VARCHAR2(32)); ❍ Security Expert Pete Finnigan


❍ Oracle Award Winner Mark Rittman
Table created. ❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
SQL> INSERT INTO atable (avalue) UKOUG's Andrew (Arfur C.) Clarke
VALUES (NULL);

❍ Newbie DBA Lisa Dobson


1 row created. ❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
SQL> INSERT INTO atable (avalue) ❍ The Pythian DBA Team Blog
VALUES ('This is not NULL'); ❍ DBA Don Seiler
❍ DBA Coskan Gundogar
1 row created.
❍ Oracle WTF
SQL> SELECT DECODE(avalue, NULL,
'This is NULL', avalue) avalue ARCHIVES
2 FROM atable; ❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/06/decode.html (2 of 4)1/9/2008 2:53:44 AM


OracleBlog: Decode

❍ May 2005
AVALUE ❍ June 2005
--------------------------------
July 2005
This is NULL

August 2005
This is not NULL

❍ September 2005
If you don't believe how useful it can ❍ October 2005
be, here is a FAQ that shows how to ❍ November 2005
use DECODE for (among other things) ❍ December 2005
avoiding divide-by-zero errors: ❍ January 2006
❍ February 2006
http://www.db.cs.ucdavis.edu/public/ ❍ March 2006
oracle/faq/decode.html ❍ April 2006
May 2006
In practise, I have seen DECODE used

June 2006
for the ORDER BY clause.

❍ July 2006
If you are still not convinced, you can ❍ August 2006
"Ask Tom" how DECODE can be used ❍ September 2006
to have a conditional foreign key. ❍ October 2006
That is, a foreign key that only ❍ November 2006
applies to certain rows! ❍ December 2006
January 2007
http://asktom.oracle.com/pls/ask/f?

February 2007
p=4950:8:::::

March 2007
F4950_P8_DISPLAYID:1249800833250

❍ April 2007
❍ May 2007
// posted by Robert Vollman @ Monday, June
❍ June 2007
20, 2005 ❍ October 2007

Comments:
Doug Burns has an awesome paper
on DECODE:

http://doug.burns.tripod.com/
decode.html
# posted by Robert Vollman : Friday, 16
September, 2005

somehow., http://doug.burns.tripod.
com/decode.html has disappeared of

http://thinkoracle.blogspot.com/2005/06/decode.html (3 of 4)1/9/2008 2:53:44 AM


OracleBlog: Decode

theface of the earth.....


# posted by Mieke : Tuesday, 13 June, 2006

Doug Burns recently moved his blog,


including all his articles. Follow the
"Doug Burns" link on the right and
you may find it on his site.
# posted by Robert Vollman : Tuesday, 13
June, 2006

Sorry, folks ;-)

If you want to find any of the old


articles, just replace doug.burns.
tripod.com with oracledoug.com, so
the decode paper is at :-

http://oracledoug.com/decode.html

Cheers,

Doug
# posted by Doug Burns : Tuesday, 04 July,
2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/06/decode.html (4 of 4)1/9/2008 2:53:44 AM


OracleBlog: DUAL Table

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated,
but it is the most powerful tool when it comes to data. That's why when I think data, I think Oracle.
I also enjoy writing, so I use this format to organise my thoughts. Please feel free to discuss any
thoughts you may have on the same topics, even old ones (I will see and respond to such
comments). You may want to start with "LIST ALL ARTICLES" under Archives.

Thursday, November 10, 2005


DUAL Table
What is the DUAL table?

The DUAL Dummy table (as it is sometimes called) is an automatically-generated


table assigned to SYS, but accessible to all users. It has a single column "DUMMY" of
type VARCHAR2(1) which has a single row with a value of 'X'.

scott@Robert> SELECT * FROM DUAL;

D
-
X

scott@Robert> DESC DUAL;


Name Null?
Type
-----------------------------------------------------------------------
--------
-------------------------------------------------
DUMMY
VARCHAR2(1)

Warning: Do not modify the DUAL table! Why would you want to anyway? It is part of
the data dictionary, which you shouldn't modify (that's a topic for another day).

What is it used for?

It is useful because it always exists, and has a single row, which is handy for select
statements with constant expressions. You could just as easily do this with any
other table with a single row, but using DUAL makes it portable among all Oracle
installations.

Example:

http://thinkoracle.blogspot.com/2005/11/dual-table.html (1 of 5)1/9/2008 2:53:46 AM


OracleBlog: DUAL Table

SELECT 1+1 FROM DUAL;


1+1
----------
2

The other reason to use the DUAL table isn't just portability, but optimization.
According to Tom Kyte, the Oracle Optimizer knows it is a special one row, one
column table. Eddie Awad tested a related assertion recently:
http://awads.net/wp/2005/11/09/dual-behavior-change/

Why is it called "DUAL"?

It was named "DUAL" because the primary intention of this table was to allow users
to create 2 rows for every row in a table by joining it to this system table. Thus
"DUAL". Chuck explained it in the January/February 2002 issue of Oracle Magazine:
http://www.oracle.com/technology/oramag/oracle/02-jan/o12sendmail.html

Of course, you can quite easily use DUAL to create as many rows as you want, using
LEVEL (or CUBE). Just Ask Tom how this is done:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:40476301944675#40756986348091

Why is it sometimes referred to as a "magic" table?

For the answer to this and any remaining questions about DUAL, just Ask Tom:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:1562813956388#14583959098556

Links

Earlier I made mention of the DUAL table, including an example:


http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html

Eddie Awad recently tested Jared Still's assertion of an interesting feature in Oracle
10g. Even if DUAL has more than one row, apparently you can trust it to always
return just a single row. Read more:
http://awads.net/wp/2005/11/08/insert-into-dual/

Selecting from the DUAL table is mentioned in Chapter 8 of the Oracle SQL
Reference Guide:
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540.pdf

// posted by Robert Vollman @ Thursday, November 10, 2005

http://thinkoracle.blogspot.com/2005/11/dual-table.html (2 of 5)1/9/2008 2:53:46 AM


OracleBlog: DUAL Table

Comments:
Can we truncate dual table?
# posted by kan123 : Thursday, 30 August, 2007

Can we create a synonym for package,function and trigger?


# posted by kan123 : Thursday, 30 August, 2007

Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I like
playing sports (hockey, soccer, ultimate, basketball, you name it) and military
board games. I also enjoy reading, walking, and playing with my 2 cats Lilly and Brutus. I'm a
database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

http://thinkoracle.blogspot.com/2005/11/dual-table.html (3 of 5)1/9/2008 2:53:46 AM


OracleBlog: DUAL Table

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006

http://thinkoracle.blogspot.com/2005/11/dual-table.html (4 of 5)1/9/2008 2:53:46 AM


OracleBlog: DUAL Table

❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/11/dual-table.html (5 of 5)1/9/2008 2:53:46 AM


OracleBlog: Dynamically assigning size of varchar2

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, May
About Me
19, 2005
Name: Robert Vollman
Dynamically Location: Calgary, Alberta, Canada
assigning
size of I was born and raised in Ottawa, and have lived in
Calgary since 1991. I like playing sports (hockey,
varchar2 soccer, ultimate, basketball, you name it) and military board
I thought I would games. I also enjoy reading, walking, and playing with my 2 cats
declare my Lilly and Brutus. I'm a database application specialist, whatever
variable-lengthed that is.
variables with a
pre-defined View my complete profile
constant. Why?

1. I'd be sure they


matched up Best Links
everywhere. ● Ask Tom Kyte
2. I could change ● Oracle Docs
them all in a ● Dan Morgan and PSOUG
single place if
Steven Feuerstein
required.

● Jonathan Lewis
But I don't think ● FAQ
you can do that in ● Connor McDonald
PL/SQL. ● The Oak Table
● Cary Millsap and Hotsos
CREATE OR ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/05/dynamically-assigning-size-of-varchar2.html (1 of 9)1/9/2008 2:53:49 AM


OracleBlog: Dynamically assigning size of varchar2

REPLACE ● Anjo Kolk and OraPerf


PACKAGE ● Dizwell Oracle Wiki
test_constants IS ● My Personal Blog
MAX_LEN
CONSTANT
NUMBER := 32;
END
test_constants;
Aggregators
Brian Duff's OraBlogs

Package created. ❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
SET ❍ Oracle's Bloglist
SERVEROUTPUT ❍ Oracle Base Aggregator
ON

-- Anonymous
Top Blogs
block Oracle's Ask Tom Kyte

DECLARE ❍ Oracle Guru Jonathan Lewis


x VARCHAR2 ❍ Blogger of the Year Eddie Awad
(test_constants. ❍ Data Warehouser David Aldridge
MAX_LEN); -- ❍ Oracle Geek Lewis Cunningham
Can't do this ❍ Database Expert James Koopmann
BEGIN ❍ Dizwell's Howard Rogers
x := 'Test ' || ❍ Oracle Master Laurent Schneider
test_constants.
Security Expert Pete Finnigan
MAX_LEN;

Oracle Award Winner Mark Rittman


dbms_output.

Doug Burns
put_line(x); ❍

END; ❍ Oracle ACE of the Year Dr. Tim Hall


❍ UKOUG's Andrew (Arfur C.) Clarke
ERROR at line 2: ❍ Newbie DBA Lisa Dobson
ORA-06550: line ❍ Coffee-Drinking DBA Jon Emmons
2, column 31: ❍ Chris Foot
PLS-00491: ❍ The Pythian DBA Team Blog
numeric literal ❍ DBA Don Seiler
required ❍ DBA Coskan Gundogar
But what about ❍ Oracle WTF
other types?
ARCHIVES
Substitute ❍ LIST ALL ARTICLES
NVARCHAR2, ❍ May 2005
VARCHAR, CHAR, June 2005
NCHAR, or

❍ July 2005

http://thinkoracle.blogspot.com/2005/05/dynamically-assigning-size-of-varchar2.html (2 of 9)1/9/2008 2:53:49 AM


OracleBlog: Dynamically assigning size of varchar2

STRING if you ❍ August 2005


like, same result. ❍ September 2005
Incidentally the ❍ October 2005
"N" just means November 2005
you are specifying

December 2005
the length in

January 2006
bytes instead of

February 2006
characters. ❍

❍ March 2006
So what is a guy ❍ April 2006
to do? ❍ May 2006
❍ June 2006
1. Just put a ❍ July 2006
comment before
August 2006
every number,

September 2006
and make it a

October 2006
practise to make ❍

sure they all ❍ November 2006


match. ❍ December 2006
❍ January 2007
DECLARE ❍ February 2007
x VARCHAR2(32); ❍ March 2007
-- test_constants. ❍ April 2007
MAX_LEN = 32 ❍ May 2007
June 2007
But here is

another option. ❍ October 2007

2. Create a table
with the types you
want, and then
use those types.

CREATE TABLE
TEST_CONSTANTS
(
MAX_LEN
VARCHAR2(32)
);

Table created.

DECLARE
x

http://thinkoracle.blogspot.com/2005/05/dynamically-assigning-size-of-varchar2.html (3 of 9)1/9/2008 2:53:49 AM


OracleBlog: Dynamically assigning size of varchar2

TEST_CONSTANTS.
MAX_LEN%TYPE;
BEGIN
x := 'Test';
dbms_output.
put_line(x);
END;

// posted by Robert
Vollman @ Thursday,

May 19, 2005

Comments:
you can use
subtypes (trick
that works with
the NULLS from
your other blog
too -- if you want
parameters that
are NOT NULL,
you can create a
subtype which is
NOT NULL and
use that type...)

ops
$tkyte@ORA9IR2>
create or replace
package types
2 as
3 subtype
identifier_type is
varchar2(30);
4 end;
5/

Package created.

ops
$tkyte@ORA9IR2>
ops

http://thinkoracle.blogspot.com/2005/05/dynamically-assigning-size-of-varchar2.html (4 of 9)1/9/2008 2:53:49 AM


OracleBlog: Dynamically assigning size of varchar2

$tkyte@ORA9IR2>
ops
$tkyte@ORA9IR2>
declare
2 l_owner types.
identifier_type;
3 begin
4 null;
5 end;
6/

PL/SQL procedure
successfully
completed.
# posted by
Thomas Kyte :
Thursday, 19 May,
2005

Thanks Tom for


the suggestions.
It is important to
know that option,
it is certainly
more elegant than
storing your types
in a table.

One problem is
the following:

create table
atable (
acol types.
identifier_type
);

ORA-00902:
invalid datatype

You can't use


types in table
creations.

http://thinkoracle.blogspot.com/2005/05/dynamically-assigning-size-of-varchar2.html (5 of 9)1/9/2008 2:53:49 AM


OracleBlog: Dynamically assigning size of varchar2

So what is a guy
to do?
1. If your
parameter is
ultimately
something to be
selected from or
inserted into a
table, use the %
TYPE of the
column in the
table.
2. If not, use a
type from a
package as Tom
described.

Do you know of
any other
advantages or
disadvantages of
defining your
types in tables
instead of in
packages?
# posted by Robert
Vollman : Friday, 20
May, 2005

Answering your
own question may
be a faux-pas,
but in following
up Tom's
suggestion with
regards to having
NOT NULL
parameters in a
stored procedure,
I discovered an
advantage to

http://thinkoracle.blogspot.com/2005/05/dynamically-assigning-size-of-varchar2.html (6 of 9)1/9/2008 2:53:49 AM


OracleBlog: Dynamically assigning size of varchar2

using package
subtypes instead
of table column %
TYPEs.

Package subtype:
The NOT NULL
property of the
type is retained in
stored procedure
parameters.

Table column %
TYPEs: The NOT
NULL property of
the type is NOT
retained in stored
procedure
parameters, so
you must validate
any NULL
parameters
yourself.

"NULL vs Nothing"
http://thinkoracle.
blogspot.
com/2005/05/
null-vs-nothing.
html

Any other
advantages or
disadvantages?
# posted by Robert
Vollman : Friday, 20
May, 2005

If you are creating


a table just to get
a type definition -
that would be
"wrong", use

http://thinkoracle.blogspot.com/2005/05/dynamically-assigning-size-of-varchar2.html (7 of 9)1/9/2008 2:53:49 AM


OracleBlog: Dynamically assigning size of varchar2

SUBTYPE in plsql.

For program
variables that are
used to fetch or
insert into tables
using table.
column%type
makes perfect
sense (null or
otherwise, the
insert will catch it)

For program
variables that are
totally internal to
your processing,
subtypes make
sense, you use
the all of the
time, edit
$ORACLE_HOME/
rdbms/admin/
stdspec.sql and
look at all of the
subtypes (and you
thought "float"
meant something
-- it just means
"number", as does
real...
# posted by
Thomas Kyte :
Sunday, 22 May, 2005

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/05/dynamically-assigning-size-of-varchar2.html (8 of 9)1/9/2008 2:53:49 AM


OracleBlog: Dynamically assigning size of varchar2

http://thinkoracle.blogspot.com/2005/05/dynamically-assigning-size-of-varchar2.html (9 of 9)1/9/2008 2:53:49 AM


OracleBlog: ENUM in Oracle

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday, May 25,


About Me
2005
Name: Robert Vollman
ENUM in Oracle Location: Calgary, Alberta, Canada
What is ENUM?
I was born and raised in Ottawa, and have
ENUM is short for
lived in Calgary since 1991. I like playing
enumeration. Its a
sports (hockey, soccer, ultimate, basketball, you name it)
useful programming
and military board games. I also enjoy reading, walking,
type that contains an
and playing with my 2 cats Lilly and Brutus. I'm a
ordered list of string
database application specialist, whatever that is.
values. The
programmer can define
the valid values View my complete profile
depending on their

Best Links
application.

Some good examples of


Ask Tom Kyte
ENUMs would be days

Oracle Docs
and months, or

something like ● Dan Morgan and PSOUG


directions ('North', ● Steven Feuerstein
'South', 'East', 'West'). ● Jonathan Lewis
● FAQ
Is there an Oracle ● Connor McDonald
'ENUM' type? ● The Oak Table
Cary Millsap and Hotsos
No, not really. But there

● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/05/enum-in-oracle.html (1 of 6)1/9/2008 2:53:51 AM


OracleBlog: ENUM in Oracle

are other ways of ● Anjo Kolk and OraPerf


accomplishing the ● Dizwell Oracle Wiki
same thing. ● My Personal Blog

For tables, just set it to


a string and add a
constraint that it is
within a certain set.
Aggregators
Brian Duff's OraBlogs

CREATE TABLE atable ( ❍ Eddie Awad's OracleNA


col1 varchar2(10), ❍ Pete Finnigan's Aggregator
CONSTRAINT ❍ Oracle's Bloglist
cons_atable_col1 ❍ Oracle Base Aggregator
CHECK (col1 IN
('Monday', 'Tuesday',
'Wednesday', 'Thursday',
Top Blogs
Oracle's Ask Tom Kyte
'Friday', 'Saturday', ❍

'Sunday')) ❍ Oracle Guru Jonathan Lewis


); ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
SQL> INSERT INTO ❍ Oracle Geek Lewis Cunningham
atable (col1) VALUES ❍ Database Expert James Koopmann
('Monday'); ❍ Dizwell's Howard Rogers
Oracle Master Laurent Schneider
1 row created.

❍ Security Expert Pete Finnigan


SQL> INSERT INTO ❍ Oracle Award Winner Mark Rittman
atable (col1) VALUES ❍ Doug Burns
('Blingday'); ❍ Oracle ACE of the Year Dr. Tim Hall
insert into atable (col1) ❍ UKOUG's Andrew (Arfur C.) Clarke
values ('Blingday') ❍ Newbie DBA Lisa Dobson
* ❍ Coffee-Drinking DBA Jon Emmons
ERROR at line 1: ❍ Chris Foot
ORA-02290: check The Pythian DBA Team Blog
constraint (ROBERT.

DBA Don Seiler


CONS_ATABLE_COL1)

DBA Coskan Gundogar


violated

❍ Oracle WTF

ARCHIVES
What happens if you
use this type in a
procedure? Will the ❍ LIST ALL ARTICLES
constraint be checked? ❍ May 2005
No. ❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2005/05/enum-in-oracle.html (2 of 6)1/9/2008 2:53:51 AM


OracleBlog: ENUM in Oracle

CREATE OR REPLACE ❍ August 2005


PROCEDURE MyProc ❍ September 2005
(in_col IN atable.col1% ❍ October 2005
TYPE) November 2005
AS

December 2005
BEGIN

January 2006
DBMS_OUTPUT.PUT_LINE

February 2006
(in_col); ❍

END; ❍ March 2006


❍ April 2006
SET SERVEROUTPUT ON; ❍ May 2006
❍ June 2006
EXEC MyProc('Monday'); ❍ July 2006
EXEC MyProc('Blingday');
❍ August 2006
So can you create a ❍ September 2006
package subtype for ❍ October 2006
this? That would be ❍ November 2006
more elegant anyway. ❍ December 2006
❍ January 2007
But according to Oracle ❍ February 2007
PL/SQL Programming ❍ March 2007
by Steven Feuerstein April 2007
Chapter 4, I don't think

May 2007
you can (check

June 2007
comments for any

refutations to this). ❍ October 2007

http://www.amazon.
com/exec/obidos/
ASIN/0596003811/
qid=1117039808/
sr=2-1/
ref=pd_bbs_b_2_1/102-
9543590-3979349

I think the best thing to


do in this case is to
create a procedure to
validate your input.

CREATE OR REPLACE
PROCEDURE MyCheck

http://thinkoracle.blogspot.com/2005/05/enum-in-oracle.html (3 of 6)1/9/2008 2:53:51 AM


OracleBlog: ENUM in Oracle

(in_col IN atable.col1%
TYPE)
AS
BEGIN
IF (in_col NOT IN
('Monday', 'Tuesday',
'Wednesday',
'Thursday', 'Friday',
'Saturday', 'Sunday'))
THEN
-- Throw Exception
here, be sure to catch it
in MyProc!!
NULL;
END IF;
END;

This approach is
consistent with Steven
Feuerstein's approach
to programming. He
suggests separating
these things into
separate procedures.
Then when a future
release of Oracle
supports a concept, or
when you figure out
how to do it, you can
make the change in a
single place.

So what is a guy to do?


1. If you want to use
enum in a table, use a
check constraint.
2. If you want to use
enum in a stored
procedure, write a
separate procedure to
validate the input.

// posted by Robert
Vollman @ Wednesday, May

http://thinkoracle.blogspot.com/2005/05/enum-in-oracle.html (4 of 6)1/9/2008 2:53:51 AM


OracleBlog: ENUM in Oracle

25, 2005

Comments:
later without having to
find all of the "where x
in ( ..... )" checks.

ops$tkyte@ORA10G>
create or replace
package my_pkg
2 as
3 type days is table of
varchar2(30);
4 set_of_days days :=
days( 'Mon', 'Tue',
'Wed', 'Thu', 'Fri', 'Sat',
'Sun' );
5 end;
6/

Package created.

ops$tkyte@ORA10G>
ops$tkyte@ORA10G>
create or replace
procedure foo( p_day in
varchar2 )
2 as
3 begin
4 if p_day MEMBER OF
my_pkg.set_of_days
5 then
6 dbms_output.put_line
( 'Tis OK' );
7 elsif NOT p_day
MEMBER OF my_pkg.
set_of_days
8 then
9 dbms_output.put_line
( 'NOT ok' );
10 else
11 dbms_output.

http://thinkoracle.blogspot.com/2005/05/enum-in-oracle.html (5 of 6)1/9/2008 2:53:51 AM


OracleBlog: ENUM in Oracle

put_line( 'We are not


sure here...' );
12 end if;
13 end;
14 /

Procedure created.

ops$tkyte@ORA10G>
exec foo('Fri');
Tis OK

PL/SQL procedure
successfully completed.

ops$tkyte@ORA10G>
exec foo('xxx');
NOT ok

PL/SQL procedure
successfully completed.

ops$tkyte@ORA10G>
exec foo(null);
We are not sure here...

PL/SQL procedure
successfully completed.
# posted by Thomas Kyte :
Thursday, 26 May, 2005

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/05/enum-in-oracle.html (6 of 6)1/9/2008 2:53:51 AM


OracleBlog: Extra Columns in a GROUP BY

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, July 01, 2005


About Me
Extra Columns in a Name: Robert Vollman
GROUP BY Location: Calgary, Alberta,
Happy Canada Day. I have a really Canada
good one today.
I was born and raised in
My problem: Ottawa, and have lived in Calgary since
1991. I like playing sports (hockey, soccer,
I have a table 'ASSIGNMENTS' that ultimate, basketball, you name it) and
keeps track of each assignment, who military board games. I also enjoy reading,
holds which assignment, and as of walking, and playing with my 2 cats Lilly
which date they have held it. and Brutus. I'm a database application
specialist, whatever that is.
It would be very handy to have a view
that shows all assignments, and who
is currently on that assignment. View my complete profile

Best Links
CREATE TABLE ASSIGNMENTS
(ASSIGNMENT VARCHAR2(32),
EMPLOYEE VARCHAR2(32), EFFECTIVE
Ask Tom Kyte
DATE);

● Oracle Docs
INSERT INTO ASSIGNMENTS ● Dan Morgan and PSOUG
(ASSIGNMENT, EMPLOYEE, EFFECTIVE) ● Steven Feuerstein
VALUES ('Prime Minister', 'Jean ● Jonathan Lewis
Chretien', '04-Nov-93'); ● FAQ
INSERT INTO ASSIGNMENTS ● Connor McDonald

http://thinkoracle.blogspot.com/2005/07/extra-columns-in-group-by.html (1 of 5)1/9/2008 2:53:54 AM


OracleBlog: Extra Columns in a GROUP BY

(ASSIGNMENT, EMPLOYEE, EFFECTIVE) The Oak Table


VALUES ('Governor General', ● Cary Millsap and Hotsos


'Adrienne Clarkson', '07-Oct-99'); ● Steve Adams and Ixora
INSERT INTO ASSIGNMENTS ● Anjo Kolk and OraPerf
(ASSIGNMENT, EMPLOYEE, EFFECTIVE) ● Dizwell Oracle Wiki
VALUES ('Prime Minister', 'Paul ● My Personal Blog
Martin', '12-Dec-03');

You must be familiar with GROUP BY.

SELECT ASSIGNMENT, MAX Aggregators


(EFFECTIVE) AS_OF FROM Brian Duff's OraBlogs

ASSIGNMENTS GROUP BY ❍ Eddie Awad's OracleNA


ASSIGNMENT; ❍ Pete Finnigan's Aggregator
Oracle's Bloglist
ASSIGNMENT AS_OF

Oracle Base Aggregator


-------------------------------- ❍

---------
Governor General 07-OCT-99 Top Blogs
Prime Minister 12-DEC-03 ❍Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
2 rows selected. ❍ Blogger of the Year Eddie Awad
Data Warehouser David Aldridge
Ok, now we would like to add in the ❍

name of the person. But whoops, ❍ Oracle Geek Lewis Cunningham


doesn't work as you'd expect. ❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
SELECT ASSIGNMENT, EMPLOYEE, MAX ❍ Oracle Master Laurent Schneider
(EFFECTIVE) AS_OF FROM ❍ Security Expert Pete Finnigan
ASSIGNMENTS GROUP BY ❍ Oracle Award Winner Mark Rittman
ASSIGNMENT; ❍ Doug Burns
Oracle ACE of the Year Dr. Tim Hall
ORA-00979: not a GROUP BY ❍

expression ❍ UKOUG's Andrew (Arfur C.) Clarke


❍ Newbie DBA Lisa Dobson
You see, we can't include any ❍ Coffee-Drinking DBA Jon Emmons
columns that aren't part of the ❍ Chris Foot
GROUP BY. And, we can't include it in ❍ The Pythian DBA Team Blog
the group by, because then we'd get ❍ DBA Don Seiler
a result no different from ❍ DBA Coskan Gundogar
assignments. ❍ Oracle WTF
There is an answer. Connor
McDonald has it: ARCHIVES
❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/07/extra-columns-in-group-by.html (2 of 5)1/9/2008 2:53:54 AM


OracleBlog: Extra Columns in a GROUP BY

http://www.oracledba.co.uk/ ❍ May 2005


tips/9i_first_last.htm ❍ June 2005
❍ July 2005
Alright, what is Connor talking ❍ August 2005
about? Basically he is grouping the September 2005
"extra" column (empno), and making

October 2005
it a secondary grouping to the main

November 2005
grouping (sal).

❍ December 2005
But, really, MIN(EMPNO)? Why are we ❍ January 2006
including an aggregate function on ❍ February 2006
empno? Well, Connor is doing it ❍ March 2006
because he wants to break ties. ❍ April 2006
❍ May 2006
Even though we don't need to break
June 2006
ties, we still need to use an

July 2006
aggregate function, otherwise it

August 2006
becomes part of the group by. Any ❍

aggregate function will do since we ❍ September 2006


shouldn't have duplicates. ❍ October 2006
❍ November 2006
DENSE_RANK , FIRST, ORDER BY ❍ December 2006
❍ January 2007
- ORDER BY will sort a set of rows by February 2007
a particular column. In Connor's case

March 2007
it is salary, in our case, it will be

April 2007
'effective'.

- DENSE_RANK provides the ❍ May 2007


positioning of a particular row within ❍ June 2007
an ordered list of rows. ❍ October 2007
- FIRST goes hand-in-hand with
DENSE_RANK and will naturally
provide us with the first, ranked row
in a ordered list of rows.

Note that the ORDER BY defaults to


ascending order, and so in our case
we either want to choose LAST or put
the ORDER BY in descending order
instead.

Essentially he is creating an ordered


list of all salaries, and choosing the
empno that shows up first on that

http://thinkoracle.blogspot.com/2005/07/extra-columns-in-group-by.html (3 of 5)1/9/2008 2:53:54 AM


OracleBlog: Extra Columns in a GROUP BY

list. Sounds like what we want!

Here is Dan Morgan's reference on


numeric functions like these:
http://www.psoug.org/reference/
number_func.html

KEEP is just a clever Oracle trick to


keep the work we're doing in the
shared pool because we're using it
twice in the same query.

So applying Connor's teachings to


our situation, we get:

CREATE OR REPLACE VIEW


CURRENT_ASSIGNMENTS AS
SELECT ASSIGNMENT,
MAX(EMPLOYEE) KEEP (DENSE_RANK
LAST ORDER BY EFFECTIVE)
EMPLOYEE,
MAX(EFFECTIVE) AS_OF
FROM ASSIGNMENTS
GROUP BY ASSIGNMENT;

SELECT * FROM
CURRENT_ASSIGNMENTS;

ASSIGNMENT EMPLOYEE AS_OF


--------------------------------
--------------------------------
---------
Governor General Adrienne Clarkson
07-OCT-99
Prime Minister Paul Martin 12-DEC-
03

2 rows selected.

Coming up in some future blog, Tom


Kyte mentioned the awesome
"MEMBER OF" feature that is in Oracle
10g. It will tell you easily whether a
value is contained in a particular set/

http://thinkoracle.blogspot.com/2005/07/extra-columns-in-group-by.html (4 of 5)1/9/2008 2:53:54 AM


OracleBlog: Extra Columns in a GROUP BY

table. I'm looking for a way to do this


in Oracle 9.

http://thinkoracle.blogspot.
com/2005/05/enum-in-oracle.html

// posted by Robert Vollman @ Friday, July 01,

2005

Comments:
In simple situations, here is the
"normal" way of doing it:

SQL> SELECT a.assignment, a.


employee, a.effective
2 FROM assignments a,
3 (SELECT assignment, MAX
(effective) as_of FROM assignments
GROUP BY assignments) a1
4 WHERE a.assignment = a1.
assignment
5 AND a.effective = a1.as_of;
# posted by Robert Vollman : Saturday, 27
August, 2005

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/07/extra-columns-in-group-by.html (5 of 5)1/9/2008 2:53:54 AM


OracleBlog: Finding Nearby Rows

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated, but it is the most powerful tool when it comes
to data. That's why when I think data, I think Oracle. I also enjoy writing, so I use this format to organise my thoughts. Please feel free to discuss
any thoughts you may have on the same topics, even old ones (I will see and respond to such comments). You may want to start with "LIST ALL
ARTICLES" under Archives.

Tuesday, May 09, 2006


Finding Nearby Rows
Today's question is how do you find rows that have values nearest the value of a given row?

Although there are many different variations on this central theme, in order to solve problems of this nature, you'll need to
know:

1. The given column's value for the given row


2. The difference between each row's value and the value of the given row
3. That row's difference's relationship to all the other rows.

Step 1 is easy, 2 and 3 are more difficult.

For starters, let's say my requirement is to find the 2 battles that started nearest the beginning of the battle of Batoche.
Here's how I first attacked that problem.
Note: You can find my test data at the end of this blog if you want to try it for yourself.

SELECT loc, difference FROM


(SELECT a.loc, ABS(a.start_date - b.start_date) difference
FROM battles a,
(SELECT start_date FROM battles WHERE loc = 'BATOCHE') b
ORDER BY difference)
WHERE rownum < 3;

LOC DIFFERENCE
-------------------- ----------------------
BATOCHE 0
CUT KNIFE 7
FISH CREEK 15

http://thinkoracle.blogspot.com/2006/05/finding-nearby-rows.html (1 of 9)1/9/2008 2:53:58 AM


OracleBlog: Finding Nearby Rows

Despite my use of ROWNUM to get just the two closest rows, I will admit that my result is not satisfying, because I don't like
going through the same data more than once. Once to find the value of the given row, and another to figure out the
differences. Blech!

I do have a better solution, but first let's say my requirements are a little tougher, to the point where this solution won't even
work. For example:

1. In the above example, the two nearest rows both happened to be prior to the given row. Let's say my requirements are to
find the rows immediately preceding the given row, and the rows immediately succeeding it.

AND let's also say

2. I want the TWO rows immediately before and immediately after instead of just one.

What then?

RANK

For starters, we can use the analytic function RANK instead of ROWNUM for an easier way to get the order in which the rows
are presented.

Once again, the 'b' query gives us the rank of our given row, and now the 'a' query will get a list of all the locations and their
respective RANK. Now we can take as many rows as we want from that centrepoint.

SELECT loc FROM


(SELECT a.loc, ABS(a.battle_num - b.battle_num) distance FROM
(SELECT loc, RANK() OVER (ORDER BY start_date) battle_num FROM battles) a,
(SELECT loc, RANK() OVER (ORDER BY start_date) battle_num FROM battles) b
WHERE b.loc = 'BATOCHE')
WHERE distance BETWEEN 1 AND 2;

LOC
--------------------
FISH CREEK
CUT KNIFE
FRENCHMAN'S BUTTE
LOON LAKE

I'm still annoyed about the inelegance of the solution, because we're still going through my data more than once. Is there a
better way?

LEAD and LAG

With LEAD and LAG you can access multiple rows without a self-join (joining a table to itself). With that, we can do all sorts of
http://thinkoracle.blogspot.com/2006/05/finding-nearby-rows.html (2 of 9)1/9/2008 2:53:58 AM
OracleBlog: Finding Nearby Rows

fancy things, such as figure out how many days have passed since the last battle started, and how long until the next one
began.

SELECT loc, start_date,


start_date - LAG(start_date, 1, NULL) OVER (ORDER BY start_date) AS last_battle,
LEAD(start_date, 1, NULL) OVER (ORDER BY start_date) - start_date AS next_battle
FROM battles;

Back to the task at hand, armed with LAG and LEAD, we can create a list of all rows including the value of the previous row,
and the value of the next one. From that, its pretty trivial to select the rows we want.

SELECT loc FROM (SELECT loc,


LAG(loc, 1, NULL) OVER (ORDER BY start_date) previous_battle,
LEAD(loc, 1, NULL) OVER (ORDER BY start_date) next_battle
FROM battles)
WHERE previous_battle = 'BATOCHE' OR next_battle = 'BATOCHE';

LOC
--------------------
CUT KNIFE
FRENCHMAN'S BUTTE

That's very nice! But what about the requirement to get the TWO rows immediately preceding and succeeding the given row,
can we still do that with LAG and LEAD?

The SQL Reference describes how to use LAG and LEAD, under Chapter 6, Functions. There it is explained that the second
parameter to LAG and LEAD is the number of rows to look. So we can look 2 battles before and after Batoche, and use
DECODE to make it a single column.

SELECT loc FROM


(SELECT loc, DECODE(LAG(loc, 1, NULL) OVER (ORDER BY start_date), 'BATOCHE', 1, 0) +
DECODE(LAG(loc, 2, NULL) OVER (ORDER BY start_date), 'BATOCHE', 1, 0) +
DECODE(LEAD(loc, 1, NULL) OVER (ORDER BY start_date), 'BATOCHE', 1, 0) +
DECODE(LEAD(loc, 2, NULL) OVER (ORDER BY start_date), 'BATOCHE', 1, 0) near_batoche
FROM battles)
WHERE near_batoche > 0;

LOC
--------------------
FISH CREEK
CUT KNIFE
FRENCHMAN'S BUTTE
LOON LAKE
http://thinkoracle.blogspot.com/2006/05/finding-nearby-rows.html (3 of 9)1/9/2008 2:53:58 AM
OracleBlog: Finding Nearby Rows

Depending how many rows you want, this query will get bigger and uglier, so you may want to revert to using the RANK
example instead. If you like the looks of LAG and LEAD, Tim Hall has a good introduction article worth reviewing.

Performance

I guess the big question is related to the performance implications of each approach. Granted I have a small amount of data,
but here are the differences I observed

ROWNUM example, 2 nearest rows:


Slowest of the three, had more parse, executes and queries than the other two combined. The query came in three pieces,
the first two of which had full table accesses, the last of which having a nested loop with a table access, a sort, and a view.

RANK example, looking 1 or 2 rows:


No real difference between 1 or 2 rows. Slower than LAG/LEAD with double the parse/execute/fetch. Came in two pieces, the
first of which had a full access, the second of which had 2 nested loops, 2 full accesses, and 2 sorts, including one that was
cartesian (49 rows).

LAG/LEAD example, looking 1 or 2 rows:


No real difference between 1 or 2 rows. Faster of the three, lowest parse/execute/fetch. Came in two pieces, both of which
had a full access, but the second of which also had a sort and a view.

In terms of performance, it looks like LAG/LEAD wins, on this sample data.

Sample data:
CREATE TABLE battles (loc VARCHAR2(20), start_date DATE, canadian VARCHAR2(20), rebel VARCHAR2(20));
INSERT INTO battles VALUES ('DUCK LAKE', '26-March-1885', 'Crozier', 'Dumont');
INSERT INTO battles VALUES ('FORT PITT', '15-April-1885', 'Dickens', 'Big Bear');
INSERT INTO battles VALUES ('FISH CREEK', '24-April-1885', 'Middleton', 'Dumont');
INSERT INTO battles VALUES ('CUT KNIFE', '2-May-1885', 'Otter', 'Poundmaker');
INSERT INTO battles VALUES ('BATOCHE', '9-May-1885', 'Middleton', 'Dumont');
INSERT INTO battles VALUES ('FRENCHMAN''S BUTTE', '28-May-1885', 'Strange', 'Wandering Spirit');
INSERT INTO battles VALUES ('LOON LAKE', '3-June-1885', 'Steele', 'Wandering Spirit');

Bonus: My favourite recent blog article was James Koopmann's recent write-up on storing Word Documents in Oracle.

// posted by Robert Vollman @ Tuesday, May 09, 2006

Comments:
Hi Robert,

Thanks for nice sum-up. I would like to mention another solution. I will also use a bit more representative test case (sorry for
flooding your "historical" table with random pseudo-events).
http://thinkoracle.blogspot.com/2006/05/finding-nearby-rows.html (4 of 9)1/9/2008 2:53:58 AM
OracleBlog: Finding Nearby Rows

So let's create table (note that I added PK which must be there anyway):
CREATE TABLE battles
(loc VARCHAR2(20),
start_date DATE,
canadian VARCHAR2(20),
rebel VARCHAR2(20),
PRIMARY KEY (loc)
);

Now let's populate with 100000 rows:


INSERT INTO battles (loc, start_date, canadian, rebel)
SELECT lvl, trunc(sysdate)-dbms_random.value(0,1000000),
'dummy field 1', 'dummy field 2'
FROM (select level lvl FROM DUAL CONNECT BY level<=100000);
COMMIT;

And build an index on start_date:


CREATE INDEX ind_battles_start_date ON battles(start_date);

Don't forget our good friend statistics:


BEGIN
SYS.DBMS_STATS.GATHER_TABLE_STATS (
OwnName => USER
,TabName => 'BATTLES'
,Method_Opt => 'FOR ALL COLUMNS SIZE 1 ');
END;
/

Now let's get the 2 previous events with autotrace on:


WITH point as (SELECT start_date FROM battles where loc='42876')
SELECT * FROM (
SELECT b.loc, s.start_date-b.start_date diff
FROM point s, battles b
WHERE b.start_date < s.start_date
ORDER BY b.start_date DESC
) WHERE rownum <= 2;
----------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 36 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | VIEW | | 2 | 36 | 2 (0)| 00:00:01 |
| 3 | NESTED LOOPS | | 2 | 84 | 2 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID | BATTLES | 1 | 14 | 1 (0)| 00:00:01 |

http://thinkoracle.blogspot.com/2006/05/finding-nearby-rows.html (5 of 9)1/9/2008 2:53:58 AM


OracleBlog: Finding Nearby Rows

|* 5 | INDEX UNIQUE SCAN | SYS_C004647 | 1 | | 1 (0)| 00:00:01 |


| 6 | TABLE ACCESS BY INDEX ROWID | BATTLES | 2 | 28 | 1 (0)| 00:00:01 |
|* 7 | INDEX RANGE SCAN DESCENDING| IND_BATTLES_START_DATE | 2 | | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------------
...
Statistics
...
8 consistent gets
...

In the same way we can get the next 2 nearest events. If we need more than 2 - just change where clause. This was done in
10gR2 and if I am not mistaken it uses new 10g feature for optimization of Top-N type queries SELECT ... FROM (SELECT ...
ORDER BY...) WHERE ROWNUM < n.

We can also put these queries together via UNION if needed, however, for puzzling reason Oracle (10.2.0.2) changes
execution plan in this case and does full index scans. I think it maybe worked around if needed.

Hope it might add a bit to you collection of ways to find nearby rows. ;-)

Regards,
Alex
# posted by Alex Gorbachev : Wednesday, 17 May, 2006

Hello Robert,

can we produce this result by using the following query with the help of oracle LAG or LEAD function.

select dname from dept

ACCOUNTING,RESEARCH,SALES,OPERATIONS

Thank you
Khurram Naseem
# posted by Khurram Naseem : Saturday, 10 November, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/05/finding-nearby-rows.html (6 of 9)1/9/2008 2:53:58 AM


OracleBlog: Finding Nearby Rows

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I like playing sports (hockey, soccer, ultimate, basketball,
you name it) and military board games. I also enjoy reading, walking, and playing with my 2 cats Lilly and Brutus. I'm a database
application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
http://thinkoracle.blogspot.com/2006/05/finding-nearby-rows.html (7 of 9)1/9/2008 2:53:58 AM
OracleBlog: Finding Nearby Rows

❍ Data Warehouser David Aldridge


❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007

http://thinkoracle.blogspot.com/2006/05/finding-nearby-rows.html (8 of 9)1/9/2008 2:53:58 AM


OracleBlog: Finding Nearby Rows

❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2006/05/finding-nearby-rows.html (9 of 9)1/9/2008 2:53:58 AM


OracleBlog: Import Export

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday,
About Me
August 01, 2005
Name: Robert Vollman
Import Location: Calgary, Alberta, Canada
Export
I recently I was born and raised in Ottawa, and have lived in
installed a new Calgary since 1991. I like playing sports (hockey,
Oracle instance soccer, ultimate, basketball, you name it) and military board
on my laptop. I games. I also enjoy reading, walking, and playing with my 2 cats
wanted to Lilly and Brutus. I'm a database application specialist, whatever
migrate my that is.
small
development View my complete profile
database
(complete with
structure and
data) from my
Best Links
main ● Ask Tom Kyte
workstation to ● Oracle Docs
my laptop. ● Dan Morgan and PSOUG
● Steven Feuerstein
It was very easy ● Jonathan Lewis
using the import ● FAQ
(IMP) and export
Connor McDonald
(EXP) tools. They

The Oak Table


are described in

Cary Millsap and Hotsos


Chapter 1 ●

(Export) and ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/08/import-export.html (1 of 6)1/9/2008 2:54:00 AM


OracleBlog: Import Export

Chapter 2 ● Anjo Kolk and OraPerf


(Import) of the ● Dizwell Oracle Wiki
Oracle Utilities ● My Personal Blog
Guide, available
here:

http://www.
oracle.com/
Aggregators
Brian Duff's OraBlogs
technology/

Eddie Awad's OracleNA


documentation/

❍ Pete Finnigan's Aggregator


index.html ❍ Oracle's Bloglist
Oracle Base Aggregator
Everything you

should need to
know is in there. Top Blogs
For good ❍ Oracle's Ask Tom Kyte
measure, I read ❍ Oracle Guru Jonathan Lewis
Chapter 8 of ❍ Blogger of the Year Eddie Awad
Tom Kyte's ❍ Data Warehouser David Aldridge
"Expert One-on- ❍ Oracle Geek Lewis Cunningham
One Oracle" on Database Expert James Koopmann
Import and

Dizwell's Howard Rogers


Export.

❍ Oracle Master Laurent Schneider


Word of caution: ❍ Security Expert Pete Finnigan
Think twice ❍ Oracle Award Winner Mark Rittman
before using ❍ Doug Burns
IMP/EXP as your ❍ Oracle ACE of the Year Dr. Tim Hall
back-up ❍ UKOUG's Andrew (Arfur C.) Clarke
strategy on ❍ Newbie DBA Lisa Dobson
large, complex ❍ Coffee-Drinking DBA Jon Emmons
databases. ❍ Chris Foot
The Pythian DBA Team Blog
Both utilities are ❍

located in ❍ DBA Don Seiler


$ORACLE_HOME/ ❍ DBA Coskan Gundogar
bin directory. ❍ Oracle WTF

ARCHIVES
You need to run
the
$ORACLE_HOME/ ❍ LIST ALL ARTICLES
rdbms/admin/ ❍ May 2005
catexp.sql file. June 2005
You can see the

❍ July 2005

http://thinkoracle.blogspot.com/2005/08/import-export.html (2 of 6)1/9/2008 2:54:00 AM


OracleBlog: Import Export

commands you ❍ August 2005


need by using ❍ September 2005
the HELP=Y ❍ October 2005
option at your November 2005
command

December 2005
prompt

❍ January 2006
C:\> EXP ❍ February 2006
HELP=Y ❍ March 2006
❍ April 2006
So for me, the ❍ May 2006
process was as ❍ June 2006
easy as this: ❍ July 2006
August 2006
1. Export the ❍

data ❍ September 2006


❍ October 2006
C:\> EXP ❍ November 2006
USERID=scott/ ❍ December 2006
tiger ❍ January 2007
OWNER=scott ❍ February 2007
FILE=scott.dmp ❍ March 2007
April 2007
2. Copy the DMP

file to the target ❍ May 2007


machine ❍ June 2007
❍ October 2007
3. Import the
data

C:\> IMP
USERID=scott/
tiger FILE=scott.
dmp FULL=Y

Done! All the


tables, triggers,
procedures,
view and
constraints, as
well as all the
data. While I was
at it, I just
created a BAT

http://thinkoracle.blogspot.com/2005/08/import-export.html (3 of 6)1/9/2008 2:54:00 AM


OracleBlog: Import Export

file out of this


and added it to
the Task
Manager to
back-up my
data regularly.
(Unix: SH file
and CRON).

As a final note,
here is a good
FQ, by Frank
Naude:
http://www.
orafaq.com/
faqiexp.htm

// posted by Robert
Vollman @ Monday,

August 01, 2005

Comments:

Word of caution:
Think twice
before using
IMP/EXP as your
back-up
strategy on
large, complex
databases.

I'd be even more


cautious to use
exp/imp and
backup in the
same sentence
(with the
exception of:
"Don't

http://thinkoracle.blogspot.com/2005/08/import-export.html (4 of 6)1/9/2008 2:54:00 AM


OracleBlog: Import Export

use exp as your


backup" of
course) ;-) .
Having said
that, exp can
play a vital part
in a backup
strategy, but
I wouldn't go as
far and call the
output a backup.

However, for
your initial
problem of
migrating data
between
databases, it
quite likely was
the best
solution.
But for the fun
of it, you might
want to
investigate rman
and clone
database (a
technique that
employes a
'real' backup).

Cheers,
Holger
# posted by
Anonymous :
Wednesday, 03
August, 2005

Laurent
Schneider wrote
something on
this:

http://thinkoracle.blogspot.com/2005/08/import-export.html (5 of 6)1/9/2008 2:54:00 AM


OracleBlog: Import Export

http://
laurentschneider.
blogspot.
com/2005/09/
migrate-
database-with-
imp-exp.html
# posted by
Robert Vollman :
Thursday, 01
September, 2005

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/08/import-export.html (6 of 6)1/9/2008 2:54:00 AM


OracleBlog: Multirow Inserts

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, May
About Me
28, 2007
Name: Robert Vollman
Multirow Location: Calgary, Alberta, Canada
Inserts
While I was born and raised in Ottawa, and have lived in
attempting to Calgary since 1991. I like playing sports (hockey,
insert several soccer, ultimate, basketball, you name it) and military board games.
rows into a I also enjoy reading, walking, and playing with my 2 cats Lilly and
table in our Brutus. I'm a database application specialist, whatever that is.
Oracle
database, a View my complete profile
colleague
dutifully
copied the
exact ANSI/ISO
Best Links
SQL standard ● Ask Tom Kyte
syntax for his ● Oracle Docs
purposes. ● Dan Morgan and PSOUG
Guess what ● Steven Feuerstein
happened? ● Jonathan Lewis
● FAQ
INSERT INTO
Connor McDonald
table

The Oak Table


(column1,

Cary Millsap and Hotsos


column2) ●

VALUES ● Steve Adams and Ixora


(value1, ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2007/05/multirow-inserts.html (1 of 8)1/9/2008 2:54:03 AM


OracleBlog: Multirow Inserts

value2), ● Dizwell Oracle Wiki


(value1, ● My Personal Blog
value2);

ERROR at line
1:
ORA-00933:
Aggregators
Brian Duff's OraBlogs
SQL command

not properly ❍ Eddie Awad's OracleNA


ended ❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
Unlike some ❍ Oracle Base Aggregator
other
databases
(DB2,
Top Blogs
Oracle's Ask Tom Kyte
PostgreSQL,

Oracle Guru Jonathan Lewis


MySQL), Oracle

doesn't ❍ Blogger of the Year Eddie Awad


support ❍ Data Warehouser David Aldridge
multirow ❍ Oracle Geek Lewis Cunningham
inserts (yet). ❍ Database Expert James Koopmann
Instead, you ❍ Dizwell's Howard Rogers
need to ❍ Oracle Master Laurent Schneider
execute these ❍ Security Expert Pete Finnigan
as separate ❍ Oracle Award Winner Mark Rittman
statements. ❍ Doug Burns
Oracle ACE of the Year Dr. Tim Hall
INSERT INTO

UKOUG's Andrew (Arfur C.) Clarke


table ❍

(column1, ❍ Newbie DBA Lisa Dobson


column2) ❍ Coffee-Drinking DBA Jon Emmons
VALUES ❍ Chris Foot
(value1, ❍ The Pythian DBA Team Blog
value2); ❍ DBA Don Seiler
❍ DBA Coskan Gundogar
1 row created. ❍ Oracle WTF
INSERT INTO
table ARCHIVES
(column1, ❍ LIST ALL ARTICLES
column2) ❍ May 2005
VALUES ❍ June 2005
(value1, ❍ July 2005
value2); ❍ August 2005

http://thinkoracle.blogspot.com/2007/05/multirow-inserts.html (2 of 8)1/9/2008 2:54:03 AM


OracleBlog: Multirow Inserts

❍ September 2005
1 row created. ❍ October 2005
November 2005
Edit: Courtesy ❍

of Laurent ❍ December 2005


Schneider (see ❍ January 2006
the ❍ February 2006
comments), ❍ March 2006
here are two ❍ April 2006
"tricks" in ❍ May 2006
inserting ❍ June 2006
several rows ❍ July 2006
with the same August 2006
statement.

❍ September 2006
Method #1: ❍ October 2006
INSERT ALL ❍ November 2006
INTO table ❍ December 2006
(column1, ❍ January 2007
column2) ❍ February 2007
VALUES ❍ March 2007
(value1, value2) ❍ April 2007
INTO table ❍ May 2007
(column1, ❍ June 2007
column2) October 2007
VALUES

(value1, value2)
...etc...
SELECT *
FROM DUAL;

Method #2:
INSERT INTO
table
(column1,
column2)
SELECT value1,
value2 FROM
DUAL UNION
ALL
SELECT value1,
value2 FROM
DUAL UNION
ALL

http://thinkoracle.blogspot.com/2007/05/multirow-inserts.html (3 of 8)1/9/2008 2:54:03 AM


OracleBlog: Multirow Inserts

...etc...
SELECT value1,
value2 FROM
DUAL;

The moral of
the story is
not to expect
Oracle to
comply with
the ANSI/ISO
SQL standard
every time. In
some ways,
like this one,
they do not
comply, and of
course Oracle
offers many
extensions to
the standard.

For more
information,
consult
Appendix B of
the Oracle SQL
Reference,
which deals
very briefly
with how your
version of
Oracle
complies with
the standard.

As for the
ANSI SQL
standard itself,
I'm not aware
of any free on-
line source. If
you want one,

http://thinkoracle.blogspot.com/2007/05/multirow-inserts.html (4 of 8)1/9/2008 2:54:03 AM


OracleBlog: Multirow Inserts

you'll have to
purchase a
copy directly
from ANSI/
ISO. There are
different levels
of standard
compliance,
Oracle
qualifies as
entry-level
compliance. I
don't know
exactly what
standards are
entry-level
and which
ones aren't,
but apparently
multi-row
inserts aren't.

// posted by
Robert
Vollman @ Monday,

May 28, 2007

Comments:
insert all
into table1
(column1,
column2)
values(1,2)
into table1
(column1,
column2)
values(3,4)
into table1
(column1,
column2)
values(5,6)

http://thinkoracle.blogspot.com/2007/05/multirow-inserts.html (5 of 8)1/9/2008 2:54:03 AM


OracleBlog: Multirow Inserts

select * from
dual;

3 row(s)
inserted.
# posted by
Laurent
Schneider :
Monday, 28 May,
2007

well, it is not
really
multirows
inserts, it is
rather
multitable
insert in the
same table
and could be
achieved with

insert into
table1(col1,
col2)
select 1,2
from dual
union all
select 3,4
from dual
union all
select 5,6
from dual

anyway, it is
not really
related to ansi
compliance.
But I thought it
was worth to
mention,

Kind regards,

http://thinkoracle.blogspot.com/2007/05/multirow-inserts.html (6 of 8)1/9/2008 2:54:03 AM


OracleBlog: Multirow Inserts

Laurent
# posted by
Laurent
Schneider :
Monday, 28 May,
2007

Do you have a
specific link
for standards
compliance of
INSERT syntax?

Your link to
the SQL
Reference
appears to be
an 11MB pdf
download.
# posted by
William
Robertson :
Monday, 28 May,
2007

No William.

I have neither
a copy of the
standard as it
relates to
INSERT, nor
Oracle
documentation
that addresses
this
specifically.

I'm basing my
understanding
of the former
on my

http://thinkoracle.blogspot.com/2007/05/multirow-inserts.html (7 of 8)1/9/2008 2:54:03 AM


OracleBlog: Multirow Inserts

colleague's
textbook.

I would LOVE
to have it ...
# posted by
Robert
Vollman : Monday,
28 May, 2007

This post has


been removed
by a blog
administrator.
# posted by
Anonymous :
Sunday, 30
September, 2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2007/05/multirow-inserts.html (8 of 8)1/9/2008 2:54:03 AM


OracleBlog: NOCOPY Hint

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, May 26, 2005


About Me
NOCOPY Hint Name: Robert Vollman
What is NOCOPY? Location: Calgary, Alberta,
Canada
'NOCOPY' is an optional 'hint' to tell
the PL/SQL 'compiler' not to go
through the overhead of making a I was born and raised in
copy of the variable, instead just send Ottawa, and have lived in Calgary since
a reference. This is generally because 1991. I like playing sports (hockey,
we don't plan on modifying it within soccer, ultimate, basketball, you name it)
the procedure. and military board games. I also enjoy
reading, walking, and playing with my 2
My first surprise was that you cats Lilly and Brutus. I'm a database
couldn't use "IN NOCOPY." Isn't application specialist, whatever that is.
NOCOPY your way of telling Oracle
you don't plan on messing around View my complete profile
with the parameter? Yes, but you
CAN'T mess with IN parameters, try it!

CREATE OR REPLACE PROCEDURE


Best Links
MyProc (in_value IN number) ● Ask Tom Kyte
AS ● Oracle Docs
BEGIN ● Dan Morgan and PSOUG
in_value := 3; ● Steven Feuerstein
END; ● Jonathan Lewis
● FAQ
PLS-00363: expression 'IN_VALUE' Connor McDonald
cannot be used as an assignment

http://thinkoracle.blogspot.com/2005/05/nocopy-hint.html (1 of 6)1/9/2008 2:54:05 AM


OracleBlog: NOCOPY Hint

target The Oak Table


● Cary Millsap and Hotsos


Therefore, it is always safe to send IN ● Steve Adams and Ixora
parameters by reference, making ● Anjo Kolk and OraPerf
NOCOPY redundant. ● Dizwell Oracle Wiki
My Personal Blog
My second surprise was that you had

to specify NOCOPY for an OUT


parameter. Because by definition isn't
an OUT parameter stating that you
plan on modifying the variable? Why Aggregators
would it be an OUT variable if you Brian Duff's OraBlogs

weren't touching it? So why would ❍ Eddie Awad's OracleNA


you NOT want NOCOPY? The answer ❍ Pete Finnigan's Aggregator
(like so many) comes from Ask Tom: ❍ Oracle's Bloglist
Oracle Base Aggregator
http://asktom.oracle.com/pls/ask/f?

p=4950:8:::::
F4950_P8_DISPLAYID:2047154868085
Top Blogs
❍ Oracle's Ask Tom Kyte
Tom explains one situation where ❍ Oracle Guru Jonathan Lewis
you want a copy rather than a ❍ Blogger of the Year Eddie Awad
reference for an OUT or IN OUT ❍ Data Warehouser David Aldridge
parameter. When you change a ❍ Oracle Geek Lewis Cunningham
NOCOPY parameter, it changes right ❍ Database Expert James Koopmann
away, instead of upon successful ❍ Dizwell's Howard Rogers
completion of the stored procedure. ❍ Oracle Master Laurent Schneider
Security Expert Pete Finnigan
Imagine you modified the parameter,

Oracle Award Winner Mark Rittman


but threw an exception before ❍

successful completion. But that ❍ Doug Burns


parameter has been changed and the ❍ Oracle ACE of the Year Dr. Tim Hall
calling procedure could be stuck with ❍ UKOUG's Andrew (Arfur C.) Clarke
a bogus value. ❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
Despite how much I trust Tom, ❍ Chris Foot
everybody knows that I don't believe ❍ The Pythian DBA Team Blog
things until I see for myself. And DBA Don Seiler
neither should you! Besides, things

DBA Coskan Gundogar


change. Here's my example.

❍ Oracle WTF
CREATE OR REPLACE PROCEDURE
NoCopyProc (in_value IN OUT ARCHIVES
NOCOPY number) ❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/05/nocopy-hint.html (2 of 6)1/9/2008 2:54:05 AM


OracleBlog: NOCOPY Hint

AS ❍ May 2005
x number; ❍ June 2005
BEGIN ❍ July 2005
DBMS_OUTPUT.PUT_LINE(in_value || ' August 2005
NoCopyProc');

September 2005
in_value := 2;

October 2005
x := 1/0;

November 2005
END; ❍

❍ December 2005
CREATE OR REPLACE PROCEDURE ❍ January 2006
CopyProc (in_value IN OUT number) ❍ February 2006
AS ❍ March 2006
x number; ❍ April 2006
BEGIN ❍ May 2006
DBMS_OUTPUT.PUT_LINE(in_value || ' ❍ June 2006
CopyProc');
July 2006
in_value := 4;

August 2006
x := 1/0;

September 2006
END;

❍ October 2006
CREATE OR REPLACE PROCEDURE ❍ November 2006
InterProc (in_value IN OUT NOCOPY ❍ December 2006
number) ❍ January 2007
AS ❍ February 2007
BEGIN ❍ March 2007
IF (in_value = 1) THEN NoCopyProc ❍ April 2007
(in_value); May 2007
ELSE CopyProc(in_value);

June 2007
END IF;

October 2007
EXCEPTION

WHEN OTHERS THEN NULL;


END;

CREATE OR REPLACE PROCEDURE


MyProc
AS
the_value NUMBER(1);
BEGIN
the_value := 1;
InterProc(the_value);
DBMS_OUTPUT.PUT_LINE(the_value);

the_value := 3;
InterProc(the_value);

http://thinkoracle.blogspot.com/2005/05/nocopy-hint.html (3 of 6)1/9/2008 2:54:05 AM


OracleBlog: NOCOPY Hint

DBMS_OUTPUT.PUT_LINE(the_value);
END;

BEGIN MyProc; END;

1 NoCopyProc
2
3 CopyProc
3

For an excellent and more detailed


overview of NOCOPY, complete with
examples, restrictions and
performance analysis, I once again
refer you to Steven Feuerstein's
writings. Although I encourage you to
add his books to your collection, this
chapter happens to be on-line for
free:

Oracle PL/SQL Programming Guide to


Oracle8i Features
http://www.unix.org.ua/orelly/oracle/
guide8i/ch10_01.htm

So what is a guy to do?

Well, first of all, it was suggested to


me that I should find a more gender-
neutral way of summing up an article.
Allow me to rephrase.

So what should we do?

1. Understand what NOCOPY means


and its uses and restrictions (by
following those links)
2. Take advantage of NOCOPY when
you want the performance advantage
of avoiding the cost of the temporary
storage for OUT or IN OUT
parameters.
3. Avoid NOCOPY when you don't
want the side effects if the procedure

http://thinkoracle.blogspot.com/2005/05/nocopy-hint.html (4 of 6)1/9/2008 2:54:05 AM


OracleBlog: NOCOPY Hint

fails early.

Remember, in the end, that NOCOPY


is just a "hint" and Oracle will do
whatever it wants anyway. Like all
hints, you have to ask yourself what
makes it necessary, and what makes
you think Oracle is going to choose
incorrectly.

// posted by Robert Vollman @ Thursday, May

26, 2005

Comments:
There was a discussion on the Dizwell
forum where apparently someone
used the NOCOPY hint and it made
the difference between hours and
seconds...

http://www.phpbbserver.com/phpbb/
viewtopic.php?
t=243&mforum=dizwellforum
# posted by Robert Vollman : Thursday, 07
July, 2005

Good One.
Keep the good work going.
Warm Regards
Sib
# posted by Anonymous : Wednesday, 27
June, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/05/nocopy-hint.html (5 of 6)1/9/2008 2:54:05 AM


OracleBlog: NOCOPY Hint

http://thinkoracle.blogspot.com/2005/05/nocopy-hint.html (6 of 6)1/9/2008 2:54:05 AM


OracleBlog: Oracle BOOLEAN

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Saturday, July 23, 2005


About Me
Oracle BOOLEAN Name: Robert Vollman
There is no BOOLEAN datatype in Location: Calgary, Alberta,
Oracle, as far as tables are Canada
concerned.

CREATE TABLE BooleanTable I was born and raised in


(MyBool BOOLEAN); Ottawa, and have lived in Calgary since
1991. I like playing sports (hockey, soccer,
ORA-00902: invalid datatype ultimate, basketball, you name it) and
military board games. I also enjoy reading,
But there is a BOOLEAN datatype in walking, and playing with my 2 cats Lilly
PL/SQL. and Brutus. I'm a database application
specialist, whatever that is.
CREATE OR REPLACE PROCEDURE
BoolProc (in_bool IN BOOLEAN) View my complete profile
AS
my_bool BOOLEAN := TRUE;
BEGIN
IF (in_bool = my_bool) THEN
Best Links
DBMS_OUTPUT.PUT_LINE('True'); ● Ask Tom Kyte
ELSE ● Oracle Docs
DBMS_OUTPUT.PUT_LINE('False or ● Dan Morgan and PSOUG
NULL'); ● Steven Feuerstein
END IF; ● Jonathan Lewis
FAQ
EXCEPTION

Connor McDonald
WHEN OTHERS

http://thinkoracle.blogspot.com/2005/07/oracle-boolean.html (1 of 4)1/9/2008 2:54:11 AM


OracleBlog: Oracle BOOLEAN

THEN The Oak Table


DBMS_OUTPUT.PUT_LINE('SQLERRM: ● Cary Millsap and Hotsos


' || SQLERRM); ● Steve Adams and Ixora
DBMS_OUTPUT.PUT_LINE('SQLCODE: ● Anjo Kolk and OraPerf
' || SQLCODE); ● Dizwell Oracle Wiki
END BoolProc; ● My Personal Blog
Why is there no Boolean in Oracle
for tables? What should we do
instead? This:
Aggregators
CREATE TABLE BoolTable (MyBool Brian Duff's OraBlogs

CHAR(1) CHECK (MyBool IN ( 'Y', ❍ Eddie Awad's OracleNA


'N' ))); ❍ Pete Finnigan's Aggregator
Oracle's Bloglist
As for the first question, as usual,

Oracle Base Aggregator


let's Ask Tom: ❍

http://asktom.oracle.com/pls/ask/f? Top Blogs


p=4950:8:2109566621053828525:: ❍ Oracle's Ask Tom Kyte
NO::F4950_P8_DISPLAYID, ❍ Oracle Guru Jonathan Lewis
F4950_P8_CRITERIA:6263249199595 ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
// posted by Robert Vollman @ Saturday, July ❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
23, 2005
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
Comments: ❍ Security Expert Pete Finnigan
thanks for your explanation about ❍ Oracle Award Winner Mark Rittman
boolean datatype in oracle that was ❍ Doug Burns
useful for me ❍ Oracle ACE of the Year Dr. Tim Hall
# posted by Anonymous : Tuesday, 09 ❍ UKOUG's Andrew (Arfur C.) Clarke
May, 2006 ❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
Yeah definitely Useful for me too ❍ The Pythian DBA Team Blog
# posted by Anonymous : Monday, 14 ❍ DBA Don Seiler
August, 2006 ❍ DBA Coskan Gundogar
❍ Oracle WTF

ya really
# posted by Anonymous : Tuesday, 07
ARCHIVES
❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/07/oracle-boolean.html (2 of 4)1/9/2008 2:54:11 AM


OracleBlog: Oracle BOOLEAN

November, 2006 ❍ May 2005


❍ June 2005
July 2005
it is realy good, but how will we call

August 2005
it

❍ September 2005
# posted by manjit singh : Tuesday, 21
❍ October 2005
November, 2006
❍ November 2005
❍ December 2005
Gubble-do-gock. ❍ January 2006
❍ February 2006
Furthermore the asktom link is ❍ March 2006
invalid. ❍ April 2006
# posted by Anonymous : Thursday, 05 ❍ May 2006
July, 2007 ❍ June 2006
❍ July 2006
❍ August 2006
Link still works for me. ❍ September 2006
October 2006
And if you think it's gobbledy-gook,

November 2006
I'd suggest just running the

provided examples. That's what ❍ December 2006


they're for. That last one essentially ❍ January 2007
creates a table with a single value ❍ February 2007
that is constrained to being either ❍ March 2007
'Y' or 'N' - functionally equivalent to ❍ April 2007
a Boolean. ❍ May 2007
# posted by Robert Vollman : Thursday, ❍ June 2007
05 July, 2007 ❍ October 2007

I see your "work around".


Nice, but does it support
all of the logical function
Y + Y = Y;
Y + N = N;
etc.

I don't know how to give feedback


to Oracle. But if I could, I
would tell them it is about time
they put aside the "purest attitude"
or whatever reason they have for

http://thinkoracle.blogspot.com/2005/07/oracle-boolean.html (3 of 4)1/9/2008 2:54:11 AM


OracleBlog: Oracle BOOLEAN

not implementing boolean data type


in there data base, and just do it (I
mean that it should come working
streight out of the box not as a
package add-on). It may bring
"closure" to an annoyance, that
should have been "fixed", and not
just circumvented, alone time ago.

Don't get me wrong, I like oracle. I


work with it every day. I have not
found a better DBMS. But it is
fustrating in this area of consistent
data types (db and pl/sql).

Thanks for the opportunity to let it


out!!!
# posted by Anonymous : Wednesday, 19
September, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/07/oracle-boolean.html (4 of 4)1/9/2008 2:54:11 AM


OracleBlog: Oracle By Example

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, July 29, 2005


Oracle By Example
I would like to elaborate on one point from my recent blog on Using
Views:

http://thinkoracle.blogspot.com/2005/07/use-views.html

The example in question is a recent case where I used Views to very


easily perform a complex query.

Let's set it up. We have a simple company with expenses and


revenues broken up by type and department. I'm ignoring many
columns/constraints and the expensetype table for simplicity.

CREATE TABLE department (


dept_name VARCHAR2(32) PRIMARY KEY,
dept_description VARCHAR2(64)
);
CREATE TABLE expenses (
dept_name REFERENCES department(dept_name),
expense_type VARCHAR2(32),
expense_description VARCHAR2(64),
expense_amount NUMBER(10,2)
);
CREATE TABLE revenues (
dept_name REFERENCES department(dept_name),
revenue_type VARCHAR2(32),

http://thinkoracle.blogspot.com/2005/07/oracle-by-example.html (1 of 7)1/9/2008 2:54:13 AM


OracleBlog: Oracle By Example

revenue_description VARCHAR2(64),
revenue_amount NUMBER(10,2)
);

Okay now I'd like to insert a little sample data so we can test some
queries

INSERT INTO department VALUES ('DEPT_A', 'Expenses Only');


INSERT INTO department VALUES ('DEPT_B', 'Revenues Only');
INSERT INTO department VALUES ('DEPT_C', 'Expenses and
Revenues');
INSERT INTO department VALUES ('DEPT_D', 'No Expenses Nor
Revenues');

INSERT INTO expenses VALUES ('DEPT_A', 'TYPE_1', 'Expense 1',


10.00);
INSERT INTO expenses VALUES ('DEPT_A', 'TYPE_2', 'Expense 2',
12.50);
INSERT INTO expenses VALUES ('DEPT_C', 'TYPE_1', 'Expense 3',
44.90);
INSERT INTO expenses VALUES ('DEPT_C', 'TYPE_3', 'Expense 4',
92.75);

INSERT INTO revenues VALUES ('DEPT_B', 'TYPE_1', 'Revenue 1',


14.60);
INSERT INTO revenues VALUES ('DEPT_B', 'TYPE_1', 'Revenue 2',
15.80);
INSERT INTO revenues VALUES ('DEPT_C', 'TYPE_4', 'Revenue 3',
47.75);
INSERT INTO revenues VALUES ('DEPT_C', 'TYPE_5', 'Revenue 4',
6.15);

We want a query that will show us every department, and its total
expenses and revenues. We want dept_name, sum(expenses), sum
(revenues), regardless of type.

Doing a single sum would be easy, we could just "GROUP BY" a


particular column. Even if we wanted to add dept_description, we
could just use Connor McDonald's trick:

http://thinkoracle.blogspot.com/2005/07/extra-columns-in-
group-by.html

http://thinkoracle.blogspot.com/2005/07/oracle-by-example.html (2 of 7)1/9/2008 2:54:13 AM


OracleBlog: Oracle By Example

For simplicity, by the way, we won't include dept_description - we


know we can using that technique.

Go ahead and write the query. I'm sure its possible! But not
everyone can figure it out, you might wind up with something really
complex.

So how will views help us? Well, we can create views that give us the
sum for expenses and values:

CREATE VIEW expensesview AS


SELECT dept_name, sum(expense_amount) expense_sum
FROM expenses
GROUP BY dept_name;
CREATE VIEW revenuesview AS
SELECT dept_name, sum(revenue_amount) revenue_sum
FROM revenues
GROUP BY dept_name;

Nothing could be easier. That is also some pretty handy views to


have. As you recall, a view can be thought of as a "virtual table" or
as a stored query. A stored query we are about to put to use.

SELECT d.dept_name, e.expense_sum, r.revenue_sum


FROM department d, expensesview e, revenuesview r
WHERE d.dept_name = e.dept_name
AND d.dept_name = r.dept_name;

Here are the results ... oops!

DEPT_NAME EXPENSE_SUM REVENUE_SUM


-------------------------------- ----------- -----------
DEPT_C 137.65 53.9

Why did we only get DEPT_C? Because, of course, either


expense_sum or revenue_sum was NULL in the other 3
departments. I'm only showing this mistake so I can show the

http://thinkoracle.blogspot.com/2005/07/oracle-by-example.html (3 of 7)1/9/2008 2:54:13 AM


OracleBlog: Oracle By Example

application of an outer join. An outer join will give you all possible
rows. Just add a (+) next to the column you're joining on.
Symbolically that means you want to add (+) rows where none exist.

SELECT d.dept_name, e.expense_sum, r.revenue_sum


FROM department d, expensesview e, revenuesview r
WHERE d.dept_name = e.dept_name(+)
AND d.dept_name = r.dept_name(+);
DEPT_NAME EXPENSE_SUM REVENUE_SUM
-------------------------------- ----------- -----------
DEPT_A 22.5
DEPT_B 30.4
DEPT_C 137.65 53.9
DEPT_D

Perfect.

We could have done this without views. Indeed, we could have


embedded the simple queries we used to make the views directly
into this final query. Maybe in an example as simple as this that
would be ok. But these kinds of things can get complex. Plus, now
other queries can take advantage of those views.

As a final note, how do you figure we can replace the NULLs up


there with zeros? The answer is something like DECODE or NVL.

http://thinkoracle.blogspot.com/2005/06/nulls-in-oracle.html

SELECT d.dept_name,
NVL(e.expense_sum,0) tot_expense,
NVL(r.revenue_sum,0) tot_revenue
FROM department d, expensesview e, revenuesview r
WHERE d.dept_name = e.dept_name(+)
AND d.dept_name = r.dept_name(+);
DEPT_NAME TOT_EXPENSE TOT_REVENUE
-------------------------------- ----------- -----------
DEPT_A 22.5 0
DEPT_B 0 30.4
DEPT_C 137.65 53.9
DEPT_D 0 0

http://thinkoracle.blogspot.com/2005/07/oracle-by-example.html (4 of 7)1/9/2008 2:54:13 AM


OracleBlog: Oracle By Example

// posted by Robert Vollman @ Friday, July 29, 2005

Comments: Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

http://thinkoracle.blogspot.com/2005/07/oracle-by-example.html (5 of 7)1/9/2008 2:54:13 AM


OracleBlog: Oracle By Example

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005

http://thinkoracle.blogspot.com/2005/07/oracle-by-example.html (6 of 7)1/9/2008 2:54:13 AM


OracleBlog: Oracle By Example

❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/07/oracle-by-example.html (7 of 7)1/9/2008 2:54:13 AM


OracleBlog: Oracle Client

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I think
data, I think Oracle. I also enjoy writing, so I use this format to organise my thoughts. Please
feel free to discuss any thoughts you may have on the same topics, even old ones (I will see
and respond to such comments). You may want to start with "LIST ALL ARTICLES" under
Archives.

Friday, June 24, 2005


Oracle Client
Here are the simple steps required for setting up an Oracle Client on a PC.

You will need:


- A working Oracle Server :)
- A compatible Oracle Client
- The service name, domain name, host name and port

1. Install Oracle SQL*Plus client on your PC

This should be quick and easy, accept all defaults.

2. Modify %ORACLE_HOME%\network\admin\tnsnames.ora

SRV_NAME.WHATEVER.COM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = host_name)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = srv_name)
)
)

3. Check %ORACLE_HOME%\network\admin\sqlnet.ora

NAMES.DEFAULT_DOMAIN = whatever.com

http://thinkoracle.blogspot.com/2005/06/oracle-client.html (1 of 4)1/9/2008 2:54:16 AM


OracleBlog: Oracle Client

NAMES.DIRECTORY_PATH= (TNSNAMES, HOSTNAME)

4. Modify %ORACLE_HOME%\network\admin\listener.ora

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = C:\oracle\ora92)
(SID_NAME = srv_name)
)

5. Test connection

sqlplus username/password@srv_name

// posted by Robert Vollman @ Friday, June 24, 2005

Comments: Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I like
playing sports (hockey, soccer, ultimate, basketball, you name it) and
military board games. I also enjoy reading, walking, and playing with my 2 cats Lilly and
Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
http://thinkoracle.blogspot.com/2005/06/oracle-client.html (2 of 4)1/9/2008 2:54:16 AM
OracleBlog: Oracle Client

● Ask Tom Kyte


● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog

http://thinkoracle.blogspot.com/2005/06/oracle-client.html (3 of 4)1/9/2008 2:54:16 AM


OracleBlog: Oracle Client

DBA Don Seiler


❍ DBA Coskan Gundogar


❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/06/oracle-client.html (4 of 4)1/9/2008 2:54:16 AM


OracleBlog: Oracle and Java

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, July 04,


About Me
2006
Name: Robert Vollman
Oracle and Location: Calgary, Alberta, Canada
Java
Last December I I was born and raised in Ottawa, and have lived
wrote about how to in Calgary since 1991. I like playing sports
create a simple Perl (hockey, soccer, ultimate, basketball, you name it) and
application that military board games. I also enjoy reading, walking, and
connected to your playing with my 2 cats Lilly and Brutus. I'm a database
Oracle database, it is application specialist, whatever that is.
high time that I
showed you how to View my complete profile
do the same in Java.

What You'll Need Best Links


1. An Oracle ● Ask Tom Kyte
database. Make sure ● Oracle Docs
you can tnsping your ● Dan Morgan and PSOUG
ORACLE_SID. Better ● Steven Feuerstein
yet, make sure you ● Jonathan Lewis
can connect with ● FAQ
sqlplus. ● Connor McDonald
The Oak Table
2. Java. It's a free ●

download from Sun. ● Cary Millsap and Hotsos


I'm using 1.5, but I've ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/07/oracle-and-java.html (1 of 7)1/9/2008 2:54:18 AM


OracleBlog: Oracle and Java

tested this on several ● Anjo Kolk and OraPerf


versions. ● Dizwell Oracle Wiki
● My Personal Blog
3. You don't need the
client installed
because we're using
the thin client. If you
want to use OCI but
Aggregators
don't want to install Brian Duff's OraBlogs

the full Oracle client, ❍ Eddie Awad's OracleNA


download the instant ❍ Pete Finnigan's Aggregator
client. ❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
Set your PATH

As part of your Java


Oracle's Ask Tom Kyte
installation, you must

have set the path to ❍ Oracle Guru Jonathan Lewis


your jdk\bin. Make ❍ Blogger of the Year Eddie Awad
sure that's there and ❍ Data Warehouser David Aldridge
add it if not. ❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
Set your CLASSPATH ❍ Dizwell's Howard Rogers
Oracle Master Laurent Schneider
If you're using Java

Security Expert Pete Finnigan


1.4 or greater, then

Oracle Award Winner Mark Rittman


ojdbc14.jar contains ❍

the classes you need. ❍ Doug Burns


You'll find it in ❍ Oracle ACE of the Year Dr. Tim Hall
ORACLE_HOME/jdbc/ ❍ UKOUG's Andrew (Arfur C.) Clarke
lib. ❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
And more ❍ Chris Foot
information on this? ❍ The Pythian DBA Team Blog
You can unzip the jar
DBA Don Seiler
file and look at the

DBA Coskan Gundogar


files inside with some

Oracle WTF
Java tools, search the ❍

Internet or, best yet,


check out ARCHIVES
ORACLE_HOME/jdbc/ ❍ LIST ALL ARTICLES
doc/javadoc.tar. ❍ May 2005
That's a complete ❍ June 2005
API: all the classes ❍ July 2005

http://thinkoracle.blogspot.com/2006/07/oracle-and-java.html (2 of 7)1/9/2008 2:54:18 AM


OracleBlog: Oracle and Java

and their parameters. ❍ August 2005


September 2005
If you're using an

October 2005
older version, you'll

November 2005
want something like

December 2005
classes12.jar instead. ❍

Follow the ❍ January 2006


installation ❍ February 2006
instructions. But do ❍ March 2006
NOT include this if ❍ April 2006
you're on 1.4 or ❍ May 2006
greater. You want ❍ June 2006
one or the other, not ❍ July 2006
both. ❍ August 2006
September 2006
There is also one

October 2006
thing that seems to ❍

always get me when I ❍ November 2006


start a java project. I ❍ December 2006
always forget to add ❍ January 2007
the local directory to ❍ February 2007
the CLASSPATH. Save ❍ March 2007
yourself the 20 ❍ April 2007
wasted minutes and ❍ May 2007
put it first. ❍ June 2007
October 2007
C:\temp>echo %

CLASSPATH%
.;c:\oracle\product
\10.1.0\db\jdbc\lib
\ojdbc14.jar

Include Your Classes

Though you may


want others, here are
the main classes
you'll need to import.
The former should be
part of your Java SDK,
the latter is in the
aforementioned
ojdbc14.jar.

http://thinkoracle.blogspot.com/2006/07/oracle-and-java.html (3 of 7)1/9/2008 2:54:18 AM


OracleBlog: Oracle and Java

import java.sql.*;
import oracle.jdbc.
pool.
OracleDataSource;

Create an
OracleDataSource

Once you've created


an OracleDataSource,
you'll be free to write
your SQL calls. My
example below shows
the syntax for a
default installation,
you'll need to modify
that second line as
appropriate.

OracleDataSource ods
= new
OracleDataSource();
ods.setURL("jdbc:
oracle:thin:scott/
tiger@localhost:1521:
ORCL");
Connection conn =
ods.getConnection();

Check the
documentation, there
are other ways of
doing this.

Query Away!

There are many ways


to use your
connection to query
your database. Here
is one quick sample I
found.

Statement stmt =

http://thinkoracle.blogspot.com/2006/07/oracle-and-java.html (4 of 7)1/9/2008 2:54:18 AM


OracleBlog: Oracle and Java

conn.createStatement
();
ResultSet rset = stmt.
executeQuery("select
'Hello World' from
dual");
while (rset.next())
System.out.println
(rset.getString(1));

Compile and Execute

You'll need to
compile your
application before
you execute.

javac JdbcVersion.java
java JdbcVersion

If you get this error:

Exception in thread
"main" java.lang.
NoClassDefFoundError

Then check your


CLASSPATH very
carefully. You can run
java with the -
verbose option to see
if you get more
information about
what's missing.

That's it!

For more
information, review
the documentation to
which the README
file points you:

1. The new technical

http://thinkoracle.blogspot.com/2006/07/oracle-and-java.html (5 of 7)1/9/2008 2:54:18 AM


OracleBlog: Oracle and Java

white paper

2. The online JDBC


doc for the most
updated information

3. The revised JDBC


FAQ

4. The JDBC
Developer's Guide
and Reference

// posted by Robert
Vollman @ Tuesday, July

04, 2006

Comments:
Hi Robert,
thanks, great clear
example!
One little suggestion,
just to make your
example also more
educative: can you
modify it to use
prepared statement
and bind variables?
So the readers could
get also the right hint
on how to query
properly and
efficiently a database,
in a scalable fashion
and without killing
performances
:-)

Franco
# posted by
Anonymous :

http://thinkoracle.blogspot.com/2006/07/oracle-and-java.html (6 of 7)1/9/2008 2:54:18 AM


OracleBlog: Oracle and Java

Wednesday, 05 July, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/07/oracle-and-java.html (7 of 7)1/9/2008 2:54:18 AM


OracleBlog: Oracle Passwords

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, October 30, 2006


About Me
Oracle Passwords Name: Robert Vollman
Hallowe'en is a time of fright and Location: Calgary, Alberta,
mystery, and some of the most Canada
common, mysterious Oracle
questions I collect involve
I was born and raised in Ottawa,
passwords. Here are some tricks
and have lived in Calgary since 1991. I like
and treats:
playing sports (hockey, soccer, ultimate,
How do you change an Oracle basketball, you name it) and military board
password? ... If you/the user games. I also enjoy reading, walking, and
forgot it? playing with my 2 cats Lilly and Brutus. I'm a
How are Oracle passwords stored? database application specialist, whatever that
Does it look the same for two is.
different users using the same
password? View my complete profile
Do the SQL Trace files reveal your

Best Links
secret password?
How do you hide your password
from others when running scripts? Ask Tom Kyte
How do you set/enforce your

Oracle Docs
password policy in Oracle?

Dan Morgan and PSOUG


Which password-related error

messages can you get in Oracle, ● Steven Feuerstein


and what do they mean? ● Jonathan Lewis
● FAQ
The scary truth is that there is no ● Connor McDonald

http://thinkoracle.blogspot.com/2006/10/oracle-passwords.html (1 of 9)1/9/2008 2:54:21 AM


OracleBlog: Oracle Passwords

mystery to any of the answers. The Oak Table


Each answer can be readily found ● Cary Millsap and Hotsos


in either the Oracle ● Steve Adams and Ixora
Documentation (more specifically, ● Anjo Kolk and OraPerf
the Oracle Administrator's Guide), ● Dizwell Oracle Wiki
or among the plentiful resources ● My Personal Blog
of the Internet. It's all in knowing
where to look! I've collected a few
answers to get you started.

Changing Your Oracle Password


Aggregators
Brian Duff's OraBlogs

If you already know your Oracle ❍ Eddie Awad's OracleNA


password, you can change it using ❍ Pete Finnigan's Aggregator
an SQL*Plus session by simply ❍ Oracle's Bloglist
typing "password" and following ❍ Oracle Base Aggregator
the instructions.

If you have the privileges, you can Top Blogs


also change a password using ❍ Oracle's Ask Tom Kyte
ALTER USER. ❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
ALTER USER username IDENTIFIED ❍ Data Warehouser David Aldridge
BY password; ❍ Oracle Geek Lewis Cunningham
That is also the trick if you have ❍ Database Expert James Koopmann
lost your password. Of course, you ❍ Dizwell's Howard Rogers
must have the privileges. ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
Hopefully its not the privileged ❍ Oracle Award Winner Mark Rittman
user you've lost the password for, ❍ Doug Burns
but if that's the case, you can ❍ Oracle ACE of the Year Dr. Tim Hall
always try to the default Oracle UKOUG's Andrew (Arfur C.) Clarke
usernames and passwords (but

Newbie DBA Lisa Dobson


presumably you changed it

Coffee-Drinking DBA Jon Emmons


already). Perhaps you want to

Chris Foot
allow more users SYSDBA

The Pythian DBA Team Blog


privileges? I'll get to that ...

❍ DBA Don Seiler


How Oracle Passwords Are Stored ❍ DBA Coskan Gundogar
❍ Oracle WTF
You can see the usernames and
encrypted passwords in the
DBA_USERS table (assuming you
ARCHIVES
❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2006/10/oracle-passwords.html (2 of 9)1/9/2008 2:54:21 AM


OracleBlog: Oracle Passwords

have privileges). ❍ May 2005


June 2005
SELECT username, password FROM

July 2005
dba_users WHERE username =

August 2005
'SCOTT';

❍ September 2005
If two users have the same ❍ October 2005
password, will it mean they'll have ❍ November 2005
the same encrypted password? ❍ December 2005
NO. You can try it yourself, or just ❍ January 2006
ask my featured blogger Steve ❍ February 2006
Callan. Steve also explains how a ❍ March 2006
DBA can't determine your secret ❍ April 2006
password by reading SQL TRACE ❍ May 2006
of your session. ❍ June 2006
July 2006
Steve also turns us onto a little

August 2006
trick where we can save that

September 2006
encrypted password and re-set it

after it was (accidentally or ❍ October 2006


deliberately) changed using ALTER ❍ November 2006
USER. ❍ December 2006
❍ January 2007
ALTER USER username IDENTIFIED ❍ February 2007
BY VALUES 'encrypted password'; ❍ March 2007
April 2007
Check out the Dizwell wiki for a

May 2007
cleaner example of restoring an

June 2007
encrypted password.

❍ October 2007
Your Oracle Password Policy

Steve also mentioned a certain


password policy script, which you
should find here:

$ORACLE_HOME/rdbms/admin/
utlpwdmg.sql

Oracle supports some fairly


sophisticated password policies,
not just requiring a certain length
or requiring numerics. I won't
elaborate on the details, which you

http://thinkoracle.blogspot.com/2006/10/oracle-passwords.html (3 of 9)1/9/2008 2:54:21 AM


OracleBlog: Oracle Passwords

can find in the Oracle


Administrator Guide.

There are plenty of (non-Oracle-


specific) articles out there on the
need for a strong password
policies. For instance, according to
a fact sheet from Red Database
Security, changing the minimum
length of a password from 8
characters to 9 can make the
different between 2 days and 57
for a brute force attack!

Oracle Password Error Messages

Speaking of Red Database


Security, they did the job of
summarizing the various error
messages you can get when you
try to log in, and what they mean.

ORA_28000: The account is locked


Wait for PASSWORD_LOCK_TIME or
contact your DBA

ORA-28001: The password has


expired
Change the password or contact
your DBA

ORA-00988: Missing or invalid


password(s)
Use double quotes for the
password (e.g. alter user scott
identified by "!alex";)

ORA-01017: Invalid username/


password; logon denied
Contact your DBA if the problem
still persists

The Password File

http://thinkoracle.blogspot.com/2006/10/oracle-passwords.html (4 of 9)1/9/2008 2:54:21 AM


OracleBlog: Oracle Passwords

I mentioned two things above:


1. Your encrypted passwords are
stored in the database, accessible
through DBA_USERS.
2. You can grant SYSDBA privileges
to other users.

If my first point is correct, what is


the password file? And what does
the second point have to do with
anything? Well, put 1 and 2
together. The password file is how
you grant those SYSDBA privileges
to other users.

How? By using ORAPWD: The


Oracle Password File Utility. You'll
find it in $ORACLE_HOME/bin, and
you can create the file like so:

orapwd file=filename
password=syspassword
entries=maxsysdbas force=Y

You can find more information in


the Oracle Administrator's Guide,
right at the top.

Speaking of which, here is another


error you might get: ORA-01996.
In this case, you were trying to
grant SYSDBA privileges to a user
when you already have assigned
this to the maximum number of
users. Use this utility to increase
your limit.

Finally ...

You wrote a script which connects


to Oracle, and you're worried that
other users can see the login
credentials you used to execute
the script. What is the correct way

http://thinkoracle.blogspot.com/2006/10/oracle-passwords.html (5 of 9)1/9/2008 2:54:21 AM


OracleBlog: Oracle Passwords

around this?

Connor McDonald discusses four


ways, using OS accounts, internal
accounts, /NOLOG and a last-
resort sqlplus trick.

Alternatively we can do what we


always do when we want to know
something about Oracle, we Ask
Tom. Or, more precisely, we
assume someone already has and
find out what he said. In this case,
he instructs us to use the
'identified externally' directive.

Normally I make a reference to


Tom Kyte the final word, but this
time the honour will go to
someone equally worthy: Jonathan
Lewis. His blog is long overdue,
and you can find his link second
from the top, right next to Tom's
(sorry Eddie).

// posted by Robert Vollman @ Monday,

October 30, 2006

Comments:
I'm honored to be just below Tom
AND Jonathan :)
# posted by Eddie Awad : Monday, 30
October, 2006

Nice blog - interesting topics,


some of which I would have never
come across yet after reading the
blog I find myself digging deeper
and deeper.

http://thinkoracle.blogspot.com/2006/10/oracle-passwords.html (6 of 9)1/9/2008 2:54:21 AM


OracleBlog: Oracle Passwords

I started using Oracle about 5


years ago when I first joined the
company I work for. Having never
used Oracle before all my learning
has stemmed from the use of
Oracle in this company. Being a
fashion retail company and not an
IT company I have found the
extent of my Oracle learning has
slowed down somewhat - not
because I have run out of things to
learn in Oracle, but because I was
trained by having to look over
someone's shoulder while they
coded - I learnt what they knew,
and therefore of course you don't
know what you don't know.

So it is refreshing when I read


blogs like yours to find out stuff I
didnt know existed in Oracle. Even
if I never use it at least I'll know
about it and understand to some
extent the uses of it.

Oracle is a massive beast - I learn


that every day.

keep up the great work!!

Gary,
Cape Town, South Africa.
# posted by gazza : Tuesday, 31
October, 2006

Robert,
Good write up. I would also like to
add that Oracle uses one-way
encryption to encrypt basically the
username and password to
produce that 16-character string.

SQL@O9.2.0.7> create user coal

http://thinkoracle.blogspot.com/2006/10/oracle-passwords.html (7 of 9)1/9/2008 2:54:21 AM


OracleBlog: Oracle Passwords

identified by mineisdirty;

User created.

SQL@O9.2.0.7> create user


coalminer identified by isdirty;

User created.

SQL@O9.2.0.7> create user


coalmine identified by isdirty;

User created.

SQL@O9.2.0.7> select username,


password from dba_users where
username like 'COAL%';

USERNAME PASSWORD
------------------------------
------------------------------
COAL 6FCDA69BF440408F
COALMINE 6FCDA69BF440408F
COALMINER 0753A36B9F404829

SQL@O9.2.0.7>

One trick to totally secured the


account with the use of IDENTIFIED
BY VALUES is to give it a string
that the encryption will never
encrypt to. E.g. ALTER USER scott
IDENTIFIED BY VALUES 'Totally
secured' or embed hidden
characters like "\n" or "\cr"
# posted by Peter K : Friday, 03
November, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/10/oracle-passwords.html (8 of 9)1/9/2008 2:54:21 AM


OracleBlog: Oracle Passwords

http://thinkoracle.blogspot.com/2006/10/oracle-passwords.html (9 of 9)1/9/2008 2:54:21 AM


OracleBlog: Oracle and Perl

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, December 15, 2005


Oracle and Perl
I work with several different databases for several different clients on
several different operating systems, often with only remote access to a
shell (as opposed to a desktop). Therefore I like to become familiar with
very common and simple technologies, like vi, sqlplus (for Oracle) and
Perl.

Writing my useful tools in Perl is very handy because I can run them
anywhere, and they can work for all databases just by having a switch on
the connection string. But of course today's example will focus on
Oracle. Perl is also very good at handling and manipulating data: perfect
for database utility scripts.

There are many different ways to write code in Perl. Some refer to Perl as
a write-only language because it is a lot easier to write than it is to read.
But I'll keep my sample simple.

#!/usr/local/perl
use DBI;
# Get a database handle by connecting to the database
$dbh = DBI->connect("dbi:Oracle:host=servername;sid=dbname",
'scott','tiger', {RaiseError => 1, AutoCommit => 1})
or die "Can't connect to database $DBI::errstr\n";
# Put together your query string
my $sql = 'SELECT * FROM emp';
# Instead you could do $dbh->do($sql) or execute

http://thinkoracle.blogspot.com/2005/12/oracle-and-perl.html (1 of 5)1/9/2008 2:54:23 AM


OracleBlog: Oracle and Perl

$sth = $dbh->prepare($sql);
while (@rows = $sth->fetchrow_array()) {

# You can access a specific field like this: $rows[0];


print "@rows\t";
}
print "\n";
$sth->finish();
# If you did an update, you could $dbh->commit()
# or $dbh->rollback() before disconnecting
$dbh->disconnect();

For more information, here is a quick and dirty FAQ:


http://www.orafaq.com/faqperl.htm

Here are some really good on-line samples


http://www.cri.univ-rennes1.fr/documentations/DBDOracle.html

There is a book on Oracle and Perl that described a bunch of Oracle DBA
utilities written in Perl. I have not read it myself, so check it out before
purchasing (and let me know what you thought).
"Perl for Oracle DBAs" by Andy Duncan and Jared Still
http://www.amazon.com/gp/product/0596002106/002-3253639-
8672853?v=glance&n=283155

// posted by Robert Vollman @ Thursday, December 15, 2005

Comments: Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

http://thinkoracle.blogspot.com/2005/12/oracle-and-perl.html (2 of 5)1/9/2008 2:54:23 AM


OracleBlog: Oracle and Perl

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann

http://thinkoracle.blogspot.com/2005/12/oracle-and-perl.html (3 of 5)1/9/2008 2:54:23 AM


OracleBlog: Oracle and Perl

❍ Dizwell's Howard Rogers


❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007

http://thinkoracle.blogspot.com/2005/12/oracle-and-perl.html (4 of 5)1/9/2008 2:54:23 AM


OracleBlog: Oracle and Perl

❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/12/oracle-and-perl.html (5 of 5)1/9/2008 2:54:23 AM


OracleBlog: Pivot and Crosstab Queries

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated, but it
is the most powerful tool when it comes to data. That's why when I think data, I think Oracle. I also enjoy
writing, so I use this format to organise my thoughts. Please feel free to discuss any thoughts you may
have on the same topics, even old ones (I will see and respond to such comments). You may want to
start with "LIST ALL ARTICLES" under Archives.

Thursday, September 01, 2005


About Me
Pivot and Crosstab Queries Name: Robert
Here is another advanced concept that will come in useful Vollman
when solving Oracle problems. Location: Calgary,
Alberta, Canada
Imagine you're trying to create a result set where the rows
need to be columns, or vice versa. In essence, you need to
"pivot" rows into columns, or vice versa. That is a very I was born and raised in Ottawa,
common requirement, and this is where you need to look and have lived in Calgary since
at a pivot (or crosstab) query to get the job done. 1991. I like playing sports
(hockey, soccer, ultimate,
As always, when you want to understand something, you basketball, you name it) and
can start by Asking Tom: military board games. I also
http://asktom.oracle.com/pls/ask/f? enjoy reading, walking, and
p=4950:8:16663421538065257584::NO:: playing with my 2 cats Lilly and
Brutus. I'm a database
F4950_P8_DISPLAYID,F4950_P8_CRITERIA:766825833740
application specialist, whatever
A simple pivot query is accomplished by basically doing the that is.
following:
1. Add some kind of count or row number to your query, if View my complete profile
necessary for the grouping

Best Links
2. Then use your (revised) original query as a sub-query
3. Use "decode" to turn rows into columns (ie. a "sparse"
matrix). Ask Tom Kyte
4. Use "max" to "squash" the multiple rows you moved to

Oracle Docs
columns, into single rows. Don't forget to group by.

Dan Morgan and PSOUG


(Note: it gets more complicated if you don't know how

Steven Feuerstein
many columns you'll need). ●

● Jonathan Lewis
Here is another one of Ask Tom's example. It clearly shows ● FAQ
how you use decode to create a "sparse" matrix, and then ● Connor McDonald
use max to "squash" it down. ● The Oak Table
http://asktom.oracle.com/pls/ask/f?p=4950:8::::: ● Cary Millsap and Hotsos
F4950_P8_DISPLAYID:124812348063 ● Steve Adams and Ixora
● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2005/09/pivot-and-crosstab-queries.html (1 of 6)1/9/2008 2:54:26 AM


OracleBlog: Pivot and Crosstab Queries

Let's look a simple example in slow motion. ● Dizwell Oracle Wiki


● My Personal Blog
Here's the data
CREATE TABLE CFL (season NUMBER(4), team VARCHAR2
(16), points NUMBER(3));
INSERT INTO CFL (season, team, points) VALUES (2004,
'Argonauts', 21);
Aggregators
INSERT INTO CFL (season, team, points) VALUES (2004, Brian Duff's OraBlogs

'Alouettes', 28); ❍ Eddie Awad's OracleNA


INSERT INTO CFL (season, team, points) VALUES (2004, ❍ Pete Finnigan's Aggregator
'Tiger-Cats', 19); ❍ Oracle's Bloglist
INSERT INTO CFL (season, team, points) VALUES (2004, ❍ Oracle Base Aggregator

Top Blogs
'Renegades', 10);
INSERT INTO CFL (season, team, points) VALUES (2003,
'Argonauts', 18); Oracle's Ask Tom Kyte
INSERT INTO CFL (season, team, points) VALUES (2003,

Oracle Guru Jonathan Lewis


'Alouettes', 26);

Blogger of the Year Eddie Awad


INSERT INTO CFL (season, team, points) VALUES (2003,

Data Warehouser David Aldridge


'Tiger-Cats', 2); ❍

INSERT INTO CFL (season, team, points) VALUES (2003, ❍ Oracle Geek Lewis Cunningham
'Renegades', 14); ❍ Database Expert James Koopmann
INSERT INTO CFL (season, team, points) VALUES (2002, ❍ Dizwell's Howard Rogers
'Argonauts', 16); ❍ Oracle Master Laurent Schneider
INSERT INTO CFL (season, team, points) VALUES (2002, ❍ Security Expert Pete Finnigan
'Alouettes', 27); ❍ Oracle Award Winner Mark
INSERT INTO CFL (season, team, points) VALUES (2002, Rittman
'Tiger-Cats', 15); ❍ Doug Burns
INSERT INTO CFL (season, team, points) VALUES (2002, ❍ Oracle ACE of the Year Dr. Tim
'Renegades', 10); Hall
UKOUG's Andrew (Arfur C.) Clarke
What we want:

A table showing each of these 4 teams and their point ❍ Newbie DBA Lisa Dobson
tables for these 3 seasons. ❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
So what is our pivot row/column? Season. ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
Step 1/2: We are using season, so we don't need to create DBA Coskan Gundogar
our own grouping field, like count, rownum, or running

Oracle WTF
total (sum) for example. That would be easy enough to do,

but let's keep this simple.


ARCHIVES
Step 3: Use "decode" to turn the season row into a column. ❍ LIST ALL ARTICLES
Take a look at our "sparse" matrix. ❍ May 2005
June 2005
SELECT team,

July 2005
DECODE (season, 2002, points, NULL) Yr2002,

August 2005
DECODE (season, 2003, points, NULL) Yr2003,

September 2005
DECODE (season, 2004, points, NULL) Yr2004 ❍

FROM (SELECT season, team, points FROM CFL); ❍ October 2005


❍ November 2005
TEAM YR2002 YR2003 YR2004 ❍ December 2005
❍ January 2006

http://thinkoracle.blogspot.com/2005/09/pivot-and-crosstab-queries.html (2 of 6)1/9/2008 2:54:26 AM


OracleBlog: Pivot and Crosstab Queries

---------------- ---------- ---------- ---------- ❍ February 2006


Argonauts 21 ❍ March 2006
Alouettes 28 ❍ April 2006
Tiger-Cats 19 ❍ May 2006
Renegades 10 ❍ June 2006
Argonauts 18
❍ July 2006
Alouettes 26
❍ August 2006
Tiger-Cats 2
Renegades 14 ❍ September 2006
Argonauts 16 ❍ October 2006
Alouettes 27 ❍ November 2006
Tiger-Cats 15 ❍ December 2006
Renegades 10 ❍ January 2007
❍ February 2007
❍ March 2007
April 2007
Step 4: Now let's use max to "squash" this into single rows.

May 2007
Don't forget GROUP BY.

❍ June 2007
SELECT team, ❍ October 2007
MAX (DECODE (season, 2002, points, NULL)) Yr2002,
MAX (DECODE (season, 2003, points, NULL)) Yr2003,
MAX (DECODE (season, 2004, points, NULL)) Yr2004
FROM (SELECT season, team, points FROM CFL)
GROUP BY team;

TEAM YR2002 YR2003 YR2004


---------------- ---------- ---------- ----------
Alouettes 27 26 28
Argonauts 16 18 21
Renegades 10 14 10
Tiger-Cats 15 2 19

Pretty cool, eh? Easy, too.

Notice that the key to this is DECODE. If DECODE is not


already part of your toolbelt, I recommend studying up.

http://thinkoracle.blogspot.com/2005/06/decode.html

Ready for a tougher example? Let's look at another Ask


Tom:
http://asktom.oracle.com/pls/ask/f?
p=4950:8:16663421538065257584::NO::
F4950_P8_DISPLAYID,F4950_P8_CRITERIA:7086279412131

For further study of pivot queries and analytic functions in


general, there is an awesome write-up in Chapter 12 of
Tom Kyte's "Expert One-on-One Oracle." You'd think I'd get

http://thinkoracle.blogspot.com/2005/09/pivot-and-crosstab-queries.html (3 of 6)1/9/2008 2:54:26 AM


OracleBlog: Pivot and Crosstab Queries

a kickback from Tom Kyte with all the promotion I'm doing,
but the honest truth is that no one explains it as well as he.

So, do you understand pivot queries now? No problems?

If so, now you're ready for one of Ask Tom's more complex
examples:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::
F4950_P8_DISPLAYID:6923393629227

Pivot Tables

One final word: don't confuse pivot queries with pivot


tables. Pivot tables are a different concept, and have
different uses (most typically to fill in missing data). Until I
blog about pivot tables, check out these two links:

Jonathan Gennick
http://www.oracle.com/technology/oramag/oracle/02-
sep/o52sql.html

Laurent Schneider
http://laurentschneider.blogspot.com/2005/08/pivot-
table.html

// posted by Robert Vollman @ Thursday, September 01, 2005

Comments:
Thanks, Robert! This article helped me today.
# posted by John : Wednesday, 23 August, 2006

Thank a lot , the information really helpful.


# posted by errant : Wednesday, 20 September, 2006

Thanks a lot...i was breaking my head since long to solve


this problem :)
# posted by Puneeta : Wednesday, 08 November, 2006

Thanks so much!!! It was really helpful


# posted by Anonymous : Wednesday, 24 January, 2007

Thank you so much!!! It really saved my day.


# posted by Anonymous : Thursday, 25 January, 2007

http://thinkoracle.blogspot.com/2005/09/pivot-and-crosstab-queries.html (4 of 6)1/9/2008 2:54:26 AM


OracleBlog: Pivot and Crosstab Queries

thanks a lot robert...u saved so much of our time and


effort..I really cannt tell how much u helped
# posted by Anonymous : Monday, 26 March, 2007

You sample and links are much appreciated. I needed


something like this only I'm using the case statement
instead of decode, both work great.
# posted by Otto : Tuesday, 08 May, 2007

Hi robert,

I was using the same trick with case statement but it was
returning wrong numbers. When I replaced case with
decode I am getting right answers. I am working on oracle
10g R2.

e.g
with yr
as
( select max(yr) cy
from sales_dtl_sum )
select
s.cst_nbr,
max( case when s.yr = yr.cy then s.dollars end)
cy_sls_dollars ,
max( case when s.yr = yr.cy-1 then s.dollars end)
py_sls_dollars,
from sales_dtl_sum s,
yr
where
s.yr in (yr.cy, yr.cy-1)
group by
s.cst_nbr

I am getting wrong values for the current year.( yr is not


null in sales_dtl_sum table). When I replace case with the
syntax of decode you have, it is returning right results.

I don't know, whether I am doing something wrong or it is


not the right way to do squash or is it a bug.

Your advise on this is highly appreciated.

Thank you very much


CT
# posted by CT : Friday, 15 June, 2007

This a very good article...god job Robert

http://thinkoracle.blogspot.com/2005/09/pivot-and-crosstab-queries.html (5 of 6)1/9/2008 2:54:26 AM


OracleBlog: Pivot and Crosstab Queries

# posted by Anonymous : Wednesday, 27 June, 2007

This article saved me!!! Thanks so much.


# posted by Anonymous : Friday, 17 August, 2007

Thanks, thanks, thanks.


# posted by Hugo : Thursday, 23 August, 2007

Thank you. This helped a lot.


# posted by Jorge : Thursday, 20 September, 2007

Thanks man, helped a lot.


# posted by Mikhail : Wednesday, 17 October, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/09/pivot-and-crosstab-queries.html (6 of 6)1/9/2008 2:54:26 AM


OracleBlog: Pivot Queries Using Variable Number of Columns

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated, but it is the
most powerful tool when it comes to data. That's why when I think data, I think Oracle. I also enjoy writing, so I
use this format to organise my thoughts. Please feel free to discuss any thoughts you may have on the same
topics, even old ones (I will see and respond to such comments). You may want to start with "LIST ALL
ARTICLES" under Archives.

Monday, April 03, 2006


Pivot Queries Using Variable Number of Columns
Pivot queries (also known as crosstab queries) are a special kind of query that can turn rows
into columns for special reporting needs. For example, if you have a table/view with three
columns (employee name, year, and salary), and you need a view that shows employee name
and salary over the years (as a single row), then a pivot query is what you want. Essentially,
you want to "pivot" the year column from being rows to being a column.

I presented a simple, introductory example last September that used Canadian Football
League teams and their points per season as an example. That example worked fine at the
time, but what happened at the end of the CFL season? You entered some new rows of data to
reflect the results of the 2005 season, but the query is hard-coded to show only 2002-2004
seasons. What should you do now? Re-write your query after every season? Fortunately, there
is a better way. That is why today I would like to expand on this example to show you how to
write a pivot query in the common case where you have an undefined number of columns (in
this case, seasons/years).

First of all, let's add the 2005 season to our data. Also remember why I like to name my
columns when I insert (or call stored procedures):
INSERT INTO CFL (season, team, points) VALUES (2005, 'Argonauts', 22);
INSERT INTO CFL (season, team, points) VALUES (2005, 'Alouettes', 20);
INSERT INTO CFL (season, team, points) VALUES (2005, 'Renegades', 14);
INSERT INTO CFL (season, team, points) VALUES (2005, 'Tiger-Cats', 10);

Our problem is that we don't know how many columns we need when we write the query. We
only know how many columns we'll need at the time the query is executed. That sounds like a
job for dynamic SQL which, along with REF CURSORs, can build an appropriate query at the
time we call it. That technique is described in detail by Tom Kyte in his book Expert One-on-
One Oracle, in Chapter 12 on Analytic Functions. I will apply this technique to our specific
problem in an upcoming article.

Tom describes another way to get around this issue on his famous AskTom website. You can
leave the seasons as rows (allowing you to have as few or as many as you need), and pivot the
non-season columns instead. His solution leads us to another way of tackling this "I don't
know how many columns I'll need" problem. Make season/points a single column.

Solution #1: Leave Seasons as rows and pivot the Team column.

CREATE OR REPLACE TYPE Teams AS OBJECT

http://thinkoracle.blogspot.com/2006/04/pivot-queries-using-variable-number-of.html (1 of 6)1/9/2008 2:54:29 AM


OracleBlog: Pivot Queries Using Variable Number of Columns

(team VARCHAR2(16), points NUMBER(3));

CREATE OR REPLACE TYPE Seasons AS TABLE OF Teams;

SELECT c1.season,
CAST(MULTISET(SELECT c2.team, sum(c2.points) tot_points
FROM CFL c2 WHERE c1.season = c2.season
GROUP BY c2.team) AS Seasons) Standings
FROM CFL c1
GROUP BY season;

SEASON
----------
STANDINGS(TEAM, POINTS)
--------------------------------------------------------------------------------
2002
SEASONS(TEAMS('Alouettes', 27), TEAMS('Argonauts', 16), TEAMS('Renegades', 10), TEAMS
('Tiger-Cats', 15))

2003
SEASONS(TEAMS('Alouettes', 26), TEAMS('Argonauts', 18), TEAMS('Renegades', 14), TEAMS
('Tiger-Cats', 2))

2004

SEASON
----------
STANDINGS(TEAM, POINTS)
--------------------------------------------------------------------------------
SEASONS(TEAMS('Alouettes', 28), TEAMS('Argonauts', 21), TEAMS('Renegades', 10), TEAMS
('Tiger-Cats', 19))

2005
SEASONS(TEAMS('Alouettes', 20), TEAMS('Argonauts', 22), TEAMS('Renegades', 14), TEAMS
('Tiger-Cats', 10))

Solution #2: Pivot Seasons, just like we did before, and create an array for seasons and points.

CREATE OR REPLACE TYPE SeasonResult AS OBJECT


(season NUMBER(4), points NUMBER(3));

CREATE OR REPLACE TYPE TeamResult AS TABLE OF SeasonResult;

SELECT c1.team,
CAST(MULTISET(SELECT c2.season, sum(c2.points) tot_points
FROM CFL c2 WHERE c1.team = c2.team
GROUP BY c2.season) AS TeamResult) Results
FROM CFL c1
GROUP BY team;

TEAM
----------------
RESULTS(SEASON, POINTS)
--------------------------------------------------------------------------------
Alouettes
TEAMRESULT(SEASONRESULT(2002, 27), SEASONRESULT(2003, 26), SEASONRESULT(2004, 28),

http://thinkoracle.blogspot.com/2006/04/pivot-queries-using-variable-number-of.html (2 of 6)1/9/2008 2:54:29 AM


OracleBlog: Pivot Queries Using Variable Number of Columns

SEASONRESULT(2005, 20))

Argonauts
TEAMRESULT(SEASONRESULT(2002, 16), SEASONRESULT(2003, 18), SEASONRESULT(2004, 21),
SEASONRESULT(2005, 22))

Renegades

TEAM
----------------
RESULTS(SEASON, POINTS)
--------------------------------------------------------------------------------
TEAMRESULT(SEASONRESULT(2002, 10), SEASONRESULT(2003, 14), SEASONRESULT(2004, 10),
SEASONRESULT(2005, 14))

Tiger-Cats
TEAMRESULT(SEASONRESULT(2002, 15), SEASONRESULT(2003, 2), SEASONRESULT(2004, 19),
SEASONRESULT(2005, 10))

There are two consequences of this approach that are less than ideal. The query itself is a
little bit complicated, involves creating types and, secondly, if we made a view from this
query, its harder to use. (Example: Query that view to get me the season record for each
team). Fortunately there is a simple change we can make that gives us a query as simple as
our original example, and where we can create a view that can be more easily used for other
queries.

Before I tell you what it is, observe one thing about Tom's solution (#1). In the simpler
example where we knew how many columns (seasons) we'd need, we pivoted the seasons. In
this example, where we didn't know how many seasons we had, we pivoted the other columns
(team, points).

We are in the fortunate position where we know how many teams we have. Why not pivot
"team" column, and then do it largely like our simpler example?

CREATE OR REPLACE VIEW CFLBySeason AS


SELECT season,
MAX(DECODE(team, 'Argonauts', points, NULL)) Argonauts,
MAX(DECODE(team, 'Alouettes', points, NULL)) Alouettes,
MAX(DECODE(team, 'Renegades', points, NULL)) Renegades,
MAX(DECODE(team, 'Tiger-Cats', points, NULL)) TigerCats
FROM CFL
GROUP BY season;

SELECT * FROM CFLBySeason;

SEASON ARGONAUTS ALOUETTES RENEGADES TIGERCATS


---------- ---------- ---------- ---------- ----------
2002 16 27 10 15
2003 18 26 14 2
2004 21 28 10 19
2005 22 20 14 10

Not only do we have a simpler query, but we can leverage the power of views to keep things

http://thinkoracle.blogspot.com/2006/04/pivot-queries-using-variable-number-of.html (3 of 6)1/9/2008 2:54:29 AM


OracleBlog: Pivot Queries Using Variable Number of Columns

simple. By turning this query into a view (called, for example, CFLBySeason), we can address
other requirements very easily.

Example:
1. Show me the most points any team has had in any one season. And it would be simple
enough to change this example to show total and/or average season performance as well.

SELECT MAX(Argonauts) Argonauts,


MAX(Alouettes) Alouettes,
MAX(Renegades) Renegades,
MAX(TigerCats) TigerCats
FROM CFLBySeason;

2. Show me how lopsided the division was each season

SELECT Season,
(Argonauts + Alouettes) TorMtl,
(Renegades + TigerCats) OttHam
FROM CFLBySeason;

3. I only care about Toronto. I want to see their season-by-season point totals.

SELECT Season, Argonauts FROM CFLBySeason;

I will admit that pivot queries can get complicated, but given how often they are the easiest
solution to complex requirements, it is worth the investment to understand them.

// posted by Robert Vollman @ Monday, April 03, 2006

Comments: Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I like playing sports
(hockey, soccer, ultimate, basketball, you name it) and military board games. I also enjoy
reading, walking, and playing with my 2 cats Lilly and Brutus. I'm a database application specialist,
whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte

http://thinkoracle.blogspot.com/2006/04/pivot-queries-using-variable-number-of.html (4 of 6)1/9/2008 2:54:29 AM


OracleBlog: Pivot Queries Using Variable Number of Columns

●Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2006/04/pivot-queries-using-variable-number-of.html (5 of 6)1/9/2008 2:54:29 AM


OracleBlog: Pivot Queries Using Variable Number of Columns

❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2006/04/pivot-queries-using-variable-number-of.html (6 of 6)1/9/2008 2:54:29 AM


OracleBlog: PL/SQL Procedure Call Overhead

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, September
About Me
30, 2005
Name: Robert Vollman
PL/SQL Location: Calgary, Alberta, Canada
Procedure
Call I was born and raised in Ottawa, and have lived in
Calgary since 1991. I like playing sports (hockey,
Overhead soccer, ultimate, basketball, you name it) and military board
Is there much games. I also enjoy reading, walking, and playing with my 2
overhead in calling cats Lilly and Brutus. I'm a database application specialist,
PL/SQL procedures? whatever that is.
I assume that if the
View my complete profile
answer is "yes,"
you'll want to avoid
procedure calls,
which would likely Best Links
mean making your ● Ask Tom Kyte
procedures bigger ● Oracle Docs
(by combining ● Dan Morgan and PSOUG
several into one).
Steven Feuerstein
That makes me

Jonathan Lewis
shudder because

FAQ
clean, modular code ●

is easier to read and ● Connor McDonald


maintain, not to ● The Oak Table
mention making it ● Cary Millsap and Hotsos
easier to develop ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (1 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

new code if its ● Anjo Kolk and OraPerf


based on reliable, ● Dizwell Oracle Wiki
tested code. ● My Personal Blog

I assume there is at
least some
overhead to calling
PL/SQL procedures.
Aggregators
I mean, if the Brian Duff's OraBlogs

procedure is not in ❍ Eddie Awad's OracleNA


the cache, you'll ❍ Pete Finnigan's Aggregator
obviously have to ❍ Oracle's Bloglist
go the disk to fetch ❍ Oracle Base Aggregator
it.

If it's already in
Top Blogs
Oracle's Ask Tom Kyte
memory, there ❍

could still be some ❍ Oracle Guru Jonathan Lewis


overhead in the ❍ Blogger of the Year Eddie Awad
passing of ❍ Data Warehouser David Aldridge
parameters. UNLESS ❍ Oracle Geek Lewis Cunningham
you can use the ❍ Database Expert James Koopmann
"NOCOPY" hint, that ❍ Dizwell's Howard Rogers
is. ❍ Oracle Master Laurent Schneider
Security Expert Pete Finnigan
http://thinkoracle.

Oracle Award Winner Mark Rittman


blogspot.

Doug Burns
com/2005/05/

❍ Oracle ACE of the Year Dr. Tim Hall


nocopy-hint.html ❍ UKOUG's Andrew (Arfur C.) Clarke
Newbie DBA Lisa Dobson
But to be honest, I

Coffee-Drinking DBA Jon Emmons


don't know how ❍

much overhead any ❍ Chris Foot


particular procedure ❍ The Pythian DBA Team Blog
call will have. Sorry ❍ DBA Don Seiler
to those that read ❍ DBA Coskan Gundogar
the title and hoped ❍ Oracle WTF
that the content
would contain the
definitive answer. I
ARCHIVES
LIST ALL ARTICLES
might have

May 2005
something more

June 2005
conclusive after ❍

❍ July 2005

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (2 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

doing some ❍ August 2005


research. In the ❍ September 2005
meantime, here is ❍ October 2005
what I do every time November 2005
I have a question: I

December 2005
test it.

❍ January 2006
Even if I showed ❍ February 2006
you a quote in a ❍ March 2006
book that shows ❍ April 2006
you how to ❍ May 2006
calculate the ❍ June 2006
overhead, I would ❍ July 2006
STILL advise testing ❍ August 2006
it. Documents can ❍ September 2006
be out-of-date,
October 2006
misunderstood and

November 2006
just plain wrong.

December 2006
You need to test it.

❍ January 2007
Here is how to test ❍ February 2007
it. ❍ March 2007
❍ April 2007
1. Write (or identify) ❍ May 2007
a stored procedure June 2007
that reflects your

October 2007
business

requirements.

CREATE OR
REPLACE
PROCEDURE DoIt
IS
BEGIN
NULL;
-- Do some stuff in
here!
END DoIt;

2. Now split that


stored procedure
into two (or more)
parts, and a master
proc

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (3 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

CREATE OR
REPLACE
PROCEDURE
DoItPartOne
IS
BEGIN
NULL;
-- Do part of the
stuff here...
END DoItPartOne;

...etc!

CREATE OR
REPLACE
PROCEDURE
DoItInParts
IS
BEGIN
DoItPartOne;
-- DoItPartTwo;
-- etc...
END DoItInParts;

3. With stats on, call


that first stored
procedure that does
everything, and
then run TKPROF to
analyse it.

ALTER SESSION SET


SQL_TRACE = TRUE;
EXEC DoIt;
ALTER SESSION SET
SQL_TRACE = FALSE;

TKPROF
robert_ora_3028.trc
robert_ora_3028.prf
explain='sys/
******** as sysdba'

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (4 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

More on gathering
and analysing
simple performance
statistics:
http://thinkoracle.
blogspot.
com/2005/09/
analyzing-query-
performance.html

4. With stats on, call


that second stored
procedure.

ALTER SESSION SET


SQL_TRACE = TRUE;
EXEC DoItInParts;
ALTER SESSION SET
SQL_TRACE = FALSE;

You may find, as I


did, that it is very
hard to set up a test
that reveals any
kind of noticeable
performance
overhead. But if the
procedures were
spread out over the
disk and not in the
cache, or if there
were lots and lots
of parameters, I bet
we could see some
overhead. But if
your procedure is
called often enough
for it to be
important to you,
the procedures
would probably be
in the cache at any
given time.

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (5 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

But don't spend too


much time in
conjecture, and
even when I do
produce some facts,
set up your tests
anyway.

// posted by Robert
Vollman @ Friday,

September 30, 2005

Comments:
you'll want to avoid
procedure calls

What a drastic idea!


But really Rob, you
now made me
think. Whenever I
call a procedure, I
will ask myself:
does this stand
alone code "unit"
really need to be
stand alone or can
it be combined with
another logically
similar unit? and
vice versa. I think it
all boils down to
good PL/SQL
programming
practice.
# posted by Eddie
Awad : Friday, 30
September, 2005

Hi.

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (6 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

You can meansure


the overhead:

SQL> CREATE OR
REPLACE
PROCEDURE
overhead_procedure
AS
2 BEGIN
3 NULL;
4 END;
5/

Procedure created.

SQL> SET
SERVEROUTPUT ON
SQL> DECLARE
2 l_loops NUMBER :
= 1000000;
3 l_start NUMBER;
4 BEGIN
5 -- Time block.
6 l_start :=
DBMS_UTILITY.
get_time;
7
8 FOR i IN 1 ..
l_loops LOOP
9
overhead_procedure;
10 END LOOP;
11
12 DBMS_OUTPUT.
put_line
('Procedure : ' ||
13 (DBMS_UTILITY.
get_time - l_start));
14
15 -- Time no
block.
16 l_start :=
DBMS_UTILITY.

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (7 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

get_time;
17
18 FOR i IN 1 ..
l_loops LOOP
19 NULL;
20 END LOOP;
21
22 DBMS_OUTPUT.
put_line('No
Procedure: ' ||
23 (DBMS_UTILITY.
get_time - l_start));
24 END;
25 /
Procedure : 129
No Procedure: 3

PL/SQL procedure
successfully
completed.

SQL> DROP
PROCEDURE
overhead_procedure;

Procedure dropped.

SQL>

Does this mean you


shouldn't use
procedures? Hell
no. Without them
you won't have
maintainable code.
The overhead for
each call is so small
I think it's safe to
say we can live with
it :)

Cheers

Tim...

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (8 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

PS. This example is


taken from my
latest book "Oracle
PL/SQL Tuning".
Plu, plug :)
# posted by Tim... :
Saturday, 01 October,
2005

In my experience
the overhead of
PLSQL procedure
invocations is so
small that you'll
most probably
never have to think
about it. In 99.99%
of all cases the
"real" overhead
comes from the way
you do things inside
the procedure(s)
and not from the
procedure
invocation itself. So
putting as much
code into a single
procedure as you
can won't help. :-)

Let's take a look at


a very basic
example.
Run this:

DECLARE
nLoops CONSTANT
NUMBER :=
10000000;
nStart NUMBER;
PROCEDURE
calculate IS

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (9 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

BEGIN
NULL;
END calculate;
BEGIN
dbms_output.enable
(buffer_size =>
10000);

nStart :=
dbms_utility.
get_time();
FOR i IN 1..nLoops
LOOP
calculate();
END LOOP;
dbms_output.
put_line('time: ' ||
ROUND
((dbms_utility.
get_time() -
nStart)/100, 3) || '
s');

nStart :=
dbms_utility.
get_time();
FOR i IN 1..nLoops
LOOP
NULL;
END LOOP;
dbms_output.
put_line('time: ' ||
ROUND
((dbms_utility.
get_time() -
nStart)/100, 3) || '
s');
END;
/

On my server the
output was:
time: 4.33 s
time: 1.47 s

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (10 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

I ran it around 10
times and got quite
similiar results with
a very small
deviation. This
shows that even in
a magnitude of 10
million invocations,
the overhead is
minimal (~3s which
is 66% in this case).
Of course this is
nothing like a real
world situation. :-)

Let's do some work


in the procedure.
What if we pass in a
parameter and
return a value
(make it a function)?

DECLARE
nLoops CONSTANT
NUMBER :=
10000000;
nStart NUMBER;
nTemp NUMBER;
FUNCTION calculate
(nParam IN
NUMBER) RETURN
NUMBER IS
BEGIN
RETURN nParam + 1;
END calculate;
BEGIN
dbms_output.enable
(buffer_size =>
10000);

nTemp := 0;
nStart :=
dbms_utility.

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (11 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

get_time();
FOR i IN 1..nLoops
LOOP
nTemp := calculate
(nTemp);
END LOOP;
dbms_output.
put_line('time: ' ||
ROUND
((dbms_utility.
get_time() -
nStart)/100, 3) || '
s');

nTemp := 0;
nStart :=
dbms_utility.
get_time();
FOR i IN 1..nLoops
LOOP
nTemp := nTemp +
1;
END LOOP;
dbms_output.
put_line('time: ' ||
ROUND
((dbms_utility.
get_time() -
nStart)/100, 3) || '
s');
END;
/

The output is:


time: 12.24 s
time: 3.75 s

The overhead
seems to be quite
"big" compared to
the previous test
(~8.5s, which is
~70% in this case),
however this is still

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (12 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

as much unrealistic
as the previous one
was. :-) Generally
you could say that
the more work you
do inside the
function call (or
procedure), the less
percentage the
overhead will be.

Let's do the test


again with a bit
more work inside
the function ...

DECLARE
nLoops CONSTANT
NUMBER :=
10000000;
nStart NUMBER;
nTemp NUMBER;
FUNCTION calculate
(nParam IN
NUMBER) RETURN
NUMBER IS
BEGIN
RETURN POWER
(nParam + 1, 2) -
POWER(nParam, 2);
END calculate;
BEGIN
dbms_output.enable
(buffer_size =>
10000);

nTemp := 0;
nStart :=
dbms_utility.
get_time();
FOR i IN 1..nLoops
LOOP
nTemp := calculate
(nTemp);

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (13 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

END LOOP;
dbms_output.
put_line('time: ' ||
ROUND
((dbms_utility.
get_time() -
nStart)/100, 3) || '
s');

nTemp := 0;
nStart :=
dbms_utility.
get_time();
FOR i IN 1..nLoops
LOOP
nTemp := POWER
(nTemp + 1, 2) -
POWER(nTemp, 2);
END LOOP;
dbms_output.
put_line('time: ' ||
ROUND
((dbms_utility.
get_time() -
nStart)/100, 3) || '
s');
END;
/

time: 47.28 s
time: 31.1 s

Now the overhead is


~16s which is ~34%
of the total running
time.

All of the above


tests use very fast,
builtin arithemtical
functions. Let's take
an example that is a
lot more realistic ...
eg. we generate

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (14 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

some output to a
browser. The
procedures in the
SYS.htp package do
a lot more (and
versatile) work than
any of the above
examples. I've split
this test into two
parts to avoid
misleading results
due to the internal
workings of the SYS.
htp package. I've
also decreased the
loop count so the
server won't run out
of memory (since
SYS.htp maintains
an internal buffer of
all the strings the
you send to the
output). :-)

DECLARE
nLoops CONSTANT
NUMBER :=
1000000;
nStart NUMBER;
sTemp VARCHAR2
(200);
PROCEDURE
calculate(sParam IN
VARCHAR2) IS
BEGIN
htp.p(sParam);
END calculate;
BEGIN
dbms_output.enable
(buffer_size =>
10000);
sTemp := LPAD('a',
200, 'a');

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (15 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

htp.init();
nStart :=
dbms_utility.
get_time();
FOR i IN 1..nLoops
LOOP
calculate(sTemp);
END LOOP;
dbms_output.
put_line('time: ' ||
ROUND
((dbms_utility.
get_time() -
nStart)/100, 3) || '
s');

htp.init();
END;
/

And the procedure-


free version ...

DECLARE
nLoops CONSTANT
NUMBER :=
1000000;
nStart NUMBER;
sTemp VARCHAR2
(200);
PROCEDURE
calculate(sParam IN
VARCHAR2) IS
BEGIN
htp.p(sParam);
END calculate;
BEGIN
dbms_output.enable
(buffer_size =>
10000);
sTemp := LPAD('a',
200, 'a');

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (16 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

htp.init();
nStart :=
dbms_utility.
get_time();
FOR i IN 1..nLoops
LOOP
htp.p(sTemp);
END LOOP;
dbms_output.
put_line('time: ' ||
ROUND
((dbms_utility.
get_time() -
nStart)/100, 3) || '
s');

htp.init();
END;
/

You should run


them in two
separate sessions,
otherwise you can
easily end up with
false results due to
the package state of
SYS.htp.

My results were:
time: 23.7 s
time: 23.27 s

You can see that


the overhead is less
than 0.5s, which
makes up less than
2% of the total
running time.

After all these tests


proove only one
thing: the overhead
seriously depends

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (17 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead

on the number of
parameters, the
type of parameters,
etc. However in real-
world situations you
should rarely worry
about overhead of
procedure
invocations. :-)
# posted by Zsolt :
Friday, 11 August, 2006

How do I call a
procedure inside a
procedure?? with
call or exec or just
with :=
# posted by
Anonymous :
Wednesday, 08 August,
2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/09/plsql-procedure-call-overhead.html (18 of 18)1/9/2008 2:54:33 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, August 11, 2006


About Me
PL/SQL Name: Robert Vollman
Procedure Call Location: Calgary, Alberta, Canada
Overhead Re-
I was born and raised in Ottawa, and have
visited lived in Calgary since 1991. I like playing
Zsolt Lajosfalvi wrote such sports (hockey, soccer, ultimate, basketball, you name
an interesting comment in it) and military board games. I also enjoy reading,
response to my earlier post walking, and playing with my 2 cats Lilly and Brutus.
about PL/SQL Procedure I'm a database application specialist, whatever that is.
Call Overhead that I felt it
deserved its own space. View my complete profile
What follows is exclusively
the work of Zsolt. My
results from verifying his Best Links
tests follow at the end. ● Ask Tom Kyte
● Oracle Docs
Zsolt: ● Dan Morgan and PSOUG
Steven Feuerstein
In my experience the

overhead of PLSQL ● Jonathan Lewis


procedure invocations is ● FAQ
so small that you'll most ● Connor McDonald
probably never have to ● The Oak Table
think about it. In 99.99% of ● Cary Millsap and Hotsos
all cases the "real" ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (1 of 11)1/9/2008 2:54:36 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

overhead comes from the ● Anjo Kolk and OraPerf


way you do things inside ● Dizwell Oracle Wiki
the procedure(s) and not ● My Personal Blog
from the procedure
invocation itself. So
putting as much code into
a single procedure as you
can won't help. :-)
Aggregators
Brian Duff's OraBlogs

Let's take a look at a very ❍ Eddie Awad's OracleNA


basic example. ❍ Pete Finnigan's Aggregator
Run this: ❍ Oracle's Bloglist
❍ Oracle Base Aggregator
DECLARE
nLoops CONSTANT
NUMBER := 10000000;
Top Blogs
Oracle's Ask Tom Kyte
nStart NUMBER; ❍

PROCEDURE calculate IS ❍ Oracle Guru Jonathan Lewis


BEGIN ❍ Blogger of the Year Eddie Awad
NULL; ❍ Data Warehouser David Aldridge
END calculate; ❍ Oracle Geek Lewis Cunningham
BEGIN ❍ Database Expert James Koopmann
dbms_output.enable ❍ Dizwell's Howard Rogers
(buffer_size => 10000); ❍ Oracle Master Laurent Schneider
Security Expert Pete Finnigan
nStart := dbms_utility.

Oracle Award Winner Mark Rittman


get_time();

Doug Burns
FOR i IN 1..nLoops LOOP ❍

calculate(); ❍ Oracle ACE of the Year Dr. Tim Hall


END LOOP; ❍ UKOUG's Andrew (Arfur C.) Clarke
dbms_output.put_line ❍ Newbie DBA Lisa Dobson
('time: ' || ROUND ❍ Coffee-Drinking DBA Jon Emmons
((dbms_utility.get_time() - ❍ Chris Foot
nStart)/100, 3) || ' s'); ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
nStart := dbms_utility. DBA Coskan Gundogar
get_time();

Oracle WTF
FOR i IN 1..nLoops LOOP

NULL;
END LOOP; ARCHIVES
dbms_output.put_line ❍ LIST ALL ARTICLES
('time: ' || ROUND ❍ May 2005
((dbms_utility.get_time() - ❍ June 2005
nStart)/100, 3) || ' s'); ❍ July 2005

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (2 of 11)1/9/2008 2:54:36 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

END; ❍ August 2005


/ ❍ September 2005
October 2005
On my server the output

November 2005
was:

December 2005
time: 4.33 s ❍

time: 1.47 s ❍ January 2006


❍ February 2006
I ran it around 10 times ❍ March 2006
and got quite similiar ❍ April 2006
results with a very small ❍ May 2006
deviation. This shows that ❍ June 2006
even in a magnitude of 10 ❍ July 2006
million invocations, the
August 2006
overhead is minimal (~3s

September 2006
which is 66% in this case).

October 2006
Of course this is nothing ❍

like a real world ❍ November 2006


situation. :-) ❍ December 2006
❍ January 2007
Let's do some work in the ❍ February 2007
procedure. What if we pass ❍ March 2007
in a parameter and return ❍ April 2007
a value (make it a function)? ❍ May 2007
June 2007
DECLARE

nLoops CONSTANT ❍ October 2007


NUMBER := 10000000;
nStart NUMBER;
nTemp NUMBER;
FUNCTION calculate
(nParam IN NUMBER)
RETURN NUMBER IS
BEGIN
RETURN nParam + 1;
END calculate;
BEGIN
dbms_output.enable
(buffer_size => 10000);

nTemp := 0;
nStart := dbms_utility.
get_time();
FOR i IN 1..nLoops LOOP

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (3 of 11)1/9/2008 2:54:36 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

nTemp := calculate
(nTemp);
END LOOP;
dbms_output.put_line
('time: ' || ROUND
((dbms_utility.get_time() -
nStart)/100, 3) || ' s');

nTemp := 0;
nStart := dbms_utility.
get_time();
FOR i IN 1..nLoops LOOP
nTemp := nTemp + 1;
END LOOP;
dbms_output.put_line
('time: ' || ROUND
((dbms_utility.get_time() -
nStart)/100, 3) || ' s');
END;
/

The output is:


time: 12.24 s
time: 3.75 s

The overhead seems to be


quite "big" compared to
the previous test (~8.5s,
which is ~70% in this case),
however this is still as
much unrealistic as the
previous one was. :-)
Generally you could say
that the more work you do
inside the function call (or
procedure), the less
percentage the overhead
will be.

Let's do the test again with


a bit more work inside the
function ...

DECLARE

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (4 of 11)1/9/2008 2:54:36 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

nLoops CONSTANT
NUMBER := 10000000;
nStart NUMBER;
nTemp NUMBER;
FUNCTION calculate
(nParam IN NUMBER)
RETURN NUMBER IS
BEGIN
RETURN POWER(nParam +
1, 2) - POWER(nParam, 2);
END calculate;
BEGIN
dbms_output.enable
(buffer_size => 10000);

nTemp := 0;
nStart := dbms_utility.
get_time();
FOR i IN 1..nLoops LOOP
nTemp := calculate
(nTemp);
END LOOP;
dbms_output.put_line
('time: ' || ROUND
((dbms_utility.get_time() -
nStart)/100, 3) || ' s');

nTemp := 0;
nStart := dbms_utility.
get_time();
FOR i IN 1..nLoops LOOP
nTemp := POWER(nTemp +
1, 2) - POWER(nTemp, 2);
END LOOP;
dbms_output.put_line
('time: ' || ROUND
((dbms_utility.get_time() -
nStart)/100, 3) || ' s');
END;
/

time: 47.28 s
time: 31.1 s

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (5 of 11)1/9/2008 2:54:36 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

Now the overhead is ~16s


which is ~34% of the total
running time.

All of the above tests use


very fast, builtin
arithemtical functions.
Let's take an example that
is a lot more realistic ... eg.
we generate some output
to a browser. The
procedures in the SYS.htp
package do a lot more (and
versatile) work than any of
the above examples. I've
split this test into two
parts to avoid misleading
results due to the internal
workings of the SYS.htp
package. I've also
decreased the loop count
so the server won't run out
of memory (since SYS.htp
maintains an internal
buffer of all the strings the
you send to the output). :-)

DECLARE
nLoops CONSTANT
NUMBER := 1000000;
nStart NUMBER;
sTemp VARCHAR2(200);
PROCEDURE calculate
(sParam IN VARCHAR2) IS
BEGIN
htp.p(sParam);
END calculate;
BEGIN
dbms_output.enable
(buffer_size => 10000);
sTemp := LPAD('a', 200,
'a');

htp.init();

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (6 of 11)1/9/2008 2:54:36 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

nStart := dbms_utility.
get_time();
FOR i IN 1..nLoops LOOP
calculate(sTemp);
END LOOP;
dbms_output.put_line
('time: ' || ROUND
((dbms_utility.get_time() -
nStart)/100, 3) || ' s');

htp.init();
END;
/

And the procedure-free


version ...

DECLARE
nLoops CONSTANT
NUMBER := 1000000;
nStart NUMBER;
sTemp VARCHAR2(200);
PROCEDURE calculate
(sParam IN VARCHAR2) IS
BEGIN
htp.p(sParam);
END calculate;
BEGIN
dbms_output.enable
(buffer_size => 10000);
sTemp := LPAD('a', 200,
'a');

htp.init();
nStart := dbms_utility.
get_time();
FOR i IN 1..nLoops LOOP
htp.p(sTemp);
END LOOP;
dbms_output.put_line
('time: ' || ROUND
((dbms_utility.get_time() -
nStart)/100, 3) || ' s');

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (7 of 11)1/9/2008 2:54:36 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

htp.init();
END;
/

You should run them in


two separate sessions,
otherwise you can easily
end up with false results
due to the package state of
SYS.htp.

My results were:
time: 23.7 s
time: 23.27 s

You can see that the


overhead is less than 0.5s,
which makes up less than
2% of the total running
time.

After all these tests proove


only one thing: the
overhead seriously
depends on the number of
parameters, the type of
parameters, etc. However
in real-world situations
you should rarely worry
about overhead of
procedure invocations. :-)

Robert:
My results were very
similar to Zsolt's:

anonymous block
completed
time: 11.28 s
time: 4.26 s

anonymous block
completed
time: 51.18 s

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (8 of 11)1/9/2008 2:54:36 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

time: 43.24 s

anonymous block
completed
time: 20.37 s

anonymous block
completed
time: 19.53 s

// posted by Robert
Vollman @ Friday, August 11,

2006

Comments:
I'm wondering if this
breaks down for the
situation of having a lot of
procedures that aren't
pinned (either explicitly or
de facto by being used
over and over and not
being aged out of the
shared pool).

Try repeating these tests


cycling through multiple
procedures with an
undersized pool or a
version of Oracle that has
shared pool memory leak
issues... :-O

You might also set


cursor_space_for_time=true
and have the procedure in
multiple sessions try to
access an object while
another is changing some
grants on the object. That
will show some overhead!

The real point here is that

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (9 of 11)1/9/2008 2:54:36 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

deciding whether and how


much overhead something
has probably will not
generalize to loaded
multiuser environments.
That's quite different than
calculating the percentage
of a chunk of code in a
bigger chunk of code or
even summating all the
code. While it is true that
doing less of something or
not doing it at all is going
to be more efficient than
doing more of something,
the interaction of doing
many things is often more
important.
# posted by Joel Garry : Friday,
11 August, 2006

hi pals, i'm trying to get


the third number of the
decimal part of a number
example: 123,3453 where
3453 is the decimal part, i
need the 5 number, extract
it. how can i do it?

thnx

rich
# posted by Anonymous :
Sunday, 12 August, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (10 of 11)1/9/2008 2:54:36 AM


OracleBlog: PL/SQL Procedure Call Overhead Re-visited

http://thinkoracle.blogspot.com/2006/08/plsql-procedure-call-overhead-re.html (11 of 11)1/9/2008 2:54:36 AM


OracleBlog: Random Numbers

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, May 24, 2005


About Me
Random Numbers Name: Robert Vollman
Let me get your advice on this one. Location: Calgary, Alberta,
Canada
Here's the situation, you need an
evenly distributed sequence of
random integers from 1 to 20. You I was born and raised in
decided to use the Oracle random Ottawa, and have lived in Calgary since
number package 'dbmsrand'. 1991. I like playing sports (hockey, soccer,
ultimate, basketball, you name it) and
Incidentally, I decided to do it this military board games. I also enjoy reading,
way after searching Ask Tom. walking, and playing with my 2 cats Lilly
and Brutus. I'm a database application
http://asktom.oracle.com/~tkyte/ specialist, whatever that is.
Misc/Random.html
http://asktom.oracle.com/pls/ask/f? View my complete profile
p=4950:8:::::
F4950_P8_DISPLAYID:831827028200
Best Links
There is a link to his web site to the ● Ask Tom Kyte
right. Bookmark it. ● Oracle Docs
Dan Morgan and PSOUG
While you're at it, bookmark Dan ●

Morgan's page (link on the right). ● Steven Feuerstein


● Jonathan Lewis
http://www.psoug.org/reference/ ● FAQ
dbms_random.html ● Connor McDonald

http://thinkoracle.blogspot.com/2005/05/random-numbers.html (1 of 5)1/9/2008 2:54:40 AM


OracleBlog: Random Numbers

The Oak Table


Ok, back to the story. ● Cary Millsap and Hotsos


Steve Adams and Ixora
After you read the instructions on

Anjo Kolk and OraPerf


using it, you probably write

Dizwell Oracle Wiki


something like this in your PL/SQL ●

stored procedure: ● My Personal Blog

Aggregators
AS
random_value number(2,0);
BEGIN
Brian Duff's OraBlogs
random_value := dbms_random.

Eddie Awad's OracleNA


value(0,20);

❍ Pete Finnigan's Aggregator


Now you notice whoops, you're ❍ Oracle's Bloglist
getting some 0s. You don't want 0. ❍ Oracle Base Aggregator

Top Blogs
Plus you're not getting very many
20s. So you do this instead
Oracle's Ask Tom Kyte
random_value := dbms_random.

Oracle Guru Jonathan Lewis


value(1,21); ❍

❍ Blogger of the Year Eddie Awad


Much better! But whoops - you're ❍ Data Warehouser David Aldridge
getting the occasional 21! So you ❍ Oracle Geek Lewis Cunningham
scratch your brain and do this: ❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
random_value := dbms_random.
Oracle Master Laurent Schneider
value(1,21);

Security Expert Pete Finnigan


random_value := MOD

Oracle Award Winner Mark Rittman


(random_value, 20) + 1; ❍

❍ Doug Burns
That should pour the 21s into the 1 ❍ Oracle ACE of the Year Dr. Tim Hall
pile, which you noticed is very, very ❍ UKOUG's Andrew (Arfur C.) Clarke
slightly lower than the others. ❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
Now you think you're getting the Chris Foot
values you want. So here are my

The Pythian DBA Team Blog


questions:

❍ DBA Don Seiler


1. Will this truly generate an even ❍ DBA Coskan Gundogar
sample of numbers from 1 to 20? ❍ Oracle WTF

ARCHIVES
Will there be the right number of 1s
and 20s?
2. Is there a better way? ❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/05/random-numbers.html (2 of 5)1/9/2008 2:54:40 AM


OracleBlog: Random Numbers

3. Say you're generating a very large ❍ May 2005


sequence, thinking about ❍ June 2005
performance, do you see any ❍ July 2005
problems with this approach I August 2005
should consider?

❍ September 2005
Here is the complete solution: ❍ October 2005
❍ November 2005
-------------------- ❍ December 2005
@utlraw ❍ January 2006
@prvtrawb.plb ❍ February 2006
@dbmsoctk ❍ March 2006
@prvtoctk.plb ❍ April 2006
@dbmsrand
❍ May 2006
create table value_holder as (f_value ❍ June 2006
NUMBER(2,0)); ❍ July 2006
❍ August 2006
create or replace procedure ❍ September 2006
ValuePlacer (number_to_generate IN ❍ October 2006
number) ❍ November 2006
AS ❍ December 2006
random_value number(2,0); January 2007
BEGIN

February 2007
for x in 1..number_to_generate

March 2007
LOOP

random_value := dbms_random. ❍ April 2007


value(1,21); ❍ May 2007
random_value := MOD ❍ June 2007
(random_value, 20) + 1; ❍ October 2007
insert into value_holder values
(random_value);
END LOOP;
END;

exec ValuePlacer(1000);

select f_value, count (f_value) from


value_holder group by f_value;
-----------------

Thanks!

// posted by Robert Vollman @ Tuesday, May

http://thinkoracle.blogspot.com/2005/05/random-numbers.html (3 of 5)1/9/2008 2:54:40 AM


OracleBlog: Random Numbers

24, 2005

Comments:
I'm not sure if I could follow your
example, but it seems to me that
what
you originally where after was this:

SQL> select rownum from


all_objects where rownum < 21
order by dbms_random.random;

ROWNUM
----------
19
10
11
15
9
1
14
16
12
7
2
8
4
6
17
13
5
3
20
18

HTH
Holger
# posted by Holger Baer : Wednesday, 25
May, 2005

Post a Comment

http://thinkoracle.blogspot.com/2005/05/random-numbers.html (4 of 5)1/9/2008 2:54:40 AM


OracleBlog: Random Numbers

<< Home

http://thinkoracle.blogspot.com/2005/05/random-numbers.html (5 of 5)1/9/2008 2:54:40 AM


OracleBlog: RAW Datatype

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, November 21, 2005


About Me
RAW Datatype Name: Robert Vollman
Earlier I mentioned the idea of using Location: Calgary, Alberta,
a RAW datatype for your table's Canada
primary key. I stumbled upon a
minor inconvenience with using the
I was born and raised in
RAW datatype today, so I thought I
Ottawa, and have lived in Calgary since
would take a step back and talk a
1991. I like playing sports (hockey, soccer,
little bit more about the RAW
ultimate, basketball, you name it) and
datatype.
military board games. I also enjoy reading,
http://thinkoracle.blogspot.
walking, and playing with my 2 cats Lilly
com/2005/06/natural-vs-synthetic- and Brutus. I'm a database application
keys.html specialist, whatever that is.

RAW(size) is used for raw binary View my complete profile


data or byte strings of length "size"
bytes (must be specified). The
maximum is 2000 bytes, but in PL/
SQL it is 32767, which can lead to Best Links
interesting situations. ● Ask Tom Kyte
● Oracle Docs
Think of RAW very much like ● Dan Morgan and PSOUG
VARCHAR2, but unlike VARCHAR,
Steven Feuerstein
RAW data will not be converted

Jonathan Lewis
depending on the character set (by

FAQ
import/export, for example). More ●

generally, Oracle will treat this as ● Connor McDonald

http://thinkoracle.blogspot.com/2005/11/raw-datatype.html (1 of 5)1/9/2008 2:54:43 AM


OracleBlog: RAW Datatype

binary data and will not interpret it The Oak Table


as a number, character, or anything ● Cary Millsap and Hotsos


else (generally done when moving ● Steve Adams and Ixora
data from one system/session to ● Anjo Kolk and OraPerf
another). ● Dizwell Oracle Wiki
My Personal Blog
RAW data can still be viewed as

characters (2 characters per byte).


Something like SQL*Plus does this
for you automatically when you
query. But RAW data is a little harder Aggregators
to use in pure SQL, because you Brian Duff's OraBlogs

often have to use HEXTORAW or ❍ Eddie Awad's OracleNA


RAWTOHEX to do your work ❍ Pete Finnigan's Aggregator
(example shortly). However in PL/ ❍ Oracle's Bloglist
SQL you can just use the UTL_RAW ❍ Oracle Base Aggregator
package.

Now back to the story.


Top Blogs
❍ Oracle's Ask Tom Kyte
In the aforementioned article I ❍ Oracle Guru Jonathan Lewis
mentioned using it as a primary key, ❍ Blogger of the Year Eddie Awad
using SYS_GUID. The advantages are ❍ Data Warehouser David Aldridge
you get a (generally) unique and ❍ Oracle Geek Lewis Cunningham
randomly-dispersed key that you
Database Expert James Koopmann
should never have to change. Please

Dizwell's Howard Rogers


note: I do not want to get dragged

Oracle Master Laurent Schneider


into a debate on whether or not it is ❍

a good idea, I'm just saying its ❍ Security Expert Pete Finnigan
possible, and has some advantages. ❍ Oracle Award Winner Mark Rittman
And yes, RAW data can be indexed ❍ Doug Burns
just fine. ❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
Now let me give you an example of ❍ Newbie DBA Lisa Dobson
the type of minor annoyance you ❍ Coffee-Drinking DBA Jon Emmons
have to deal with when using RAW Chris Foot
datatypes.

❍ The Pythian DBA Team Blog


Associative arrays, also referred to ❍ DBA Don Seiler
as: ❍ DBA Coskan Gundogar
1. Hash arrays: in other languages, ❍ Oracle WTF

ARCHIVES
like Perl, that is what they are called
2. "Index-by tables": because they
are declared just like nested tables ❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2005/11/raw-datatype.html (2 of 5)1/9/2008 2:54:43 AM


OracleBlog: RAW Datatype

except with "index by" added to it. ❍ May 2005


Can not use RAW datatypes as their ❍ June 2005
keys. ❍ July 2005
August 2005
For this example I will use "NUMBER"

September 2005
instead of the %ROWTYPE you would ❍

have if using RAW(16) as your ❍ October 2005


primary key. ❍ November 2005
❍ December 2005
DECLARE ❍ January 2006
TYPE ASS_TYPE IS TABLE OF NUMBER ❍ February 2006
INDEX BY RAW(16); ❍ March 2006
test_ass ASS_TYPE; ❍ April 2006
BEGIN
May 2006
test_ass(SYS_GUID()) := 1;

June 2006
test_ass(SYS_GUID()) := 2;

July 2006
test_ass(SYS_GUID()) := 3; ❍

END; ❍ August 2006


❍ September 2006
PLS-00315: Implementation ❍ October 2006
restriction: unsupported table index ❍ November 2006
type ❍ December 2006
January 2007
So you have to convert it to

February 2007
VARCHAR2 in order to use it, using

March 2007
RAWTOHEX. You can use HEXTORAW

to turn it back. Here is a working ❍ April 2007


example: ❍ May 2007
❍ June 2007
DECLARE ❍ October 2007
TYPE ASS_TYPE IS TABLE OF NUMBER
INDEX BY VARCHAR2(32);
test_ass ASS_TYPE;
BEGIN
test_ass(RAWTOHEX(SYS_GUID())) :=
1;
test_ass(RAWTOHEX(SYS_GUID())) :=
2;
test_ass(RAWTOHEX(SYS_GUID())) :=
3;
END;

---

http://thinkoracle.blogspot.com/2005/11/raw-datatype.html (3 of 5)1/9/2008 2:54:43 AM


OracleBlog: RAW Datatype

Related Info:

There is some additional


information the Oracle SQL
Reference and Oracle Application
Developer's Guide - Fundamentals.

Other binary data types, depending


on your version, include BLOB, Bfile,
LONG RAW, and others.

Here is a link to an AskTom


discussion on RAW
http://asktom.oracle.com/pls/ask/f?
p=4950:8:::::
F4950_P8_DISPLAYID:142612348066

// posted by Robert Vollman @ Monday,

November 21, 2005

Comments:
This post has been removed by a
blog administrator.
# posted by Anonymous : Saturday, 26
November, 2005

Great, concise post.


If I use a guid surrogate pk I save
table space by using raw(16) but
lose it by indexing on rawtohex(16),
right?
# posted by Anonymous : Wednesday, 19
April, 2006

Hi
Great,info on RAW datatype,
How about it using it in DBI(Perl) for
binding raw values?

http://thinkoracle.blogspot.com/2005/11/raw-datatype.html (4 of 5)1/9/2008 2:54:43 AM


OracleBlog: RAW Datatype

Is there any support for RAW in DBI?


# posted by LAKSHMINARAYANAN
SESHADRI : Friday, 22 September, 2006

If i am right SQL_BINARY or
SQL_VARBINARY are bound as RAW
in Oracle when using DBD::Oracle
(Oracle Driver).

I read using RAW datatype as PKs is


useful in making scalable,
distributed applications .Generation
of PKs is done in middleware. How
far is this true?
# posted by LAKSHMINARAYANAN
SESHADRI : Friday, 22 September, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/11/raw-datatype.html (5 of 5)1/9/2008 2:54:43 AM


OracleBlog: Recursion vs Iteration

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, June 27, 2006


About Me
Recursion vs Iteration Name: Robert Vollman
When writing code to do repetitive tasks, Location: Calgary,
the two primary approaches are iteration Alberta, Canada
and recursion. Generally you can use either
one interchangeably, but potentially with
I was born and raised
different performance and complexity.
in Ottawa, and have lived in Calgary
A recursive function calls itself (possibly since 1991. I like playing sports
more than once), with different (hockey, soccer, ultimate,
parameters, and defines an exit clause that basketball, you name it) and
is guaranteed to be reached. military board games. I also enjoy
reading, walking, and playing with
CREATE OR REPLACE FUNCTION my 2 cats Lilly and Brutus. I'm a
FIBONACCI_REC (in_number IN NUMBER) database application specialist,
RETURN NUMBER DETERMINISTIC whatever that is.
AS
BEGIN View my complete profile
CASE
WHEN in_number = 1 THEN RETURN 1;
WHEN in_number = 2 THEN RETURN 1;
ELSE RETURN (FIBONACCI_REC (in_number
Best Links
Ask Tom Kyte
- 1) + FIBONACCI_REC (in_number - 2));

END CASE; ● Oracle Docs


END; ● Dan Morgan and PSOUG
● Steven Feuerstein
An iterative function includes a loop, which ● Jonathan Lewis

http://thinkoracle.blogspot.com/2006/06/recursion-vs-iteration.html (1 of 10)1/9/2008 2:54:46 AM


OracleBlog: Recursion vs Iteration

iterates a pre-determined number of ● FAQ


times, or checks for an exit clause every ● Connor McDonald
time through. ● The Oak Table
● Cary Millsap and Hotsos
CREATE OR REPLACE FUNCTION
Steve Adams and Ixora
FIBONACCI_IT (in_number IN NUMBER)

Anjo Kolk and OraPerf


RETURN NUMBER DETERMINISTIC

Dizwell Oracle Wiki


AS ●

fib1 NUMBER := 1; ● My Personal Blog


fib2 NUMBER := 1;
fib3 NUMBER := 1;
fib4 NUMBER;
BEGIN Aggregators
FOR fib4 IN 3 .. in_number Brian Duff's OraBlogs

LOOP ❍ Eddie Awad's OracleNA


fib3 := fib1 + fib2; ❍ Pete Finnigan's Aggregator
fib1 := fib2; Oracle's Bloglist
fib2 := fib3;

Oracle Base Aggregator


END LOOP;

RETURN fib3;
END;
Top Blogs
❍ Oracle's Ask Tom Kyte
The advantages and disadvantages of the ❍ Oracle Guru Jonathan Lewis
two are not always obvious, and you ❍ Blogger of the Year Eddie Awad
should really take it on a case-by-case ❍ Data Warehouser David Aldridge
basis. When in doubt: test it. But generally: ❍ Oracle Geek Lewis Cunningham
Database Expert James Koopmann
1. Recursion may be slower, and use

Dizwell's Howard Rogers


greater resources, because of the extra

function calls. ❍ Oracle Master Laurent Schneider


❍ Security Expert Pete Finnigan
2. Recursion may lead to simpler, shorter, ❍ Oracle Award Winner Mark Rittman
easier-to-understand functions, especially ❍ Doug Burns
for mathematicians who are comfortable ❍ Oracle ACE of the Year Dr. Tim Hall
with induction formulae. ❍ UKOUG's Andrew (Arfur C.) Clarke
Newbie DBA Lisa Dobson
Either way, one of the most critical aspects

Coffee-Drinking DBA Jon Emmons


of writing either a recursive or an iterative

Chris Foot
function is to have an exit clause (or "base ❍

case" for recursions) that is checked at ❍ The Pythian DBA Team Blog
every recursion/iteration and is ❍ DBA Don Seiler
guaranteed to be reached at some finite ❍ DBA Coskan Gundogar
point, given any input. Otherwise you will ❍ Oracle WTF
get either:

http://thinkoracle.blogspot.com/2006/06/recursion-vs-iteration.html (2 of 10)1/9/2008 2:54:46 AM


OracleBlog: Recursion vs Iteration

Infinite Recursion: More and more


functions being spawned, never closing,
ARCHIVES
LIST ALL ARTICLES
using up resources until there are none

May 2005
left, possibly crashing the system.

❍ June 2005
Infinite loop: A loop that cycles forever, ❍ July 2005
burning CPU and never completing. ❍ August 2005
❍ September 2005
I can illustrate this point with my recursive ❍ October 2005
example above. Do NOT try this, but if you ❍ November 2005
inserted a negative number, what do you
December 2005
think would happen? Infinite recursion.

❍ January 2006
Now you have not only the basics on ❍ February 2006
iteration and recursion, but, based on the ❍ March 2006
topic I chose for the sample code, ❍ April 2006
knowledge that I saw "Da Vinci Code" ❍ May 2006
recently. ❍ June 2006
❍ July 2006
// posted by Robert Vollman @ Tuesday, June 27, ❍ August 2006
2006 ❍ September 2006
❍ October 2006
❍ November 2006
Comments: ❍ December 2006
Do NOT try this, but if you inserted a ❍ January 2007
negative number, what do you think would ❍ February 2007
happen? ❍ March 2007
April 2007
Did you learn that from experience? ;-)

❍ May 2007
LewisC ❍ June 2007
# posted by LewisC : Tuesday, 27 June, 2006 ❍ October 2007

You are right, recursive is much more


slower...

SQL> SELECT fibonacci_rec(35) FROM dual;

FIBONACCI_REC(35)
-----------------
9227465

http://thinkoracle.blogspot.com/2006/06/recursion-vs-iteration.html (3 of 10)1/9/2008 2:54:46 AM


OracleBlog: Recursion vs Iteration

Executed in 50,963 seconds

SQL> SELECT fibonacci_it(35) FROM dual;

FIBONACCI_IT(35)
----------------
9227465

Executed in 0,07 seconds

SQL>
# posted by Mennan : Sunday, 01 October, 2006

Your benchmark is wrong or at least very


confusing.

You are presenting two versions of


Fibonacci and you are claming that the
performance difference is due to "the extra
function calls". That's very far from being a
complete explanation and it can be very
confusing for people reading this article.

The main difference is algorithmical. The


recursion uses a trivial exponential
algorithm (because the recursive calls are
overlaping), whereas the iterative one uses
a dynamic programing altorithm with
linear execution time.

Btw. : Fibonacci is the first example of pure


algorithmic gain in a dynamic programing
course.

In order to build a correct benchmark you


must
- either chose a case where recursive and
iterative versions have the same time
complexity (say linear). For example, use
the sum of the first n integers.
- or explain that the poor performance of
the recursive function from your example

http://thinkoracle.blogspot.com/2006/06/recursion-vs-iteration.html (4 of 10)1/9/2008 2:54:46 AM


OracleBlog: Recursion vs Iteration

come from the huge algorithmic difference


and not from the lack of performance of
the recursive calls.

You should really update this post,


because as it is it represents a pure
disinformation.
# posted by Andrei Marculescu : Thursday, 08
February, 2007

"Pure disinformation?"

I make many points, you feel one of my


suggestions is correct but unclear, and you
jump to "pure disinformation?" :)

Anyway, thanks for that clarification. The


examples were provided to show how the
same problem is solved using the different
methods, not as benchmarks. But the
better performance of the iterative
function is a direct result of using
iteration. You could never find as good an
"algorithmic" solution using recursion:
every time you'd get more recursive
function calls than iterative loops.

I think this just goes to show that:


"you should really take it on a case-by-
case basis. When in doubt: test it."
# posted by Robert Vollman : Thursday, 08
February, 2007

> I make many points, you feel one of my


suggestions is
> correct but unclear, and you jump to
"pure disinformation?" :)

you are right : I should have used the word


misinformation instead. Sorry about that

> I think this just goes to show that:

http://thinkoracle.blogspot.com/2006/06/recursion-vs-iteration.html (5 of 10)1/9/2008 2:54:46 AM


OracleBlog: Recursion vs Iteration

> "you should really take it on a case-by-


case basis. When in doubt: test it."

I would say better : "When in doubt: think,


and if you are still in doubt, than test it".
The simple reason being that sometimes
thinking can go faster than testing.
:-)
# posted by Andrei Marculescu : Friday, 09
February, 2007

> You could never find as good an


"algorithmic" solution using recursion:
> every time you'd get more recursive
function calls than iterative loops

yes you can do it : use a lookup in an array


(or hash table) before doing the recursive
call. the size of the array is the maximum
number of Fibonacci we can compute. In
this case, you have n-1 calls, instead of
2^n calls (quite a difference, right ? ;-)).

something like that (Java - C# like syntax,


hope it's OK for you) :
private int[] fibonacci;

public Fibonacci() {
// this could be replaced with lazy
initialization too, but there would be an
additional overhead
fibonacci = new int
[MAX_FIBONACCI_NUMBER];
fibonacci[0] = 1;
fibonacci[1] = 1;
}

public int FibonacciRecLookup(int n) {


int fib1 = fibonacci[n-1] != 0 ? fibonacci[n-
1] : FibonacciRecLookup(n-1);
int fib2 = fibonacci[n-2] != 0 ? fibonacci[n-
2] : FibonacciRecLookup(n-2);
fibonacci[n] = fib1 + fib2;

http://thinkoracle.blogspot.com/2006/06/recursion-vs-iteration.html (6 of 10)1/9/2008 2:54:46 AM


OracleBlog: Recursion vs Iteration

return fibonacci[n];
}

Of course, in this case we have the same


number of function calls as iterative loops,
but there's another overhead : the extra
lookups. But we still have a quite simple
code, similar to the recursive one.

This can be used as a general technique to


obtain the optimal tradeof between
performance and code simplicity.
# posted by Andrei Marculescu : Friday, 09
February, 2007

"Misinformation" - Yes, who said


Rumanians had no sense of humour?

Do you believe that your provided example


is true recursion? Even if so, you seem to
be suggesting that you must use
programming techniques to make
recursion almost as fast as iteration.
Which, in the end, is still an agreement
with my initial assertions.

P.S. Testing is more reliable than thinking.


# posted by Robert Vollman : Friday, 09 February,
2007

> Do you believe that your provided


example is true recursion?

absolutely, an intelligent recursion.

> you seem to be suggesting that you


must use programming techniques to
make recursion almost as fast as iteration

I'm only suggesting that


1. when you want to compare recursive
and iterative algorithms, the only reliable

http://thinkoracle.blogspot.com/2006/06/recursion-vs-iteration.html (7 of 10)1/9/2008 2:54:46 AM


OracleBlog: Recursion vs Iteration

way to get a fair comparison is to look at


the *best* recursive and at the *best*
iterative algorithms. Unfortunately you
made a comparison between the worst
possible recursive algorithm and a good
iterative one. So your comparison can not
lead to good conclusions regarding the
"function call overhead".
2. When implementing recursion, one
should take into account that there are
many ways to do it

> Which, in the end, is still an agreement


with my initial assertions.

in your dreams :-)

> P.S. Testing is more reliable than


thinking.

that's not always true. For instance, in your


example, one can see immediately that the
recursion performs in time 2^n
(exponential) whereas the iteration
performs in time n (linear). Once you get
that, testing is useless (it takes longer and
have no added value, it only confirms an
obvious difference). If there is no strong
evidence of the algorithmic difference,
testing become more reliable.

and please note that I am not speaking of


unit or functional testing, but of
performance testing. Unit ant functional
are obviously more reliable than thinking.
But when doing performance testing,
algorithmic thinking can be a valuable tool.
# posted by Andrei Marculescu : Friday, 09
February, 2007

Now that we're talking about procedure


call overhead ...

http://thinkoracle.blogspot.com/2006/06/recursion-vs-iteration.html (8 of 10)1/9/2008 2:54:46 AM


OracleBlog: Recursion vs Iteration

http://thinkoracle.blogspot.com/2006/08/
plsql-procedure-call-overhead-re.html

(Hint: It's negligible)


# posted by Robert Vollman : Friday, 09 February,
2007

A bit late, but usually it's even faster if you


rewrite the recursive function... For
fibonacci you can find such a function at
(eg:) http://mathforum.org/library/
drmath/view/52686.html

Notice that this function does not require


you to calculate the previous n-1 results...
# posted by Tim Van Wassenhove : Wednesday, 20
June, 2007

If you don't have to calculate the previous


n-1 results, how does it qualify as
recursive?
# posted by Robert Vollman : Wednesday, 20 June,
2007

I am smart, and I have data structure


today. and I LOVE IT!

data storage is sexy once u get to feel it..


# posted by Anonymous : Thursday, 09 August,
2007

I try to compute or to google closed-form


first, when I'm computing anything like
fibonacci..
complexity is then O(1)

http://en.wikipedia.org/wiki/
Fibonacci_number#Closed_form_expression

http://thinkoracle.blogspot.com/2006/06/recursion-vs-iteration.html (9 of 10)1/9/2008 2:54:46 AM


OracleBlog: Recursion vs Iteration

# posted by www.radino.eu/blog : Thursday, 27


December, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/06/recursion-vs-iteration.html (10 of 10)1/9/2008 2:54:46 AM


OracleBlog: Refreshing Data

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, June 13, 2006


About Me
Refreshing Data Name: Robert Vollman
Moving data from one Location: Calgary, Alberta, Canada
database to another is a very
common task for a database
I was born and raised in Ottawa, and
administrator. So common, in
have lived in Calgary since 1991. I like
fact, that I have never
playing sports (hockey, soccer, ultimate,
bothered to write about it,
basketball, you name it) and military board games.
because most DBAs already
I also enjoy reading, walking, and playing with my
have their own preferred
2 cats Lilly and Brutus. I'm a database application
method.
specialist, whatever that is.
If you haven't chosen your
approach yet, allow me to View my complete profile
show you the general flow,

Best Links
some points to keep in mind,
and some of the decisions
you'll have to make based Ask Tom Kyte
upon the nature of your data

Oracle Docs
and the tools at your disposal.

● Dan Morgan and PSOUG


1. Lose Your Integrity ● Steven Feuerstein
● Jonathan Lewis
What do you do when you ● FAQ
have one tables that relies on ● Connor McDonald
another, through a foreign ● The Oak Table
key? In order to avoid having ● Cary Millsap and Hotsos

http://thinkoracle.blogspot.com/2006/06/refreshing-data.html (1 of 7)1/9/2008 2:54:49 AM


OracleBlog: Refreshing Data

your import fail, you would ● Steve Adams and Ixora


need to have the tables ● Anjo Kolk and OraPerf
loaded in the right order. Or, ● Dizwell Oracle Wiki
you could just disable all ● My Personal Blog
constraints.

Why all constraints? Why not


just the foreign keys? Well,
checking constraints takes
Aggregators
time. Presumably this is data Brian Duff's OraBlogs

you're grabbing from an ❍ Eddie Awad's OracleNA


environment where these ❍ Pete Finnigan's Aggregator
constraints have already been ❍ Oracle's Bloglist
checked, why check them ❍ Oracle Base Aggregator
again? If you don't trust that
data, don't worry, you'll catch
the errors when you try to re-
Top Blogs
Oracle's Ask Tom Kyte
enable the constraints later

Oracle Guru Jonathan Lewis


on.

❍ Blogger of the Year Eddie Awad


You may want to disable ❍ Data Warehouser David Aldridge
triggers while you're at it. ❍ Oracle Geek Lewis Cunningham
Presumably those have ❍ Database Expert James Koopmann
already fired when the data ❍ Dizwell's Howard Rogers
was first entered, and those ❍ Oracle Master Laurent Schneider
can be time consuming as ❍ Security Expert Pete Finnigan
well. ❍ Oracle Award Winner Mark Rittman
Doug Burns
While you're in the disabling

mood, drop your indexes. It ❍ Oracle ACE of the Year Dr. Tim Hall
will just take time to update ❍ UKOUG's Andrew (Arfur C.) Clarke
them with every row you ❍ Newbie DBA Lisa Dobson
insert. Just drop them now ❍ Coffee-Drinking DBA Jon Emmons
and re-create them when ❍ Chris Foot
you're done. Much faster over- ❍ The Pythian DBA Team Blog
all. ❍ DBA Don Seiler
DBA Coskan Gundogar
One more thing, you want to

Oracle WTF
do these and all subsequent

steps with logging turned off.


Why keep a redo log of each ARCHIVES
transaction? That's just taking ❍ LIST ALL ARTICLES
time and space. Chances are ❍ May 2005
your mentality is that either ❍ June 2005

http://thinkoracle.blogspot.com/2006/06/refreshing-data.html (2 of 7)1/9/2008 2:54:49 AM


OracleBlog: Refreshing Data

all the data gets in, or all of it ❍ July 2005


doesn't. ❍ August 2005
September 2005
2. Wipe Out Your Data

❍ October 2005
You may already have data in ❍ November 2005
the target database that you ❍ December 2005
want to replace. You could ❍ January 2006
insert your data in such a way ❍ February 2006
that it checks if the data ❍ March 2006
already exists before adding ❍ April 2006
it. But that takes time and ❍ May 2006
effort. Instead, you may just ❍ June 2006
want to wipe out and re-
July 2006
insert all your data.

❍ August 2006
What is the best way to ❍ September 2006
eliminate your data? Don't use ❍ October 2006
"delete." Delete is for ❍ November 2006
selectively deleting a subset ❍ December 2006
of rows, or if you want to be ❍ January 2007
able to rollback your work. ❍ February 2007
Instead, in this case, truncate ❍ March 2007
your data. No logging: much ❍ April 2007
faster. ❍ May 2007
By the way, when you're ❍ June 2007
truncating, you'll be glad that ❍ October 2007
you disabled your foreign key
constraints. Otherwise you'd
have to be very careful in the
order you truncated your
tables.

You may want to consider


using "reuse storage" which
will keep the space reserved
for the data. Since you're
probably going to be inserting
a roughly equal or superior
amount of data, this will save
you from having to expand
your extents during the
import.

http://thinkoracle.blogspot.com/2006/06/refreshing-data.html (3 of 7)1/9/2008 2:54:49 AM


OracleBlog: Refreshing Data

An alternative to all this is to


drop all the tables and then
have your import process re-
create the tables with the data
involved. That option is only
appealing if you're not 100%
confident the table structure
is the same, otherwise I don't
see the point.

Before you wipe out your


data, I'm assuming either you
already have a backup, or you
don't care about this data.
Otherwise, you should have
done this first:

3. Dump Your Data

Which is outside the scope of


this article. :)

4. Copy Your Dump

5. Import the Data

There are many different tools


you can use to import your
data, and each one has many
different methods and
options. Here is a brief list of
your choices which, of course,
depend on how you dumped
your data.

SQL*Loader/SQLLDR (Check
the Oracle Server Utilities
Guide, Part 2)
IMP utility
Oracle 10g Data Pump Export
and Import (DBMS_DATAPUMP)
Oracle Data Manager (Oracle
Enterprise Manager Console)

http://thinkoracle.blogspot.com/2006/06/refreshing-data.html (4 of 7)1/9/2008 2:54:49 AM


OracleBlog: Refreshing Data

Your own custom application


(possibly using Oracle Call
Interface/OCI).

If your data import is still


ridiculously slow, ask yourself
if you're using RAID 5. Are
you? RAID 5 is slow, man. No
getting around that, that's the
nature of the beast.

6. Restore Your Integrity

Now that the job is done, it is


time to restore your integrity
(and lose your faith in man).
Re-enable your constraints,
and triggers, and restore your
indexes. This may take some
time, so get a coffee.

7. Recalculate Statistics

In order for the optimizer to


work effectively you'll need to
re-calculate your statistics
(DBMS_STATS.
GATHER_SCHEMA_STATISTICS).
If it knows how big the tables
are, the optimizer will be able
to make the best choices in
query plans. You can import
the statistics, if they were
kept up-to-date in your
production system, but might
as well gather them now.

That's it!

This was by no means meant


to be a comprehensive step-
by-step guide with an
exhaustive list of everything
to consider. But at least now

http://thinkoracle.blogspot.com/2006/06/refreshing-data.html (5 of 7)1/9/2008 2:54:49 AM


OracleBlog: Refreshing Data

I've made an attempt to draw


out the basic flow, and some
of the things you should keep
in mind. Hopefully this will
help you design a solution of
your own, most appropriate
for your data and how you
use it.

// posted by Robert
Vollman @ Tuesday, June 13, 2006

Comments:
Rob,

Good outline. I think a lot of


people will find it useful. It's
one of those things we all
have to do but no one ever
seems to write about.

LewisC
# posted by LewisC : Tuesday, 13
June, 2006

Regarding "reuse storAGE",


HOW does append mode
insert combine with this?

I am a bit confused:

Append mode (as in insert /*


+ append */) implies blocks
are directly formatted on the
data files. I am not sure if this
means all data is created
AFTER the HWM. If
everythinhg goes after HWM,
then reuse storage would
probably not work - right?

http://thinkoracle.blogspot.com/2006/06/refreshing-data.html (6 of 7)1/9/2008 2:54:49 AM


OracleBlog: Refreshing Data

Please comment.

Thanks.
# posted by Anonymous :
Saturday, 17 June, 2006

I'm not sure I understand your


question, and I'm also not
sure I could, especially
without a test case.

I also think your best bet is to


post the question in a forum
or newsgroup where several
others could join me in having
the opportunity to help.

Thanks,
Robert
# posted by Robert Vollman :
Monday, 19 June, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/06/refreshing-data.html (7 of 7)1/9/2008 2:54:49 AM


OracleBlog: ROWNUM and ROWID

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, October 06, 2005


ROWNUM and ROWID
Questions:
How do I limit the number of rows returned by a query?
How do I write a query to get the Top-N salaries from the employee
table?
How can I add unique, sequential numbers to an existing table?
How can I differentiate between two completely identical rows?
How can I find a faster way to retrieve a queried row?
How can I find the last row processed in a big batch?

There is one thing all these questions have in common: the answer
involves either ROWNUM or ROWID.

So what is ROWNUM and ROWID?

First of all, both are covered in the SQL Reference, Basic Elements of
Oracle SQL, Chapter 2:
http://download-west.oracle.com/docs/cd/B10501_01/server.920/
a96540.pdf

They are also both referred to as pseudo-columns. That is, they are
not "real" columns that will show up when you DESC a table. They
don't actually exist anywhere in the database. But they're available for
you to use.

In fact, ROWNUM only exists for a row once it is retrieved from a

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (1 of 11)1/9/2008 2:54:52 AM


OracleBlog: ROWNUM and ROWID

query. It represents the sequential order in which Oracle has retrieved


the row. Therefore it will always exist, be at least 1, and be unique
(among the rows returned by the query). Obviously it will change from
query-to-query. Let's look at a quick example:

scott@Robert> SELECT ROWNUM, ENAME, SAL


2 FROM EMP;
ROWNUM ENAME SAL
---------- ---------- ----------
1 SMITH 800
2 ALLEN 1600
3 WARD 1250
4 JONES 2975
5 MARTIN 1250
6 BLAKE 2850
7 CLARK 2450
8 SCOTT 3000
9 VOLLMAN 5000
10 TURNER 1500
11 ADAMS 1100
12 JAMES 950
13 FORD 3000
14 MILLER 1300

Ok so let's say we want the 5 highest paid employees. Should be easy:

scott@Robert> SELECT ROWNUM, ENAME, SAL


2 FROM EMP
3 WHERE ROWNUM < 6
4 ORDER BY SAL DESC;
ROWNUM ENAME SAL
---------- ---------- ----------
4 JONES 2975
2 ALLEN 1600
3 WARD 1250
5 MARTIN 1250
1 SMITH 800

Whoops! Turns out ROWNUM is assigned before results are ordered,

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (2 of 11)1/9/2008 2:54:52 AM


OracleBlog: ROWNUM and ROWID

not after. Knowing that, we can write it like this:

scott@Robert> SELECT ENAME, SAL


2 FROM (SELECT ENAME, SAL FROM EMP ORDER BY SAL DESC) E
3 WHERE ROWNUM < 6;
ENAME SAL
---------- ----------
VOLLMAN 5000
SCOTT 3000
FORD 3000
JONES 2975
BLAKE 2850

What about ROWID? ROWID actually represents the physical location of


the record/row in the database. That being the case, it is (according to
Oracle documentation) the fastest way to retrieve a particular row.
Faster than an index, even.

Can you use ROWID to differentiate between duplicate rows?


Yes, you can. Since it actually represents the physical location of a
row, no two rows within the same table will have the same ROWID.
Notice the caveat I added: within the same table. If you're using
clustering, two records from different tables could theoretically share
the same ROWID.

Do ROWIDs change?
Yes, especially with index organized or partitioned tables. Because
ROWIDs represent the physical location of a record/row, the ROWID
will change every time the record is physically moved.

Can you use ROWID as a primary key?


No, that's not advisable. While the ROWID will be unique, you would
ideally want to use a primary key that doesn't change.

How do you use ROWID to figure out what was the last record that was
processed?
Using DBMS_SQL.LAST_ROW_ID to get the ROWID of the last row
processed.

You'll see ROWNUM and ROWID pop up occasionally within solutions


to problems on AskTom and various Discussion Forums, so I
recommend adding it to your own toolbelt as well.

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (3 of 11)1/9/2008 2:54:52 AM


OracleBlog: ROWNUM and ROWID

// posted by Robert Vollman @ Thursday, October 06, 2005

Comments:
Can I use rowid as a primary key

SQL> create table t1(c1 number);

Table created.

SQL> alter table t1 add constraint pk_t1


2 primary key (rowid);
primary key (rowid)
*
ERROR at line 2:
ORA-00904: "ROWID": invalid identifier

Not only not advisable, not doable. You won't be able to reference it in
a foreign key constraint either.

Cheers

Niall
# posted by Niall : Thursday, 06 October, 2005

> Do ROWIDs change?


also in 10g when you "shrink space", you have to enable row
movement
# posted by Laurent Schneider : Thursday, 06 October, 2005

I need to pick a nit here.

"the 5 highest paid employees"

SELECT ENAME, SAL


FROM (SELECT ENAME, SAL FROM EMP ORDER BY SAL DESC) E
WHERE ROWNUM < 6;

This is not quite correct. In reality, this query will return exactly five
employees, who will be *among* the set of employees who have the

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (4 of 11)1/9/2008 2:54:52 AM


OracleBlog: ROWNUM and ROWID

five highest salaries.

For example, if Bloggs had a salary of 2850, he may or may not


appear in the result set instead of Blake, because they have the same
salary - and on different runs of the same query you may get different
results.

The correct answer to "the 5 highest paid employees" may have more
than 5 rows, so ROWNUM is not an acceptable solution. One could use
the RANK or DENSE_RANK analytic functions to resolve this.

Cheers
Jeff
# posted by Jeffrey Kemp : Thursday, 06 October, 2005

jeff,
> () where rownum<6
I find this is correct, it is all about the specification.

Query above return the five highest paid employees. In case of


duplicates (for the 5th and 6th place for example), oracle decides who
to chose, and will never return more than five rows.

Use rank, dense_rank, row_number/rownum strictly depends on how


you are going to handle duplicates. If you do not specify it explicitely,
there is no wrong and no right answer.

cheers
Laurent
# posted by Laurent Schneider : Friday, 07 October, 2005

Rob,
Good intro to ROWNUM and ROWID. In theory, you could use ROWID as
a primary key but why would you? You will have to create a column
where you can store the ROWID and to be able to update this column
when the rows are migrated/moved.

Laurent,
I agree with Jeff that the example query that Rob showed only retrieve
the first five records not the top five highest salaries (as there could
be more than 5). I would think that a question like this from the
business will mean "show me all employees who are paid the top five

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (5 of 11)1/9/2008 2:54:52 AM


OracleBlog: ROWNUM and ROWID

salaries".
# posted by Peter K : Friday, 07 October, 2005

peter, I do not disagree with Jeff, his solution is accurate, but if


"Business" does not specify correctly , there is than no correct or
incorrect answer.

Top-N sql queries (order by in subquery), typically use this example to


define how to define the 5 highest paid employees, no matter if some
other employee has the same sal as the n°5 but do not figure in the
list.

If business want to give exactly 5 teadybears for exactly 5 persons, it


will be fine :-)

cheers
# posted by Laurent Schneider : Saturday, 08 October, 2005

How do I find, The first 3 records that were inserted into a particular
table or The last 10 records inserted into the table.
Assumption we are using distributed database and we do not have any
column storing creation date time.
# posted by Sunaad Rao : Thursday, 02 March, 2006

Sunaad,

To my knowledge, there is no easy way to tell, for any arbitrary table


with NO column (anywhere) storing creation time date and with NO
sequential IDs, which were the last n records inserted into a table.

However, there are some very smart Oracle people who may know
some trick. Try posting your question to an Oracle forum.

Thanks,
Robert
# posted by Robert Vollman : Thursday, 02 March, 2006

I have a question here.

Suppose I have a table my_tab as:

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (6 of 11)1/9/2008 2:54:52 AM


OracleBlog: ROWNUM and ROWID

SQL> desc my_tab


Name Null? Type
----------------------------------------- --------
----------------------------
COL1 NOT NULL NUMBER(38)
COL2 NOT NULL DATE
COL3 NOT NULL NUMBER(38)
COL4 NOT NULL VARCHAR2(10)

SQL> select * from my_tab;

COL1 COL2 COL3 COL4


---------- --------- ---------- ----------
1 11-NOV-81 3 sandeep
3 11-NOV-81 4 sumeet
5 11-NOV-81 6 other

Now if I run the following query to fetch the row with highest value in
cols3, I get the results as mentioned by you in your blog

SQL> select * from my_tab where rownum < 2 order by col3 desc;

COL1 COL2 COL3 COL4


---------- --------- ---------- ----------
1 11-NOV-81 3 sandeep

i.e it fetches all rows, assigns them rownum, fetches first row from the
set and then tried to perform the sorting on first row.

But if the sort key is a primary key (i.e. col1 in this case), we see
different behavior. Sorting precedes allocation of rownum:

SQL> select * from my_tab where rownum < 2 order by col1 desc;

COL1 COL2 COL3 COL4


---------- --------- ---------- ----------
5 11-NOV-81 6 other

My query is why is there a different behaviour if sort key is a primary


key.
# posted by Sandeep Warikoo : Tuesday, 02 January, 2007

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (7 of 11)1/9/2008 2:54:52 AM


OracleBlog: ROWNUM and ROWID

Sandeep,

The ROWNUM is assigned before the sort. In Oracle, rows will be


fetched in different ways (and orders) depending on things such as
keys, indexes, how the table is organised, the where clauses you used,
and so on.

That's all that is happening. You can learn more about how Oracle is
fetching the rows by looking at the query plan.

Robert
# posted by Robert Vollman : Tuesday, 02 January, 2007

This post has been removed by a blog administrator.


# posted by ashok : Thursday, 24 May, 2007

This post has been removed by a blog administrator.


# posted by ashok : Thursday, 24 May, 2007

write an ANSI-92 standard query


SELECT A.A1,B.B1
FROM A,B
WHERE A.A1=B.B1(+)
# posted by laxman : Thursday, 16 August, 2007

what is difference between in the following


select a1
from a
where exists(select 1 from b where a.a1=b.b1)

select a1
from a
where a1 in (select b.b1 from b)
# posted by laxman : Thursday, 16 August, 2007

abcd
1xyz
1abc

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (8 of 11)1/9/2008 2:54:52 AM


OracleBlog: ROWNUM and ROWID

3txz

a is primary key

a1 b1 c1 d1
1 x1 y1 z1
2 a1 b1 c1
1)updating coloumns b,c,d in table A from table B wherever join
condition is satisfied A.a=B.a1
2)results of table A after the update
# posted by laxman : Thursday, 16 August, 2007

I'm glad to make this site available as a resource, but you still have to
do your own homework.

However, you'll be happy to know that I've got articles that show you
how to answer each of your questions. Make use my site's search bar!
# posted by Robert Vollman : Thursday, 16 August, 2007

Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (9 of 11)1/9/2008 2:54:52 AM


OracleBlog: ROWNUM and ROWID

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (10 of 11)1/9/2008 2:54:52 AM


OracleBlog: ROWNUM and ROWID

❍ Newbie DBA Lisa Dobson


❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/10/rownum-and-rowid.html (11 of 11)1/9/2008 2:54:52 AM


OracleBlog: UNION ALL

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated, but it
is the most powerful tool when it comes to data. That's why when I think data, I think Oracle. I also enjoy
writing, so I use this format to organise my thoughts. Please feel free to discuss any thoughts you may
have on the same topics, even old ones (I will see and respond to such comments). You may want to
start with "LIST ALL ARTICLES" under Archives.

Wednesday, August 10, 2005


About Me
UNION ALL Name: Robert
You want to write a query that contains the rows from 2 or Vollman
more tables. What you want to use is one of Oracle's set Location: Calgary,
operators: UNION, INTERSECT, or MINUS. (Note: in the ANSI Alberta, Canada
SQL standard, MINUS is referred to as EXCEPT). My example
will deal with UNION.
I was born and raised in Ottawa,
You may have tables containing your employees, and have lived in Calgary since
contractors and clients, each with their own unique and 1991. I like playing sports
appropriate columns. For illustrative purposes, however, (hockey, soccer, ultimate,
let's consider only their names and phone numbers. basketball, you name it) and
military board games. I also
CREATE TABLE Employee (e_name VARCHAR2(32), enjoy reading, walking, and
e_phonenumber VARCHAR2(16)); playing with my 2 cats Lilly and
CREATE TABLE Contractor (c_name VARCHAR2(32), Brutus. I'm a database
c_phonenumber VARCHAR2(16), c_startcontract DATE, application specialist, whatever
c_endcontract DATE); that is.
CREATE TABLE Client (c_name VARCHAR2(32),
c_phonenumber VARCHAR2(16)); View my complete profile

Let's get some sample data:

INSERT INTO Employee VALUES ('Joe Smith', '555-555-


Best Links
1234'); ● Ask Tom Kyte
INSERT INTO Contractor VALUES ('Adam Johnson', '555- ● Oracle Docs
555-8888', '01-Jan-04', '01-Mar-04'); ● Dan Morgan and PSOUG
INSERT INTO Contractor VALUES ('Bob Jackson', '555-555- ● Steven Feuerstein
1111', '01-Jan-04', NULL); ● Jonathan Lewis
INSERT INTO Contractor VALUES ('Adam Johnson', '555- ● FAQ
555-8888', '01-Jan-05', '01-Mar-05'); Connor McDonald
INSERT INTO Client VALUES ('Bill Taylor', '555-555-6767');

The Oak Table


INSERT INTO Client VALUES ('Adam Johnson', '555-555-

Cary Millsap and Hotsos


8888');

● Steve Adams and Ixora


What you would like to do is create a view to contain all the ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2005/08/union-all.html (1 of 5)1/9/2008 2:54:55 AM


OracleBlog: UNION ALL

phone numbers. You can use the UNION operator, which is ● Dizwell Oracle Wiki
very easy. Write your queries however you wish, just make ● My Personal Blog
sure that they all have the same number of columns and
similar data types.

SELECT e_name, e_phonenumber FROM Employee


UNION
Aggregators
SELECT c_name, c_phonenumber FROM Contractor Brian Duff's OraBlogs

UNION ❍ Eddie Awad's OracleNA


SELECT c_name, c_phonenumber FROM Client; ❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
E_NAME E_PHONENUMBER ❍ Oracle Base Aggregator
--------------------------------
Adam Johnson
----------------
555-555-8888 Top Blogs
Bill Taylor 555-555-6767 ❍ Oracle's Ask Tom Kyte
Bob Jackson 555-555-1111 ❍ Oracle Guru Jonathan Lewis
Joe Smith 555-555-1234 ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
Excellent! ❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
But observe two things: ❍ Oracle Master Laurent Schneider
1. The order of the results have been re-arranged ❍ Security Expert Pete Finnigan
2. There are no duplicates. ❍ Oracle Award Winner Mark
Rittman
Actually, 1 and 2 are tied closely together. Oracle re-
Doug Burns
arranges the results in order to put identical rows next to ❍

each other and remove duplicates. On large tables, you ❍ Oracle ACE of the Year Dr. Tim
may get a bit of a performance hit. Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
If you don't care about removing duplicates, or especially if ❍ Newbie DBA Lisa Dobson
you want the duplicates, use UNION ALL instead: ❍ Coffee-Drinking DBA Jon Emmons
Chris Foot
SELECT e_name, e_phonenumber FROM Employee

The Pythian DBA Team Blog


UNION ALL

DBA Don Seiler


SELECT c_name, c_phonenumber FROM Contractor

DBA Coskan Gundogar


UNION ALL ❍

SELECT c_name, c_phonenumber FROM Client; ❍ Oracle WTF

E_NAME E_PHONENUMBER ARCHIVES


-------------------------------- ---------------- ❍ LIST ALL ARTICLES
Joe Smith 555-555-1234 ❍ May 2005
Adam Johnson 555-555-8888 ❍ June 2005
Bob Jackson 555-555-1111 ❍ July 2005
Adam Johnson 555-555-8888 ❍ August 2005
Bill Taylor 555-555-6767 ❍ September 2005
Adam Johnson 555-555-8888
❍ October 2005
❍ November 2005
❍ December 2005
If you want them sorted, but don't want duplicates ❍ January 2006

http://thinkoracle.blogspot.com/2005/08/union-all.html (2 of 5)1/9/2008 2:54:55 AM


OracleBlog: UNION ALL

removed, you can include an ORDER BY clause. Use UNION ❍ February 2006
with ORDER BY if you want duplicates removed and you ❍ March 2006
want a guaranteed order. ❍ April 2006
May 2006
SELECT e_name, e_phonenumber FROM Employee

June 2006
UNION ALL

July 2006
SELECT c_name, c_phonenumber FROM Contractor

UNION ALL ❍ August 2006


SELECT c_name, c_phonenumber FROM Client ❍ September 2006
ORDER BY 1; ❍ October 2006
❍ November 2006
❍ December 2006
E_NAME E_PHONENUMBER ❍ January 2007
-------------------------------- ----------------
❍ February 2007
Adam Johnson 555-555-8888
❍ March 2007
Adam Johnson 555-555-8888
❍ April 2007
Adam Johnson 555-555-8888
Bill Taylor 555-555-6767 ❍ May 2007
Bob Jackson 555-555-1111 ❍ June 2007
Joe Smith 555-555-1234 ❍ October 2007

If you just want to remove duplicates within tables, but not


in the merged set, try the DISTINCT clause.

SELECT DISTINCT e_name, e_phonenumber FROM Employee


UNION ALL
SELECT DISTINCT c_name, c_phonenumber FROM
Contractor
UNION ALL
SELECT DISTINCT c_name, c_phonenumber FROM Client;

E_NAME E_PHONENUMBER
-------------------------------- ----------------
Joe Smith 555-555-1234
Adam Johnson 555-555-8888
Bob Jackson 555-555-1111
Adam Johnson 555-555-8888
Bill Taylor 555-555-6767

I guess it all depends what you want.

Here is Dan Morgan's reference on Built-In Operators:


http://www.psoug.org/reference/ora_operators.html

But you also want to check out the Oracle SQL Reference,
Chapter 8: SQL Queries and Subqueries.

For your reading pleasure, check out this article by

http://thinkoracle.blogspot.com/2005/08/union-all.html (3 of 5)1/9/2008 2:54:55 AM


OracleBlog: UNION ALL

Jonathan Gennick on set operators, including UNION:


http://five.pairlist.net/pipermail/oracle-
article/2003/000003.html

Administrative note: I've added a new section to include the


links to all the Oracle blogs I regularly visit, to save you
from going here:
http://thinkoracle.blogspot.com/2005/07/oracle-blogs.
html

// posted by Robert Vollman @ Wednesday, August 10, 2005

Comments:
I'm a little surprised by your implication that if you use a
UNION then Oracle will sort the results for you without you
using an order by.

It's definately what it appears to do, but Oracle makes no


promises of the fact. Certainly I can find no evidence here
or here.
I believe it wil sort the results in a way that will make it
possible for the UNION to take place, which may or may not
be sorted as far as a human user is concerned.

To quote Tom Kyte (from here)

"you want data sorted? You better use ORDER BY"


# posted by Rob Baillie : Thursday, 11 August, 2005

Thanks - that was a serious enough error that I edited the


article.

Thanks also for the links. Based on appearances, it's easy


to assume that UNION will predictably order your results,
but that's actually an unsafe, false assumption to rely on.
# posted by Robert Vollman : Thursday, 11 August, 2005

The website is very useful for freshers like me


continue ur support to people like me
hats off!!
# posted by Anonymous : Friday, 25 May, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/08/union-all.html (4 of 5)1/9/2008 2:54:55 AM


OracleBlog: UNION ALL

http://thinkoracle.blogspot.com/2005/08/union-all.html (5 of 5)1/9/2008 2:54:55 AM


http://thinkoracle.blogspot.com/2006/04/updating-views.html

S4 Ind Software Pvt Ltd

URL you requested has been blocked. URL = thinkoracle.


blogspot.com/2006/04/updating-views.html

For Technical Support Contact : sysadmin

http://thinkoracle.blogspot.com/2006/04/updating-views.html1/9/2008 2:54:55 AM
OracleBlog: Using Bad Names in Oracle

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, June 27,


About Me
2005
Name: Robert Vollman
Using Bad Location: Calgary, Alberta, Canada
Names in
Oracle I was born and raised in Ottawa, and have lived in
In Oracle, you Calgary since 1991. I like playing sports (hockey,
can't start a table, soccer, ultimate, basketball, you name it) and military board
procedure or games. I also enjoy reading, walking, and playing with my 2 cats
variable name Lilly and Brutus. I'm a database application specialist, whatever
with a number. that is.

SQL> CREATE View my complete profile


TABLE 123Table
(aval NUMBER);
CREATE TABLE
123Table (aval
Best Links
Ask Tom Kyte
NUMBER)

* ● Oracle Docs
ERROR at line 1: ● Dan Morgan and PSOUG
ORA-00903: ● Steven Feuerstein
invalid table name ● Jonathan Lewis
● FAQ
You can get ● Connor McDonald
around this ● The Oak Table
simply using Cary Millsap and Hotsos
quotes.

● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/06/using-bad-names-in-oracle.html (1 of 3)1/9/2008 2:54:59 AM


OracleBlog: Using Bad Names in Oracle

● Anjo Kolk and OraPerf


SQL> CREATE ● Dizwell Oracle Wiki
TABLE ● My Personal Blog
"123Table" (aval
NUMBER);

Table created.
Aggregators
This will take the Brian Duff's OraBlogs

name very ❍ Eddie Awad's OracleNA


literally. So ❍ Pete Finnigan's Aggregator
literally, in fact, ❍ Oracle's Bloglist
that you can no Oracle Base Aggregator
longer rely on

Oracle's typical
case-insensitivity.
Top Blogs
❍ Oracle's Ask Tom Kyte
SQL> drop table ❍ Oracle Guru Jonathan Lewis
"123TABLE"; ❍ Blogger of the Year Eddie Awad
drop table ❍ Data Warehouser David Aldridge
"123TABLE" ❍ Oracle Geek Lewis Cunningham
* Database Expert James Koopmann
ERROR at line 1:

Dizwell's Howard Rogers


ORA-00942:

Oracle Master Laurent Schneider


table or view does

Security Expert Pete Finnigan


not exist ❍

❍ Oracle Award Winner Mark Rittman


You can also use ❍ Doug Burns
quotes to use ❍ Oracle ACE of the Year Dr. Tim Hall
reserved words. ❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
SQL> CREATE
Coffee-Drinking DBA Jon Emmons
TABLE

Chris Foot
"TABLE" ("NUMBER"

The Pythian DBA Team Blog


NUMBER);

❍ DBA Don Seiler


Table created. ❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
// posted by Robert
Vollman @ Monday,

June 27, 2005 ❍ LIST ALL ARTICLES


❍ May 2005
❍ June 2005
Comments: ❍ July 2005

http://thinkoracle.blogspot.com/2005/06/using-bad-names-in-oracle.html (2 of 3)1/9/2008 2:54:59 AM


OracleBlog: Using Bad Names in Oracle

Post a ❍ August 2005


Comment ❍ September 2005
❍ October 2005
<< Home ❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/06/using-bad-names-in-oracle.html (3 of 3)1/9/2008 2:54:59 AM


OracleBlog: Using DECODE to exploit COUNT/NULL feature

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics, even
old ones (I will see and respond to such comments). You may want to start with "LIST ALL
ARTICLES" under Archives.

Tuesday, October 04, 2005


Using DECODE to exploit COUNT/NULL feature
Not long ago, I mentioned that if you do a COUNT on a column (as
opposed to on * or a constant), the result will not include rows that have a
NULL value for that column.

http://thinkoracle.blogspot.com/2005/09/nulls-in-count.html

Apparently you can exploit this situation, by using DECODE, and improve
the efficiency of your queries.

http://www.akadia.com/services/ora_decode.html

I found that very interesting. However, I had to check it for myself. Why?
Because this assertion may be:
1. Applicable only to a different version than mine (9.2.0.6).
2. Misunderstood by me.
3. Just plain wrong.

Note: My first attempt at this was a case of #2, therefore this article was
updated after my error was kindly pointed out by Gary Myers

Here is the test I ran which confirmed the results.

CREATE TABLE ReallyBigTable AS SELECT * FROM all_objects;

**Note: I did this about 15-20 times to get a really big table.

http://thinkoracle.blogspot.com/2005/10/using-decode-to-exploit-countnull.html (1 of 8)1/9/2008 2:55:02 AM


OracleBlog: Using DECODE to exploit COUNT/NULL feature

ALTER SESSION SET SQL_TRACE = TRUE;

SELECT rbt1.the_count, rbt1.the_sum,


rbt2.the_count, rbt2.the_sum FROM
(SELECT COUNT(*) the_count, SUM(object_id) the_sum
FROM ReallyBigTable WHERE object_type='TABLE') rbt1,
(SELECT COUNT(*) the_count, SUM(object_id) the_sum
FROM ReallyBigTable WHERE object_type='INDEX') rbt2;

ALTER SESSION SET SQL_TRACE = FALSE;

TKPROF robert_ora_2236.trc robert_ora_2236.prf explain='sys/******** as


sysdba'

ALTER SESSION SET SQL_TRACE = TRUE;

SELECT COUNT(DECODE(object_type,'TABLE','*',NULL)) the_count,


SUM(DECODE(object_type,'TABLE',object_id,NULL)) the_sum,
COUNT(DECODE(object_type,'INDEX','*',NULL)) the_count2,
SUM(DECODE(object_type,'INDEX',object_id,NULL)) the_sum2
FROM ReallyBigTable;

ALTER SESSION SET SQL_TRACE = FALSE;

TKPROF robert_ora_2416.trc robert_ora_2416.prf explain='sys/******** as


sysdba'

The DECODE version completed twice as quickly, because it only need to


make one pass through the data instead of 2.

Excerpt of the results:

SELECT rbt1.the_count, rbt1.the_sum,


rbt2.the_count, rbt2.the_sum FROM
(SELECT COUNT(*) the_count, SUM(object_id)
the_sum FROM ReallyBigTable
WHERE object_type='TABLE') rbt1,
(SELECT COUNT(*) the_count, SUM(object_id)
the_sum FROM ReallyBigTable
WHERE object_type='INDEX') rbt2
call count cpu elapsed disk query
------- ------ -------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0
Execute 1 0.00 0.00 0 0
Fetch 2 0.64 2.97 16994 17542

http://thinkoracle.blogspot.com/2005/10/using-decode-to-exploit-countnull.html (2 of 8)1/9/2008 2:55:02 AM


OracleBlog: Using DECODE to exploit COUNT/NULL feature

------- ------ -------- ---------- ---------- ----------


total 4 0.64 2.97 16994 17542
SELECT COUNT(DECODE(object_type,'TABLE','*',NULL)) the_count,
SUM(DECODE(object_type,'TABLE',object_id,NULL)) the_sum,
COUNT(DECODE(object_type,'INDEX','*',NULL)) the_count2,
SUM(DECODE(object_type,'INDEX',object_id,NULL)) the_sum2
FROM ReallyBigTable
call count cpu elapsed disk query
------- ------ -------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0
Execute 1 0.00 0.00 0 0
Fetch 2 0.60 1.76 8498 8771
------- ------ -------- ---------- ---------- ----------
total 4 0.60 1.76 8498 8771

// posted by Robert Vollman @ Tuesday, October 04, 2005

Comments:
I think the implication of
http://www.akadia.com/services/ora_decode.html
was that, rather than running two queries with similar predicates, you can
just run one, using decodes (or CASE) to differentiate the results into
separate columns.

Your test could be changed to measure


SELECT COUNT(*), SUM(object_id) FROM ReallyBigTable
WHERE object_type='TABLE'
and
SELECT COUNT(*), SUM(object_id) FROM ReallyBigTable
WHERE object_type='INDEX'

against

SELECT COUNT(DECODE(object_type,'TABLE','*',NULL)) tab_count,


SUM(DECODE(object_type,'TABLE',object_id,NULL)) tab_sum
COUNT(DECODE(object_type,'INDEX','*',NULL)) ind_count,
SUM(DECODE(object_type,'INDEX',object_id,NULL)) ind_sum
FROM ReallyBigTable
where object_type in ('TABLE','INDEX')

What surprised me about your results is the increase in disk. I'd expect

http://thinkoracle.blogspot.com/2005/10/using-decode-to-exploit-countnull.html (3 of 8)1/9/2008 2:55:02 AM


OracleBlog: Using DECODE to exploit COUNT/NULL feature

both to do a full scan, and so come out the same there.


# posted by Gary Myers : Tuesday, 04 October, 2005

This is similar to what I was discussing in http://doug.burns.tripod.com/


decode.html and if you compare apples to apples, as mentioned by Gary,
I've always seen an improvement.

Cheers,

Doug
# posted by Doug Burns : Wednesday, 05 October, 2005

Then I guess this was a case of #2 (misunderstood!)

Expect the corrected version of that post very shortly and thanks for the
help Gary and Doug.
# posted by Robert Vollman : Wednesday, 05 October, 2005

Hi Rob,

Whilst I know this is only intended as a pure performance comparison, I


found this example a bit confusing

"SELECT COUNT(DECODE(object_type,'TABLE','*',NULL)) the_count,


SUM(DECODE(object_type,'TABLE',object_id,NULL)) the_sum,
COUNT(DECODE(object_type,'INDEX','*',NULL)) the_count2,
SUM(DECODE(object_type,'INDEX',object_id,NULL)) the_sum2
FROM ReallyBigTable"

mainly because I'm not sure why you would SUM(object_id). I know it's just
gash test data, but even then, adding one to the total would be closer to
what you'd do in a real app as it would give you a sensible result i.e. How
many object_type='TABLE' and how many object_type='INDEX'. Summing
object_id would give you a total that doesn't seem very useful. So maybe
this would be clearer?

"SELECT SUM(DECODE(object_type,'TABLE',1)) num_tables,


SUM(DECODE(object_type,'INDEX',1)) num_indexes
FROM ReallyBigTable"

You also don't strictly need the NULLs in there at all as they're implicit.

http://thinkoracle.blogspot.com/2005/10/using-decode-to-exploit-countnull.html (4 of 8)1/9/2008 2:55:02 AM


OracleBlog: Using DECODE to exploit COUNT/NULL feature

CASE would be another, more flexible alternative.

Just suggestions. Hope they make sense.

Cheers,

Doug
# posted by Doug Burns : Wednesday, 05 October, 2005

Thanks Doug:

1. There was no practical business purpose to this example, I just wanted


to SUM something, and object_id was the first numerical column I saw.

2. I don't like to "rely" on things (like the NULL being the default case)
unless I have to. This makes it (1) obvious what the default case is, and (2)
makes it more resilient to changes in future versions. Just personal
perference.

3. I like DECODE. :)
# posted by Robert Vollman : Wednesday, 05 October, 2005

"2. I don't like to "rely" on things (like the NULL being the default case)
unless I have to. This makes it (1) obvious what the default case is, and (2)
makes it more resilient to changes in future versions. Just personal
perference."

No, that's a good policy, not just preference.

"3. I like DECODE. :)"

There's no accounting for taste ;-)

Cheers,

Doug
# posted by Doug Burns : Wednesday, 05 October, 2005

Ha, I see you have changed the test cases. I have been meaning to
comment on the fact that the akadia article was to show that you can use
DECODE to do a single pass of the data instead of multiple passes via

http://thinkoracle.blogspot.com/2005/10/using-decode-to-exploit-countnull.html (5 of 8)1/9/2008 2:55:02 AM


OracleBlog: Using DECODE to exploit COUNT/NULL feature

multiple SELECTS (as Gary mentioned) in which case, you would expect the
DECODE (single pass) to be more efficient.

Good job.
# posted by Peter K : Friday, 07 October, 2005

Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2005/10/using-decode-to-exploit-countnull.html (6 of 8)1/9/2008 2:55:02 AM


OracleBlog: Using DECODE to exploit COUNT/NULL feature

● Dizwell Oracle Wiki


● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
Oracle's Ask Tom Kyte

❍ Oracle Guru Jonathan Lewis


❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005

http://thinkoracle.blogspot.com/2005/10/using-decode-to-exploit-countnull.html (7 of 8)1/9/2008 2:55:02 AM


OracleBlog: Using DECODE to exploit COUNT/NULL feature

❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/10/using-decode-to-exploit-countnull.html (8 of 8)1/9/2008 2:55:02 AM


OracleBlog: Variable Constraints

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday, June 15, 2005


About Me
Variable Constraints Name: Robert Vollman
You can't use variables in Location: Calgary, Alberta, Canada
constraints.

CREATE OR REPLACE PACKAGE I was born and raised in Ottawa, and


test_constants IS have lived in Calgary since 1991. I
test_val CONSTANT NUMBER := like playing sports (hockey, soccer, ultimate,
20; basketball, you name it) and military board
END test_constants; games. I also enjoy reading, walking, and playing
with my 2 cats Lilly and Brutus. I'm a database
CREATE TABLE atable ( application specialist, whatever that is.
a_id NUMBER,
CONSTRAINT atable_test View my complete profile
CHECK (a_id > test_constants.
test_val)
); Best Links
ORA-00904: ● Ask Tom Kyte
"TEST_CONSTANTS"."TEST_VAL": ● Oracle Docs
invalid identifier ● Dan Morgan and PSOUG
● Steven Feuerstein
Check Constraints can NOT ● Jonathan Lewis
contain subqueries, so forget ● FAQ
about doing it that way. ● Connor McDonald
The Oak Table
It is basically only for ●

comparisons and simple ● Cary Millsap and Hotsos

http://thinkoracle.blogspot.com/2005/06/variable-constraints.html (1 of 3)1/9/2008 2:55:05 AM


OracleBlog: Variable Constraints

operations. ● Steve Adams and Ixora


● Anjo Kolk and OraPerf
How about this convoluted way ● Dizwell Oracle Wiki
of achieving the goal. Create a ● My Personal Blog
trigger that will check the value
upon insert or update, and
then trigger a special
constraint.
Aggregators
SQL> CREATE TABLE atable ( Brian Duff's OraBlogs

2 a_id NUMBER, ❍ Eddie Awad's OracleNA


3 a_error NUMBER, ❍ Pete Finnigan's Aggregator
4 CONSTRAINT id_too_high ❍ Oracle's Bloglist
CHECK (a_error <> 1) ❍ Oracle Base Aggregator
5 );

Table created.
Top Blogs
❍ Oracle's Ask Tom Kyte
SQL> CREATE OR REPLACE ❍ Oracle Guru Jonathan Lewis
TRIGGER atable_trig ❍ Blogger of the Year Eddie Awad
2 BEFORE INSERT OR UPDATE ❍ Data Warehouser David Aldridge
OF a_id ON atable FOR EACH Oracle Geek Lewis Cunningham
ROW

Database Expert James Koopmann


3 BEGIN

Dizwell's Howard Rogers


4 IF :new.a_id > test_constants.

Oracle Master Laurent Schneider


test_val THEN :new.a_error := ❍

1; ❍ Security Expert Pete Finnigan


5 END IF; ❍ Oracle Award Winner Mark Rittman
6 END; ❍ Doug Burns
7/ ❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
Trigger created. ❍ Newbie DBA Lisa Dobson
Coffee-Drinking DBA Jon Emmons
SQL> INSERT INTO atable (a_id)

Chris Foot
VALUES (1);

❍ The Pythian DBA Team Blog


1 row created. ❍ DBA Don Seiler
❍ DBA Coskan Gundogar
SQL> INSERT INTO atable (a_id) ❍ Oracle WTF
VALUES (21);
INSERT INTO atable (a_id)
VALUES (21)
ARCHIVES
* ❍ LIST ALL ARTICLES
ERROR at line 1: ❍ May 2005
❍ June 2005

http://thinkoracle.blogspot.com/2005/06/variable-constraints.html (2 of 3)1/9/2008 2:55:05 AM


OracleBlog: Variable Constraints

ORA-02290: check constraint ❍ July 2005


(SCOTT.ID_TOO_HIGH) violated ❍ August 2005
September 2005
Check the comments to see if

October 2005
someone has a better way.

❍ November 2005
Related links: ❍ December 2005
http://thinkoracle.blogspot. ❍ January 2006
com/2005/05/enum-in-oracle. ❍ February 2006
html ❍ March 2006
❍ April 2006
// posted by Robert ❍ May 2006
Vollman @ Wednesday, June 15, 2005 ❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
Comments: ❍ October 2006
Well, just use *CONTEXTS* for ❍ November 2006
that ... :o) ❍ December 2006
# posted by Anonymous : Saturday, ❍ January 2007
15 April, 2006 ❍ February 2007
❍ March 2007
April 2007
Post a Comment

❍ May 2007
<< Home ❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/06/variable-constraints.html (3 of 3)1/9/2008 2:55:05 AM


OracleBlog: View Constraints

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday,
About Me
November 10,
Name: Robert Vollman
2006
Location: Calgary, Alberta, Canada
View
Constraints I was born and raised in Ottawa, and have lived in
You have a table Calgary since 1991. I like playing sports (hockey,
with all your soccer, ultimate, basketball, you name it) and military board
company's games. I also enjoy reading, walking, and playing with my 2 cats
financial Lilly and Brutus. I'm a database application specialist, whatever
transactions. that is.
There is another
table which View my complete profile
references a
subset of these
financial
transactions (ie.
Best Links
transactions with ● Ask Tom Kyte
certain ● Oracle Docs
properties). ● Dan Morgan and PSOUG
● Steven Feuerstein
Your current ● Jonathan Lewis
solution to ● FAQ
maintain the Connor McDonald
integrity is to set

● The Oak Table


up a foreign key,
Cary Millsap and Hotsos
referencing the

● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (1 of 11)1/9/2008 2:55:07 AM


OracleBlog: View Constraints

transactions ● Anjo Kolk and OraPerf


table, and then ● Dizwell Oracle Wiki
write a trigger to ● My Personal Blog
make sure that
any records
reference only
transactions that
have the correct
Aggregators
Brian Duff's OraBlogs
properties.

❍ Eddie Awad's OracleNA


However, you ❍ Pete Finnigan's Aggregator
were struck with ❍ Oracle's Bloglist
a brilliant idea to ❍ Oracle Base Aggregator
use views for a
more elegant Top Blogs
solution. You ❍ Oracle's Ask Tom Kyte
create a view on Oracle Guru Jonathan Lewis
the transactions

Blogger of the Year Eddie Awad


table that

Data Warehouser David Aldridge


contains only the

proper subset, ❍ Oracle Geek Lewis Cunningham


and then set up ❍ Database Expert James Koopmann
a foreign key to ❍ Dizwell's Howard Rogers
the view instead. ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
You create the ❍ Oracle Award Winner Mark Rittman
view, including ❍ Doug Burns
the appropriate Oracle ACE of the Year Dr. Tim Hall
primary key

UKOUG's Andrew (Arfur C.) Clarke


constraint, and

Newbie DBA Lisa Dobson


you're all set to

go. Except when ❍ Coffee-Drinking DBA Jon Emmons


you create your ❍ Chris Foot
table to ❍ The Pythian DBA Team Blog
reference that ❍ DBA Don Seiler
view, you see ❍ DBA Coskan Gundogar
this: ❍ Oracle WTF

ERROR at line 1:
ORA-02270: no
ARCHIVES
matching unique ❍ LIST ALL ARTICLES
or primary key ❍ May 2005
for this column- ❍ June 2005
list ❍ July 2005

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (2 of 11)1/9/2008 2:55:07 AM


OracleBlog: View Constraints

❍ August 2005
Have you done ❍ September 2005
something ❍ October 2005
wrong? ❍ November 2005
December 2005
No. You've come ❍

up with a very ❍ January 2006


clever solution, ❍ February 2006
but ❍ March 2006
unfortunately ❍ April 2006
one that isn't ❍ May 2006
supported. ❍ June 2006
According to ❍ July 2006
Oracle's SQL ❍ August 2006
Reference, ❍ September 2006
"Oracle does not ❍ October 2006
enforce view ❍ November 2006
constraints. ❍ December 2006
However, you
January 2007
can enforce

February 2007
constraints on

March 2007
views through ❍

constraints on ❍ April 2007


base tables." ❍ May 2007
❍ June 2007
Of course, ❍ October 2007
referencing the
base table
doesn't do you
any good,
because there
are transactions
in there that
aren't valid
references for
your new table.
Quoting Dan
Morgan: "The
point of the
syntax is to
prevent
violations when
people do DML

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (3 of 11)1/9/2008 2:55:07 AM


OracleBlog: View Constraints

(inserts, updates,
deletes through
the view). It does
not truly serve
the same
purpose as a
"real" primary
key and can not
be used in the
same way."

However,
reading on, both
Table 17-3
(Object Privileges
Available for
Particular
Objects) and this
sentence seems
to offer some
hope that your
solution can be
achieved. "To
create a foreign
key constraint, in
addition, the
parent table or
view must be in
your own
schema, or you
must have the
REFERENCES
privilege on the
columns of the
referenced key in
the parent table
or view."

Alas, the
documentation is
misleading here.
It's talking about
the view itself

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (4 of 11)1/9/2008 2:55:07 AM


OracleBlog: View Constraints

having a foreign
key, not the
primary. Observe.

SQL> CREATE
TABLE basetable
2 (id VARCHAR2
(32) PRIMARY
KEY, amount
NUMBER(10),
other_columns
VARCHAR2(32));

Table created.

SQL> GRANT
REFERENCES (id)
ON basetable TO
PUBLIC;

Grant succeeded.

SQL> CREATE OR
REPLACE
base_view
2 AS SELECT *
FROM basetable
WHERE amount >
100;

View created.

SQL> ALTER view


base_view ADD
CONSTRAINT
pk_view PRIMARY
KEY (id) RELY
DISABLE
NOVALIDATE;

View altered.

SQL> GRANT
REFERENCES (id)
ON base_view TO

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (5 of 11)1/9/2008 2:55:07 AM


OracleBlog: View Constraints

PUBLIC;

Grant succeeded.

SQL> CREATE
TABLE referring
(person
VARCHAR2(32)
PRIMARY KEY,
2 base_id
REFERENCES
base_view(id));
CREATE TABLE
referring (person
VARCHAR2(32)
PRIMARY KEY,
*
ERROR at line 1:
ORA-02270: no
matching unique
or primary key
for this column-
list

That is not to say


that there isn't a
more elegant
solution to your
problem. One of
the many things
I've learned
about Oracle is
this: if
something clever
isn't working, re-
examine your
schema.

In fact that is
precisely the
advice that
Oracle ACE
Andrew "Arfur

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (6 of 11)1/9/2008 2:55:07 AM


OracleBlog: View Constraints

C." Clarke gave


someone in your
exact same
position, who
had wisely
posted his
problem to a
forum (instead of
asking a dummy
like me).

For instance, you


could instead
create a table
representing the
subset of
financial
transactions you
want, and
another
identically-
structured table
for all other
transactions, and
then your
transactions
table could be a
view of both.
That's what one
expert
considered.
However, I'm not
sure that's what
you want:
maintaining two
identical tables.
Plus, now your
financial
transactions
table is a view
and can't be
referenced,
putting you in

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (7 of 11)1/9/2008 2:55:07 AM


OracleBlog: View Constraints

the same boat


for some other
table.

I didn't intend to
offer a specific
suggestion for
your schema
because it would
require knowing
a lot more about
your business,
these tables, and
what your
requirements
really are. I'm
just saying that
there may be an
elegant solution
if you take a
closer look.

I preach views
because they
serve so many
useful purposes.
Unfortunately,
managing this
type of integrity
constraint
directly isn't one
of them. Stick to
your trigger.

// posted by Robert
Vollman @ Friday,
November 10, 2006

Comments:
You could use
materialized

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (8 of 11)1/9/2008 2:55:07 AM


OracleBlog: View Constraints

views to solve
this kind of
problem.

Create an MV
instead of an
ordinary view;
then you can
apply (and
enforce) any
constraints on
the table that is
created to
support the MV.
# posted by
Jeffrey Kemp :
Saturday, 11
November, 2006

Well, it seems
like subclassing.
If some entity A
exists on ER
diagramm (Or
base table in db
schema), which
references a
subset of
instances (rows)
of another entity
B, then you
certainly have a
subclass of B
representing that
subset. You may
try to implement
subclassing in
several ways,
trigger or MV or
somehow else. I
usually prefer
more common

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (9 of 11)1/9/2008 2:55:07 AM


OracleBlog: View Constraints

(as I believe)
solution - two
tables with the
"shared" same id
column. I.e.:

create table B(idb


int not null,
constraint pkB
primary key
(idb));
create table C
(idb int not null,
constraint fkC
foreign key (idb)
references B
(idb));
and may be:
create table D
(idd int not null,
constraint fkD
foreign key (idd)
references B
(idb));

then you have a


choice on how to
distribute rest of
columns
between B,C and
D.

after that you


can reference
needed table:
create table A
(ida int not null,
idb int,constraint
fkA foreign key
(idb) references C
(idb));

Still any view can


combine B,C,D

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (10 of 11)1/9/2008 2:55:07 AM


OracleBlog: View Constraints

as necessary.

Check the link:


http://www.orm.
net/pdf/Subtype.
pdf
# posted by
Michael
Mekhanoshin :
Saturday, 27 January,
2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/11/view-constraints.html (11 of 11)1/9/2008 2:55:07 AM


OracleBlog: Which instance am I in?

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, July 18, 2005


About Me
Which Name: Robert Vollman
instance am I Location: Calgary, Alberta, Canada
in?
Here's an easy one a I was born and raised in Ottawa, and have lived
colleague asked me. in Calgary since 1991. I like playing sports
(hockey, soccer, ultimate, basketball, you name it) and
You are logged into military board games. I also enjoy reading, walking, and
your default session playing with my 2 cats Lilly and Brutus. I'm a database
(example: sqlplus application specialist, whatever that is.
scott/tiger with no
@instance) View my complete profile

You want to know


which instance you
are logged into.
Best Links
● Ask Tom Kyte
You can't query V$ ● Oracle Docs
tables directly, ● Dan Morgan and PSOUG
because you're not ● Steven Feuerstein
logged in as SYS. ● Jonathan Lewis
FAQ
So while looking

Connor McDonald
around at similar ●

questions on Jonathan ● The Oak Table


Lewis' cooperative ● Cary Millsap and Hotsos
FAQ: ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/07/which-instance-am-i-in.html (1 of 3)1/9/2008 2:55:10 AM


OracleBlog: Which instance am I in?

http://www.jlcomp. ● Anjo Kolk and OraPerf


demon.co.uk/faq/ ● Dizwell Oracle Wiki
MySessID.html ● My Personal Blog

I saw SYS_CONTEXT.

Aggregators
That looked like it
would do the trick. So
I looked it up in my Brian Duff's OraBlogs

favourite reference,
Eddie Awad's OracleNA
Dan Morgan's:

Pete Finnigan's Aggregator


http://www.psoug.

Oracle's Bloglist
org/reference/

Oracle Base Aggregator


sys_context.html

And came up with Top Blogs


this: ❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
SELECT SYS_CONTEXT ❍ Blogger of the Year Eddie Awad
(‘USERENV’,’DB_NAME’) ❍ Data Warehouser David Aldridge
FROM DUAL; ❍ Oracle Geek Lewis Cunningham
You can also get the ❍ Database Expert James Koopmann
'INSTANCE' using this, ❍ Dizwell's Howard Rogers
but that doesn't do ❍ Oracle Master Laurent Schneider
you any good if you ❍ Security Expert Pete Finnigan
can't query the V ❍ Oracle Award Winner Mark Rittman
$INSTANCE table. ❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
That solves the UKOUG's Andrew (Arfur C.) Clarke
problem, but I'm sure

Newbie DBA Lisa Dobson


that's just one of

Coffee-Drinking DBA Jon Emmons


many ways to do it:

❍ Chris Foot
1. Some other queries ❍ The Pythian DBA Team Blog
on some system ❍ DBA Don Seiler
tables, and/or ❍ DBA Coskan Gundogar
2. Some command- ❍ Oracle WTF
line command, and/or
3. Some environment
file somewhere.
ARCHIVES
❍ LIST ALL ARTICLES
Also, I know some ❍ May 2005
people who put this ❍ June 2005
directly into their ❍ July 2005

http://thinkoracle.blogspot.com/2005/07/which-instance-am-i-in.html (2 of 3)1/9/2008 2:55:10 AM


OracleBlog: Which instance am I in?

sqlplus prompt. ❍ August 2005


❍ September 2005
// posted by Robert ❍ October 2005
Vollman @ Monday, July 18,
❍ November 2005
2005 ❍ December 2005
❍ January 2006
❍ February 2006
Comments: ❍ March 2006
Eddie Awad wrote a April 2006
post on SYS_CONTEXT

May 2006
as well:

❍ June 2006
http://awads.net/ ❍ July 2006
wp/2005/08/05/ ❍ August 2006
sys_context-in- ❍ September 2006
oracle/ ❍ October 2006
# posted by Robert ❍ November 2006
Vollman : Tuesday, 09 ❍ December 2006
August, 2005 ❍ January 2007
❍ February 2007
❍ March 2007
Post a Comment ❍ April 2007
May 2007
<< Home

❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/07/which-instance-am-i-in.html (3 of 3)1/9/2008 2:55:10 AM


OracleBlog: Windowing Clauses

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics, even
old ones (I will see and respond to such comments). You may want to start with "LIST ALL
ARTICLES" under Archives.

Tuesday, May 30, 2006


Windowing Clauses
Answer: "Analytic Functions"

Question: "I have become quite comfortable, perhaps even adept, with
basic SQL queries. I am ready to learn how to do more with my data. What
do you recommend I study?"

Given how often I write about analytic functions, my answer may not come
as a surprise. To those who have been studying along with me, I would
like to add one more tool to our toolbelts. Following up on my recent
article about finding nearby rows, I would like to touch on windowing
clauses.

Life Without Windowing Clauses

Quick, find me the average of a value for all rows in a table. No problem,
right? Use the analytic function AVG.

Note: Sample data can be found at the end of the article.

SELECT AVG(votes) FROM elections;

AVG(VOTES)
----------------------
357315.2307692307692307692307692307692308

Great. Now, find me that average only for a certain range of data, say from

http://thinkoracle.blogspot.com/2006/05/windowing-clauses.html (1 of 9)1/9/2008 2:55:17 AM


OracleBlog: Windowing Clauses

elections in 1990s only. Again, no problem.

SELECT AVG(votes) FROM elections WHERE election BETWEEN 1990 and


1999;

AVG(VOTES)
----------------------
461947.5

Ok. Now, for each row, find me the average from a 10 year range before
and after.

Um... errr...

How about the simply the average including the preceding and succeeding
rows?

Um ... errr ... what was the link to your article on finding nearby rows
again?

To the Rescue

Well you can relax. I am about to show you how to answer these
questions, and others like it. We'll answer these questions using
windowing clauses, which are the integral part of analytic functions that
define the set of rows you wish to work with.

First let's review analytic functions. You can go read Chapter 6 of the SQL
Reference, but generally, an analytic function comes in the following form:

ANALYTIC FUNCTION (ARGUMENT) OVER (QUERY PARTITION CLAUSE,


ORDER BY CLAUSE, WINDOWING CLAUSE);

Using windowing clauses, you can define which row to start with, which
row to end with including, if you wish, in reference to a specific row
(either by a range, or row number).

Now to let you off the hook. Here is an example of how to use windowing
clauses to determine the average of a column for a 10-year range, and an
average including the rows immediately before and after.

SELECT election, leader, votes,


CEIL(AVG(votes) OVER (ORDER BY election RANGE BETWEEN 10 preceding
AND 10 following)) ten_year,
CEIL(AVG(votes) OVER (ORDER BY election ROWS BETWEEN 1 preceding

http://thinkoracle.blogspot.com/2006/05/windowing-clauses.html (2 of 9)1/9/2008 2:55:17 AM


OracleBlog: Windowing Clauses

AND 1 following)) before_after


FROM elections;

ELECTION LEADER VOTES TEN_YEAR


BEFORE_AFTER
-------- ------------ ------------ ------------
-------------
1959 Kirby 98730 93184
75004
1963 Harradance 51278 144122
93184
1967 Lougheed 129544 189250
159252
1971 Lougheed 296934 251124
265414
1975 Lougheed 369764 358565
358265
1979 Lougheed 408097 399552
455449
1982 Lougheed 588485 420075
454455
1986 Getty 366783 434118
440838
1989 Getty 367244 442418
391336
1993 Klein 439981 457035
430380
1997 Klein 483914 467097
517049
2001 Klein 627252 492060
509420
2004 Klein 417092 509420 522172

Armed with the knowledge of the windowing clause, we are finally


beginning to unleash the full power of analytic functions. With that in
mind, a closer look at the other two types of clauses are in order.

Query Partition Clause

Strictly speaking, the windowing clause is not the only way to define the
set of rows you wish to work with. The query partition clause can achieve
that same goal by grouping your data on a single, specific value (or set of

http://thinkoracle.blogspot.com/2006/05/windowing-clauses.html (3 of 9)1/9/2008 2:55:17 AM


OracleBlog: Windowing Clauses

values).

For example, say we wanted the average number of votes by leader. No


problem using GROUP BY, right?

SELECT leader, AVG(votes) avg_votes FROM elections GROUP BY leader;

LEADER AVG_VOTES
-------------------------------- ----------------------
Getty 367013.5
Harradance 51278
Kirby 98730
Klein 492059.75
Lougheed 358564.8

By using the partitioning clause we can achieve the same result, but use it
in other ways. For example, to compare the average to every row.

SELECT election, leader, votes,


CEIL(votes - AVG (votes) OVER (PARTITION BY leader)) diff
FROM elections ORDER BY diff desc;

ELECTION LEADER VOTES DIFF


-------- ------------- --------- ---------
1982 Lougheed 588485 229921
2001 Klein 627252 135193
1979 Lougheed 408097 49533
1975 Lougheed 369764 11200
1989 Getty 367244 231
1963 Harradance 51278 0
1959 Kirby 98730 0
1986 Getty 366783 -230
1997 Klein 483914 -8145
1993 Klein 439981 -52078
1971 Lougheed 296934 -61630
2004 Klein 417092 -74967
1967 Lougheed 129544 -229020

Putting the partitioning clause and the windowing clause together is like
mixing chocolate and peanut butter. Alone, they're great, together they're

http://thinkoracle.blogspot.com/2006/05/windowing-clauses.html (4 of 9)1/9/2008 2:55:17 AM


OracleBlog: Windowing Clauses

even better. We could solve such complex problems as "For each row,
show me the average that includes the immediately preceding and
succeeding rows that share the same id."

Further Reading

Other than the SQL Reference, and Chapter 19 "SQL for Analysis" of the
Data Warehousing Guide, my primary sources include Chapter 12 of Tom
Kyte's "Expert One-on-One Oracle" and Daniel Morgan's on-line reference.

Beyond that, there are a lot of fine articles on specific applications. For
beginners, I would review an anonymous contribution to Howard Rogers'
wiki introduction to analytic functions, which also includes a great
example.

I will close with the final ingredient to analytic functions, the order by
clause.

Creating Rolling Averages

By using the order by clause within the context of the analytic function,
we can create rolling averages.

SELECT election, leader, votes,


CEIL(AVG (votes) OVER (ORDER BY election)) rolling_avg
FROM elections;

ELECTION LEADER VOTES ROLLING_AVG


-------- ------------- ---------- -------------
1959 Kirby 98730 98730
1963 Harradance 51278 75004
1967 Lougheed 129544 93184
1971 Lougheed 296934 144122
1975 Lougheed 369764 189250
1979 Lougheed 408097 225725
1982 Lougheed 588485 277548
1986 Getty 366783 288702
1989 Getty 367244 297429
1993 Klein 439981 311684
1997 Klein 483914 327342
2001 Klein 627252 352334
2004 Klein 417092 357316

http://thinkoracle.blogspot.com/2006/05/windowing-clauses.html (5 of 9)1/9/2008 2:55:17 AM


OracleBlog: Windowing Clauses

--

Sample data used in this article:

CREATE TABLE elections (election NUMBER(4), party VARCHAR2(32), leader


VARCHAR2(32), seats NUMBER(2), votes NUMBER(7), tot_seats NUMBER(2),
tot_votes NUMBER(7));

INSERT INTO elections VALUES (2004, 'PC', 'Klein', 61, 417092, 83,
890700);
INSERT INTO elections VALUES (2001, 'PC', 'Klein', 74, 627252, 83,
1013152);
INSERT INTO elections VALUES (1997, 'PC', 'Klein', 63, 483914, 83,
845713);
INSERT INTO elections VALUES (1993, 'PC', 'Klein', 51, 439981, 83,
989025);
INSERT INTO elections VALUES (1989, 'PC', 'Getty', 59, 367244, 83,
829189);
INSERT INTO elections VALUES (1986, 'PC', 'Getty', 61, 366783, 83,
713654);
INSERT INTO elections VALUES (1982, 'PC', 'Lougheed', 75, 588485, 79,
944936);
INSERT INTO elections VALUES (1979, 'PC', 'Lougheed', 74, 408097, 79,
710963);
INSERT INTO elections VALUES (1975, 'PC', 'Lougheed', 69, 369764, 75,
590200);
INSERT INTO elections VALUES (1971, 'PC', 'Lougheed', 49, 296934, 75,
639862);
INSERT INTO elections VALUES (1967, 'PC', 'Lougheed', 6, 129544, 65,
498351);
INSERT INTO elections VALUES (1963, 'PC', 'Harradance', 0, 51278, 63,
403444);
INSERT INTO elections VALUES (1959, 'PC', 'Kirby', 1, 98730, 65, 413516);

// posted by Robert Vollman @ Tuesday, May 30, 2006

Comments: Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/05/windowing-clauses.html (6 of 9)1/9/2008 2:55:17 AM


OracleBlog: Windowing Clauses

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
❍ Brian Duff's OraBlogs
❍ Eddie Awad's OracleNA
❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

http://thinkoracle.blogspot.com/2006/05/windowing-clauses.html (7 of 9)1/9/2008 2:55:17 AM


OracleBlog: Windowing Clauses

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006

http://thinkoracle.blogspot.com/2006/05/windowing-clauses.html (8 of 9)1/9/2008 2:55:17 AM


OracleBlog: Windowing Clauses

❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2006/05/windowing-clauses.html (9 of 9)1/9/2008 2:55:17 AM


OracleBlog: Fun With Tom Kyte

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated,
but it is the most powerful tool when it comes to data. That's why when I think data, I think
Oracle. I also enjoy writing, so I use this format to organise my thoughts. Please feel free to
discuss any thoughts you may have on the same topics, even old ones (I will see and respond to
such comments). You may want to start with "LIST ALL ARTICLES" under Archives.

Monday, February 26, 2007


About Me
Fun With Tom Kyte Name: Robert
As devoted readers may have noticed, my new job Vollman
doesn't involve nearly as much work with Oracle. I Location: Calgary,
stay sharp by reading Ask Tom, the very site that has Alberta, Canada
provided me with 90% of the answers that I can't find
in Oracle documentation or figure out on my own. I was born and raised in Ottawa,
and have lived in Calgary since
Those of you who may find it nerdly to spend lunch 1991. I like playing sports
hours reading Oracle Q&A are actually really missing (hockey, soccer, ultimate,
out. It's far more entertaining than you may realise. basketball, you name it) and
To prove my point, just from posts updated in the military board games. I also
past week alone, here are some little hilarious enjoy reading, walking, and
comments that can only come from Tom Kyte. playing with my 2 cats Lilly and
Brutus. I'm a database
1. Archiving Huge Database
application specialist, whatever
that is.
This question is a tad vague, ambiguous and
unanswerable. How long is a piece of string?
View my complete profile
2. Internationalization

Translation table used for processing input was: Best Links


Ask Tom Kyte
wud = would ●

u = you ● Oracle Docs


ur = your ● Dan Morgan and PSOUG
abt = about ● Steven Feuerstein
● Jonathan Lewis
I think your keyboard might be on the fritz? Vowels ● FAQ
are disappearing left and right ● Connor McDonald
The Oak Table
3. SQL Query

http://thinkoracle.blogspot.com/2007/02/fun-with-tom-kyte.html (1 of 5)1/9/2008 2:55:20 AM


OracleBlog: Fun With Tom Kyte

● Cary Millsap and Hotsos


Joins are not evil. ● Steve Adams and Ixora
Anjo Kolk and OraPerf
Databases were BORN to join.

● Dizwell Oracle Wiki


Joins are not evil. ● My Personal Blog

4. Collection Variable Types

Your naming convention would drive me utterly nuts Aggregators


Brian Duff's OraBlogs
5. What Don't You Like About Oracle? ❍

❍ Eddie Awad's OracleNA


*((char*)0) = "go away"; ❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
6. Backup Recovery ❍ Oracle Base Aggregator

You have done it totally wrong. Top Blogs


Do it right. ❍Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
Look - there is one thing and one thing only a DBA is ❍ Blogger of the Year Eddie Awad
not allowed to mess up. We can fix everything EXCEPT ❍ Data Warehouser David Aldridge
a bad backup. Everything else is just a mistake. ❍ Oracle Geek Lewis Cunningham
Screwing up your backups is far far beyond a mistake ❍ Database Expert James Koopmann
-- it is grounds for immediate "good bye, you are the Dizwell's Howard Rogers
weakest link".

❍ Oracle Master Laurent Schneider


Could you, in theory, perhaps -- maybe -- get lucky ❍ Security Expert Pete Finnigan
and be able to use them? maybe, sometimes, on ❍ Oracle Award Winner Mark
Tuesday when it is raining. Rittman
❍ Doug Burns
Is it smart (NOT) ❍ Oracle ACE of the Year Dr. Tim
Is it the right way (NOT) Hall
Is it even a teeny tiny bit reliable (NOT) ❍ UKOUG's Andrew (Arfur C.) Clarke
Newbie DBA Lisa Dobson
I fail to see how your example even "makes sense".

❍ Coffee-Drinking DBA Jon Emmons


BONUS: ❍ Chris Foot
❍ The Pythian DBA Team Blog
Q: TOM you are not only expert of Oracle but also ❍ DBA Don Seiler
Windows.....Thanks it worked. ❍ DBA Coskan Gundogar
Oracle WTF
A: I think I've just been insulted :)

7. Fast Refresh is Taking Longer Than Complete ARCHIVES


Refresh of Materialized View ❍ LIST ALL ARTICLES
❍ May 2005
Just set: ❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2007/02/fun-with-tom-kyte.html (2 of 5)1/9/2008 2:55:20 AM


OracleBlog: Fun With Tom Kyte

fast=true ❍ August 2005


❍ September 2005
in the init.ora. ❍ October 2005
November 2005
Sorry - it is Monday and my sense of humor is just

December 2005
getting warmed up :) ❍

❍ January 2006
8. REDO Logs Generated from PL/SQL ❍ February 2006
❍ March 2006
Allow me to be blunt. That would be stupid. 100%. ❍ April 2006
May 2006
9. Logminer

❍ June 2006
July 2006
Tell the DBA ok ❍

❍ August 2006
They will hate themselves for totally messing up their ❍ September 2006
lives. ❍ October 2006
❍ November 2006
I don't know what else to say - this is a horrible idea, ❍ December 2006
a great way for the DBA to ensure they have a job for January 2007
life - but a job that no human being would actually

February 2007
want.

❍ March 2007
10. Designing Tables ❍ April 2007
❍ May 2007
Q: How can we achieve, easier developer ❍ June 2007
understanding of the table design, without one ❍ October 2007
explaining the table design document / ER Model.
A: Telepathy I suppose?

BONUS: The All-Time Classic

Oracle Database

Q: Dear tom can u tell me the meaning of recursive


query?

"U" is not available.

I have never met this "U" person.

Do you know how to contact "U" - they get a lot of


requests, it would be great if I could pass the
questions on to them.

May "I" answer the question?

// posted by Robert Vollman @ Monday, February 26, 2007

http://thinkoracle.blogspot.com/2007/02/fun-with-tom-kyte.html (3 of 5)1/9/2008 2:55:20 AM


OracleBlog: Fun With Tom Kyte

Comments:
Ok, I laughed out loud at this myself.

Hmmmmmm
# posted by Thomas Kyte : Monday, 26 February, 2007

The answer to #3 is *almost* a great haiku. One extra


syllable in the middle though!
# posted by Don : Monday, 26 February, 2007

Robert, good humourous summary...sure gives us a


few chuckles...and the scary thing is...the Internet is
forever!! :0
# posted by Peter K : Monday, 26 February, 2007

Excellent stuff, thanks for pointing that out.


# posted by Harry : Tuesday, 06 March, 2007

This post has been removed by a blog administrator.


# posted by shoe stretchers : Friday, 23 March, 2007

I always liked:

The limitation was taken off but i am still getting the


same error, or can you please comment on
the query.

Thanks.

Followup September 17, 2003 - 6pm US/Eastern:

the query lines up very nicely.

http://asktom.oracle.com/pls/asktom/f?
p=100:11:0::::
P11_QUESTION_ID:4269591917792#12474142488374
# posted by Stephan : Wednesday, 07 November, 2007

Post a Comment

http://thinkoracle.blogspot.com/2007/02/fun-with-tom-kyte.html (4 of 5)1/9/2008 2:55:20 AM


OracleBlog: Fun With Tom Kyte

<< Home

http://thinkoracle.blogspot.com/2007/02/fun-with-tom-kyte.html (5 of 5)1/9/2008 2:55:20 AM


OracleBlog: Oracle Beefs

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, April 05, 2007


About Me
Oracle Beefs Name: Robert Vollman
I've got very few beefs with Location: Calgary, Alberta, Canada
Oracle. It is extremely
complicated and tough to
I was born and raised in Ottawa, and have
learn compared to other
lived in Calgary since 1991. I like playing
relational databases, but
sports (hockey, soccer, ultimate, basketball, you name
that's partially offset by the
it) and military board games. I also enjoy reading,
tremendous
walking, and playing with my 2 cats Lilly and Brutus.
documentation, and the
I'm a database application specialist, whatever that is.
huge Oracle community.

Don't get me wrong, I love View my complete profile


Oracle. I'm regularly
impressed by the
sophisticated and often Best Links
clever ways it handles the ● Ask Tom Kyte
requirements of an RDBMS, ● Oracle Docs
and quick to recommend
Dan Morgan and PSOUG
its use. But before making

Steven Feuerstein
that recommendation, I

Jonathan Lewis
make it clear that this ●

advantage has a trade-off: ● FAQ


expense. ● Connor McDonald
● The Oak Table
Oracle is expensive by ● Cary Millsap and Hotsos
itself, both in money and ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2007/04/oracle-beefs.html (1 of 8)1/9/2008 2:55:23 AM


OracleBlog: Oracle Beefs

in resources. Furthermore, ● Anjo Kolk and OraPerf


it can be difficult to find ● Dizwell Oracle Wiki
people that know it well, or ● My Personal Blog
to train your own staff. You
better be sure that you are
planning on taking
advantage of the benefits
of using a more powerful,
Aggregators
Brian Duff's OraBlogs
fast and reliable RDBMS

Eddie Awad's OracleNA


before choosing Oracle. ❍

Too often I have seen ❍ Pete Finnigan's Aggregator


software developed for ❍ Oracle's Bloglist
Oracle, but seemingly ❍ Oracle Base Aggregator

Top Blogs
going to great pains to
actually AVOID using the
packages, features and ❍ Oracle's Ask Tom Kyte
facilities Oracle has built- Oracle Guru Jonathan Lewis
in to maintain data

Blogger of the Year Eddie Awad


integrity and speed up

Data Warehouser David Aldridge


data access.

❍ Oracle Geek Lewis Cunningham


My other beefs with Oracle ❍ Database Expert James Koopmann
are mostly just pet peeves. ❍ Dizwell's Howard Rogers
It still boggles me how ❍ Oracle Master Laurent Schneider
they can refuse to ❍ Security Expert Pete Finnigan
introduce a Boolean type ❍ Oracle Award Winner Mark Rittman
because we don't NEED it, ❍ Doug Burns
and yet introduce all sorts ❍ Oracle ACE of the Year Dr. Tim Hall
of convoluted features (like
UKOUG's Andrew (Arfur C.) Clarke
DBMS_ADVANCED_REWRITE,

Newbie DBA Lisa Dobson


another pet peeve). I also

Coffee-Drinking DBA Jon Emmons


wish that constraints on

Chris Foot
views could be enforced.

❍ The Pythian DBA Team Blog


Speaking of pet peeves, ❍ DBA Don Seiler
there has been a whole ❍ DBA Coskan Gundogar
discussion on AskTom over ❍ Oracle WTF
the past couple of years.
Here are my top ten most ARCHIVES
interesting: ❍ LIST ALL ARTICLES
❍ May 2005
1. The "table or view does
June 2005
not exist" error message

❍ July 2005

http://thinkoracle.blogspot.com/2007/04/oracle-beefs.html (2 of 8)1/9/2008 2:55:23 AM


OracleBlog: Oracle Beefs

should include the name of ❍ August 2005


the invalid table/view. ❍ September 2005
October 2005
2. A lot of people

November 2005
mentioned wanting better

December 2005
formatting in SQL*Plus ❍

❍ January 2006
3. Niall Litchfield has a ❍ February 2006
good rumination about ❍ March 2006
binds that started a bit of a ❍ April 2006
discussion: ❍ May 2006
June 2006
I really don't see why

July 2006
"select cols from tab where

August 2006
pk = 10;" should be ❍

radically worse than "select ❍ September 2006


cols from tab where pk = : ❍ October 2006
b1;" I know why it is, I just ❍ November 2006
wish it wasn't. ❍ December 2006
❍ January 2007
4. Look for Alberto ❍ February 2007
Dell'Era's desire for better ❍ March 2007
instrumentation. I find April 2007
Oracle's instrumentation

May 2007
far superior to others

June 2007
RDBMS, but I agree there's

always room for ❍ October 2007


improvement.

5. Customized errors
messages for constraint
violations, like in Sybase.
Example: alter table
widgets add constraint
cost_chk check (cost <
100) error "Widget cost
must be less than $100";

6. There were some who


wanted to be able to
disable implicit type
conversion

7. Check out Connor

http://thinkoracle.blogspot.com/2007/04/oracle-beefs.html (3 of 8)1/9/2008 2:55:23 AM


OracleBlog: Oracle Beefs

McDonald's 19 suggestions
(what, he couldn't think of
1 more to make a round
number?)

8. Better support for


business rules in the
database. I interpret this as
being able to support
multi-table check
constraints without
restoring to triggers: I'd
love that. ANSI has it.

9. Stop treating empty


strings as NULL (I'm not
touching this one, I'm just
saying it's interesting).

10. Having an auto-


incrementing identity
column, without using
sequences and such.

Incidentally, don't expect


Tom to defend Oracle on
every point. He himself has
a few beefs I've heard over
the years: autonomous
transactions, "WHEN
OTHERS" exception
handling, triggers, and
others.

Final point: please check


out and enjoy some blogs
that are new among my
links: Don Seiler and
Coskan Gundogar.

// posted by Robert
Vollman @ Thursday, April 05,

2007

http://thinkoracle.blogspot.com/2007/04/oracle-beefs.html (4 of 8)1/9/2008 2:55:23 AM


OracleBlog: Oracle Beefs

Comments:
I'm with you on the issue
of dozens of obscure DBMS
packages appearing when
everyday features seem to
be crying out for
implementation (or fixing),
although I suppose
different people have their
own ideas of what is
obscure and what is life-
changing. I can only
imagine there must be a
lot of sites out there saying
"DBMS_PCLXUTIL - at last!"
while presumably not
having much use for
FORALL and object types
which have been broken
for years. The campaign to
fix DBMS_OUTPUT took 10
years so I'm not holding
my breath.
# posted by William
Robertson : Thursday, 05 April,
2007

Regarding Booleans in SQL,


I agree it is frustrating that
there is no built-in way to
define a Yes/No indicator,
and as a result applications
end up with a random
assortment of Y/N, 1/0
etc. However Booleans
would be a huge change to
the language and require a
correspondingly huge
change to client interfaces.
Tools like SQL*Plus would

http://thinkoracle.blogspot.com/2007/04/oracle-beefs.html (5 of 8)1/9/2008 2:55:23 AM


OracleBlog: Oracle Beefs

have to be able to interpret


them, presumably using
'TRUE'/'FALSE' rather than
translating them into
NLS_LANGUAGE
('VRAI'/'FAUX'?), along with
the corresponding
middleware products like
OCI and JDBC. We would
need an IS [NOT] TRUE
operator, but should we
also allow a Boolean to
stand alone as a WHERE
predicate or in a CASE
expression? Should we be
able to use expressions
like "sal > 1000" in a
SELECT list and have them
implicitly cast to Boolean,
or should there be
additional functions,
perhaps

BOOLEAN(sal > 1000)

or just

CAST(sal > 1000 AS


BOOLEAN)

That would open up the


way for some funky
constructions like

SELECT ename, (sal >


1000) = (mgr IS NULL)
FROM emp
WHERE is_permanent;

I'd certainly be interested


to see this sort of thing,
but I can understand
Oracle's reluctance to
make such a huge change

http://thinkoracle.blogspot.com/2007/04/oracle-beefs.html (6 of 8)1/9/2008 2:55:23 AM


OracleBlog: Oracle Beefs

to the language and the


related products (i.e. all of
them).
# posted by William
Robertson : Friday, 06 April, 2007

length of a string with


white space oracle

how can we get the length


of a string excluding white
spaces..
In the following query
select length('shankar
selvakani') from dual;
results in value 17 but how
to exclude the blankspace
and find the length of the
string.... Any functions or
query...
# posted by valentine :
Monday, 20 August, 2007

Hi
Here i am with a new
scenario where WHY do we
need an exception
overall???
What is the benifits or what
exactly does this
exceptions do with any
programming constructs,
not only with oracle, any
programming languages???

On the whole we are going


to check for the exception
(a condition) that we can
do with a simple If..Else..
End IF construct in oracle

http://thinkoracle.blogspot.com/2007/04/oracle-beefs.html (7 of 8)1/9/2008 2:55:23 AM


OracleBlog: Oracle Beefs

(for example)..

Please clarify me....!!!!!!!!!!!

Valentine
# posted by valentine :
Thursday, 23 August, 2007

This post has been


removed by a blog
administrator.
# posted by Anonymous :
Sunday, 30 September, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2007/04/oracle-beefs.html (8 of 8)1/9/2008 2:55:23 AM


OracleBlog: Oracle Gurus

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, October 31, 2006


About Me
Oracle Gurus Name: Robert Vollman
"Becoming an Oracle guru Location: Calgary, Alberta, Canada
doesn't take remarkable
intelligence or a pricey
I was born and raised in Ottawa, and
Harvard degree, but it does
have lived in Calgary since 1991. I
take persistence, drive, and a
like playing sports (hockey, soccer, ultimate,
dedication to excellence."
basketball, you name it) and military board games.
- Don Burleson, How to
I also enjoy reading, walking, and playing with my
become an Oracle Guru 2 cats Lilly and Brutus. I'm a database application
specialist, whatever that is.
Despite the appearance of
merely trying to promote his
View my complete profile
team (most notably Steve
Karam), Mr. Burleson actually
raises some interesting points
on a thought-provoking Best Links
question. ● Ask Tom Kyte
Oracle Docs
What Makes an Oracle Guru?

● Dan Morgan and PSOUG


So what does it take to ● Steven Feuerstein
become an Oracle guru, ● Jonathan Lewis
according to him? I'll group ● FAQ
his dozen points into the ● Connor McDonald
underlying broad categories: ● The Oak Table
● Cary Millsap and Hotsos

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (1 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

1. Credentials ● Steve Adams and Ixora


A stellar education with ● Anjo Kolk and OraPerf
prestigious degrees, awards, ● Dizwell Oracle Wiki
and certifications. ● My Personal Blog

2. Communicating Their
Knowledge
Via insightful blogs,
publishing opportunities, and
Aggregators
polished communications Brian Duff's OraBlogs

skills. ❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
3. Attitude ❍ Oracle's Bloglist
Seeks challenging job ❍ Oracle Base Aggregator
opportunities, and is
characterized by a "can do"
attitude.
Top Blogs
❍ Oracle's Ask Tom Kyte
Who Are the Gurus? ❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
Before I can properly evaluate ❍ Data Warehouser David Aldridge
Mr. Burleson's assertions, I Oracle Geek Lewis Cunningham
need to know who the Oracle

Database Expert James Koopmann


gurus are. So I unleashed the

Dizwell's Howard Rogers


"Google Guru Wars" (say that

Oracle Master Laurent Schneider


five times fast). Here are the ❍

results of this dubious test: ❍ Security Expert Pete Finnigan


❍ Oracle Award Winner Mark Rittman
Most popular results for ❍ Doug Burns
"Oracle Guru" on Google ❍ Oracle ACE of the Year Dr. Tim Hall
878 Jonathan Lewis ❍ UKOUG's Andrew (Arfur C.) Clarke
762 Tom Kyte ❍ Newbie DBA Lisa Dobson
646 Don Burleson ❍ Coffee-Drinking DBA Jon Emmons
486 Mike Ault ❍ Chris Foot
216 Steve Adams ❍ The Pythian DBA Team Blog
3 Robert Vollman :) ❍ DBA Don Seiler
❍ DBA Coskan Gundogar
Do they all meet Burleson's ❍ Oracle WTF
Three Criteria? Well the
criteria are fairly subjective,
but from what I know of these
ARCHIVES
5, they certainly do. ❍ LIST ALL ARTICLES
❍ May 2005
But let me ask two questions: ❍ June 2005

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (2 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

1. Is there something MORE to ❍ July 2005


being an Oracle guru? ❍ August 2005
2. Is there something ❍ September 2005
extraneous in Burleson's October 2005
Requirements?

❍ November 2005
What is a Guru? ❍ December 2005
❍ January 2006
In my experience, guru simply ❍ February 2006
means anyone with a very ❍ March 2006
high level of knowledge and ❍ April 2006
understanding. Generally I ❍ May 2006
think it is also implied that ❍ June 2006
they have a following of some
July 2006
kind.

❍ August 2006
Strictly translated, guru can ❍ September 2006
mean "teacher" - and in many ❍ October 2006
places like India and ❍ November 2006
Indonesia I understand that ❍ December 2006
guru is generally used in that ❍ January 2007
sense. Certainly we picture ❍ February 2007
gurus as having mentors. ❍ March 2007
April 2007
Reviewing Burleson's Three

May 2007
Criteria

❍ June 2007
With that in mind, let's take ❍ October 2007
one final pass through the
three criteria.

1. Credentials

Our first goal must be to get


past the subjectiveness of this
criteria. After all, who is to
decide which degree is
prestigious enough, which
certifications are necessary,
and which awards qualify?

That being said, it's fair to say


that an Oracle guru would
certainly be capable of

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (3 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

earning a post-secondary
degree, Oracle certification,
and an Oracle ACE. But I
would also suppose that they
may not have had the
opportunity nor the desire to
pursue this. These may be
necessary to PROMOTE
oneself as a guru, but not
necessarily to BE one.

Nevertheless, this is still a


valid criteria. But instead of
tangible things like degrees,
certifications and awards,
which (if I may be so bold)
would be possible (though
extremely difficult) to
accumulate without attaining
a thorough understanding of
Oracle, we need to measure it
based upon the actual
understanding.

How do you measure an


actual understanding of
Oracle? I don't have that
answer, but I might propose
to test their understanding,
through questions and
problems. Then again, I
suppose that's what academic
institutions, award review
boards and certification
exams do ...

2. Communicating Their
Knowledge

I didn't like this criteria at first


because it excluded some
amazing DBAs with whom I
have had the pleasure to
work. However, given the

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (4 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

definition of a guru I
reviewed, it would seem like
educating others is a
necessary qualification.

Still, I've seen some people


communicate a relatively
mediocre understanding of
Oracle through numerous
papers and books and blogs.
I've also seen brilliant writers
publish only a single book (if
any), and an unarguable guru
like Jonathan Lewis, until very
recently, had no blog at all.

I've seen some people answer


countless questions on Oracle
forums, and yet never really
impart true insight or wisdom.

So again, this criteria suffers


from subjectiveness. How do
we measure how effectively a
potential guru has
communicated their
knowledge? Number of
students? Questions
answered? The students'
understanding of Oracle?
Some combination thereof? If
so, how do we test the
understanding of the students
if I've already conceded above
that I don't know how to
measure someone's
understand of Oracle in the
first place?

3. Attitude

Despite being the most


subjective criteria of the
three, I found the attitude that

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (5 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

Oracle gurus share to be the


most interesting, and the one
on which I wish Don Burleson
had elaborated further.

I like the way he describe


Oracle gurus as those that
seek challenges, and have a
"can do" attitude. To me,
those two qualities perfectly
sum up how I've been able
identify good sources of
mentorship in my career.
Some people might have
fantastic knowledge and
experience, but like to stick to
what they know, and are
stubbornly cynical about any
problem that falls outside
their comfort zone.

Wrapping Up

Sadly, I really don't think I've


answered any questions or
cleared anything up on this
matter, and I apologise for
that. However, if I have helped
to promote and advance the
discussion, then I'm glad I
took the time to share my
thoughts with everyone. I'd
love to hear yours: what
makes an Oracle guru?

// posted by Robert
Vollman @ Tuesday, October 31,

2006

Comments:
Q: what makes an Oracle guru?
A: Knowledge, and lots of it,

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (6 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

plus the willingness to share it.


# posted by Eddie Awad :
Tuesday, 31 October, 2006

I would say that Don


contradict himself with regard
to the degree, "doesn't take a
pricey Harvard degree" and
later saying that "a stellar
education with prestigious
degrees" is a must.

I agree with Eddie, no use


being a guru if you are not
willing to share the knowledge
and I will add "be willing to
teach the why and how"...a lot
of consultants could not be
bother with teaching the why
and is only willing to show the
how (which is similar to
"giving a man a fish so that he
can only eat for a day instead
of teaching him how to fish so
that he can feed himself for a
lifetime."

ShyPy is the word verification.


# posted by Peter K : Tuesday, 31
October, 2006

What's wrong with Steve


Karam? ;)

I agree that guru has


experience and is willing to
share it. Not just for money,
but for the honest to
goodness desire to get Oracle
to the public, to teach people,
to help others succeed where

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (7 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

the guru has. A guru is one


who has not only attained the
knowledge of their specific
craft, but the wisdom of how
to truly use it. They do not
need to proclaim themselves a
guru. Their wisdom, desire,
and intuition show it. When a
guru enters a conversation or
speaks publicly, people walk
away thinking, "Wow. Now
that's a guru." Lastly, a guru is
a leader. They don't follow the
trends, or post fifth on a
message board to be safe,
they come right out, right or
wrong, and assert themselves.

When it comes to Oracle


specifically, I usually identify
the guru as the one who can
get in front of people and
answer any question. Not
because they know it all by
memory...but because they
have the intuition. If they
don't know the answer, they
are resourceful enough to find
it, and quick. Certifications
don't make the guru, but the
guru will usually seek
certifications because it's
prudent to do so if they are
capable. The Oracle guru isn't
afraid to test their backup
plan. They are not afraid to go
to the boss and ask for a
bigger licensing budget. And
most importantly, for all their
knowledge, they still
understand that Oracle is a
widespread and complicated
software, and so they know

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (8 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

and acknowledge that they


could possibly be wrong.

Now that's a guru!


# posted by Steve Karam :
Tuesday, 31 October, 2006

I'd definitely say that Tom


Kyte has a "following".
Surprise to not see HJR on
that list. Perhaps we need to
do some google bombing for
our favorite "gurus". ;)

/me goes back to reading the


Oracle 10g DBA handbook to
learn something about his
profession.
# posted by Don Seiler : Tuesday,
31 October, 2006

I'll leave this comment on the


way to go read that Burleson
article...

http://kevinclosson.
wordpress.com/

:-)
# posted by Kevin Closson :
Tuesday, 31 October, 2006

my feeling is that a guru has


the ability to take complex
concepts and explain them to
not so smart people like me.
# posted by shrek : Wednesday,
01 November, 2006

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (9 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

Nope, neither Howard Rogers


nor Dizwell seemed to get a
lot of hits. Although I agree
he is very knowledgeable, is
an instructor, and publishes a
wealth of great information
on-line.

The only others I could find


with 3-digit hits:
Steven Feuerstein 146
Cary Millsap 131
# posted by Robert Vollman :
Wednesday, 01 November, 2006

a good write-up on what it


takes to be an "Oracle Guru".
Having a little bit if Sanskrit
background - to me
"A Guru was a guide who
attained complete insight on
the subject. Gurus also train
their followers to become a
teacher"
while I have worked with
many Gurus in the past
( knowledge in other areas) I
think what instantly made me
realize that they were truly
Guru's was attitude. Attitude
just not to reject all
limitations and move forward,
but to share their wisdom and
insight with others in a
seamless and joyful way.
There is no doubt that every
one listed in your blog are
Oracle experts and continue
to help the Oracle community
# posted by Vidya
Balasubramanian : Wednesday, 01
November, 2006

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (10 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

Hear hear Vidya, well said! Or


should I say, "namaste!"

I also like a definition I heard


once of "guruji," which is
applicable: He Who gives full
peace of mind by solving
problems.
# posted by Steve Karam :
Wednesday, 01 November, 2006

"There is no doubt that every


one listed in your blog are
Oracle experts"

Well, except Shrek.

Just kidding! :)
# posted by Robert Vollman :
Wednesday, 01 November, 2006

By the way (as if I hadn't said


enough), here's a good article
on how to be a good guru
from Andrew Clarke at Radio
Free Tooting:

http://radiofreetooting.
blogspot.com/2005/11/how-
to-be-good-guru.html
# posted by Steve Karam :
Wednesday, 01 November, 2006

Thanks for the plug, Steve.


This thread has inspired me to
some more musing on Oracle
Gurus ...

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (11 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

http://radiofreetooting.
blogspot.com/2006/11/
oracle-guru-is-it-you.html

Cheers, APC
# posted by APC : Thursday, 02
November, 2006

Guru. One translation says

Gu = darkness
Ru = light

Guru = the One that takes you


from darkness to Light.

So he could be a myth
buster ;) Reminds me of Tom
Kyte and JL.

- Naresh
# posted by Anonymous : Sunday,
05 November, 2006

Mr. Burleson actually has


more to say on this topic
(including "Robert Vollman
(one of my favorite bloggers)"):

http://www.dba-oracle.com/
t_how_to_become_oracle_guru.
htm

Not all his quotes are mine,


read carefully to know which
ones.

I've said this before, but I just


want to reiterate that I mean
no disrespect when I refer to
people in the familiar (ie. first
names). It would appear that

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (12 of 13)1/9/2008 2:55:28 AM


OracleBlog: Oracle Gurus

Mr. Burleson prefers the


formal, and although he has
not asked me to, I have edited
my post to reflect that
preference.
# posted by Robert Vollman :
Thursday, 07 December, 2006

In Yoga, the most common


definition for a Guru is "a
bringer of light", so I agree
with Naresh.

I can flick a light switch. Can't


I be a guru? :)

Cheers

Tim...
# posted by Tim... : Friday, 08
December, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/10/oracle-gurus.html (13 of 13)1/9/2008 2:55:28 AM


OracleBlog: SQL Interview Questions

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Sunday, June 03,


About Me
2007
Name: Robert Vollman
SQL Location: Calgary, Alberta, Canada
Interview
Questions I was born and raised in Ottawa, and have lived in
You pick up the Calgary since 1991. I like playing sports (hockey,
candidate's soccer, ultimate, basketball, you name it) and military board
resume and it games. I also enjoy reading, walking, and playing with my 2 cats
proudly proclaims Lilly and Brutus. I'm a database application specialist, whatever
"SQL Expert: 10 that is.
Years." Your boss
trusts you, as the View my complete profile
technical expert

Best Links
on the team, to
participate briefly
in the interview to ● Ask Tom Kyte
gauge this Oracle Docs
individual's

Dan Morgan and PSOUG


knowledge of

Steven Feuerstein
SQL. Where to

Jonathan Lewis
begin? ●

● FAQ
I have asked ● Connor McDonald
literally hundreds ● The Oak Table
of different ● Cary Millsap and Hotsos
questions during ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (1 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

interviews over ● Anjo Kolk and OraPerf


the past decade. ● Dizwell Oracle Wiki
Some were simple ● My Personal Blog
questions that
were nevertheless
remarkably
effective ways of
rating a
Aggregators
Brian Duff's OraBlogs
candidate's

Eddie Awad's OracleNA


comfort-level in ❍

SQL, whereas ❍ Pete Finnigan's Aggregator


others just ❍ Oracle's Bloglist
wasted precious ❍ Oracle Base Aggregator

Top Blogs
interview time.
Let me save you
the latter! ❍ Oracle's Ask Tom Kyte
Oracle Guru Jonathan Lewis
First I ask the

Blogger of the Year Eddie Awad


candidate how ❍

they would ❍ Data Warehouser David Aldridge


personally rate ❍ Oracle Geek Lewis Cunningham
their own ❍ Database Expert James Koopmann
understanding of ❍ Dizwell's Howard Rogers
SQL. I'm also ❍ Oracle Master Laurent Schneider
curious what ❍ Security Expert Pete Finnigan
databases and ❍ Oracle Award Winner Mark Rittman
tools they've used ❍ Doug Burns
to write their SQL. ❍ Oracle ACE of the Year Dr. Tim Hall
This gives me a
UKOUG's Andrew (Arfur C.) Clarke
good idea where I

Newbie DBA Lisa Dobson


should begin my

Coffee-Drinking DBA Jon Emmons


questioning. ❍

❍ Chris Foot
Basic Questions ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
Asking a question ❍ DBA Coskan Gundogar
about joins is the ❍ Oracle WTF
common
consensus for an
opening question.
ARCHIVES
More specifically, ❍ LIST ALL ARTICLES
does the ❍ May 2005
candidate know ❍ June 2005
the different ❍ July 2005

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (2 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

types of joins, or ❍ August 2005


at least the ❍ September 2005
difference ❍ October 2005
between an inner ❍ November 2005
join and an outer December 2005
join?

❍ January 2006
Assuming that ❍ February 2006
goes well, I follow ❍ March 2006
up with a ❍ April 2006
question that ❍ May 2006
involves using ❍ June 2006
GROUP BY and/or ❍ July 2006
HAVING. For ❍ August 2006
example, given an ❍ September 2006
EMPLOYEE table October 2006
and a

November 2006
DEPARTMENT

December 2006
table, how would

January 2007
you select the ❍

combined salary ❍ February 2007


of each ❍ March 2007
department that ❍ April 2007
has a higher ❍ May 2007
combined salary ❍ June 2007
than mine? ❍ October 2007

Intermediate
Questions

With the sanity


checks out of the
way, we can get
into some more
meaningful
technical
discussions.
Among my
favourites is to
solicit their
perspective of
what NULL is and
what it means.

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (3 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

After all, to write


correct SQL
queries, isn't this
understanding
important? How
many queries
have you read
that caused
problems because
the author
mishandled
NULLs? Will this
candidate make
the same
mistake? Do they
know that NULL
and nothing are
different, and in
what ways? Do
they know that
neither NULL =
NULL nor NULL
<> NULL are true?

Before proceeding
to the grand
finale, I pepper
the candidate
with variations of
the following
three questions
that, though
simple, seem to
have done an
exemplary job
narrowing down
someone's level
of experience.
First, do they
know the four
isolation levels?
Secondly, do they
know what a bind

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (4 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

variable is and
why they should
be used (do they
even know what a
soft parse is)?
Finally, what is
the DUAL table?

Advanced
Questions

All of this is
leading up to
analytic functions,
one of my true
litmus tests to the
proficiency of
one's knowledge
of SQL. There are
literally dozens of
questions I have
asked: YOU need
to pick one that
specifically relates
to the type of
work relevant to
the open position.
Here are some
possibilities to
choose from:
- Open with the
basic concept of
selecting data
over a partition (a
running total,
perhaps)
- Follow-up by
writing a Top-N
query
- Put together a
standard pivot/
crosstab query
- Try handling

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (5 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

hierarchical/
recursive queries
(using CONNECT
BY)

I feel there is no
real need to know
the exact analytic
function and write
out the precise
syntax, but to
truly qualify your
SQL at the higher
level requires the
ability to know
how to truly
unleash the
power of an
Oracle database.
So tell me, did
they head in the
right direction, or
ask for a glass of
water and slip out?

Wrapping Up

Generally I have
managed to keep
the discussion
under the
previously
unrealistic 15-
minute limit that's
imposed upon
me. On rare
occasions I'm
treated to the
delightful
combination of a
candidate that
has breezed
through the
interview and a

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (6 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

boss taking his


time re-joining
us. In that case,
I've been known
to serve up some
advanced history
questions. Who is
Ted Codd? Did
they know about
his 12 rules? Do
they get a blank
expression on
their face when I
ask them what
"System R" is?

At the very least,


even if they know
SQL backwards
and forwards,
they'll still have
something
interesting to
look up when
they get home.

// posted by Robert
Vollman @ Sunday,

June 03, 2007

Comments:
12 rules you say...
so you wont hire
the ones that say
18? :)
# posted by Örjan
Bernt Lundberg :
Sunday, 03 June, 2007

Great questions.

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (7 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

When DBA'ing at a
university, I
interviewed the
expected number
of "recently
graduated but
rating myself as
expert"
candidates. The
NULL questions
consistently had
'em running for
the hills. "Huh?
Three-valued
logic, what's that?"

:-)
# posted by Beth :
Sunday, 03 June, 2007

Great post. As a
candidate would I
get extra marks
for spotting your
trick question?

'Do they know


that both NULL =
NULL and NULL
<> NULL are
false?'

declare
x BOOLEAN;
begin
x := (null=null);
if (x)
then
dbms_output.
put_line
('NULL=NULL IS
TRUE');

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (8 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

elsif not (x)


then
dbms_output.
put_line
('NULL=NULL IS
FALSE');
elsif x is null
then
dbms_output.
put_line
('NULL=NULL IS
NULL');
end if;

x:= (null<>null);
if (x)
then
dbms_output.
put_line
('NULL<>NULL IS
TRUE');
elsif not (x)
then
dbms_output.
put_line
('NULL<>NULL IS
FALSE');
elsif x is null
then
dbms_output.
put_line
('NULL<>NULL IS
NULL');
end if;
end;
/

NULL=NULL IS
NULL
NULL<>NULL IS
NULL

PL/SQL procedure
successfully

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (9 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

completed.
# posted by RGT :
Sunday, 03 June, 2007

Hahaha, definitely
RGT!!!
# posted by Robert
Vollman : Sunday, 03
June, 2007

Articles like this


really wind me
up. In my
experience, the
resident Oracle
'techie' should be
the last person to
tech screen a
prospective DBA
candidate. Their
hidden agenda is
often two fold.
First, don't let
your boss hire
someone smarter
or more
knowledgeable
that you so you
retain your 'head
honcho' status.
Second, find the
most obscure
used-once-in-a-
career questions
to catch the
candidate out and
make yourself
feel superior.

Understanding

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (10 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

relational
concepts and
knowing how to
ADMINISTER the
Oracle database
should be
expected.
Knowing the ins
and outs of SQL
analytical
functions? Erm....
wouldn't that be
more important
and RELEVANT if
you were an
Oracle
DEVELOPER?

The range of
options,
configurations,
platforms,
operating
systems, storage
set-ups, etc. is
huge when it
comes to
administering
Oracle databases.
No DBA, and I
mean NO DBA,
can possibly know
them all like the
back of their
hand.

Again, in my
experience, the
best DBAs
obviously know a
great deal about
many specific
subject areas and

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (11 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

those they're not


so sure about
they know where
to look or who to
ask.

Personally, with 15
+ years of Oracle
DBA experience
working on
virtually every
flavor of UNIX and
Windows/Linux,
ranging from
thousands of
online users to
just a handful,
from T bytes of
data to a few
hundred M bytes,
backed with every
OCP DBA
certification you
can get going all
the way back to
7.3 and a degree
in Computer
Science thrown in
just for fun, I get
a bit insulted
when some
Johnny-Come-
Lately Oracle tech
guru wannabe
starts asking me
in an interview
when I'd use
BETWEEN and
when I'd use
HAVING.

An interview is
supposed to be a

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (12 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

two way street of


open
communication.
Respect to flow
BOTH ways. The
best interviews
I've been involved
with have been
conducted by
people who
KNOW HOW TO
INTERVIEW and
allow the
candidate to
expand on what
they're good and
and know how to
do rather than
focus on what
they don't know
and don't know
how to do.
# posted by
Anonymous :
Wednesday, 06 June,
2007

Quick question:
where did I saying
anything about
DBAs?

This is about SQL.

If you want to hire


a DBA and your
first question is
"how good is his/
her SQL?" I think
you have a
problem.

By the way, did

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (13 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

you click on that


very first link? Do
the arguments I
made over one
year ago look
familiar? :)
# posted by Robert
Vollman : Wednesday,
06 June, 2007

Point taken.
Perhaps you're
unaware that your
site is being
linked to in
today's
searchoracle.com
email newsletter,
in an article called
"SQL interview
questions; getting
hired as a DBA".
Hence my
response with my
DBA hat on. I
meant no
disrespect to you
personally, hence
I stressed "in my
experience".

I did check out


the "first link" you
mentioned. Kudos
Robert. It oozed
common sense. I
especially
appreciated the
'does not need to
regurgitate
syntax'
philosophy.

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (14 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

Writing
something from
memory in 1
minute or looking
it up in 3. What's
the practical
difference?

Interviewing
highly technical
people is difficult.
No question
about it. The
hiring manager
asking his
existing staff to
either contribute
questions or do
the interview for
them is very
common, in my
experience. And
also quite wrong,
in my opinion.

As I mentioned,
I've been a DBA
for a long time,
but does that
qualify me to
interview other
DBAs or even
Oracle
developers? I
don't think so. I'm
certainly able to
ask technical
questions and
know if the
answer that
comes back is
correct or not,
but that's not

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (15 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

really an
interview, is it?

Unfortunately, in
the dozens of
permanent and
contract positions
I've held over the
years, only a
small handful
have been
managed by
someone who (a)
knew what they
were doing; (b)
knew what I did
and (c)
understood/
appreciated what
I needed to know/
do in order to get
my work done.
I'm sure this is
the root cause
why the not-so-
good candidates
get jobs. Better
screening is
needed and some
of your tips and
pointers are
helpful. I know
one thing for
certain, Oracle's
OCP DBA exams
ain't it! ;-)
# posted by
Anonymous :
Wednesday, 06 June,
2007

Advice to all of

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (16 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

you, don't ask a


question in an
interview that you
just happened to
stumble upon or
are very happy it's
a question that
you alone or a
selected few
know. That means
that tid bit of
information is not
really that
pertinent, how
can you be happy
to send
candidates
running for the
hills? I have
studied under the
tutelage of some
very brilliant
people, one
created the
tracking system
for UPS (Nardi)
and as they
taught me it's
very easy to find
hard questions
that people can't
answer. I feel
most of you are
full of cyber
arrogance.....

I don't care who I


offend
# posted by
Anonymous :
Monday, 30 July, 2007

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (17 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

I strongly URGE
people who feel
the same way to
visit that first link
(http://
thinkoracle.
blogspot.
com/2006/02/
oracle-interview-
questions.html).

Check out the


fifth rule. Quoting
myself: "Just
remember, the
purpose of the
interview isn't to
make YOU look
clever"

That being said, I


don't care if
someone wrote
UPS ... if they
don't understand
what NULL is,
they probably
made some
serious mistakes.
If they don't know
about isolation
levels their app
might corrupt the
data as more
users use it
simultaneously.
Without using
bind variables, it'll
be slower than
molasses. These
are all highly
pertinent, which
ones do you think

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (18 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

aren't?

You're not
offending me, but
I offered to you
what has worked
for me. If you've
got a better
system, stick with
it, but it is a little
rude to assume
I'm arrogant.
Maybe that means
you're insecure?
# posted by Robert
Vollman : Monday, 30
July, 2007

Hey,

Long time no hear


(see?). Hope
things are going
well for you.

LewisC
# posted by
LewisC : Saturday,
18 August, 2007

Hi Lewis. I
changed jobs
March 2006, and
this new job
doesn't involve as
much Oracle as
previous
positions. End
result: fewer
posts.

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (19 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

But yes, all is well.


I'm happy to leave
this resource to
others, and there
will still be new
content. Best
thing is to use my
RSS feed so you
can be alerted
when there's
something new.
# posted by Robert
Vollman : Sunday, 19
August, 2007

Hi,
Am back with a
small comment,
You know
triggers... Yes i
just wanna know
where these
triggers are
mostly used...
Or put up this
way, Why we
gonna for
triggers.... I have
read some
articles, in most
of it they say that
the triggers are
for just providing
constraints and
for some
database error
logging or some
thing like that
cannt be done
with normal
oracle stmts....

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (20 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

Pls help, Just


wanna know why
trigger are for
and "where" do
we use it often...
Pls try to mail
me...
unthirudan@gmail.
com

Regards,
Valentine M.
# posted by
valentine :
Saturday, 01
September, 2007

This post has


been removed by
a blog
administrator.
# posted by
Anonymous :
Sunday, 30 September,
2007

This post has


been removed by
a blog
administrator.
# posted by
Anonymous :
Tuesday, 06
November, 2007

This post has


been removed by
a blog
administrator.
# posted by raw

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (21 of 22)1/9/2008 2:55:31 AM


OracleBlog: SQL Interview Questions

minerals makeup :
Sunday, 11 November,
2007

Hi,
nice blog, even I
am working on
similar sort of
blog. have a look
when you get
time.
http://yepoocha.
blogspot.com
# posted by
Element : Saturday,
01 December, 2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2007/06/sql-interview-questions.html (22 of 22)1/9/2008 2:55:31 AM


OracleBlog: What Makes a Great Oracle Blog?

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, May
About Me
25, 2007
Name: Robert Vollman
What Location: Calgary, Alberta, Canada
Makes a
Great I was born and raised in Ottawa, and have lived in
Calgary since 1991. I like playing sports (hockey,
Oracle soccer, ultimate, basketball, you name it) and military board games.
Blog? I also enjoy reading, walking, and playing with my 2 cats Lilly and
Along the side Brutus. I'm a database application specialist, whatever that is.
of my page,
you'll see my View my complete profile
favourite
Oracle blogs
listed. I
carefully
Best Links
maintain this ● Ask Tom Kyte
list of fellow ● Oracle Docs
enthusiasts ● Dan Morgan and PSOUG
whose ● Steven Feuerstein
opinions and ● Jonathan Lewis
insights I most ● FAQ
especially want ● Connor McDonald
to follow ● The Oak Table
among the ● Cary Millsap and Hotsos
seemingly Steve Adams and Ixora
hundreds of

● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (1 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

Oracle blogs ● Dizwell Oracle Wiki


that are out ● My Personal Blog
there. Studying
them, I think

Aggregators
you'll find that
each of them
share the same
Brian Duff's OraBlogs
core qualities

Eddie Awad's OracleNA


listed below.

❍ Pete Finnigan's Aggregator


1. Accuracy ❍ Oracle's Bloglist
❍ Oracle Base Aggregator
Accuracy is an
absolute must.
Just because
Top Blogs
Oracle's Ask Tom Kyte
its an informal

Oracle Guru Jonathan Lewis


blog from an ❍

independent ❍ Blogger of the Year Eddie Awad


individual ❍ Data Warehouser David Aldridge
shouldn't ❍ Oracle Geek Lewis Cunningham
relieve it from ❍ Database Expert James Koopmann
the same ❍ Dizwell's Howard Rogers
standard of ❍ Oracle Master Laurent Schneider
accuracy that ❍ Security Expert Pete Finnigan
you'd find in a ❍ Oracle Award Winner Mark Rittman
paper ❍ Doug Burns
published by
Oracle ACE of the Year Dr. Tim Hall
Oracle

UKOUG's Andrew (Arfur C.) Clarke


themselves.

❍ Newbie DBA Lisa Dobson


For just one ❍ Coffee-Drinking DBA Jon Emmons
example, ❍ Chris Foot
consider ❍ The Pythian DBA Team Blog
Jonathan Lewis' ❍ DBA Don Seiler
blog, and his ❍ DBA Coskan Gundogar
track record of ❍ Oracle WTF
reliable
solutions. But
you don't have
ARCHIVES
LIST ALL ARTICLES
to be a guru to

May 2005
be accurate!

June 2005
Indeed, if your ❍

articles are ❍ July 2005


❍ August 2005

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (2 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

targetted to ❍ September 2005


novices, that's ❍ October 2005
even more ❍ November 2005
reason why December 2005
you should

January 2006
make sure

February 2006
everything you

March 2006
write is fully ❍

tested and ❍ April 2006


error-free, ❍ May 2006
right? ❍ June 2006
❍ July 2006
2. Relevance ❍ August 2006
September 2006
The occasional

October 2006
off-topic

November 2006
article can be a ❍

pleasant ❍ December 2006


change of ❍ January 2007
pace, as can ❍ February 2007
writing about ❍ March 2007
some other ❍ April 2007
unrelated ❍ May 2007
technology. ❍ June 2007
But write too ❍ October 2007
many, and
then nobody
knows if
they're going
to get an
insight into the
performance of
the MINUS
operator, or
something
about spiders.

A great blog
must
consistently
provide
material
relevant to the

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (3 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

community.
Readers can
also quickly
sniff out and
abandon
bloggers who
are doing
nothing more
than marketing
their products,
their books, or
their services.

By contrast,
consider Pete
Finnigan's
blog. Each and
every visit, I
know I'm going
to get his
latest insight
into Oracle
security
matters. Comb
his articles,
and I doubt
you'll come
across any
covering the
details of his
hotel room at
UKOUG or a
rant about
Wordpress.

Bear in mind,
that a great
Oracle article
doesn't
necessarily
have to be
technical to be
relevant. For

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (4 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

example,
consider
Coskan
Gundogar's
recent series
aimed at new
DBAs, and
invalid DBAs,
which you'll
find to be not
only relevant,
but also
thought-
provoking.

3. Genuine
Insight

A great Oracle
blog has to be
more than just
a syntax
reference.
Some crappy
blogs do
nothing more
than recycle
someone else's
work, either by
linking or
actually
copying it,
which falls
anywhere
between
plagiarism,
and a complete
waste of time.

Instead, a
great Oracle
article is the
one that shows

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (5 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

you HOW to
solve
problems. It
teaches you a
new approach
to using Oracle
technology.
Among my
favourites are
the articles
that provide
insights that I
couldn't find
anywhere else,
and that I'm
not likely to
have
experienced or
figured out on
my own.

The blogs that


compose the
list on the side
are replete
with examples,
but consider
Andrew "Arfur
C" Clarke, and
his recent post
on the INSERT
ALL syntax. His
article, which
was built on
Pythian article
about multi-
table inserts,
guides us
through his
thinking (with
examples), all
the way to his
neat solution.

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (6 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

4. Readability

Oracle is very
complex
technology.
Some people
think that they
are impressing
everyone by
showing how
they're capable
of coming up
with
sophisticated
and complex
solutions. What
a load of crap.
Anyone can do
that, and no
one wants to
read about it.
A great Oracle
blog, by
contrast, can
take a
complicated
problem and
make it look so
easy and
simple that
even Shrek can
understand it.

A great Oracle
blog uses easy,
simple, every
day language,
and
remembers
that not all its
readers enjoy
English as their
first language.

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (7 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

These blogs
rarely forget to
explain and
define all the
acronyms,
abbreviations
and industry
terms used.

As just one
example,
consider Lewis
Cunningham's
latest article
about implicit
vs explicit
conversion. A
big part of
Lewis'
popularity is
his ability to
present his
ideas in clear,
plain language
accessible to
readers of all
levels. Notice
as well that his
articles deliver
specific,
relevant, useful
Oracle insights.

5. Posting
Frequently

A great blog
doesn't need
to have a new
article each
and every day,
but if there
isn't new

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (8 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

material of
some kind of
regular basis,
people may
assume its
been
abandoned.
Blogging on a
regular basis
allows people
to become
familiar and
comfortable
with its style
and approach,
and look
forward to its
perspective on
future topics.

Like most
readers, I only
have the time
to regularly
follow a
limited
numbers of
blogs (in my
case, up to
20). How many
of my favourite
blogs did I
have to stop
following
because the
author stopped
blogging
regularly? (Edit:
List removed
because it was
easily
misunderstood
as criticism)

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (9 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

6. Concise,
tested,
working
examples

Your article
may have been
accurate for
your purposes,
for your
version, and in
your
environment,
but what about
mine? Of
course I trust
you, but by
providing a
concise,
tested,
working
example, I can
verify if your
solutions are
accurate for
me in my
world.

A great Oracle
blogger knows
that examples
are critical for
communication.
Despite your
best efforts, if
the reader still
doesn't
understand the
material, they
at least have a
working
example to
play with until

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (10 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

they do. They


can even use it
as a basis for
future
research,
including
coming back
to you with
questions. If
you need an
example,
consider
Laurent
Schneider, who
has become
famous for
helping
thousands by
posting
working
solutions, both
on Oracle
forums and his
blog.

7. Googlability.

Within a week,
most people
have read a
newly-posted
article. Then it
dies off, and is
usually
forgotten,
never to be
read again.
After all, how
often do you
find yourself
browsing the
archives?
Never ... not

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (11 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

when you're
keeping up
with all the
new articles.
This
phenomenon
is especially
tragic for the
great articles
written by new
bloggers
before they
become
popular and/or
start appearing
on aggregators
(for example,
Don Seiler,
who has
maintained an
excellent blog
for years but
was only
recently added
to some
aggregators).

By including
searchable
phrases within
the article and
in its titles,
there's a good
chance that it
can be picked
up by Google
when someone
is researching
that particular
topic. Great
articles include
common
search

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (12 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

phrases, like
Oracle error
messages,
specific
commands,
and popular
expressions.

8. Opportunity
for Discourse

A great article
is one that
covers an
interesting
topic that not
only ties into
the work of
other bloggers,
but even
stimulates
further
discussion. All
the blogs in
my list allow
comments,
and in every
case the
comments are
read and
followed up
upon.

Writing articles
that generate
discussions
makes us more
than just a
collection of
random
observations,
and into a true
Oracle
blogging

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (13 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

community. It
evolves us into
a community
with articles
that build on
the ideas of
others, and
that becomes
more than just
the sum of its
blogs.

9. Pointers to
more
information

Typically the
restrictions
imposed by
the blogging
medium allows
only a short
look at a
particular
topic.
Therefore, in
anticipation of
the thirst for
more
information
that it
stimulates, a
great blog
consistently
directs the
reader to such
sources.
Furthermore,
this helps
readers who
are
experiencing
similar

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (14 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

problems (but
not the exact
same one).

For a great
example, look
no further than
the 2006
Oracle blogger
of the year
Eddie Awad.
His recent
article on
forward
declaration
and mutual
recursion not
only contains
information
hard to find
elsewhere,
working
examples, and
an active
discussion, but
Eddie also
unfailingly
links to Oracle
documentation.

10.
Enthusiasm,
and Humour

Oracle can be
dry, I admit it.
It can
sometimes feel
like a big,
complex,
bloated mass
of three-letter
initials and

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (15 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

acronyms.
That's why it's
a treat to catch
the humour
and/or
enthusiasm a
colleague
might have for
a particular
topic.

Don't forget
that the most
popular Oracle
blog of all is
undoubtedly
Tom Kyte's,
who is well-
reknowned for
both his
tireless
enthusiasm,
and his
entertaining
style (and wit).
As for humour,
the perfect
example is the
Oracle WTF
maintained by
William
Robertson et al.

But the energy


doesn't
necessarily
have to be
humourous,
nor positive
and uplifting.
Negative,
critical or
cynical rants

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (16 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

written with
equal energy
can be highly
captivating,
such as
Dizwell's
Howard
Rogers' rants,
which are the
stuff of
legends. (As
are Tim Hall's)

Great Oracle
Blogs

I would like to
thank my
fellow Oracle
bloggers listed
to the side,
both past,
present and
future. Your
insights have
consistently
improved my
understanding,
interest and
appreciation
for Oracle.
That is
certainly the
hallmark of a
great Oracle
blog.
Furthermore,
you have all
been a great
influence in my
own blog (ie
THIS blog),
which surely

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (17 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

wouldn't have
been this much
fun to write
without you.

With that in
mind, I just
updated my
list with
another great
Oracle blog,
that of Chris
Foot. I
recommend
reading his
latest series on
his favourite
features in
Oracle 10g.

// posted by
Robert
Vollman @ Friday,

May 25, 2007

Comments:
ow!

mea culpa -
for reasons I
will blog about
- mea maxima
culpa.

word
verification
jmklbxdm a
java class
shortly to be
introduced in
EBS 12

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (18 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

methinks.
# posted by
Niall : Friday,
25 May, 2007

thank my
fellow Oracle
bloggers listed
to the side

And I would
like to thank
you for this
nice article and
for being part
of a growing
Oracle
bloggers
community
that is leading
the Oracle
online
community in
general.
# posted by
Eddie Awad :
Friday, 25 May,
2007

How many of
my favourite
blogs did I
have to stop
following
because the
author stopped
blogging
regularly?

Well, using any


RSS reader,

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (19 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

you can still


follow up
blogs with one
post per
month/quarter
without any
overhead on
your side so
reading 10
mostly idle
blogs would be
just like
following up
one active.
# posted by
Alex : Friday,
25 May, 2007

Very nice post.


This is one to
bookmark. I do
however, take
one tiny
exception to
something you
said under
"Readability".
Sometimes I
like to find a
complex
solution even
when a simple
solution would
suffice,
provided that
the complex
solution
demonstraits
how to
combine
features in
novel ways.

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (20 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

# posted by M.
Moore : Friday, 25
May, 2007

This post has


been removed
by the author.
# posted by
Joel Garry :
Friday, 25 May,
2007

Great
metablog!

I too have been


saddened
when great
posters (not
just blogs) go
into cloaked
mode. Never
know what to
say, since
there are so
many possible
reasons.
# posted by
Joel Garry :
Friday, 25 May,
2007

It was meant
as praise, not
criticism. I
wouldn't mind
decreased
blogging if
they weren't
such fine blogs.

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (21 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

Yes, I still
quasi-follow
them all on the
various RSS
aggregators,
but I hope I'm
not too far on
a limb when I
say that a
great Oracle
blog has more
than a handful
of topical
posts per year!
# posted by
Robert
Vollman : Friday,
25 May, 2007

Yeah, I've been


working to
increase my
frequency and,
hopefully,
relevance. I'm
up to 1 post
every 3-4 days
now.
# posted by
Dominic
Delmolino : Friday,
25 May, 2007

Good post,
good timing !

I'm starting
blogging again
- as of
yesterday in

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (22 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

fact! Hopefully
I'll keep going
a little longer
this time. I've
got a few
subjects
planned to get
me started.

I'm now at ...


http://
oracleandy.
wordpress.
com/

Andrew
Campbell
# posted by
Andy : Friday,
25 May, 2007

I was
pleasantly
surprised and
humbled to
see my name
among others
such as Sue
Harper,
Mogens
Norgaard, Anjo
Kolk, etc. I
don't mind
that it was in a
negative sense;
I agree, I don't
post very often.

I guess my
personal belief
is only to post
if I think I've

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (23 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

got something
interesting to
say - which
means no
annoying
"sorry I haven't
blogged for a
while" blog
posts.
# posted by
Jeffrey Kemp :
Saturday, 26 May,
2007

This post has


been removed
by the author.
# posted by M.
Moore : Saturday,
26 May, 2007

I also do not
care if a blog
post happens
only once in a
long while. My
feed reader
will let me
know when
there is a new
post, so it
would not be a
problem for
me to
subscribe to
many blogs
that only
posted a few
times a year.
Hopefully,
technical

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (24 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

bloggers, will
not feel
obligated to
say something
just because
it's time. Many
blogs with
differing
objects and
publishing
frequencies
and skill levels
are a 'good
thing'. This
way, there is
always a
chance that I
will find one
crappier than
my own! ;-)
# posted by M.
Moore : Saturday,
26 May, 2007

Ok does
everyone at
least agree I
was 9 for 10? :)
# posted by
Robert
Vollman : Saturday,
26 May, 2007

I'd say 9.9 for


10. Hope to
read more like
it.
# posted by M.
Moore : Saturday,
26 May, 2007

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (25 of 26)1/9/2008 2:55:34 AM


OracleBlog: What Makes a Great Oracle Blog?

great post
Robert and
thank you for
including mine
too :)

Keep blogging
# posted by
Coskan
Gundogar :
Monday, 28 May,
2007

This post has


been removed
by a blog
administrator.
# posted by
Anonymous :
Sunday, 30
September, 2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2007/05/what-makes-great-oracle-blog.html (26 of 26)1/9/2008 2:55:34 AM


OracleBlog: On Vacation

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, May 26,


About Me
2005
Name: Robert Vollman
On Vacation Location: Calgary, Alberta, Canada
I am taking a much
needed vacation to I was born and raised in Ottawa, and have lived
Italy for my brother's in Calgary since 1991. I like playing sports
wedding. (hockey, soccer, ultimate, basketball, you name it) and
military board games. I also enjoy reading, walking, and
I'll post new material
playing with my 2 cats Lilly and Brutus. I'm a database
on June 13th, so
application specialist, whatever that is.
please check back
then.
View my complete profile
In the mean time,

Best Links
here is how you can
pass your break time,
apart from reading
Ask Tom Kyte
my recent posts

Oracle Docs
(including one today)

or visiting the links ● Dan Morgan and PSOUG


on the right: ● Steven Feuerstein
● Jonathan Lewis
1. The Dizwell Forum ● FAQ
has some great ● Connor McDonald
Oracle discussions on ● The Oak Table
many topics. ● Cary Millsap and Hotsos
● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/05/on-vacation.html (1 of 3)1/9/2008 2:55:37 AM


OracleBlog: On Vacation

http://www. ● Anjo Kolk and OraPerf


phpbbserver.com/ ● Dizwell Oracle Wiki
phpbb/index.php? ● My Personal Blog
mforum=dizwellforum

2. Oracle magazine
has great articles, Aggregators
especially Ask Tom Brian Duff's OraBlogs

and Steven ❍ Eddie Awad's OracleNA


Feuerstein's PL/SQL Pete Finnigan's Aggregator
Best Practises:

❍ Oracle's Bloglist
http://www.oracle. ❍ Oracle Base Aggregator
com/technology/
index.html Top Blogs
❍ Oracle's Ask Tom Kyte
3. Lots of other ❍ Oracle Guru Jonathan Lewis
Oracle professionals ❍ Blogger of the Year Eddie Awad
have blogs. I enjoy ❍ Data Warehouser David Aldridge
many of them, but ❍ Oracle Geek Lewis Cunningham
based on frequency Database Expert James Koopmann
of updates and

Dizwell's Howard Rogers


number of Oracle-

Oracle Master Laurent Schneider


related posts, my

Security Expert Pete Finnigan


favourites are David ❍

Aldridge and Niall ❍ Oracle Award Winner Mark Rittman


Litchfield: ❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
http://oraclesponge. ❍ UKOUG's Andrew (Arfur C.) Clarke
blogspot.com/ ❍ Newbie DBA Lisa Dobson
http://www.niall. ❍ Coffee-Drinking DBA Jon Emmons
litchfield.dial.pipex. ❍ Chris Foot
com/ ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
Please look under ❍ DBA Coskan Gundogar
"Comments" for more ❍ Oracle WTF
ideas, and of course
contribute your own. ARCHIVES
Arrivederci! ❍ LIST ALL ARTICLES
❍ May 2005
// posted by Robert ❍ June 2005
Vollman @ Thursday, May ❍ July 2005

http://thinkoracle.blogspot.com/2005/05/on-vacation.html (2 of 3)1/9/2008 2:55:37 AM


OracleBlog: On Vacation

❍ August 2005
26, 2005
❍ September 2005
❍ October 2005
Comments: ❍ November 2005
This post has been ❍ December 2005
removed by a blog ❍ January 2006
administrator. ❍ February 2006
# posted by St Louis ❍ March 2006
Cardinals BUFF : Tuesday, ❍ April 2006
11 October, 2005 ❍ May 2006
❍ June 2006
❍ July 2006
Post a Comment
❍ August 2006
September 2006
<< Home

❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/05/on-vacation.html (3 of 3)1/9/2008 2:55:37 AM


OracleBlog: Constraints

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, June
About Me
30, 2005
Name: Robert Vollman
Constraints Location: Calgary, Alberta, Canada
No blog from
me. But here is I was born and raised in Ottawa, and have lived in
an excellent one Calgary since 1991. I like playing sports (hockey,
from Jeff Hunter soccer, ultimate, basketball, you name it) and military board
that I wish I'd games. I also enjoy reading, walking, and playing with my 2 cats
written. Lilly and Brutus. I'm a database application specialist, whatever
that is.
http://marist89.
blogspot.
View my complete profile
com/2005/06/
deferrable-
constraints_29.
html
Best Links
● Ask Tom Kyte
Also, check his ● Oracle Docs
Comments to ● Dan Morgan and PSOUG
see Doug Burns' ● Steven Feuerstein
link to an article ● Jonathan Lewis
by Chris Date. ● FAQ
● Connor McDonald
// posted by Robert
The Oak Table
Vollman @ Thursday,

● Cary Millsap and Hotsos


June 30, 2005
● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/06/constraints.html (1 of 3)1/9/2008 2:55:39 AM


OracleBlog: Constraints

● Anjo Kolk and OraPerf


● Dizwell Oracle Wiki
● My Personal Blog
Comments:
Wow, 1000 visits
according to
StatCounter. Aggregators
Brian Duff's OraBlogs
I looked at the

Eddie Awad's OracleNA


logs and actually

Pete Finnigan's Aggregator


got 42 unique ❍

visitors today. ❍ Oracle's Bloglist


Who are all you ❍ Oracle Base Aggregator
people?!?

I didn't think this


Top Blogs
❍ Oracle's Ask Tom Kyte
would be for
Oracle Guru Jonathan Lewis
anyone other

Blogger of the Year Eddie Awad


than me, so it's

Data Warehouser David Aldridge


actually very

gratifying to hear ❍ Oracle Geek Lewis Cunningham


that other people ❍ Database Expert James Koopmann
find my ❍ Dizwell's Howard Rogers
misadventures in ❍ Oracle Master Laurent Schneider
Oracle so ❍ Security Expert Pete Finnigan
interesting! ❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
Thanks! ❍ Oracle ACE of the Year Dr. Tim Hall
# posted by
❍ UKOUG's Andrew (Arfur C.) Clarke
Robert Vollman :
❍ Newbie DBA Lisa Dobson
Thursday, 30 June,
❍ Coffee-Drinking DBA Jon Emmons
2005
❍ Chris Foot
❍ The Pythian DBA Team Blog
Post a ❍ DBA Don Seiler
Comment ❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
<< Home

❍ LIST ALL ARTICLES


❍ May 2005
❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2005/06/constraints.html (2 of 3)1/9/2008 2:55:39 AM


OracleBlog: Constraints

❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/06/constraints.html (3 of 3)1/9/2008 2:55:39 AM


OracleBlog: Oracle Blogs

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, July
About Me
21, 2005
Name: Robert Vollman
Oracle Location: Calgary, Alberta, Canada
Blogs
If you enjoy this I was born and raised in Ottawa, and have lived in
blog, there may Calgary since 1991. I like playing sports (hockey,
be other Oracle- soccer, ultimate, basketball, you name it) and military board
related blogs games. I also enjoy reading, walking, and playing with my 2 cats
you will also Lilly and Brutus. I'm a database application specialist, whatever
enjoy reading. that is.
You may be
surprised to View my complete profile
learn just how
many good
Oracle blogs are
out there. I
Best Links
follow quite a ● Ask Tom Kyte
few on a daily or ● Oracle Docs
casual basis. ● Dan Morgan and PSOUG
Here are my ● Steven Feuerstein
favourites. ● Jonathan Lewis
● FAQ
Brian Duff hosts
Connor McDonald
OraBlogs, which

The Oak Table


picks up several

Cary Millsap and Hotsos


of the below ●

Oracle blogs, so ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/07/oracle-blogs.html (1 of 10)1/9/2008 2:55:42 AM


OracleBlog: Oracle Blogs

it can be a one- ● Anjo Kolk and OraPerf


stop blog. ● Dizwell Oracle Wiki
http://www. ● My Personal Blog
orablogs.com/
orablogs/

Tom Kyte, Aggregators


respected Brian Duff's OraBlogs

author of "Ask Eddie Awad's OracleNA
Tom." Covers a

Pete Finnigan's Aggregator


pretty wide

Oracle's Bloglist
spectrum of

Oracle Base Aggregator


Oracle-related ❍

topics, including
new things and Top Blogs
"best practises." ❍ Oracle's Ask Tom Kyte
This is on ❍ Oracle Guru Jonathan Lewis
practically ❍ Blogger of the Year Eddie Awad
everyone's ❍ Data Warehouser David Aldridge
favourite blog ❍ Oracle Geek Lewis Cunningham
list, and every
Database Expert James Koopmann
post gets

Dizwell's Howard Rogers


dozens of

Oracle Master Laurent Schneider


comments. ❍

http://tkyte. ❍ Security Expert Pete Finnigan


blogspot.com/ ❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
Niall Litchfield ❍ Oracle ACE of the Year Dr. Tim Hall
has one of the ❍ UKOUG's Andrew (Arfur C.) Clarke
first Oracle ❍ Newbie DBA Lisa Dobson
blogs I read. He ❍ Coffee-Drinking DBA Jon Emmons
has interesting ❍ Chris Foot
posts on a ❍ The Pythian DBA Team Blog
variety of topics ❍ DBA Don Seiler
including DBA Coskan Gundogar
htmldb, and

Oracle WTF
Oracle 10g.

http://www.niall.
litchfield.dial.
ARCHIVES
pipex.com/ ❍ LIST ALL ARTICLES
❍ May 2005
Howard Rogers ❍ June 2005
is the master of ❍ July 2005

http://thinkoracle.blogspot.com/2005/07/oracle-blogs.html (2 of 10)1/9/2008 2:55:42 AM


OracleBlog: Oracle Blogs

the Dizwell ❍ August 2005


Forum. The ❍ September 2005
discussions ❍ October 2005
therein are ❍ November 2005
generally the December 2005
inspiration for

January 2006
his posts. His

February 2006
passionate

March 2006
Oracle rants ❍

give his blog a ❍ April 2006


lot of flavour. ❍ May 2006
http://www. ❍ June 2006
dizwell.com/ ❍ July 2006
blogindex.html ❍ August 2006
❍ September 2006
David Aldridge, ❍ October 2006
is an all- ❍ November 2006
purpose Oracle ❍ December 2006
warehouse ❍ January 2007
specialist. I love ❍ February 2007
his posts on March 2007
warehouse

April 2007
design and

May 2007
maintenance. He

also posts ❍ June 2007


regularly about ❍ October 2007
Oracle 10g and
its features.
http://
oraclesponge.
blogspot.com/

Mark Rittman is
a database
warehouse
developer and
covers a lot of
stuff, like
modelling. He
has a link to all
the Oracle blogs
that are out
there (good or

http://thinkoracle.blogspot.com/2005/07/oracle-blogs.html (3 of 10)1/9/2008 2:55:42 AM


OracleBlog: Oracle Blogs

bad), so you can


go through
there and pick
your favourites.
http://www.
rittman.net/

Jeff Hunter is an
Oracle DBA with
a relatively new
blog. He posts a
wide variety of
topics, and he is
on a lot of
people's
favourites list.
http://marist89.
blogspot.com/

Tim Hall is an
Oracle DBA,
designer and
developer. Posts
on a variety of
topics and is not
shy about
sharing his
opinions.
Despite the fact
that he doesn't
use IDEs, he's
one of the few
people who
mention them.
http://oracle-
base.blogspot.
com/

Doug Burns,
another Oracle
DBA, reads and
writes papers
and books. I

http://thinkoracle.blogspot.com/2005/07/oracle-blogs.html (4 of 10)1/9/2008 2:55:42 AM


OracleBlog: Oracle Blogs

count on him to
post about the
latest news and
papers/books of
interest.
http://doug.
burns.tripod.
com/oracle/

Pete Finnigan,
an Oracle
security expert,
provides the
latest news of
bugs and
security flaws.
Even though I'm
not into security
that much, I still
enjoy his posts.
http://www.
petefinnigan.
com/weblog/
entries

Eddie Awad, an
Oracle
application
developer who
posts
interesting
things about
Oracle as he
finds them. Also
talks about
ColdFusion and
Biztalk
occasionally.
Has me in his
blogroll! :)
http://awads.
net/wp/

http://thinkoracle.blogspot.com/2005/07/oracle-blogs.html (5 of 10)1/9/2008 2:55:42 AM


OracleBlog: Oracle Blogs

Peter Scott is a
manager (!) in
charge of an
Oracle data
warehouse. As a
result his posts
are generally
about the
situation of the
day, which is
usually of
significance to
everyone.
http://pjs-
random.
blogspot.com/

Lisa Dobson, an
Oracle DBA
whose brand
new blog
focuses on the
Newbie
perspective.
http://
newbiedba.
blogspot.com/

Amis
Technology
Corner has a
number of
Oracle
professionals
from various
backgrounds
that post on a
variety of topics,
including
Oracle-related
events and
publications,

http://thinkoracle.blogspot.com/2005/07/oracle-blogs.html (6 of 10)1/9/2008 2:55:42 AM


OracleBlog: Oracle Blogs

and various
designs and
features.
http://
technology.amis.
nl/blog/

Mike Ault, a
Burleson
consultant and
published
author, posts on
a variety of
Oracle-related
topics related to
his interesting
adventures
while
consulting. No
comments
allowed,
ostensibly for
legal reasons
but people
posted a lot of
corrections
when they were
allowed.
http://mikerault.
blogspot.com/

Robert Freeman,
another
Burleson
consultant and a
15-year Oracle
DBA, posts on a
variety of
Oracle-related
topics of
interest to
DBAs, including
the types of

http://thinkoracle.blogspot.com/2005/07/oracle-blogs.html (7 of 10)1/9/2008 2:55:42 AM


OracleBlog: Oracle Blogs

problems he
sees and solves
and things he
finds in the
latest releases.
http://
robertgfreeman.
blogspot.com/

If you know of
any other
Oracle-related
blogs that you
enjoy, please
add a Comment
so I can check it
out. Please
spread the word
of these great
blogs!

// posted by Robert
Vollman @ Thursday,

July 21, 2005

Comments:
Thanks to Nuno:

Anjo Kolk
http://oraperf.
blogspot.com/

Thanks to
"Captain
Obvious":

Sue Harper's
Blog:
http://www.
groundside.com/
blog/content/

http://thinkoracle.blogspot.com/2005/07/oracle-blogs.html (8 of 10)1/9/2008 2:55:42 AM


OracleBlog: Oracle Blogs

SueHarper/

Peter K's Blog:


http://
pkhosblog.
blogspot.com/

And thanks to
Peter K's links:

Chris Foot:
http://www.
dbazine.com/
blogs/blog-cf/
chrisfoot/
# posted by
Robert Vollman :
Friday, 22 July, 2005

Rob,

Mike Ault allows


comments on
his blog (I just
left him one, in
fact). However,
Robert Freeman
currently does
not nor does
Don himself.

Happy blogging!
# posted by Bill
S. : Friday, 22 July,
2005

http://
laurentschneider.
blogspot.com/

http://www.adp-

http://thinkoracle.blogspot.com/2005/07/oracle-blogs.html (9 of 10)1/9/2008 2:55:42 AM


OracleBlog: Oracle Blogs

gmbh.ch/
# posted by
Anonymous :
Wednesday, 31
August, 2005

This post has


been removed
by a blog
administrator.
# posted by
Ayisha : Friday,
24 August, 2007

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/07/oracle-blogs.html (10 of 10)1/9/2008 2:55:42 AM


OracleBlog: Regular Expressions in Oracle

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, July 05,


About Me
2005
Name: Robert Vollman
Regular Location: Calgary, Alberta, Canada
Expressions
in Oracle I was born and raised in Ottawa, and have lived in
I was recently asked Calgary since 1991. I like playing sports (hockey,
to do a blog about soccer, ultimate, basketball, you name it) and military board
Regular Expressions games. I also enjoy reading, walking, and playing with my 2
in Oracle 10, cats Lilly and Brutus. I'm a database application specialist,
because they were whatever that is.
cool.
View my complete profile
They are cool.

Except to people
that get spooked by
Best Links
a bunch of [: ● Ask Tom Kyte
whatever:] in their ● Oracle Docs
code, and feel their ● Dan Morgan and PSOUG
lunch come up ● Steven Feuerstein
when they see '[^:] ● Jonathan Lewis
+,\?.{3} (tip: if that ● FAQ
is you, don't ever ● Connor McDonald
read Perl code). ● The Oak Table
Cary Millsap and Hotsos
Anyway I can not do

a blog on Regular ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/07/regular-expressions-in-oracle.html (1 of 7)1/9/2008 2:55:44 AM


OracleBlog: Regular Expressions in Oracle

Expressions in ● Anjo Kolk and OraPerf


Oracle 10 for two ● Dizwell Oracle Wiki
reasons: ● My Personal Blog

1. I only blog about


what I'm currently
working on and
studying, and
Aggregators
Brian Duff's OraBlogs
2. I use Oracle 9. ❍

❍ Eddie Awad's OracleNA


But no worries. ❍ Pete Finnigan's Aggregator
There is a great ❍ Oracle's Bloglist
article on Oracle ❍ Oracle Base Aggregator
Regular Expressions:

http://www.oracle.
Top Blogs
Oracle's Ask Tom Kyte
com/technology/

Oracle Guru Jonathan Lewis


oramag/

Blogger of the Year Eddie Awad


webcolumns/

Data Warehouser David Aldridge


2003/techarticles/

Oracle Geek Lewis Cunningham


rischert_regexp_pt1.

Database Expert James Koopmann


html

❍ Dizwell's Howard Rogers


Oracle Master Laurent Schneider
Hmph, looks like I

blogged about ❍ Security Expert Pete Finnigan


Oracle Regular ❍ Oracle Award Winner Mark Rittman
Expressions after ❍ Doug Burns
all. ❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
Oh yes, and here is ❍ Newbie DBA Lisa Dobson
your Regular ❍ Coffee-Drinking DBA Jon Emmons
Expression Chris Foot
reference, courtesy

The Pythian DBA Team Blog


of (who else) Dan

DBA Don Seiler


Morgan:

❍ DBA Coskan Gundogar


http://www.psoug. ❍ Oracle WTF
org/reference/
regexp.html ARCHIVES
❍ LIST ALL ARTICLES
He covers ❍ May 2005
REGEXP_INSTR, ❍ June 2005
REGEXP_LIKE, ❍ July 2005

http://thinkoracle.blogspot.com/2005/07/regular-expressions-in-oracle.html (2 of 7)1/9/2008 2:55:44 AM


OracleBlog: Regular Expressions in Oracle

REGEXP_REPLACE, ❍ August 2005


REGEXP_SUBSTR. ❍ September 2005
❍ October 2005
// posted by Robert
November 2005
Vollman @ Tuesday, July

❍ December 2005
05, 2005 ❍ January 2006
❍ February 2006
❍ March 2006
Comments:
April 2006
i have implemented

May 2006
the oracle regexp in

a a system we are ❍ June 2006


currently ❍ July 2006
developing. our ❍ August 2006
system is fairly ❍ September 2006
tranactional and the ❍ October 2006
query that contains ❍ November 2006
the regular ❍ December 2006
expressions runs ❍ January 2007
on the order of 50K ❍ February 2007
times in a short March 2007
period of time (as

April 2007
fast a possible).

❍ May 2007
we placed the ❍ June 2007
actual regexp call in ❍ October 2007
a function that
simpley returns 1
or 0 for a hit or not,
the function
accepts the string
to be tested, the
rows in the table
selected over with
the regexp_like
actually contain the
regexp, reversed
from most
examples.

are they any


performance
considerations for

http://thinkoracle.blogspot.com/2005/07/regular-expressions-in-oracle.html (3 of 7)1/9/2008 2:55:44 AM


OracleBlog: Regular Expressions in Oracle

using regexp. we
have moved to a
much larger
database box disk
wise and have little
or no I/O
contention, but the
CPUs are more or
less the the same
(Dual, dual core
3.0GHz intel). The
evaluation the the
regexp queries has
more or less
remained
unchanged in the
migration.

FUNCTION
isValidItemId
(pItemId varchar2,
pCriteriaExpression
varchar2) RETURN
integer is
retval integer;
expectedCount
integer;
hitCount integer;

begin
if
(pCriteriaExpression
is not null) then
begin
-- see how many
matches this item
should have
select criteria_count
into expectedCount
from my_item mi
where mi.id =
pMyItemId;

http://thinkoracle.blogspot.com/2005/07/regular-expressions-in-oracle.html (4 of 7)1/9/2008 2:55:44 AM


OracleBlog: Regular Expressions in Oracle

if (expectedCount >
0) then
begin
-- now see how
many we get with
the criteria
expreesion
select count(ic.id)
into hitCount
from item_criteria
ic,
item_item_criteria iic
where ic.id = iic.
item_criteria_id
and iic.item_id =
pItemId
and regexp_like
(pCriteriaExpression,
iic.criteria_regexp);

if (hitCount =
expectedCount)
then
retval:=1;
else
retval:=0;
end if;
end;
else
retval:=1;
end if;
end;
else
retval:= 1;
end if;
return (retval);
end;
# posted by
Anonymous :
Tuesday, 13 June, 2006

http://thinkoracle.blogspot.com/2005/07/regular-expressions-in-oracle.html (5 of 7)1/9/2008 2:55:44 AM


OracleBlog: Regular Expressions in Oracle

Sorry, can't help


you. I'm still using
Oracle 9 (no
regexp).

You can study the


Oracle 10g
documentation, and
run some of your
own tests. Or you
could Ask Tom:

http://asktom.
oracle.com

Beyond that, try


posting your
questions in a
discussion forum.
# posted by Robert
Vollman : Tuesday, 13
June, 2006

Hi Robert,
still running Oracle
9i?

Well now you can


practice with 10G
regular expressions
at the on-line
Regular Expression
Workbench for
Oracle 10G.

So, you have no


more excuses now.

;-)

Flavio
# posted by Byte64 :

http://thinkoracle.blogspot.com/2005/07/regular-expressions-in-oracle.html (6 of 7)1/9/2008 2:55:44 AM


OracleBlog: Regular Expressions in Oracle

Friday, 06 April, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/07/regular-expressions-in-oracle.html (7 of 7)1/9/2008 2:55:44 AM


OracleBlog: New Blogs

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday,
About Me
August 29, 2005
Name: Robert Vollman
New Blogs Location: Calgary, Alberta, Canada
Not long ago, I
wrote a blog on I was born and raised in Ottawa, and have lived in
all the Oracle Calgary since 1991. I like playing sports (hockey,
Blogs out there: soccer, ultimate, basketball, you name it) and military board
games. I also enjoy reading, walking, and playing with my 2 cats
http://
Lilly and Brutus. I'm a database application specialist, whatever
thinkoracle.
that is.
blogspot.
com/2005/07/ View my complete profile
oracle-blogs.
html

Not long after


Best Links
that, I included ● Ask Tom Kyte
a list of links to ● Oracle Docs
all the blogs I ● Dan Morgan and PSOUG
follow (see the ● Steven Feuerstein
side, below ● Jonathan Lewis
links). ● FAQ
Connor McDonald
Well there have

The Oak Table


been a couple of

Cary Millsap and Hotsos


changes and ●

new additions. ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/08/new-blogs.html (1 of 4)1/9/2008 2:55:47 AM


OracleBlog: New Blogs

The most ● Anjo Kolk and OraPerf


exciting of ● Dizwell Oracle Wiki
which is I found ● My Personal Blog
a blog by
Laurent

Aggregators
Schneider. He is
one of my
favourite
Brian Duff's OraBlogs
posters from the

Eddie Awad's OracleNA


Oracle Forum:

❍ Pete Finnigan's Aggregator


http://forums. ❍ Oracle's Bloglist
oracle.com/ ❍ Oracle Base Aggregator
forums/forum.
jspa? Top Blogs
forumID=75 ❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
His posts ❍ Blogger of the Year Eddie Awad
usually involve ❍ Data Warehouser David Aldridge
how to use ❍ Oracle Geek Lewis Cunningham
Oracle to solve Database Expert James Koopmann
someone's

Dizwell's Howard Rogers


problems. Over

Oracle Master Laurent Schneider


the months I've

Security Expert Pete Finnigan


been reading ❍

this forum, I've ❍ Oracle Award Winner Mark Rittman


seen him cover ❍ Doug Burns
a wide spectrum. ❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
Here is a link to ❍ Newbie DBA Lisa Dobson
one of of his ❍ Coffee-Drinking DBA Jon Emmons
most recent ❍ Chris Foot
articles:
❍ The Pythian DBA Team Blog
http:// ❍ DBA Don Seiler
laurentschneider. ❍ DBA Coskan Gundogar
Oracle WTF
blogspot. ❍

com/2005/08/
pivot-table.html
ARCHIVES
❍ LIST ALL ARTICLES
There are a few ❍ May 2005
other changes: ❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2005/08/new-blogs.html (2 of 4)1/9/2008 2:55:47 AM


OracleBlog: New Blogs

Doug Burns ❍ August 2005


changed his ❍ September 2005
blog's location: ❍ October 2005
http:// ❍ November 2005
oracledoug. ❍ December 2005
blogspot.com/ ❍ January 2006
February 2006
Radoslav

March 2006
Rusinov has a

April 2006
new blog, which

he has kicked ❍ May 2006


off with a ❍ June 2006
discussion of ❍ July 2006
the latest ❍ August 2006
Burleson ❍ September 2006
Boondoggle on ❍ October 2006
PGA: ❍ November 2006
http://dba-blog. ❍ December 2006
blogspot.com/ ❍ January 2007
❍ February 2007
Hopefully these March 2007
blogs will make

April 2007
up for my lack

May 2007
of content

recently! ❍ June 2007


❍ October 2007
// posted by Robert
Vollman @ Monday,

August 29, 2005

Comments:
And here is the
blogging
community on
OTN
# posted by
Eddie Awad :
Monday, 29 August,
2005

http://thinkoracle.blogspot.com/2005/08/new-blogs.html (3 of 4)1/9/2008 2:55:47 AM


OracleBlog: New Blogs

thanks for your


comment!
yours sincerly,
Laurent
# posted by
Laurent
Schneider :
Wednesday, 31
August, 2005

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/08/new-blogs.html (4 of 4)1/9/2008 2:55:47 AM


OracleBlog: OraBlogs!

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday,
About Me
August 09,
Name: Robert Vollman
2005
Location: Calgary, Alberta, Canada
OraBlogs!
Brian Duff I was born and raised in Ottawa, and have lived in
maintains a Calgary since 1991. I like playing sports (hockey,
blog that soccer, ultimate, basketball, you name it) and military board games.
brings I also enjoy reading, walking, and playing with my 2 cats Lilly and
together all the Brutus. I'm a database application specialist, whatever that is.
feeds from the
various Oracle
View my complete profile
blogs that are
out there.

http://www. Best Links


orablogs.com/ ● Ask Tom Kyte
orablogs/ ● Oracle Docs
● Dan Morgan and PSOUG
There are ● Steven Feuerstein
some fine Jonathan Lewis
blogs that are

FAQ
not included

Connor McDonald
because they

do not support ● The Oak Table


RSS 2.0 feed. ● Cary Millsap and Hotsos
Mine was one ● Steve Adams and Ixora
such case, I ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2005/08/orablogs.html (1 of 5)1/9/2008 2:55:49 AM


OracleBlog: OraBlogs!

used atom. ● Dizwell Oracle Wiki


Peter Scott and ● My Personal Blog
Doug Burns
then pointed

Aggregators
me to
Feedburner. It
converts your
Brian Duff's OraBlogs
feed from one

Eddie Awad's OracleNA


format into

Pete Finnigan's Aggregator


another. ❍

❍ Oracle's Bloglist
http://www. ❍ Oracle Base Aggregator

Top Blogs
feedburner.
com/
❍ Oracle's Ask Tom Kyte
Just go to their ❍ Oracle Guru Jonathan Lewis
web site, type ❍ Blogger of the Year Eddie Awad
in the URL to
Data Warehouser David Aldridge
your feed, and

Oracle Geek Lewis Cunningham


then accept all

Database Expert James Koopmann


the defaults. ❍

Just be sure ❍ Dizwell's Howard Rogers


that you have ❍ Oracle Master Laurent Schneider
these three ❍ Security Expert Pete Finnigan
settings ❍ Oracle Award Winner Mark Rittman
(courtesy of ❍ Doug Burns
Doug): ❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
1) Do NOT Newbie DBA Lisa Dobson
select

Coffee-Drinking DBA Jon Emmons


Smartfeed

Chris Foot
2) Select

Convert ❍ The Pythian DBA Team Blog


Format Burner ❍ DBA Don Seiler
3) Select RSS ❍ DBA Coskan Gundogar
2.0 from the ❍ Oracle WTF

ARCHIVES
list of options.

If all goes well,


LIST ALL ARTICLES
this should be

May 2005
my first post

on OraBlogs. It ❍ June 2005


would be great ❍ July 2005
❍ August 2005

http://thinkoracle.blogspot.com/2005/08/orablogs.html (2 of 5)1/9/2008 2:55:49 AM


OracleBlog: OraBlogs!

to kick things ❍ September 2005


off with a great ❍ October 2005
post but, alas, ❍ November 2005
I have nothing December 2005
to post about

January 2006
today. Instead,

February 2006
just like a bad

March 2006
80s sitcom, I ❍

will do a ❍ April 2006


"flashback ❍ May 2006
highlight ❍ June 2006
episode. Here ❍ July 2006
are my 5 ❍ August 2006
favourite posts ❍ September 2006
from my 3 ❍ October 2006
months of ❍ November 2006
existence: ❍ December 2006
January 2007
May 17th:

NULL is not ❍ February 2007


nothing ❍ March 2007
http:// ❍ April 2007
thinkoracle. ❍ May 2007
blogspot. ❍ June 2007
com/2005/05/ ❍ October 2007
null-vs-
nothing.html

June 10th:
NULLs in
Oracle (kind of
a "Part 2")
http://
thinkoracle.
blogspot.
com/2005/06/
nulls-in-oracle.
html

July 1st
(Canada Day):
Extra Columns

http://thinkoracle.blogspot.com/2005/08/orablogs.html (3 of 5)1/9/2008 2:55:49 AM


OracleBlog: OraBlogs!

in a Group By
http://
thinkoracle.
blogspot.
com/2005/07/
extra-columns-
in-group-by.
html

July 26th: Use


Constraints!
http://
thinkoracle.
blogspot.
com/2005/07/
use-
constraints.
html

July 29th:
Using Views
and other
techniques to
solve a
particular
problem
http://
thinkoracle.
blogspot.
com/2005/07/
oracle-by-
example.html

// posted by
Robert
Vollman @ Tuesday,
August 09, 2005

Comments:

http://thinkoracle.blogspot.com/2005/08/orablogs.html (4 of 5)1/9/2008 2:55:49 AM


OracleBlog: OraBlogs!

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/08/orablogs.html (5 of 5)1/9/2008 2:55:49 AM


OracleBlog: Wanted: Your Unwanted Oracle/DB Books

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday,
About Me
September 20,
Name: Robert Vollman
2005
Location: Calgary, Alberta, Canada
Wanted:
Your I was born and raised in Ottawa, and have lived in
Unwanted Calgary since 1991. I like playing sports (hockey,
soccer, ultimate, basketball, you name it) and military board games.
Oracle/ I also enjoy reading, walking, and playing with my 2 cats Lilly and
DB Books Brutus. I'm a database application specialist, whatever that is.
Please excuse
the spammy View my complete profile
post today. But
I would like to
ask anyone
who is reading
Best Links
Ask Tom Kyte
this who may

have unwanted ● Oracle Docs


Oracle (8 and ● Dan Morgan and PSOUG
up) or General ● Steven Feuerstein
DB (College) ● Jonathan Lewis
books to ● FAQ
contact me ● Connor McDonald
(email address ● The Oak Table
is in my ● Cary Millsap and Hotsos
profile). ● Steve Adams and Ixora
● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2005/09/wanted-your-unwanted-oracledb-books.html (1 of 4)1/9/2008 2:55:52 AM


OracleBlog: Wanted: Your Unwanted Oracle/DB Books

Rather than ● Dizwell Oracle Wiki


gather dust on ● My Personal Blog
your shelf, I
can give them

Aggregators
a good home. I
will pay for
shipping costs
Brian Duff's OraBlogs
to Canada, and

Eddie Awad's OracleNA


you will have

Pete Finnigan's Aggregator


my heartfelt ❍

appreciation. ❍ Oracle's Bloglist


❍ Oracle Base Aggregator

Top Blogs
Many thanks!

// posted by
Oracle's Ask Tom Kyte
Robert

Vollman @ Tuesday, ❍ Oracle Guru Jonathan Lewis


September 20, ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
2005
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
Comments: ❍ Dizwell's Howard Rogers
Rob, ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
A sensible ❍ Oracle Award Winner Mark Rittman
request. I just ❍ Doug Burns
wish you'd
Oracle ACE of the Year Dr. Tim Hall
asked a couple

UKOUG's Andrew (Arfur C.) Clarke


of months ago

Newbie DBA Lisa Dobson


when I was ❍

giving quite a ❍ Coffee-Drinking DBA Jon Emmons


few away to ❍ Chris Foot
worthy homes. ❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
I could do ❍ DBA Coskan Gundogar
James Morle's ❍ Oracle WTF
book for you,
but I'm pretty
sure that's
ARCHIVES
available ❍ LIST ALL ARTICLES
online for free ❍ May 2005
anyway. ❍ June 2005
Absolutely no ❍ July 2005
negative ❍ August 2005

http://thinkoracle.blogspot.com/2005/09/wanted-your-unwanted-oracledb-books.html (2 of 4)1/9/2008 2:55:52 AM


OracleBlog: Wanted: Your Unwanted Oracle/DB Books

comment ❍ September 2005


intended (I ❍ October 2005
kept it during ❍ November 2005
the clear-out, ❍ December 2005
after all) but I January 2006
don't refer

February 2006
back to that

March 2006
one much.

❍ April 2006
Cheers, ❍ May 2006
❍ June 2006
Doug ❍ July 2006
# posted by
❍ August 2006
Doug Burns : ❍ September 2006
Tuesday, 20 ❍ October 2006
September, 2005
❍ November 2006
❍ December 2006
Here is the link ❍ January 2007
to James ❍ February 2007
Morle's book: ❍ March 2007
http://www. ❍ April 2007
scaleabilities. ❍ May 2007
co.uk/papers/ ❍ June 2007
scalingOracle8i. ❍ October 2007
pdf

I'll still take a


hardcopy, if
you want to
give it a good
home, though!
# posted by
Robert
Vollman : Tuesday,
20 September,
2005

It's all yours -


email me the
details.

Cheers,

http://thinkoracle.blogspot.com/2005/09/wanted-your-unwanted-oracledb-books.html (3 of 4)1/9/2008 2:55:52 AM


OracleBlog: Wanted: Your Unwanted Oracle/DB Books

Doug
# posted by
Doug Burns :
Wednesday, 21
September, 2005

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/09/wanted-your-unwanted-oracledb-books.html (4 of 4)1/9/2008 2:55:52 AM


OracleBlog: Oracle WTF

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Thursday, September 01,


About Me
2005
Name: Robert Vollman
Oracle WTF Location: Calgary, Alberta, Canada
Another great way to learn
Oracle is to study mistakes. I was born and raised in Ottawa, and
have lived in Calgary since 1991. I like
Generally people have
playing sports (hockey, soccer, ultimate,
(misguided) reasons behind
basketball, you name it) and military board games.
their mistakes, and studying
I also enjoy reading, walking, and playing with my
them can improve your
2 cats Lilly and Brutus. I'm a database application
understanding of Oracle. As
specialist, whatever that is.
such I'd like you to check out
a new blog out there
dedicated to the most View my complete profile
spectacular

Best Links
misunderstandings of Oracle:

http://oracle-wtf.blogspot.
Ask Tom Kyte
com/

● Oracle Docs
Dan Morgan and PSOUG
It's written by William ●

Robertson, James Padfield, ● Steven Feuerstein


Thai Rices, Adrian Billington ● Jonathan Lewis
and inspired by http:// ● FAQ
thedailywtf.com. ● Connor McDonald
● The Oak Table
Another advantage of this ● Cary Millsap and Hotsos

http://thinkoracle.blogspot.com/2005/09/oracle-wtf.html (1 of 3)1/9/2008 2:55:54 AM


OracleBlog: Oracle WTF

blog, as compared to the 20- ● Steve Adams and Ixora


plus (and growing) other ● Anjo Kolk and OraPerf
Oracle blogs out there, is you ● Dizwell Oracle Wiki
a more likely to get a laugh ● My Personal Blog
out of it. Or at least a good
cry.

For those of you who enjoy


the Dizwell Forum, I have
Aggregators
gotten into the habit of Brian Duff's OraBlogs

posting the occasional WTF ❍ Eddie Awad's OracleNA


there myself: ❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
http://www.phpbbserver. ❍ Oracle Base Aggregator
com/phpbb/viewtopic.php?
t=310&mforum=dizwellforum
http://www.phpbbserver.
Top Blogs
❍ Oracle's Ask Tom Kyte
com/phpbb/viewtopic.php? ❍ Oracle Guru Jonathan Lewis
t=383&mforum=dizwellforum ❍ Blogger of the Year Eddie Awad
http://www.phpbbserver. ❍ Data Warehouser David Aldridge
com/phpbb/viewtopic.php? ❍ Oracle Geek Lewis Cunningham
t=417&mforum=dizwellforum ❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
By the way, "WTF" stands for Oracle Master Laurent Schneider
"What the F." As in "What the

Security Expert Pete Finnigan


F was the developer

Oracle Award Winner Mark Rittman


thinking?" :)

❍ Doug Burns
// posted by Robert ❍ Oracle ACE of the Year Dr. Tim Hall
Vollman @ Thursday, September 01, ❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
2005
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
Comments: ❍ The Pythian DBA Team Blog
Oh, fantastic. Thank you so ❍ DBA Don Seiler
much for posting this! ❍ DBA Coskan Gundogar
❍ Oracle WTF
Cheers,

Doug
ARCHIVES
❍ LIST ALL ARTICLES
# posted by Doug Burns :
May 2005
Thursday, 01 September, 2005

❍ June 2005

http://thinkoracle.blogspot.com/2005/09/oracle-wtf.html (2 of 3)1/9/2008 2:55:54 AM


OracleBlog: Oracle WTF

❍ July 2005
Thanks for the link... ❍ August 2005
❍ September 2005
Cheers! ❍ October 2005
Amar ❍ November 2005
# posted by adewri : Monday, 05 ❍ December 2005
September, 2005 ❍ January 2006
❍ February 2006
❍ March 2006
Post a Comment
❍ April 2006
May 2006
<< Home

❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/09/oracle-wtf.html (3 of 3)1/9/2008 2:55:54 AM


OracleBlog: Database Specialists

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, October 04, 2005


About Me
Database Name: Robert Vollman
Specialists Location: Calgary, Alberta, Canada
Recently Dr. Tim Hall posted a
brief blog on SQL Tuning. He I was born and raised in Ottawa, and
may have based it on a have lived in Calgary since 1991. I like
number of questions on the playing sports (hockey, soccer, ultimate,
topic that have popped up basketball, you name it) and military board games.
recently on some of the I also enjoy reading, walking, and playing with my
Oracle forums. 2 cats Lilly and Brutus. I'm a database application
specialist, whatever that is.
http://oracle-base.blogspot.
com/2005/10/no-shortcuts- View my complete profile
for-sql-tuning.html

You might also have seen


Steve Callan's 2-part article
Best Links
on Oracle Performance Tuning ● Ask Tom Kyte
on DBASupport.com: ● Oracle Docs
● Dan Morgan and PSOUG
http://www.dbasupport.com/ ● Steven Feuerstein
oracle/ora10g/perfTuning01. ● Jonathan Lewis
shtml ● FAQ
● Connor McDonald
So I was searching for a good ● The Oak Table
article I had once read on this
● Cary Millsap and Hotsos

http://thinkoracle.blogspot.com/2005/10/database-specialists.html (1 of 3)1/9/2008 2:55:57 AM


OracleBlog: Database Specialists

topic, and I found it. Here it ● Steve Adams and Ixora


is, courtesy of Ian Jones and ● Anjo Kolk and OraPerf
Roger Schrag of Database ● Dizwell Oracle Wiki
Specialists: ● My Personal Blog

http://www.dbspecialists.
com/presentations.
html#perf_bottleneck Aggregators
Brian Duff's OraBlogs
The articles on their site are ❍

sometimes dated, but I still ❍ Eddie Awad's OracleNA


find them useful and ❍ Pete Finnigan's Aggregator
interesting. Here is a ❍ Oracle's Bloglist
particularly fun article on ❍ Oracle Base Aggregator

Top Blogs
"Database Mysteries" courtesy
of Chris Lawson:
Oracle's Ask Tom Kyte
http://www.dbspecialists.

Oracle Guru Jonathan Lewis


com/presentations.

Blogger of the Year Eddie Awad


html#dba_mysteries

❍ Data Warehouser David Aldridge


❍ Oracle Geek Lewis Cunningham
// posted by Robert
Vollman @ Tuesday, October 04, ❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
2005 ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
Oracle Award Winner Mark Rittman
Comments:

Oh, and here is a link to the ❍ Doug Burns


FAQ Jonathan Lewis maintains ❍ Oracle ACE of the Year Dr. Tim Hall
on Performance. You can also ❍ UKOUG's Andrew (Arfur C.) Clarke
get their by clicking "FAQ" on ❍ Newbie DBA Lisa Dobson
my "best links." ❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
http://www.jlcomp.demon.co. ❍ The Pythian DBA Team Blog
uk/faq/ind_faq.
DBA Don Seiler
html#Performance_and_Tuning

❍ DBA Coskan Gundogar


# posted by Robert Vollman : ❍ Oracle WTF
Tuesday, 04 October, 2005

ARCHIVES
Post a Comment ❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005

http://thinkoracle.blogspot.com/2005/10/database-specialists.html (2 of 3)1/9/2008 2:55:57 AM


OracleBlog: Database Specialists

<< Home ❍ July 2005


❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/10/database-specialists.html (3 of 3)1/9/2008 2:55:57 AM


OracleBlog: Oracle Essays

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, November 04, 2005


About Me
Oracle Essays Name: Robert Vollman
Recently I recommended "Oracle Location: Calgary, Alberta,
Insights," a book containing a series of Canada
Oracle-related essays by some of the
top authors in our community. For
I was born and raised in
those who are interested in reading
Ottawa, and have lived in Calgary since
some more essays, consider some of
1991. I like playing sports (hockey,
the following samples from a variety of
soccer, ultimate, basketball, you name
my favourite authors on a variety of
it) and military board games. I also
topics. The best part is that these are
enjoy reading, walking, and playing with
free!
my 2 cats Lilly and Brutus. I'm a
Re-building Indexes: When, How, Why database application specialist,
by Jonathan Lewis whatever that is.
http://www.jlcomp.demon.co.uk/
indexes.doc View my complete profile

Programming Humility: Dealing with


the Reality of Errors by Steven Best Links
Feuerstein of Quest Software ● Ask Tom Kyte
http://www.odtug.com/Handouts_05/ ● Oracle Docs
Feuerstein.zip ● Dan Morgan and PSOUG
Steven Feuerstein
Locking and Concurrency by Tom Kyte

Jonathan Lewis
http://www.dbazine.com/oracle/or-

FAQ
articles/kyte1/

http://thinkoracle.blogspot.com/2005/11/oracle-essays.html (1 of 3)1/9/2008 2:55:59 AM


OracleBlog: Oracle Essays

Connor McDonald

Practical Guide to Oracle Data ● The Oak Table


Warehousing by David Aldridge ● Cary Millsap and Hotsos
http://databasejournal.com/features/ ● Steve Adams and Ixora
oracle/article.php/3098791 ● Anjo Kolk and OraPerf
Dizwell Oracle Wiki
Query Tuning Using DBMS_STATS by

My Personal Blog
Dave Ensor

http://www.dbazine.com/oracle/or-
articles/ensor6

String Aggregation Techniques by Dr.


Aggregators
Tim Hall Brian Duff's OraBlogs

http://www.oracle-base.com/ ❍ Eddie Awad's OracleNA


articles/10g/ ❍ Pete Finnigan's Aggregator
StringAggregationTechniques.php ❍ Oracle's Bloglist
❍ Oracle Base Aggregator
Bind Variables Explained by Mark
Rittman
http://www.rittman.net/
Top Blogs
❍ Oracle's Ask Tom Kyte
archives/000832.html ❍ Oracle Guru Jonathan Lewis
Blogger of the Year Eddie Awad
The following two articles are also

Data Warehouser David Aldridge


worth mentioning again. ❍

❍ Oracle Geek Lewis Cunningham


Why a 99%+ Database Buffer Cache Hit ❍ Database Expert James Koopmann
Ratio is Not Ok, by Cary Millsap of ❍ Dizwell's Howard Rogers
Hotsos ❍ Oracle Master Laurent Schneider
http://www.oradream.com/pdf/Why% ❍ Security Expert Pete Finnigan
20a%2099%20Cahe%20Hit%20Ratio% ❍ Oracle Award Winner Mark Rittman
20is%20Not%20OK.pdf ❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
Why I Invented YAPP by Anjo Kolk (Free ❍ UKOUG's Andrew (Arfur C.) Clarke
registration for download) Newbie DBA Lisa Dobson
http://www.oraperf.com/logon.html?

❍ Coffee-Drinking DBA Jon Emmons


rpage=download.php/yapp_anjo_kolk.
❍ Chris Foot
pdf ❍ The Pythian DBA Team Blog
DBA Don Seiler
While recommending some reading, I'm

DBA Coskan Gundogar


also including my favourite Oracle ❍

community debates of 2005: ❍ Oracle WTF

The great Burleson/Kyte debate on ARCHIVES


http://thinkoracle.blogspot.com/2005/11/oracle-essays.html (2 of 3)1/9/2008 2:55:59 AM
OracleBlog: Oracle Essays

"Predictive Reorganization" ❍ LIST ALL ARTICLES


http://asktom.oracle.com/pls/ask/f? ❍ May 2005
p=4950:8:8515227363337669542:: ❍ June 2005
NO::F4950_P8_ ❍ July 2005
DISPLAYID, ❍ August 2005
F4950_P8_CRITERIA:35336203098853 ❍ September 2005
❍ October 2005
The great Dizwell Forum debate: ❍ November 2005
"Natural vs Surrogate keys" ❍ December 2005
http://www.phpbbserver.com/phpbb/
❍ January 2006
viewtopic.php? ❍ February 2006
t=189&mforum=dizwellforum&sid=135 ❍ March 2006
April 2006
The great Burleson/Lewis debate on

May 2006
"Supersizing your PGA"

http://asktom.oracle.com/pls/ask/f? ❍ June 2006


July 2006
p=4950:8::::: ❍

August 2006
F4950_P8_DISPLAYID:47466211228419

❍ September 2006
// posted by Robert Vollman @ Friday, November
❍ October 2006
❍ November 2006
04, 2005 ❍ December 2006
❍ January 2007
❍ February 2007
Comments: Post a Comment
❍ March 2007
April 2007
<< Home ❍

❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/11/oracle-essays.html (3 of 3)1/9/2008 2:55:59 AM


OracleBlog: More Oracle Essays

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, November
About Me
11, 2005
Name: Robert Vollman
More Oracle Location: Calgary, Alberta, Canada
Essays
I recently posted an I was born and raised in Ottawa, and have lived in
assorted list of Calgary since 1991. I like playing sports (hockey,
Oracle essays from soccer, ultimate, basketball, you name it) and military board
some of my games. I also enjoy reading, walking, and playing with my 2
favourite Oracle cats Lilly and Brutus. I'm a database application specialist,
authors: whatever that is.
http://thinkoracle.
blogspot. View my complete profile
com/2005/11/

Best Links
oracle-essays.html

There are so many


Ask Tom Kyte
other great Oracle

Oracle Docs
writers out there

pleased to provide ● Dan Morgan and PSOUG


free insights into ● Steven Feuerstein
Oracle. So I thought ● Jonathan Lewis
I'd share a few ● FAQ
more with Troy and ● Connor McDonald
everyone else. ● The Oak Table
Remember that ● Cary Millsap and Hotsos
each of these ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/11/more-oracle-essays.html (1 of 5)1/9/2008 2:56:02 AM


OracleBlog: More Oracle Essays

authors have ● Anjo Kolk and OraPerf


written several ● Dizwell Oracle Wiki
papers, let me ● My Personal Blog
know if you have
trouble locating
more work from
your favourites. Aggregators
Improving SQL Brian Duff's OraBlogs

Efficiency Using ❍ Eddie Awad's OracleNA


CASE by Doug Burns ❍ Pete Finnigan's Aggregator
http://doug.burns. ❍ Oracle's Bloglist
tripod.com/case.pdf ❍ Oracle Base Aggregator

Exploiting and
Protecting Oracle
Top Blogs
Oracle's Ask Tom Kyte
by Pete Finnigan for

Oracle Guru Jonathan Lewis


PenTest Limited

Blogger of the Year Eddie Awad


http://downloads.

Data Warehouser David Aldridge


securityfocus.com/

Oracle Geek Lewis Cunningham


library/oracle-

Database Expert James Koopmann


security.pdf

❍ Dizwell's Howard Rogers


Write Better SQL ❍ Oracle Master Laurent Schneider
Using Regular ❍ Security Expert Pete Finnigan
Expressions by ❍ Oracle Award Winner Mark Rittman
Alice Rischert for ❍ Doug Burns
Oracle ❍ Oracle ACE of the Year Dr. Tim Hall
http://www.oracle. ❍ UKOUG's Andrew (Arfur C.) Clarke
com/technology/ ❍ Newbie DBA Lisa Dobson
oramag/ ❍ Coffee-Drinking DBA Jon Emmons
webcolumns/2003/ ❍ Chris Foot
techarticles/ ❍ The Pythian DBA Team Blog
rischert_regexp_pt1. ❍ DBA Don Seiler
html ❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
What, Where, When,
Why - Selecting
Oracle LIST ALL ARTICLES
Development Tools

May 2005
by Ken Atkins from

June 2005
ODTUG 2001

❍ July 2005

http://thinkoracle.blogspot.com/2005/11/more-oracle-essays.html (2 of 5)1/9/2008 2:56:02 AM


OracleBlog: More Oracle Essays

http://www. ❍ August 2005


arrowsent.com/ ❍ September 2005
oratip/whatwhere. ❍ October 2005
doc ❍ November 2005
❍ December 2005
Getting Fast Results ❍ January 2006
From STATSPACK ❍ February 2006
by Bjorn Engsig for March 2006
Miracle A/S

April 2006
http://www.

May 2006
miracleas.dk/tools/

June 2006
Miracle_1_statspack.

❍ July 2006
pdf
❍ August 2006
September 2006
SQL Tuning With

Statistics by ❍ October 2006


Wolfgang Breitling ❍ November 2006
for Centrex ❍ December 2006
http://www. ❍ January 2007
centrexcc.com/SQL ❍ February 2007
%20Tuning%20with% ❍ March 2007
20Statistics.pdf ❍ April 2007
❍ May 2007
The VARRAY Data ❍ June 2007
Type by Howard ❍ October 2007
Rogers of Dizwell
http://www.dizwell.
com/oracle/
articles/the_varray.
html

SQL In, XML Out by


Jonathan Gennick
for Oracle
Magazine May/June
2003
http://www.oracle.
com/technology/
oramag/oracle/03-
may/o33xml.html

Planning Extents by

http://thinkoracle.blogspot.com/2005/11/more-oracle-essays.html (3 of 5)1/9/2008 2:56:02 AM


OracleBlog: More Oracle Essays

Steve Adams for


Ixora
http://www.ixora.
com.au/tips/
creation/extents.
htm

Oracle Collections:
A Definition in Plain
English by Lewis R.
Cunningham
http://blogs.
ittoolbox.com/
oracle/guide/
archives/005924.
asp

Sorry, no Oracle
papers from your
favourite blogger! :)

// posted by Robert
Vollman @ Friday,

November 11, 2005

Comments:
Thanks for the link,
Rob.

Even more
impressively, you
picked the CASE
paper over the
DECODE paper,
despite your
personal preference
for DECODE ;-)

Cheers,

http://thinkoracle.blogspot.com/2005/11/more-oracle-essays.html (4 of 5)1/9/2008 2:56:02 AM


OracleBlog: More Oracle Essays

Doug
# posted by Doug
Burns : Saturday, 12
November, 2005

Same here, thanks


for the good
resource! Patrick
# posted by
Anonymous :
Saturday, 12 November,
2005

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2005/11/more-oracle-essays.html (5 of 5)1/9/2008 2:56:02 AM


OracleBlog: 10,000?

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday,
About Me
November 09,
Name: Robert Vollman
2005
Location: Calgary, Alberta, Canada
10,000?
This marks my I was born and raised in Ottawa, and have lived in
60th post since I Calgary since 1991. I like playing sports (hockey,
started in May, soccer, ultimate, basketball, you name it) and military board
and, according to games. I also enjoy reading, walking, and playing with my 2 cats
my stat counter I Lilly and Brutus. I'm a database application specialist, whatever
have had 10,000 that is.
hits.
View my complete profile
I was expecting
100, and even if
100 was the
current total, it Best Links
would still be ● Ask Tom Kyte
worthwhile for ● Oracle Docs
me to share my ● Dan Morgan and PSOUG
thoughts. Steven Feuerstein
Knowing that my

Jonathan Lewis
ideas have been

FAQ
read 10,000

times makes me ● Connor McDonald


feel more excited ● The Oak Table
about sharing ● Cary Millsap and Hotsos
them. ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/11/10000.html (1 of 3)1/9/2008 2:56:04 AM


OracleBlog: 10,000?

● Anjo Kolk and OraPerf


So whoever all of ● Dizwell Oracle Wiki
you are, you have ● My Personal Blog
my thanks, and I
will definitely
continue to write
about Oracle for
as long as people
Aggregators
are willing to Brian Duff's OraBlogs

read it! ❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
Cheers! ❍ Oracle's Bloglist
❍ Oracle Base Aggregator
// posted by Robert
Vollman @ Wednesday,
November 09, 2005
Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
Comments: ❍ Data Warehouser David Aldridge
I have ❍ Oracle Geek Lewis Cunningham
contributed to a ❍ Database Expert James Koopmann
few hits out of ❍ Dizwell's Howard Rogers
the 10,000 (so ❍ Oracle Master Laurent Schneider
far). Thanks, and ❍ Security Expert Pete Finnigan
keep on sharing... ❍ Oracle Award Winner Mark Rittman
# posted by Eddie ❍ Doug Burns
Awad : Wednesday, ❍ Oracle ACE of the Year Dr. Tim Hall
09 November, 2005
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
Coffee-Drinking DBA Jon Emmons
I have also been ❍

responsible for a ❍ Chris Foot


couple of the ❍ The Pythian DBA Team Blog
hits. Thanks for ❍ DBA Don Seiler
the great list of ❍ DBA Coskan Gundogar
essays in your ❍ Oracle WTF
previous post - I
am still going
through them.
ARCHIVES
❍ LIST ALL ARTICLES
# posted by Troy : ❍ May 2005
Thursday, 10
❍ June 2005
November, 2005
❍ July 2005

http://thinkoracle.blogspot.com/2005/11/10000.html (2 of 3)1/9/2008 2:56:04 AM


OracleBlog: 10,000?

❍ August 2005
Count me in too. ❍ September 2005
Keep up the good ❍ October 2005
work. ❍ November 2005
❍ December 2005
Cheers, ❍ January 2006
February 2006
Doug

❍ March 2006
# posted by Doug
❍ April 2006
Burns : Saturday, 12
❍ May 2006
November, 2005
❍ June 2006
❍ July 2006
Post a ❍ August 2006
Comment ❍ September 2006
❍ October 2006
<< Home ❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2005/11/10000.html (3 of 3)1/9/2008 2:56:04 AM


OracleBlog: Best Of OracleBlog

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday,
About Me
December 21,
Name: Robert Vollman
2005
Location: Calgary, Alberta, Canada
Best Of
OracleBlog I was born and raised in Ottawa, and have lived in
I got named in Calgary since 1991. I like playing sports (hockey,
ComputerWorld's soccer, ultimate, basketball, you name it) and military board
"Best IT Blogs on games. I also enjoy reading, walking, and playing with my 2 cats
the Net." Lilly and Brutus. I'm a database application specialist, whatever
Granted, only in that is.
the "buffer
overflow" section, View my complete profile
but still - that's
pretty cool!

http://www.
Best Links
computerworld. ● Ask Tom Kyte
com/blogs/ ● Oracle Docs
node/1466? ● Dan Morgan and PSOUG
source=nlt_blg ● Steven Feuerstein
● Jonathan Lewis
Maybe it is ● FAQ
another ● Connor McDonald
consequence of ● The Oak Table
the Thomas Kyte ● Cary Millsap and Hotsos
Effect? ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2005/12/best-of-oracleblog.html (1 of 10)1/9/2008 2:56:07 AM


OracleBlog: Best Of OracleBlog

● Anjo Kolk and OraPerf


http:// ● Dizwell Oracle Wiki
thinkoracle. ● My Personal Blog
blogspot.
com/2005/12/
thomas-kyte-
effect.html Aggregators
Brian Duff's OraBlogs

Anyway, I feel ❍ Eddie Awad's OracleNA


very fortunate for ❍ Pete Finnigan's Aggregator
having this new Oracle's Bloglist
audience, but I

Oracle Base Aggregator


feel bad for

having nothing
really intelligent Top Blogs
to say. So I ❍ Oracle's Ask Tom Kyte
thought I would ❍ Oracle Guru Jonathan Lewis
link to some of ❍ Blogger of the Year Eddie Awad
my favourite ❍ Data Warehouser David Aldridge
earlier posts, and ❍ Oracle Geek Lewis Cunningham
some of my most ❍ Database Expert James Koopmann
popular "hits", to Dizwell's Howard Rogers
give you an idea

Oracle Master Laurent Schneider


of what I like to

Security Expert Pete Finnigan


chat about.

❍ Oracle Award Winner Mark Rittman


To my more ❍ Doug Burns
frequent visitors ❍ Oracle ACE of the Year Dr. Tim Hall
like Doug, Eddie, ❍ UKOUG's Andrew (Arfur C.) Clarke
Laurent, Gary, ❍ Newbie DBA Lisa Dobson
Peter, David, ❍ Coffee-Drinking DBA Jon Emmons
William, and so ❍ Chris Foot
on, as well as any The Pythian DBA Team Blog
lurkers, I would

DBA Don Seiler


appreciate

DBA Coskan Gundogar


hearing your

Oracle WTF
picks, too. ❍

Here is the brief ARCHIVES


list of my ❍ LIST ALL ARTICLES
highlights: ❍ May 2005
June 2005
1. NULL

❍ July 2005

http://thinkoracle.blogspot.com/2005/12/best-of-oracleblog.html (2 of 10)1/9/2008 2:56:07 AM


OracleBlog: Best Of OracleBlog

❍ August 2005
I posted a few September 2005
articles on this,

October 2005
because there are

November 2005
quite a few errors

December 2005
casual database ❍

programmers ❍ January 2006


may make in ❍ February 2006
their ❍ March 2006
misunderstanding ❍ April 2006
of NULL and how ❍ May 2006
its treated in ❍ June 2006
Oracle. To put it ❍ July 2006
bluntly, NULL is ❍ August 2006
NOT nothing! If ❍ September 2006
ever I write a
October 2006
proper article for

November 2006
publication, it

December 2006
will likely be on

this topic. ❍ January 2007


❍ February 2007
NULL vs Nothing: ❍ March 2007
http:// ❍ April 2007
thinkoracle. ❍ May 2007
blogspot. ❍ June 2007
com/2005/05/ ❍ October 2007
null-vs-nothing.
html
NULLs in Oracle:
http://
thinkoracle.
blogspot.
com/2005/06/
nulls-in-oracle.
html
Using NULL to
exploit the
COUNT/NULL
feature:
http://
thinkoracle.
blogspot.

http://thinkoracle.blogspot.com/2005/12/best-of-oracleblog.html (3 of 10)1/9/2008 2:56:07 AM


OracleBlog: Best Of OracleBlog

com/2005/10/
using-decode-to-
exploit-countnull.
html

2. Best Practises

I like to blog a lot


on what I feel are
best practises for
database
programming.
Please allow me
to pick three of
the most general
of the bunch,
where I have
promoted Views,
Constraints and
Packages:

Use Views:
http://
thinkoracle.
blogspot.
com/2005/07/
use-views.html
Use Constraints:
http://
thinkoracle.
blogspot.
com/2005/07/
use-constraints.
html
Oracle Packages:
http://
thinkoracle.
blogspot.
com/2005/10/
oracle-packages.
html

http://thinkoracle.blogspot.com/2005/12/best-of-oracleblog.html (4 of 10)1/9/2008 2:56:07 AM


OracleBlog: Best Of OracleBlog

3. Advanced
Concepts

Occasionally I
blog on a
technique that
would only come
to the attention
of someone who
has used Oracle
to solve a more
complex
problem. Here is
one example of
that.

Pivot and
Crosstab
Queries:
http://
thinkoracle.
blogspot.
com/2005/09/
pivot-and-
crosstab-queries.
html

4. High-Hit Posts

There were two


posts that, for
various reasons,
seem to have
higher hit-counts
than the others.
Here they are:

Analyzing Query
Performance:
http://
thinkoracle.
blogspot.

http://thinkoracle.blogspot.com/2005/12/best-of-oracleblog.html (5 of 10)1/9/2008 2:56:07 AM


OracleBlog: Best Of OracleBlog

com/2005/09/
analyzing-query-
performance.html
UTL_HTTP:
http://
thinkoracle.
blogspot.
com/2005/08/
utlhttp.html

5. Putting it all
together

In "Oracle by
Example" I
brought together
many concepts
into one.
http://
thinkoracle.
blogspot.
com/2005/07/
oracle-by-
example.html

Throughout my
blog you'll also
see book reviews,
top 20 lists, and
lots of little tips
and tricks I
discover. As
you'll note, I
appreciate any
feedback, and I
get an email if
you leave a
comment even
on an old post,
so please feel
free to do so.

http://thinkoracle.blogspot.com/2005/12/best-of-oracleblog.html (6 of 10)1/9/2008 2:56:07 AM


OracleBlog: Best Of OracleBlog

I would also like


to direct my new
visitors to the
blogs I enjoy the
most. You can
see the list on
the right-hand
side, but other
than Tom Kyte's,
which you have
surely already
visited (http://
tkyte.blogspot.
com), I would like
to draw particular
attention to these
two:

Doug Burns:
http://
oracledoug.
blogspot.com
Eddie Awad:
http://awads.net/
wp

I enjoy ALL those


blogs, but if you
only have time
for a couple,
please check
those out.

Warning to Doug
and Eddie: You
might experience
the first ever
Robert Vollman
Effect!

// posted by Robert
Vollman @ Wednesday,
December 21, 2005

http://thinkoracle.blogspot.com/2005/12/best-of-oracleblog.html (7 of 10)1/9/2008 2:56:07 AM


OracleBlog: Best Of OracleBlog

Comments:
It's really cool
indeed to be
mentioned in
ComputerWorld.
Thanks for
drawing a
particular
attention to my
blog. I will be
anxiously waiting
for the "Robert
Vollman Effect".

I remember that
both our blogs
were added to
OraBlogs.com
around the same
time and since
then our
readership has
increased
steadily (I know
mine has). I can
tell you that this
blogging thing
has given me
pleasure and
more friends, not
to mention more
knowledge.

Keep it up Rob....

Oh! and Merry


Xmas...
# posted by Eddie
Awad : Wednesday,
21 December, 2005

http://thinkoracle.blogspot.com/2005/12/best-of-oracleblog.html (8 of 10)1/9/2008 2:56:07 AM


OracleBlog: Best Of OracleBlog

Rob,

No sign of a
traffic bonanza
yet, but I'll give it
time because the
Tom Kyte effect
is certainly
starting to kick in
a little :-

76 www.orablogs.
com/orablogs/
35 tkyte.blogspot.
com/
15 oracledoug.
blogspot.
com/2005/12/i-
swear-i-didnt-
know.html
9 oracledoug.
blogspot.
com/2005/12/
bill-vs-tom-kyte.
html
8 oracledoug.
blogspot.com/
7 www.orafaq.
com/aggregator
6 www.google.
com/search?
hl=en&q=sql
decode
6 www.google.
com/reader/lens/
6 www.google.it/
search?
hl=it&q=wml and
stylesheet&meta=
5 my.yahoo.com/
index.html

http://thinkoracle.blogspot.com/2005/12/best-of-oracleblog.html (9 of 10)1/9/2008 2:56:07 AM


OracleBlog: Best Of OracleBlog

Thanks for the


positive
comment in any
case.

As for my
favourite blogs, I
think you
covered them all
above. In
general, I liked
the ones about
commonly-used
features that
people might not
have come across
before or had
forgotten about.

Have a great
holiday and best
of luck for the
new year.

Cheers,

Doug
# posted by Doug
Burns : Thursday, 22
December, 2005

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2005/12/best-of-oracleblog.html (10 of 10)1/9/2008 2:56:07 AM


OracleBlog: Odds and Ends

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Friday, January 20, 2006


About Me
Odds and Ends Name: Robert Vollman
PL/SQL vs J2EE, Part 2 Location: Calgary, Alberta,
Canada
I knew there was going to be some
discussion following up my previous
post on using stored procedures I was born and raised in
instead of embedding SQL in your Ottawa, and have lived in Calgary since
J2EE application. Some of it you can 1991. I like playing sports (hockey,
read in the comments, others you can soccer, ultimate, basketball, you name it)
find on other people's blogs. and military board games. I also enjoy
reading, walking, and playing with my 2
Original Article cats Lilly and Brutus. I'm a database
Tim Hall's Response (and Here). application specialist, whatever that is.
Harry Boswell's Response
View my complete profile
Dizwell Discussion: Database
Independence

I also saw a similar discussion that Best Links


had taken place over a year ago. ● Ask Tom Kyte
Check out these posts by Mark ● Oracle Docs
Rittman and Dave Warnock for a ● Dan Morgan and PSOUG
Point-Counterpoint on the debate. ● Steven Feuerstein
Jonathan Lewis
Mark Rittman ●

FAQ
Dave Warnock's Response

● Connor McDonald

http://thinkoracle.blogspot.com/2006/01/odds-and-ends.html (1 of 5)1/9/2008 2:56:10 AM


OracleBlog: Odds and Ends

Gary Myers and Harold Ramis The Oak Table


Separated At Birth ● Cary Millsap and Hotsos


● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
Oracle's Bloglist
Gary Myers

❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
Harold Ramis ❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
In seriousness, I've enjoyed Gary ❍ Doug Burns
Myers' blog for quite some time, but I ❍ Oracle ACE of the Year Dr. Tim Hall
particularly enjoyed his recent series ❍ UKOUG's Andrew (Arfur C.) Clarke
of blogs on the 12 SELECTs of ❍ Newbie DBA Lisa Dobson
Christmas, so I thought I would Coffee-Drinking DBA Jon Emmons
highlight it for you to enjoy again.

Chris Foot
12 Selects of Christmas, Part I

The Pythian DBA Team Blog


12 Selects of Christmas, Part II

DBA Don Seiler


12 Selects of Christmas, Part III

❍ DBA Coskan Gundogar


12 Selects of Christmas, Part IV ❍ Oracle WTF

Neat Tricks
ARCHIVES
Some time ago I posted an article on ❍ LIST ALL ARTICLES

http://thinkoracle.blogspot.com/2006/01/odds-and-ends.html (2 of 5)1/9/2008 2:56:10 AM


OracleBlog: Odds and Ends

UTL_HTTP that gave Pete Finnigan a ❍ May 2005


security-related heart attack. Just ❍ June 2005
when he was recovering, Doug Burns ❍ July 2005
posted a neat little trick that will give August 2005
him another stroke. Apparently within

September 2005
SQL*Plus you can execute an SQL

October 2005
script somewhere on the Internet. Try

November 2005
it! ❍

❍ December 2005
UTL_HTTP Post ❍ January 2006
Pete Finnigan ❍ February 2006
Doug Burns ❍ March 2006
❍ April 2006
Blog Updates ❍ May 2006
❍ June 2006
I've noticed Tony Andrews, whose July 2006
blog I quoted in my last post, has

August 2006
some new content including an

September 2006
interesting So Doku Solver in PL/SQL.

Check it out here, and hope he ❍ October 2006


continues to post: ❍ November 2006
Tony Andrews PL/SQL So Doku Solver ❍ December 2006
❍ January 2007
Another new Oracle blog to check out ❍ February 2007
is Yas'. I've enjoyed several of his ❍ March 2007
postings recently, so its hard to pick ❍ April 2007
just one to highlight, but given its ❍ May 2007
similarity to my recent post on Bulk ❍ June 2007
Binding and FORALL, here is one on October 2007
BULK COLLECT.

My FORALL
Yas' BULK COLLECT

Ask Tom

I spend a fair bit of my Oracle web-


surfing time over on AskTom. If you
ask many of us, we'll say its an
invaluable source of information, and
also houses some very interesting
discussions. Here are three samples
of discussions I've been following
recently.

http://thinkoracle.blogspot.com/2006/01/odds-and-ends.html (3 of 5)1/9/2008 2:56:10 AM


OracleBlog: Odds and Ends

Driving Tables
Introduction to Analytical Functions
Batch Processing

Old Post Updates

The original intention of this blog


was to have a place to organise my
thoughts on things that I have
learned about Oracle. Therefore,
generally a post here is merely one of
the early stages of my exploration on
a particular topic. I usually continue
my exploration, and doubtlessly
continue to find interesting articles
on the same topics. Here are two
examples.

You may have noticed that I talk a lot


about NULL, how funny it is, and how
misunderstandings lead to errors. I
mentioned recently that if I were to
write an article it would probably be
about NULLs. I was flipping through
an Oracle magazine I had missed
from last Summer and saw that Lex
de Haan and Jonathan Gennick had
beaten me to it.
Nulls: Nothing to Worry About

Last Fall I blogged on using ROWNUM


and ROWID, and I just recently found
an awesome post on AMIS to
demonstrate the power of using
ROWNUM to improve performance.
Original Post on ROWNUM
Alex Nuijten on ROWNUM

Finally

My final order of business is related


to Oracle only in that it involves one
of our favourite PL/SQL experts,

http://thinkoracle.blogspot.com/2006/01/odds-and-ends.html (4 of 5)1/9/2008 2:56:10 AM


OracleBlog: Odds and Ends

Steven Feuerstein. Steven recently


started a personal blog, and even
posted an article in response to a
questionable comment I left on
Eddie's Blog.

Eddie Awad
Steven Feuerstein is a nut?

But rather than talk about nuts, I


would really like to highlight just how
much Steven Feuerstein's work has
helped me, and how it can help
others. You can see my blog is
littered with examples, here is
another, about how to hide your code:

Steven Feuerstein Q&A: Hiding PL/SQL


My Article about Steven Feuerstein on
Refactoring

// posted by Robert Vollman @ Friday, January

20, 2006

Comments: Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/01/odds-and-ends.html (5 of 5)1/9/2008 2:56:10 AM


OracleBlog: Meeting Tom Kyte

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Sunday, June 18, 2006


About Me
Meeting Tom Kyte Name: Robert
"You have redeemed my faith, after last year's Vollman
presentation, which was such a Location: Calgary,
disappointment."- One of Tom Kyte's biggest Alberta, Canada
fans in COUG
I was born and raised in Ottawa,
and have lived in Calgary since
1991. I like playing sports
(hockey, soccer, ultimate,
basketball, you name it) and
military board games. I also
enjoy reading, walking, and
playing with my 2 cats Lilly and
Brutus. I'm a database
application specialist, whatever
that is.

View my complete profile

Renowned Oracle expert and author of highly


popular blog, pictured here with Tom Kyte. Best Links
● Ask Tom Kyte
I first met Tom Kyte about twenty minutes ● Oracle Docs
before his presentation about his favourite
Dan Morgan and PSOUG
features in Oracle 10g. When I went up to

http://thinkoracle.blogspot.com/2006/06/meeting-tom-kyte.html (1 of 3)1/9/2008 2:56:13 AM


OracleBlog: Meeting Tom Kyte

introduce myself, I figured he was putting the ● Steven Feuerstein


final touches on his presentation, but he was ● Jonathan Lewis
actually answering questions for his AskTom ● FAQ
web site. I guess you have to find the time for ● Connor McDonald
that somewhere! ● The Oak Table
Cary Millsap and Hotsos
Due in part to his reputation for fine speeches

Steve Adams and Ixora


(his biggest fan notwithstanding), there were ●

quite a few people in attendance. Tom reports ● Anjo Kolk and OraPerf
having answered 33,000 different Oracle- ● Dizwell Oracle Wiki
related questions. I wonder how many people ● My Personal Blog
were there hoping they could find that one
question that pushed him over the edge.
Sadly, no such luck.

I enjoyed the presentation myself, despite still


Aggregators
Brian Duff's OraBlogs
being on Oracle 9. Based on some of the

Eddie Awad's OracleNA


features, including DBMS_SQLTUNE which

Pete Finnigan's Aggregator


uses SQL Profiles to find patterns in your data ❍

that can help speed up queries, I wonder how ❍ Oracle's Bloglist


long before he comes to town announcing ❍ Oracle Base Aggregator
that the next release of Oracle is sentient.

I was a little surprised to hear his excitement


Top Blogs
❍ Oracle's Ask Tom Kyte
about DBMS_ADVANCED_REWRITE, which
Oracle Guru Jonathan Lewis
allows you to tell Oracle "listen, when I write

Blogger of the Year Eddie Awad


this query, what I REALLY want is this

Data Warehouser David Aldridge


completely different query." I can't believe I'm ❍

going to have to learn to start typing ❍ Oracle Geek Lewis Cunningham


"FOR_REAL" after all my queries. Maybe in ❍ Database Expert James Koopmann
Oracle 11 we'll need ❍ Dizwell's Howard Rogers
"NO_SERIOUSLY_I_MEAN_IT". ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
On a more serious note, it sounds like Oracle ❍ Oracle Award Winner Mark
10 has a lot more bells and whistles Rittman
ultimately aimed to speed things up. Take PL/ ❍ Doug Burns
SQL compilation for example. When you
Oracle ACE of the Year Dr. Tim
"CREATE OR REPLACE" it will check whether a

Hall
recompilation is really necessary, and will also
UKOUG's Andrew (Arfur C.) Clarke
look for optimizations within your code. I

Newbie DBA Lisa Dobson


guess the end result is a little bit more ❍

overhead to check for things, but faster ❍ Coffee-Drinking DBA Jon Emmons
results, especially for inexperienced ❍ Chris Foot
programmers. ❍ The Pythian DBA Team Blog

http://thinkoracle.blogspot.com/2006/06/meeting-tom-kyte.html (2 of 3)1/9/2008 2:56:13 AM


OracleBlog: Meeting Tom Kyte

DBA Don Seiler


Afterwards we all retired to Bottlescrew Bill's ❍ DBA Coskan Gundogar


for COUG's annual social, where I enjoyed ❍ Oracle WTF
Tom's stories almost as much as his
presentation. In contrast to the light-hearted
ribbing with which I began this post, virtually
ARCHIVES
everyone ranks him as one of the very best ❍ LIST ALL ARTICLES
Oracle speakers. I'm really glad he paid us a ❍ May 2005
visit, and look forward to hearing him again. ❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
// posted by Robert Vollman @ Sunday, June 18, 2006 ❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
Comments: Post a Comment ❍ February 2007
❍ March 2007
<< Home ❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2006/06/meeting-tom-kyte.html (3 of 3)1/9/2008 2:56:13 AM


OracleBlog: Call For Topics

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday,
About Me
June 07, 2006
Name: Robert Vollman
Call For Location: Calgary, Alberta, Canada
Topics
This morning I I was born and raised in Ottawa, and have lived in
read that fellow Calgary since 1991. I like playing sports (hockey,
Oracle blogger soccer, ultimate, basketball, you name it) and military board
Tim Hall is games. I also enjoy reading, walking, and playing with my 2 cats
looking for Lilly and Brutus. I'm a database application specialist, whatever
Oracle topics on that is.
which to base his
next article. It View my complete profile
occurs to me that
since changing
positions a few
months ago that I
Best Links
have dealt with ● Ask Tom Kyte
Oracle a lot less ● Oracle Docs
than previously, ● Dan Morgan and PSOUG
and am open to ● Steven Feuerstein
hearing some ● Jonathan Lewis
ideas. ● FAQ
● Connor McDonald
Virtually all my The Oak Table
articles are based

Cary Millsap and Hotsos


on questions I

● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/06/call-for-topics.html (1 of 4)1/9/2008 2:56:15 AM


OracleBlog: Call For Topics

get from ● Anjo Kolk and OraPerf


customers or ● Dizwell Oracle Wiki
colleagues, or ● My Personal Blog
problems I have
to solve in my
day-to-day work.
There are times
when that stream
Aggregators
Brian Duff's OraBlogs
is a trickle, and

Eddie Awad's OracleNA


times when its a ❍

raging river. ❍ Pete Finnigan's Aggregator


❍ Oracle's Bloglist
Right now its a ❍ Oracle Base Aggregator
trickle. But I'd
like to keep up
the momentum
Top Blogs
Oracle's Ask Tom Kyte
rather than have

Oracle Guru Jonathan Lewis


this blog go the

Blogger of the Year Eddie Awad


way of my Sybase ❍

Data Warehouser David Aldridge


blog.

❍ Oracle Geek Lewis Cunningham


And don't confine ❍ Database Expert James Koopmann
your questions to ❍ Dizwell's Howard Rogers
my area of ❍ Oracle Master Laurent Schneider
interest ❍ Security Expert Pete Finnigan
(development), ❍ Oracle Award Winner Mark Rittman
because I happen ❍ Doug Burns
to know that ❍ Oracle ACE of the Year Dr. Tim Hall
several other ❍ UKOUG's Andrew (Arfur C.) Clarke
excellent
Newbie DBA Lisa Dobson
bloggers like

Coffee-Drinking DBA Jon Emmons


Eddie Awad, Gary

Chris Foot
Myers, Tom Kyte,

The Pythian DBA Team Blog


Doug Burns and

DBA Don Seiler


others may also

DBA Coskan Gundogar


pick up on any

Oracle WTF
ideas you leave in

my comments.
ARCHIVES
Well maybe not ❍ LIST ALL ARTICLES
Tom, I think he ❍ May 2005
gets enough ❍ June 2005
questions. :) ❍ July 2005

http://thinkoracle.blogspot.com/2006/06/call-for-topics.html (2 of 4)1/9/2008 2:56:15 AM


OracleBlog: Call For Topics

❍ August 2005
// posted by Robert
Vollman @ Wednesday, ❍ September 2005
❍ October 2005
June 07, 2006
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
Comments:
March 2006
I'd like to keep

April 2006
up the

momentum ❍ May 2006


❍ June 2006
Maybe this will ❍ July 2006
help: http://www. ❍ August 2006
problogger.net/ ❍ September 2006
battling- ❍ October 2006
bloggers-block/ ❍ November 2006
December 2006
Otherwise,

January 2007
browsing the ❍

Oracle Docs, ❍ February 2007


especially ❍ March 2007
hunting and ❍ April 2007
learning new and ❍ May 2007
less known ❍ June 2007
features, is a ❍ October 2007
good source of
ideas.
# posted by Eddie
Awad : Wednesday,
07 June, 2006

You can talk


about the new
rules engine in
10gr2 .
# posted by
gonen :
Wednesday, 07 June,
2006

http://thinkoracle.blogspot.com/2006/06/call-for-topics.html (3 of 4)1/9/2008 2:56:15 AM


OracleBlog: Call For Topics

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/06/call-for-topics.html (4 of 4)1/9/2008 2:56:15 AM


OracleBlog: Ask Tom

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, July
About Me
25, 2006
Name: Robert Vollman
Ask Tom Location: Calgary, Alberta, Canada
In keeping with
the theme of I was born and raised in Ottawa, and have lived in
my most Calgary since 1991. I like playing sports (hockey,
recent post, I soccer, ultimate, basketball, you name it) and military board games.
just couldn't I also enjoy reading, walking, and playing with my 2 cats Lilly and
stop laughing Brutus. I'm a database application specialist, whatever that is.
at Tom's most
recent
View my complete profile
response to a
question about
recursive sql.
Best Links
// posted by ● Ask Tom Kyte
Robert
Oracle Docs
Vollman @ Tuesday,

● Dan Morgan and PSOUG


July 25, 2006
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
Comments: ● The Oak Table
That was
Cary Millsap and Hotsos
funny :)

# posted by
● Steve Adams and Ixora
● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2006/07/ask-tom.html (1 of 3)1/9/2008 2:56:18 AM


OracleBlog: Ask Tom

Eddie Awad :
● Dizwell Oracle Wiki
Tuesday, 25 July, ● My Personal Blog
2006

how long does


the catproc.sql
Aggregators
Brian Duff's OraBlogs
take

Eddie Awad's OracleNA


# posted by

❍ Pete Finnigan's Aggregator


Anonymous :
❍ Oracle's Bloglist
Friday, 15
September, 2006 ❍ Oracle Base Aggregator

Top Blogs
Hi, i am really, ❍ Oracle's Ask Tom Kyte
really, new at ❍ Oracle Guru Jonathan Lewis
HTMLDB and Blogger of the Year Eddie Awad
want to know

Data Warehouser David Aldridge


the best way to

Oracle Geek Lewis Cunningham


learn the

Database Expert James Koopmann


program. Also ❍

i have been ❍ Dizwell's Howard Rogers


trying to ❍ Oracle Master Laurent Schneider
research ❍ Security Expert Pete Finnigan
validations and ❍ Oracle Award Winner Mark Rittman
can't seem to ❍ Doug Burns
find easy ❍ Oracle ACE of the Year Dr. Tim Hall
explainations ❍ UKOUG's Andrew (Arfur C.) Clarke
for them (i just ❍ Newbie DBA Lisa Dobson
get course ❍ Coffee-Drinking DBA Jon Emmons
overviews) ❍ Chris Foot
pls help :{ ❍ The Pythian DBA Team Blog
# posted by ❍ DBA Don Seiler
Anonymous :
❍ DBA Coskan Gundogar
Tuesday, 05 ❍ Oracle WTF

ARCHIVES
December, 2006

LIST ALL ARTICLES


Hi,

❍ May 2005
I didn't find ❍ June 2005
out how to ❍ July 2005
post question ❍ August 2005

http://thinkoracle.blogspot.com/2006/07/ask-tom.html (2 of 3)1/9/2008 2:56:18 AM


OracleBlog: Ask Tom

in ask tom ❍ September 2005


home page, ❍ October 2005
How can I join ❍ November 2005
and ask ❍ December 2005
question? ❍ January 2006
February 2006
My question is:

Can I create ❍ March 2006


physical ❍ April 2006
standby ❍ May 2006
database using ❍ June 2006
10.1.0.5 for ❍ July 2006
10.1.0.2 ❍ August 2006
❍ September 2006
Thanks ❍ October 2006
# posted by
❍ November 2006
Anonymous :
❍ December 2006
Friday, 21
January 2007
September, 2007

❍ February 2007
❍ March 2007
Post a ❍ April 2007
Comment ❍ May 2007
❍ June 2007
<< Home ❍ October 2007

http://thinkoracle.blogspot.com/2006/07/ask-tom.html (3 of 3)1/9/2008 2:56:18 AM


OracleBlog: Finding Information

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday, July 19, 2006


About Me
Finding Information Name: Robert
QUESTION Vollman
Location: Calgary,
Hi Robert,
Alberta, Canada
I don't understand the meaning of any of the
items on the query plan. I was born and raised in Ottawa,
and have lived in Calgary since
Is there some document that would explain 1991. I like playing sports
what they are? If there is, where can I get it? (hockey, soccer, ultimate,
basketball, you name it) and
Thanks. military board games. I also
enjoy reading, walking, and
ANSWER playing with my 2 cats Lilly and
Brutus. I'm a database
That's the best kind of question. Instead of
application specialist, whatever
sending me a query plan and asking me to
that is.
interpret it for you, you're asking me for the
means to do it yourself. Which is good
View my complete profile
because there is so much I don't understand
about Oracle that I would have to study up to
help you anyway.

Oracle Documentation
Best Links
● Ask Tom Kyte
Oracle Docs
I love Oracle documentation. I can usually find

Dan Morgan and PSOUG


what I want in there, complete with examples ●

http://thinkoracle.blogspot.com/2006/07/finding-information.html (1 of 4)1/9/2008 2:56:22 AM


OracleBlog: Finding Information

and explanations. So let's start there. ● Steven Feuerstein


● Jonathan Lewis
Once you have navigated to Oracle's ● FAQ
documentation page, you'll want to select ● Connor McDonald
"View Library" and then go thorugh the ● The Oak Table
searching page. ● Cary Millsap and Hotsos
Steve Adams and Ixora
Choosing the right phrase can be tricky. In

Anjo Kolk and OraPerf


this case, try TKPROF, Query Plan, Execution ●

Plan. ● Dizwell Oracle Wiki


● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
Searching with any of these three phrases Data Warehouser David Aldridge
points rather conclusively at the Oracle

❍ Oracle Geek Lewis Cunningham


Performance Tuning Guide and Reference. ❍ Database Expert James Koopmann
Taking a look through it, it seems to have lots Dizwell's Howard Rogers
of information to get you started on how to

Oracle Master Laurent Schneider


understand the execution plans you see in the

Security Expert Pete Finnigan


TKPROF output.

❍ Oracle Award Winner Mark


Ask Tom Rittman
❍ Doug Burns
The second thing I like to do is Ask Tom. He ❍ Oracle ACE of the Year Dr. Tim
has answered 33,000 questions, meaning that Hall
in any case, my question was probably ❍ UKOUG's Andrew (Arfur C.) Clarke
already asked. Sometimes his answers include ❍ Newbie DBA Lisa Dobson
links to other information. ❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog

http://thinkoracle.blogspot.com/2006/07/finding-information.html (2 of 4)1/9/2008 2:56:22 AM


OracleBlog: Finding Information

DBA Don Seiler


❍ DBA Coskan Gundogar


❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
Searching our three chosen phrases points to ❍ February 2006
one Ask Tom article in particular that might ❍ March 2006
be helpful. ❍ April 2006
❍ May 2006
Google ❍ June 2006
July 2006
Sometimes I can google around to find

August 2006
articles on a topic. Normally I favour sources I ❍

trust, like Jonathan Lewis or something. In ❍ September 2006


this case, googling found me this article: ❍ October 2006
❍ November 2006
Use EXPLAIN PLAN and TKRPOF To Tune Your ❍ December 2006
Applications, by Roger Schrag ❍ January 2007
❍ February 2007
Still Stuck? ❍ March 2007
April 2007
If you've gone through these sources and you

May 2007
still haven't found the information you're ❍

looking for, it's time for a degree of ❍ June 2007


intrepidity. ❍ October 2007

I would certainly want to contact my fellow


Oracle specialists. But rather than contact one
individually with an open-ended question, I
would post a message to a forum or message
board, making sure to highlight what I had
already looked for, what I had already found,

http://thinkoracle.blogspot.com/2006/07/finding-information.html (3 of 4)1/9/2008 2:56:22 AM


OracleBlog: Finding Information

and specifically how it came up short.

It is possible that the information I'm looking


for has never been written. If so, that would
be a great opportunity for me to do some
research and make my own, new contribution
to the Oracle community.

// posted by Robert Vollman @ Wednesday, July 19, 2006

Comments:
Robert,

Based on the number of times I've found


myself explaining this kind of thing, I think
this'll prove really useful for a lot of people.
Nice one.

Cheers,

Doug
# posted by Doug Burns : Wednesday, 19 July, 2006

You ought to add this to the Performance


Tuning wiki.
# posted by Joel Garry : Friday, 21 July, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/07/finding-information.html (4 of 4)1/9/2008 2:56:22 AM


OracleBlog: Something To Do Right Now

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Wednesday,
About Me
September 13,
Name: Robert Vollman
2006
Location: Calgary, Alberta, Canada
Something
To Do I was born and raised in Ottawa, and have lived in
Right Now Calgary since 1991. I like playing sports (hockey,
soccer, ultimate, basketball, you name it) and military board
If you're still
games. I also enjoy reading, walking, and playing with my 2 cats
using any of the
Lilly and Brutus. I'm a database application specialist, whatever
default Oracle
that is.
username/
passwords on
View my complete profile
any of your
databases, go
change it now.
Best Links
I could blog ● Ask Tom Kyte
about this for 1- ● Oracle Docs
2 pages, but for ● Dan Morgan and PSOUG
two reasons: Steven Feuerstein
1. I think it is an

Jonathan Lewis
obvious (but oft-

FAQ
neglected) thing

to do, and ● Connor McDonald


2. You can use ● The Oak Table
the time you ● Cary Millsap and Hotsos
would have spent ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/09/something-to-do-right-now.html (1 of 3)1/9/2008 2:56:24 AM


OracleBlog: Something To Do Right Now

reading my ● Anjo Kolk and OraPerf


persuasive ● Dizwell Oracle Wiki
arguments to ● My Personal Blog
actually go
change your
passwords.

So go do it now.
Aggregators
Brian Duff's OraBlogs

// posted by Robert ❍ Eddie Awad's OracleNA


Vollman @ Wednesday, ❍ Pete Finnigan's Aggregator
September 13, 2006 ❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Comments:
Top Blogs
❍ Oracle's Ask Tom Kyte
Post a
❍ Oracle Guru Jonathan Lewis
Comment
❍ Blogger of the Year Eddie Awad
Data Warehouser David Aldridge
<< Home

❍ Oracle Geek Lewis Cunningham


❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2006/09/something-to-do-right-now.html (2 of 3)1/9/2008 2:56:24 AM


OracleBlog: Something To Do Right Now

❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2006/09/something-to-do-right-now.html (3 of 3)1/9/2008 2:56:24 AM


OracleBlog: Protecting PL/SQL Code

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Saturday, September 02, 2006


Protecting PL/SQL Code
There are two broad categories of reasons why PL/SQL programmers
wouldn't want others to read their code:

Reason #1 Protection
The programmers wish to protect their code from theft, misuse or
alteration (among other things).

Reason #2 Malicious Reasons


The code is meant to do harm, or may have some potentially
dangerous errors they wish to cover up.

I don't believe in hidden code, because open code is easier to debug,


reuse, and it is obviously easier to detect (deliberately or
accidentally) harmful code.

But regardless of whether code you have received from a vendor or


contractor is protected or not, you should be testing it thoroughly
before using it anyway. Plus, these methods are already thoroughly
documented in a number of places, not the least of which by expert
Steven Feuerstein and also in Oracle's documentation.

In fact, the example I'm using is from Oracle's documentation.

Normally, after creating a stored procedure, the source code can be


access through a SOURCE table, like so:

http://thinkoracle.blogspot.com/2006/09/protecting-plsql-code.html (1 of 8)1/9/2008 2:56:26 AM


OracleBlog: Protecting PL/SQL Code

SQL> SELECT text FROM USER_SOURCE


SQL> WHERE name = 'WRAPTEST' order by line;

TEXT
-----------------------------------------------------------

PROCEDURE wraptest IS
TYPE emp_tab IS TABLE OF emp%ROWTYPE INDEX BY PLS_INTEGER;
all_emps emp_tab;
BEGIN
SELECT * BULK COLLECT INTO all_emps FROM emp;
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE('Emp Id: ' || all_emps(i).empno);
END LOOP;
END;

How can we avoid this?

My first thought is simply not to load the procedure into the


database at all. Leave the procedure as an SQL file on the server, and
execute it remotely. About a year ago, I engaged some Oracle
programmers in such an approach, check that earlier article for a
brief discussion on the advantages and disadvantages of keeping
your code out of the database:
PL/SQL Code Storage: Files vs In-DB Packages

Anyone with access to the server will can still read your code, using
an editor of some kind. But perhaps your server is capable of
restricting access to your satisfaction.

You'll note that those Oracle programmers largely agreed that if your
code is in the database, it should be wrapped and/or part of a
package. First let's look at wrapping.

Wrapping, otherwise known as obfuscation, is a method of changing


your human-readable PL/SQL code into text that is readable only by
Oracle. In that sense, it can be compiled and executed like any other
code, but it is protected in the sense that it won't make sense to
anyone except Oracle.

You can learn how to use the wrap utility from either Dan Morgan, or
Oracle's PL/SQL User's Guide and Reference (Appendix C), but I'll
show you what I mean right now.

http://thinkoracle.blogspot.com/2006/09/protecting-plsql-code.html (2 of 8)1/9/2008 2:56:26 AM


OracleBlog: Protecting PL/SQL Code

1. Put your PL/SQL code in an SQL file.


2. From the command line, issue the wrap command. The syntax is
wrap iname=input_file [oname=output_file]

wrap iname=wraptest.sql oname=wraptest.plb

3. From SQL*Plus, execute the resulting PLB file to load the stored
procedure, and even execute it for verification (omitted here).

SQL> @wraptest.plb

Procedure created.

4. Try to read the code, either by opening the PLB file, or querying a
SOURCE table. PLB is a standard Oracle extension, sometimes
referred to as "PL/SQL Binary." But it isn't binary, it's text: you can go
ahead and read it.

SQL> SELECT text FROM USER_SOURCE WHERE name = 'WRAPTEST'


order by line;

(garbage removed)

Now is wrapping a perfect solution? Well no. First of all, Oracle


doesn't claim that it is undecipherable. Edited: In fact, leading Oracle
security expert Pete Finnigan has made a presentation available that
summarizes how to read wrapped code.

It also has a few annoying limitations, none of which I'll prove here,
but they include the fact that you can't wrap triggers (just call a
wrapped proc from your trigger), can't be copied to an earlier
release, and all Oracle comments (--) are deleted.

I hear there may be a superior solution in Oracle 10, as part of the


DBMS_DDL package. That solution doesn't even require a command-
line step, it can be done directly in the database. If you're ahead of
me, and using Oracle 10, give it a try using Dan Morgan's reference
for the syntax.

Speaking of packages, the more important lesson to learn from those


Oracle programmers was to put your code into packages. You can
make the specification public, so everyone can understand them, and
then restrict access (and wrap) the implementation details.

Using packages and wrapping your code is the standard method of

http://thinkoracle.blogspot.com/2006/09/protecting-plsql-code.html (3 of 8)1/9/2008 2:56:26 AM


OracleBlog: Protecting PL/SQL Code

protection. As a closing note, there are plenty of other compelling


reasons to use Oracle packages too. I wrote about that once before,
and also included some links where you can get the finer details on
how to use them:
Oracle Packages - And why/how you should use them.

// posted by Robert Vollman @ Saturday, September 02, 2006

Comments:
Hi Robert,

You should take a look at my presentation from the BlackHat 2006


Las Vegas conference this year. See my post How to Unwrap PL/SQL
BlackHat las vegas 2006 presentation slides are available which
shows how to unwrap PL/SQL!

cheers

Pete
# posted by Pete Finnigan : Sunday, 03 September, 2006

Thanks Pete! I loved your presentations, so I did you one better and
edited my post to include your link at the appropriate place.

Your presentation begs the question: why would someone want to


unwrap PL/SQL code anyway? Because you can verify it by testing it.
Is theft the only reason to unwrap code?
# posted by Robert Vollman : Sunday, 03 September, 2006

Hi Robert,

Thanks for the update. I am not aware first hand of anyone using an
unwrapper maliciously but there are plenty of uses for one. I know
that unwrappers are used to find bugs in built in packages for
instance by some security researchers and I also know that some
security product companies are using unwrappers to allow their tools
to detect CPU updates and to establish how to check for fixed
vulnerabilities.

There are lots of uses for a PL/SQL unwrapper, malicious and not but

http://thinkoracle.blogspot.com/2006/09/protecting-plsql-code.html (4 of 8)1/9/2008 2:56:26 AM


OracleBlog: Protecting PL/SQL Code

the underlying reason in all cases is the same. This is to be able to


read someone elses source code.

The message I am trying to get across in my paper is that the wrap


mechanism is not secure, if you really want to protect source code
then dont write directly in PL/SQL use a compiled language but these
are not secure either as tools like strings can be used to extract SQL
for instance.

cheers

pete
# posted by Pete Finnigan : Monday, 04 September, 2006

Why would people want to unwrap pl/sql?

In my case, it would be because I am trying to figure out why some


calls through an incredibly poorly documented Oracle Warehouse
Builder API are failing, and it would sure as hell be easier to debug
what I need to change in my scripts or what it is that I have
misconfigured if I could simply see what Oracle is trying to do with
the values I am passing in!

In other words - not for malicious purposes but rather because


beating my head against a wall using "Trial and Error" as the only
available programming technique really sucks when I could step
through the code and solve my problems simply if only it weren't
wrapped.

Which explains how I found your journal after searching for an Oracle
unwrap utility.....

Cheers,
Mike
# posted by Michael B : Tuesday, 12 September, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/09/protecting-plsql-code.html (5 of 8)1/9/2008 2:56:26 AM


OracleBlog: Protecting PL/SQL Code

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
● The Oak Table
● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
❍ Brian Duff's OraBlogs
❍ Eddie Awad's OracleNA
❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
http://thinkoracle.blogspot.com/2006/09/protecting-plsql-code.html (6 of 8)1/9/2008 2:56:26 AM
OracleBlog: Protecting PL/SQL Code

❍ Oracle's Ask Tom Kyte


❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
❍ LIST ALL ARTICLES
❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006

http://thinkoracle.blogspot.com/2006/09/protecting-plsql-code.html (7 of 8)1/9/2008 2:56:26 AM


OracleBlog: Protecting PL/SQL Code

❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2006/09/protecting-plsql-code.html (8 of 8)1/9/2008 2:56:26 AM


OracleBlog: Oracle Conferences

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday, October
About Me
24, 2006
Name: Robert Vollman
Oracle Location: Calgary, Alberta, Canada
Conferences
If you follow the I was born and raised in Ottawa, and have lived in
various blogs on Calgary since 1991. I like playing sports (hockey,
the right, you'll soccer, ultimate, basketball, you name it) and military board
see that practically games. I also enjoy reading, walking, and playing with my 2
everybody (except cats Lilly and Brutus. I'm a database application specialist,
me) is currently whatever that is.
attending Oracle
OpenWorld 2006. View my complete profile
It's an annual
convention held in
San Francisco late
in the year. Lasts
Best Links
about 4 days, and ● Ask Tom Kyte
costs around 2000 ● Oracle Docs
USD$. ● Dan Morgan and PSOUG
● Steven Feuerstein
I'd love to attend ● Jonathan Lewis
Oracle OpenWorld ● FAQ
some day. Or
Connor McDonald
practically any

The Oak Table


conference. I

Cary Millsap and Hotsos


would especially ●

like to visit the ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/10/oracle-conferences.html (1 of 4)1/9/2008 2:56:29 AM


OracleBlog: Oracle Conferences

annual conference ● Anjo Kolk and OraPerf


hosted by UKOUG. ● Dizwell Oracle Wiki
It generally takes ● My Personal Blog
place shortly after
Oracle OpenWorld,

Aggregators
and its about the
same cost, but
maybe a few
Brian Duff's OraBlogs
hundred bucks

Eddie Awad's OracleNA


cheaper. Makes up

for the airfare to ❍ Pete Finnigan's Aggregator


Birmingham. ❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
Maybe for a warm-
up I'd finally meet
up with Dan Oracle's Ask Tom Kyte
Morgan at the

Oracle Guru Jonathan Lewis


Puget Sound

Blogger of the Year Eddie Awad


Oracle User's

Group's OracleDay ❍ Data Warehouser David Aldridge


in Seattle. It's one ❍ Oracle Geek Lewis Cunningham
day, and I'm pretty ❍ Database Expert James Koopmann
sure its cheap (or ❍ Dizwell's Howard Rogers
free) for members. ❍ Oracle Master Laurent Schneider
If you're not in my ❍ Security Expert Pete Finnigan
area, check out ❍ Oracle Award Winner Mark Rittman
the calendar I got ❍ Doug Burns
from the OTN web ❍ Oracle ACE of the Year Dr. Tim Hall
site that lists some ❍ UKOUG's Andrew (Arfur C.) Clarke
of the local user ❍ Newbie DBA Lisa Dobson
groups annual Coffee-Drinking DBA Jon Emmons
meetings.

❍ Chris Foot
Judging from that ❍ The Pythian DBA Team Blog
list, there are ❍ DBA Don Seiler
three other ❍ DBA Coskan Gundogar
conferences I ❍ Oracle WTF
would keep my
eye on: ARCHIVES
LIST ALL ARTICLES
1. Oracle

Development Tool ❍ May 2005


Users Group ❍ June 2005
❍ July 2005

http://thinkoracle.blogspot.com/2006/10/oracle-conferences.html (2 of 4)1/9/2008 2:56:29 AM


OracleBlog: Oracle Conferences

Kaleidoscope, in ❍ August 2005


June, to be held in ❍ September 2005
Daytona Florida ❍ October 2005
next year. November 2005
2. The 2nd ever

December 2005
PL/SQL-specific

January 2006
OPP 2007, for 2

February 2006
days in February/ ❍

March in San ❍ March 2006


Francisco. ❍ April 2006
3. Oracle ❍ May 2006
Applications User ❍ June 2006
Group Collaborate ❍ July 2006
2007 in Las Vegas ❍ August 2006
next April for 4 ❍ September 2006
days. ❍ October 2006
November 2006
If ever I do go to

December 2006
my first Oracle

convention, I'll be ❍ January 2007


sure to mention it ❍ February 2007
here and hopefully ❍ March 2007
I can meet some ❍ April 2007
of you there. ❍ May 2007
❍ June 2007
// posted by Robert ❍ October 2007
Vollman @ Tuesday,

October 24, 2006

Comments:
Actually Rob, it
should cost less if
you register early
and also get a
special code for
additional
discount from
your Oracle rep.
Just ask. :D

I've spoken to

http://thinkoracle.blogspot.com/2006/10/oracle-conferences.html (3 of 4)1/9/2008 2:56:29 AM


OracleBlog: Oracle Conferences

Oracle vancouver
about reviving the
local Vancouver
User group but
have not gotten
too much of a
positive response
yet.
# posted by Peter
K : Tuesday, 24
October, 2006

I'll put ina word


for the Hotsos
Symposium as
well. That was my
first conference
and it was a real
eye-opener. Very
worthwhile
# posted by David
Aldridge : Tuesday, 31
October, 2006

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/10/oracle-conferences.html (4 of 4)1/9/2008 2:56:29 AM


OracleBlog: 100,000 more?

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Tuesday,
About Me
November 14,
Name: Robert Vollman
2006
Location: Calgary, Alberta, Canada
100,000
more? I was born and raised in Ottawa, and have lived in
18 months. Calgary since 1991. I like playing sports (hockey,
107 posts. soccer, ultimate, basketball, you name it) and military board games.
110,000 reads. I also enjoy reading, walking, and playing with my 2 cats Lilly and
Brutus. I'm a database application specialist, whatever that is.
Not too long
ago I reacted View my complete profile
with humble
incredulity that
10,000 people
had read what I
Best Links
had to say ● Ask Tom Kyte
about Oracle. ● Oracle Docs
● Dan Morgan and PSOUG
Here I am, ● Steven Feuerstein
exactly one ● Jonathan Lewis
year later, and ● FAQ
there have
Connor McDonald
been 100,000

The Oak Table


more visits. I'm

Cary Millsap and Hotsos


almost afraid ●

to continue, ● Steve Adams and Ixora


will I be talking ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2006/11/100000-more_14.html (1 of 6)1/9/2008 2:56:31 AM


OracleBlog: 100,000 more?

about ● Dizwell Oracle Wiki


1,000,000 in ● My Personal Blog
November
2007?

I wonder why
people are
Aggregators
Brian Duff's OraBlogs
reading my

blog because, ❍ Eddie Awad's OracleNA


despite how ❍ Pete Finnigan's Aggregator
numerous we ❍ Oracle's Bloglist
are, it seems ❍ Oracle Base Aggregator

Top Blogs
like every other
Oracle blogger
knows this ❍ Oracle's Ask Tom Kyte
material far Oracle Guru Jonathan Lewis
better than I.

Blogger of the Year Eddie Awad


So I've taken

Data Warehouser David Aldridge


the time to ask

some of you ❍ Oracle Geek Lewis Cunningham


why. ❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
Although it ❍ Oracle Master Laurent Schneider
would be nice ❍ Security Expert Pete Finnigan
if someone did ❍ Oracle Award Winner Mark Rittman
me the ❍ Doug Burns
compliment of Oracle ACE of the Year Dr. Tim Hall
disputing my

UKOUG's Andrew (Arfur C.) Clarke


claim, instead

Newbie DBA Lisa Dobson


it appears that

Coffee-Drinking DBA Jon Emmons


my lack of ❍

expertise is ❍ Chris Foot


part of the ❍ The Pythian DBA Team Blog
appeal. It ❍ DBA Don Seiler
seems the ❍ DBA Coskan Gundogar
average Oracle ❍ Oracle WTF
user out there
is closer to my
level rather
ARCHIVES
LIST ALL ARTICLES
than some

May 2005
expert like,

June 2005
say, Laurent ❍

July 2005
Schneider or

❍ August 2005

http://thinkoracle.blogspot.com/2006/11/100000-more_14.html (2 of 6)1/9/2008 2:56:31 AM


OracleBlog: 100,000 more?

Jeff Hunter. ❍ September 2005


❍ October 2005
Perhaps that ❍ November 2005
makes my December 2005
work more

January 2006
accessible. The

February 2006
complexities of

Oracle often ❍ March 2006


make you feel ❍ April 2006
dumb, so you ❍ May 2006
can come to ❍ June 2006
me to feel ❍ July 2006
smart again. :) ❍ August 2006
❍ September 2006
In that vein, I'd October 2006
like to get

November 2006
some of you

December 2006
started on your

own blogs. You ❍ January 2007


may feel ❍ February 2007
intimidated ❍ March 2007
because of all ❍ April 2007
the experts out ❍ May 2007
there, but if ❍ June 2007
anything I'm ❍ October 2007
proof that you
don't have to
be an Oracle
guru to make a
contribution.

I think you'd
be surprised at
just how warm
a reception
you'll receive
no matter what
level you're at.
If you'd like to
give it a try,
I'm offering
you an
audience on

http://thinkoracle.blogspot.com/2006/11/100000-more_14.html (3 of 6)1/9/2008 2:56:31 AM


OracleBlog: 100,000 more?

my blog. I'd be
happy to
answer
questions,
review your
first few posts,
and invite
others here to
do the same,
until you have
decided
whether or not
blogging is for
you.

My contact
information is
in my profile, I
look forward to
hearing from
you! And
thanks for
reading!

// posted by
Robert
Vollman @ Tuesday,
November 14,

2006

Comments:
it wouldn't be,
maybe, that
you're GOOD
at explaining
things?;-)
# posted by
shrek :
Tuesday, 14
November, 2006

http://thinkoracle.blogspot.com/2006/11/100000-more_14.html (4 of 6)1/9/2008 2:56:31 AM


OracleBlog: 100,000 more?

thats great!!!
as always any
feedback on
my posts will
be appreciated.
# posted by
Vidya
Balasubramanian :
Tuesday, 14
November, 2006

I must agree
with the other
comment
poster - you
do explain
things well,
you give
examples,
links to other
sites/blogs
with more info
and you keep it
concise.
I think being
concise the
most
important
thing - it is up
to the reader
to delve deeper
or take the
next step and
get more info
and this is
provided by
the links you
generally
include.
All in all, easy
reading,
interesting

http://thinkoracle.blogspot.com/2006/11/100000-more_14.html (5 of 6)1/9/2008 2:56:31 AM


OracleBlog: 100,000 more?

topics, to the
point - i'll be
back.
# posted by
gazza :
Wednesday, 15
November, 2006

Post a
Comment

<< Home

http://thinkoracle.blogspot.com/2006/11/100000-more_14.html (6 of 6)1/9/2008 2:56:31 AM


OracleBlog: REGEXP_LIKE

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Monday, December
About Me
04, 2006
Name: Robert Vollman
REGEXP_LIKE Location: Calgary, Alberta, Canada
Recently I invited
anyone who has I was born and raised in Ottawa, and have lived
been considering in Calgary since 1991. I like playing sports
joining the Oracle (hockey, soccer, ultimate, basketball, you name it) and
blogging community military board games. I also enjoy reading, walking, and
to jump right in. playing with my 2 cats Lilly and Brutus. I'm a database
Please, help me application specialist, whatever that is.
encourage John H:
View my complete profile
Robert,

Way cool blog. I


really need to create Best Links
one too. I like to ● Ask Tom Kyte
adhere to best Oracle Docs
practices and love to

Dan Morgan and PSOUG


read stuff from Tom

Steven Feuerstein
K. and Steven F.!

● Jonathan Lewis
I have a question on ● FAQ
regular expression ● Connor McDonald
check constraints ● The Oak Table
and was wondering ● Cary Millsap and Hotsos
if you can help: ● Steve Adams and Ixora

http://thinkoracle.blogspot.com/2006/12/regexplike.html (1 of 8)1/9/2008 2:56:34 AM


OracleBlog: REGEXP_LIKE

● Anjo Kolk and OraPerf


alter table ● Dizwell Oracle Wiki
logical_address ● My Personal Blog
modify (address_ip
check (

regexp_like
(address_ip,'((^([2][0-
Aggregators
5]{2}\.|[2][0-4][0-9] Brian Duff's OraBlogs

\.| ❍ Eddie Awad's OracleNA


([0-1]\d\d)\.|\d\d\.| ❍ Pete Finnigan's Aggregator
\d\.)) ❍ Oracle's Bloglist
([2][0-5]{2}\.|[2][0-4] ❍ Oracle Base Aggregator
[0-9]\.|
([0-1]\d\d)\.|\d\d\.|
\d\.){2})(([2][0-5]{2}
Top Blogs
Oracle's Ask Tom Kyte
$)| ❍

([0-1]\d\d$)|(\d\d$)| ❍ Oracle Guru Jonathan Lewis


(\d$))'))) ❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
Isn't there a better ❍ Oracle Geek Lewis Cunningham
way to write this? ❍ Database Expert James Koopmann
Oh! the pattern ❍ Dizwell's Howard Rogers
works in a Oracle Master Laurent Schneider
regexp_substr but

Security Expert Pete Finnigan


not in the

Oracle Award Winner Mark Rittman


regexp_like. Thanks

Doug Burns
in advance... ❍

❍ Oracle ACE of the Year Dr. Tim Hall


I applaud what John ❍ UKOUG's Andrew (Arfur C.) Clarke
is trying to do: ❍ Newbie DBA Lisa Dobson
manage the integrity ❍ Coffee-Drinking DBA Jon Emmons
of the data in the ❍ Chris Foot
database. His ❍ The Pythian DBA Team Blog
request is a common ❍ DBA Don Seiler
one, and I wish it ❍ DBA Coskan Gundogar
were even more ❍ Oracle WTF
common. Too many
databases are
designed to simply
ARCHIVES
trust that whatever ❍ LIST ALL ARTICLES
application is ❍ May 2005
providing the IP ❍ June 2005
address has already ❍ July 2005

http://thinkoracle.blogspot.com/2006/12/regexplike.html (2 of 8)1/9/2008 2:56:34 AM


OracleBlog: REGEXP_LIKE

checked it. ❍ August 2005


❍ September 2005
Unfortunately, I'm ❍ October 2005
limited in what November 2005
assistance I can

December 2005
provide with regards

January 2006
to regular

February 2006
expressions. Since

March 2006
I'm still using Oracle

April 2006
9, I can't take

advantage of one of ❍ May 2006


the finest features of ❍ June 2006
Oracle 10. I get a lot ❍ July 2006
of questions about ❍ August 2006
REGEXP in the past ❍ September 2006
year and a half, but I ❍ October 2006
can't offer much ❍ November 2006
more than those ❍ December 2006
links to articles and ❍ January 2007
references. ❍ February 2007
Wanting to offer ❍ March 2007
John something of ❍ April 2007
value, I wondered ❍ May 2007
how I would address ❍ June 2007
this issue in Oracle ❍ October 2007
9. I recall coming
across this once
before, but we
actually chose to
store the IP address
as a 32-bit integer
which, by the way, is
the same way our OS
stored it. I wrote a
quick procedure that
would convert that
32-bit integer into a
readable IP address
(or "dotted-quad"
notation). The
specific details are
proprietary to the

http://thinkoracle.blogspot.com/2006/12/regexplike.html (3 of 8)1/9/2008 2:56:34 AM


OracleBlog: REGEXP_LIKE

company for which I


worked at the time,
but it should be easy
enough to reproduce
if you went that
route.

Of course, this
approach didn't
check that the 32-
bit integer was
convertible to an IP
address valid to my
application. That
problem, however, is
a specific case of a
very common
general requirement:
write a constraint to
check the validity of
a string. Briefly, in a
case like this, I
would convert the IP
address to special
coded string using
TRANSLATE, and
then CHECK if that
string matched a set
pattern. Further, in
particular complex
cases, I often resort
to checking the
constraint with a
trigger.

In the end, I
suggested John post
this question in an
Oracle forum. There
are lots of people
there, including
things who are
familiar with REGEXP

http://thinkoracle.blogspot.com/2006/12/regexplike.html (4 of 8)1/9/2008 2:56:34 AM


OracleBlog: REGEXP_LIKE

(unlike me) who can


give him a hand. But
I believe he came up
with a satisfactory
solution on his own.
I'm including it here,
and I know he would
appreciate a critique
if anyone familiar
with REGEXP has
something to offer.

alter table
logical_address
add constraint
la_address_ip_chk
check (
regexp_like(
address_ip,
'((^([2][0-5]{2}\.|[2]
[0-4][0-9]\.|([0-1]\d
\d)\.|\d\d\.|\d\.))([2]
[0-5]'||
'{2}\.|[2][0-4][0-9]\.|
([0-1]\d\d)\.|\d\d\.|
\d\.){2})(([2][0-5]{2}
$)|'||
'([0-1]\d\d$)|(\d\d
$)|(\d$))'
)
);

alter table
logical_address
add constraint
la_address_mac_chk
check (
regexp_like
(address_mac,
'((([0-9]|[A-Z]){2})(:))
{5}([0-9]|[A-Z]){2}|
((([0-9]|[A-Z]){2})(-))
{5}'||

http://thinkoracle.blogspot.com/2006/12/regexplike.html (5 of 8)1/9/2008 2:56:34 AM


OracleBlog: REGEXP_LIKE

'([0-9]|[A-Z]){2}'
)
);

alter table
logical_address
add constraint
la_port_chk
check (
regexp_like
(address_port,'[0! -9]
{5}| [0-9]{4}')
);

// posted by Robert
Vollman @ Monday,

December 04, 2006

Comments:
it seems very wrong,
a mac address is
hexadecimal and
cannot contain G-Z
characters...

ip

regexp_like
(address_ip,'(([01]?[0-
9]?[0-9]|2[0-4][0-9]|
25[0-5])\.){3}([01]?
[0-9]?[0-9]|2[0-4][0-
9]|25[0-5])')

mac

regexp_like
(address_mac,','([0-
9A-F]?[0-9A-F]:){5}
[0-9A-F]?[0-9A-F]')

http://thinkoracle.blogspot.com/2006/12/regexplike.html (6 of 8)1/9/2008 2:56:34 AM


OracleBlog: REGEXP_LIKE

for port, no idea


what he tried, the
most logical could be
to_number
(addess_port)
between 0 and 65535
# posted by Laurent
Schneider : Monday, 04
December, 2006

I noticed
performance issues
when using
regexp_like in
10.2.0.2. It didn't
use index on
2.7billion partitioned
table.

When using good old


like (with or clause
to add more
patterns) yielded a
performance
improvement for me.
With good old like,
my query runs in 2
minutes, with
regexp_like, it takes
20+ minutes.

I like regexp_*
commands, but I am
slightly weary to use
them in my code.

raj
# posted by Rjamya :
Tuesday, 05 December,
2006

http://thinkoracle.blogspot.com/2006/12/regexplike.html (7 of 8)1/9/2008 2:56:34 AM


OracleBlog: REGEXP_LIKE

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2006/12/regexplike.html (8 of 8)1/9/2008 2:56:34 AM


OracleBlog: REPOST: Pivot and Crosstab Queries

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be complicated, but it
is the most powerful tool when it comes to data. That's why when I think data, I think Oracle. I also enjoy
writing, so I use this format to organise my thoughts. Please feel free to discuss any thoughts you may
have on the same topics, even old ones (I will see and respond to such comments). You may want to
start with "LIST ALL ARTICLES" under Archives.

Thursday, January 25, 2007


About Me
REPOST: Pivot and Crosstab Queries Name: Robert
Here is another advanced concept that will come in useful Vollman
when solving Oracle problems. Location: Calgary,
Alberta, Canada
Imagine you're trying to create a result set where the rows
need to be columns, or vice versa. In essence, you need to
"pivot" rows into columns, or vice versa. That is a very I was born and raised in Ottawa,
common requirement, and this is where you need to look and have lived in Calgary since
at a pivot (or crosstab) query to get the job done. 1991. I like playing sports
(hockey, soccer, ultimate,
As always, when you want to understand something, you basketball, you name it) and
can start by Asking Tom. military board games. I also
enjoy reading, walking, and
A simple pivot query is accomplished by basically doing the playing with my 2 cats Lilly and
following: Brutus. I'm a database
1. Add some kind of count or row number to your query, if application specialist, whatever
necessary for the grouping that is.
2. Then use your (revised) original query as a sub-query
3. Use "decode" to turn rows into columns (ie. a "sparse" View my complete profile
matrix).
4. Use "max" to "squash" the multiple rows you moved to
columns, into single rows. Don't forget to group by.
(Note: it gets more complicated if you don't know how
Best Links
Ask Tom Kyte
many columns you'll need). ●

● Oracle Docs
Here is another one of Ask Tom's examples. It clearly ● Dan Morgan and PSOUG
shows how you use decode to create a "sparse" matrix, and ● Steven Feuerstein
then use max to "squash" it down. ● Jonathan Lewis
● FAQ
Let's look a simple example in slow motion. ● Connor McDonald
The Oak Table
Here's the data

CREATE TABLE CFL (season NUMBER(4), team VARCHAR2 ● Cary Millsap and Hotsos
(16), points NUMBER(3)); ● Steve Adams and Ixora
INSERT INTO CFL (season, team, points) VALUES (2004, ● Anjo Kolk and OraPerf

http://thinkoracle.blogspot.com/2007/01/repost-pivot-and-crosstab-queries.html (1 of 7)1/9/2008 2:56:37 AM


OracleBlog: REPOST: Pivot and Crosstab Queries

'Argonauts', 21); ● Dizwell Oracle Wiki


INSERT INTO CFL (season, team, points) VALUES (2004, ● My Personal Blog
'Alouettes', 28);
INSERT INTO CFL (season, team, points) VALUES (2004,

Aggregators
'Tiger-Cats', 19);
INSERT INTO CFL (season, team, points) VALUES (2004,
'Renegades', 10);
Brian Duff's OraBlogs
INSERT INTO CFL (season, team, points) VALUES (2003,

Eddie Awad's OracleNA


'Argonauts', 18);

Pete Finnigan's Aggregator


INSERT INTO CFL (season, team, points) VALUES (2003, ❍

'Alouettes', 26); ❍ Oracle's Bloglist


INSERT INTO CFL (season, team, points) VALUES (2003, ❍ Oracle Base Aggregator
'Tiger-Cats', 2);
INSERT INTO CFL (season, team, points) VALUES (2003, Top Blogs
'Renegades', 14); ❍ Oracle's Ask Tom Kyte
INSERT INTO CFL (season, team, points) VALUES (2002, ❍ Oracle Guru Jonathan Lewis
'Argonauts', 16); Blogger of the Year Eddie Awad
INSERT INTO CFL (season, team, points) VALUES (2002,

Data Warehouser David Aldridge


'Alouettes', 27);

Oracle Geek Lewis Cunningham


INSERT INTO CFL (season, team, points) VALUES (2002,

Database Expert James Koopmann


'Tiger-Cats', 15); ❍

INSERT INTO CFL (season, team, points) VALUES (2002, ❍ Dizwell's Howard Rogers
'Renegades', 10); ❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
What we want: ❍ Oracle Award Winner Mark
A table showing each of these 4 teams and their point Rittman
tables for these 3 seasons. ❍ Doug Burns
Oracle ACE of the Year Dr. Tim
So what is our pivot row/column? Season.

Hall
Step 1/2: We are using season, so we don't need to create ❍ UKOUG's Andrew (Arfur C.) Clarke
our own grouping field, like count, rownum, or running ❍ Newbie DBA Lisa Dobson
total (sum) for example. That would be easy enough to do, ❍ Coffee-Drinking DBA Jon Emmons
but let's keep this simple. ❍ Chris Foot
❍ The Pythian DBA Team Blog
Step 3: Use "decode" to turn the season row into a column. ❍ DBA Don Seiler
Take a look at our "sparse" matrix. ❍ DBA Coskan Gundogar
Oracle WTF
SELECT team, ❍

DECODE (season, 2002, points, NULL) Yr2002,


DECODE (season, 2003, points, NULL) Yr2003, ARCHIVES
DECODE (season, 2004, points, NULL) Yr2004 ❍ LIST ALL ARTICLES
FROM (SELECT season, team, points FROM CFL); ❍ May 2005
❍ June 2005
TEAM YR2002 YR2003 YR2004 ❍ July 2005
---------------- ---------- ---------- ---------- ❍ August 2005
Argonauts 21 ❍ September 2005
Alouettes 28 ❍ October 2005
Tiger-Cats 19
❍ November 2005
Renegades 10
❍ December 2005
Argonauts 18
❍ January 2006

http://thinkoracle.blogspot.com/2007/01/repost-pivot-and-crosstab-queries.html (2 of 7)1/9/2008 2:56:37 AM


OracleBlog: REPOST: Pivot and Crosstab Queries

Alouettes 26 ❍ February 2006


Tiger-Cats 2 ❍ March 2006
Renegades 14 ❍ April 2006
Argonauts 16 ❍ May 2006
Alouettes 27 ❍ June 2006
Tiger-Cats 15
❍ July 2006
Renegades 10
❍ August 2006
❍ September 2006
❍ October 2006
Step 4: Now let's use max to "squash" this into single rows. ❍ November 2006
Don't forget GROUP BY. ❍ December 2006
January 2007
SELECT team,

February 2007
MAX (DECODE (season, 2002, points, NULL)) Yr2002,

March 2007
MAX (DECODE (season, 2003, points, NULL)) Yr2003,

April 2007
MAX (DECODE (season, 2004, points, NULL)) Yr2004 ❍

FROM (SELECT season, team, points FROM CFL) ❍ May 2007


GROUP BY team; ❍ June 2007
❍ October 2007
TEAM YR2002 YR2003 YR2004
---------------- ---------- ---------- ----------
Alouettes 27 26 28
Argonauts 16 18 21
Renegades 10 14 10
Tiger-Cats 15 2 19

Pretty cool, eh? Easy, too.

Notice that the key to this is DECODE. If DECODE is not


already part of your toolbelt, I recommend studying up.

Ready for a tougher example? Let's look at another Ask


Tom.

For further study of pivot queries and analytic functions in


general, there is an awesome write-up in Chapter 12 of
Tom Kyte's "Expert One-on-One Oracle." You'd think I'd get
a kickback from Tom Kyte with all the promotion I'm doing,
but the honest truth is that no one explains it as well as he.

So, do you understand pivot queries now? No problems?

If so, now you're ready for one of Ask Tom's more complex
examples.

Pivot Tables

One final word: don't confuse pivot queries with pivot


tables. Pivot tables are a different concept, and have

http://thinkoracle.blogspot.com/2007/01/repost-pivot-and-crosstab-queries.html (3 of 7)1/9/2008 2:56:37 AM


OracleBlog: REPOST: Pivot and Crosstab Queries

different uses (most typically to fill in missing data). Until I


blog about pivot tables, check out these two links:

Jonathan Gennick Updated


Laurent Schneider

Originally posted September 1, 2005

// posted by Robert Vollman @ Thursday, January 25, 2007

Comments:
Pivoting in SQL using the 10g Model :)

Test was done on Oracle Database 10g Express Edition


Release 10.2.0.1.0

SQL> create table test(id varchar2(2), des varchar2(4), t


number);

Table created

SQL> INSERT INTO test values(’A',’a1′,12);

1 row inserted

SQL> INSERT INTO test values(’A',’a2′,3);

1 row inserted

SQL> INSERT INTO test values(’A',’a3′,1);

1 row inserted

SQL> INSERT INTO test values(’B',’a1′,10);

1 row inserted

SQL> INSERT INTO test values(’B',’a2′,23);

1 row inserted

SQL> INSERT INTO test values(’C',’a3′,45);

1 row inserted

SQL> commit;

Commit complete

SQL> SELECT * FROM test;

http://thinkoracle.blogspot.com/2007/01/repost-pivot-and-crosstab-queries.html (4 of 7)1/9/2008 2:56:37 AM


OracleBlog: REPOST: Pivot and Crosstab Queries

ID DES T
– —- ———-
A a1 12
A a2 3
A a3 1
B a1 10
B a2 23
C a3 45

6 rows selected

SQL> select distinct i, A1, A2, A3


2 from test c
3 model
4 ignore nav
5 dimension by(c.id i,c.des d)
6 measures(c.t t, 0 A1, 0 A2, 0 A3)
7 rules(
8 A1[any,any] = t[cv(i),d = ‘a1′],
9 A2[any,any] = t[cv(i),d = ‘a2′],
10 A3[any,any] = t[cv(i),d = ‘a3′]
11 );

I A1 A2 A3
– ———- ———- ———-
C 0 0 45
B 10 23 0
A 12 3 1

SQL> select distinct d, A, B, C


2 from test c
3 model
4 ignore nav
5 dimension by(c.id i,c.des d)
6 measures(c.t t, 0 A, 0 B, 0 C)
7 rules(
8 A[any,any] = t[i = ‘A’, cv(d)],
9 B[any,any] = t[i = ‘B’, cv(d)],
10 C[any,any] = t[i = ‘C’, cv(d)]
11 );

DABC
—- ———- ———- ———-
a1 12 10 0
a3 1 0 45
a2 3 23 0

SQL> explain plan set statement_id ‘menn’ for


2 select distinct d, A, B, C
3 from test c
4 model

http://thinkoracle.blogspot.com/2007/01/repost-pivot-and-crosstab-queries.html (5 of 7)1/9/2008 2:56:37 AM


OracleBlog: REPOST: Pivot and Crosstab Queries

5 ignore nav
6 dimension by( c.id i,c.des d)
7 measures(c.t t, 0 A, 0 B, 0 C)
8 rules(
9 A[any,any] = t[i = ‘A’, cv(d)],
10 B[any,any] = t[i = ‘B’, cv(d)],
11 C[any,any] = t[i = ‘C’, cv(d)]
12 );

Explained

SQL> select plan_table_output from table(dbms_xplan.


display(’plan_table’,'menn’));

PLAN_TABLE_OUTPUT
——————————————————————————–
Plan hash value: 160770444
—————————————————————————-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
—————————————————————————-
| 0 | SELECT STATEMENT | | 6 | 120 | 3 (34)| 00:00:01 |
| 1 | HASH UNIQUE | | 6 | 120 | 3 (34)| 00:00:01 |
| 2 | SQL MODEL ORDERED | | 6 | 120 | | |
| 3 | TABLE ACCESS FULL| TEST | 6 | 120 | 2 (0)| 00:00:01 |
—————————————————————————-

Oracle® Database Data Warehousing Guide 10g Release 2


(10.2)
Chapter 22 SQL for Modeling
http://download-uk.oracle.com/docs/cd/B19306_01/
server.102/b14223/sqlmodel.htm#sthref1855
# posted by Tonguç : Thursday, 25 January, 2007

Also for most people this comes out to be the simplest


solution;

INSERT ALL
INTO sales_info VALUES (employee_id,week_id,sales_MON)
INTO sales_info VALUES (employee_id,week_id,sales_TUE)
INTO sales_info VALUES (employee_id,week_id,sales_WED)
INTO sales_info VALUES (employee_id,week_id,sales_THUR)
INTO sales_info VALUES (employee_id,week_id, sales_FRI)
SELECT EMPLOYEE_ID, week_id, sales_MON, sales_TUE,
sales_WED, sales_THUR, sales_FRI
FROM sales_source_data;

5 rows created.

Best regards.
# posted by Tonguç : Friday, 26 January, 2007

http://thinkoracle.blogspot.com/2007/01/repost-pivot-and-crosstab-queries.html (6 of 7)1/9/2008 2:56:37 AM


OracleBlog: REPOST: Pivot and Crosstab Queries

simple yet profound - as DBA's we reallyc cannot get away


from having to cascase rows to columns and vice versa for
numerous Reports.
Using the dimension in the query probably needs to OLAP
option.
# posted by Vidya Balasubramanian : Monday, 29 January, 2007

Post a Comment

<< Home

http://thinkoracle.blogspot.com/2007/01/repost-pivot-and-crosstab-queries.html (7 of 7)1/9/2008 2:56:37 AM


OracleBlog: Global Temporary Tables

OracleBlog
I love data. Collecting, storing, manipulating, studying and using data. Oracle may be
complicated, but it is the most powerful tool when it comes to data. That's why when I
think data, I think Oracle. I also enjoy writing, so I use this format to organise my
thoughts. Please feel free to discuss any thoughts you may have on the same topics,
even old ones (I will see and respond to such comments). You may want to start with
"LIST ALL ARTICLES" under Archives.

Sunday, October 21, 2007


Global Temporary Tables
I listened intently to the new Oracle programmer as he described all the
struggles he's been having on his first big project. As I've done many
times already in his short career, I interrupt with some words of wisdom.

"It's time to add Global Temporary Tables to your toolbelt."

"What are those?" he asks, as he opens the directory with the Oracle
documentation. I smile. He has already learned where I always send him
first.

"They're the ultimate work tables," I continue. "They're permanent


tables, where you can add and modify session-specific data without
affecting other sessions."

"What's so special about that?" he asks. "Even with regular tables, you
can add and modify the data all you want without affecting other
sessions. Just don't commit, and remember to rollback when your
session is done."

"Oh yeah? And what about all the persistent work you're doing in your
session? How do you commit that?"

"Oh yeah. Does it allow for indexes, and triggers, and views with
regular tables?"

"Yep, all of that. See for yourself, it's easy. You've got the manual in

http://thinkoracle.blogspot.com/2007/10/global-temporary-tables.html (1 of 7)1/9/2008 2:56:40 AM


OracleBlog: Global Temporary Tables

front of you, so you drive."

Then I watched as he opened one session, and created a global


temporary table.

SQL> CREATE GLOBAL TEMPORARY TABLE worktable (x NUMBER(3));


Table created.

He opened another session and was pleased to see the table there. He
then added a row in the first session, committed it, and was planning to
use the other session to see if the data was there. But instead he was in
for a little surprise.

SQL> INSERT INTO worktable (x) VALUES (1);


1 row created.
SQL> SELECT * FROM worktable;
X
----------
1
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
no rows selected

"Hey!" he shouted. Heads popped up in nearby cubicles. "Where did it


go?"

"Keep reading," I said, gesturing towards the "ON COMMIT" options for
Global Temporary Tables. "By default, every time you commit your data,
it is assumed that you want to clear out your work tables. Try
PRESERVE."

He dropped the table, and tried again.

SQL> CREATE GLOBAL TEMPORARY TABLE worktable


2 (x NUMBER(3))
3 ON COMMIT PRESERVE ROWS;
Table created.
SQL> INSERT INTO worktable (x) VALUES (1);
1 row created.

http://thinkoracle.blogspot.com/2007/10/global-temporary-tables.html (2 of 7)1/9/2008 2:56:40 AM


OracleBlog: Global Temporary Tables

SQL> SELECT * FROM worktable;


X
----------
1
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
X
----------
1

"That's better," he smiled. Now let's check the other session.

SQL> SELECT * FROM worktable;


no rows selected

"Excellent. So this data will remain there until my session ends?"

"Yep. Try it." He exited his session, logged back in, and sure enough
the data was gone. "This is great. But what if I want to get rid of the
data at some point in my session?"

"Truncate. Truncating the work table will only truncate the data in your
session, not all the data."

"Hey neat. Thanks, this will be very useful. What are you doing for lunch
later?"

"Aren't you even going to try it? What, you're just going to trust me?" I
said. I think he was a little surprised that I would I'd rather talk about
work tables than lunch. Frankly, so am I. Thankfully, he worked quickly,
typing first in his second session.

SQL> INSERT INTO worktable (x) VALUES (2)


1 row created.
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
X
----------

http://thinkoracle.blogspot.com/2007/10/global-temporary-tables.html (3 of 7)1/9/2008 2:56:40 AM


OracleBlog: Global Temporary Tables

2
SQL> TRUNCATE TABLE worktable;
Table truncated.
SQL> SELECT * FROM worktable;
no rows selected
SQL> commit;
Commit complete.

"I don't think you need all those commits," I laughed. "But ok, now look
back in your first session. If the row you added previously isn't there,
then I'm a big fat liar. Otherwise, we can talk about lunch."

SQL> SELECT * FROM worktable;


X
----------
1

"So how about sushi?" he asked.

"Sushi?" I groaned. "Haven't you learned anything from me?"

// posted by Robert Vollman @ Sunday, October 21, 2007

Comments:
I like that style. Thanks Robert.
# posted by Oracloid : Friday, 26 October, 2007

Master and the apprentice

Thank you for coming back with your style of making excellent reading.
# posted by Coskan Gundogar : Tuesday, 30 October, 2007

This post has been removed by a blog administrator.


# posted by Densis : Wednesday, 07 November, 2007

http://thinkoracle.blogspot.com/2007/10/global-temporary-tables.html (4 of 7)1/9/2008 2:56:40 AM


OracleBlog: Global Temporary Tables

This is the best style that an article can have...Greattt!!! Please do post
more in this style when time permits. Thanks a lottt!!!!
# posted by manjusha : Monday, 03 December, 2007

Awesome post! Please do sahre ur knowledge thru ur posts!

Looking forward for more!

~ Siri
# posted by Siri : Wednesday, 05 December, 2007

Post a Comment

<< Home

About Me
Name: Robert Vollman
Location: Calgary, Alberta, Canada

I was born and raised in Ottawa, and have lived in Calgary since 1991. I
like playing sports (hockey, soccer, ultimate, basketball, you name it)
and military board games. I also enjoy reading, walking, and playing with my 2 cats
Lilly and Brutus. I'm a database application specialist, whatever that is.

View my complete profile

Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ

http://thinkoracle.blogspot.com/2007/10/global-temporary-tables.html (5 of 7)1/9/2008 2:56:40 AM


OracleBlog: Global Temporary Tables

Connor McDonald

● The Oak Table


● Cary Millsap and Hotsos
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
● Dizwell Oracle Wiki
● My Personal Blog

Aggregators
Brian Duff's OraBlogs

❍ Eddie Awad's OracleNA


❍ Pete Finnigan's Aggregator
❍ Oracle's Bloglist
❍ Oracle Base Aggregator

Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
❍ Oracle Geek Lewis Cunningham
❍ Database Expert James Koopmann
❍ Dizwell's Howard Rogers
❍ Oracle Master Laurent Schneider
❍ Security Expert Pete Finnigan
❍ Oracle Award Winner Mark Rittman
❍ Doug Burns
❍ Oracle ACE of the Year Dr. Tim Hall
❍ UKOUG's Andrew (Arfur C.) Clarke
❍ Newbie DBA Lisa Dobson
❍ Coffee-Drinking DBA Jon Emmons
❍ Chris Foot
❍ The Pythian DBA Team Blog
❍ DBA Don Seiler
❍ DBA Coskan Gundogar
❍ Oracle WTF

ARCHIVES
http://thinkoracle.blogspot.com/2007/10/global-temporary-tables.html (6 of 7)1/9/2008 2:56:40 AM
OracleBlog: Global Temporary Tables

❍ LIST ALL ARTICLES


❍ May 2005
❍ June 2005
❍ July 2005
❍ August 2005
❍ September 2005
❍ October 2005
❍ November 2005
❍ December 2005
❍ January 2006
❍ February 2006
❍ March 2006
❍ April 2006
❍ May 2006
❍ June 2006
❍ July 2006
❍ August 2006
❍ September 2006
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007

http://thinkoracle.blogspot.com/2007/10/global-temporary-tables.html (7 of 7)1/9/2008 2:56:40 AM

You might also like