Escolar Documentos
Profissional Documentos
Cultura Documentos
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.
Aggregators
Brian Duff's OraBlogs
❍
October 2007
their maximum values, and are any in danger of
❍
-- 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));
with a "gap."
2006 17 comments
5. Is not a "gotcha"
attempting to fill?
Closing Thoughts
http://www.orafaq.com/forum/t/9760/2/
http://www.databasejournal.com/features/oracle/
article.php/3085171
comments
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
comments
PHONE_NO
------------
619.455.1998
1 row created.
1 row created.
T
-
TRA
---
abc
1 row created.
1 row created.
comments
What is SOA?
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
comments
SourceForge
Have you been overlooking the wealth of handy
tools and code on SourceForge?
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.
comments
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.
My Personal Blog
are in July/August.
●
Oracle's Bloglist
Feuerstein about how to hide your
❍
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
❍ 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
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.
● 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
❍
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
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
●
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
Wednesday,
March 01, 2006
Handling
exceptions - A
how-to guide.
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
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:
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
Monday, July
04, 2005
SQLCODE and
SQLERRM in
INSERTs
How-To
Guides:
Wednesday,
September 14,
2005
Analyzing
Query
Performance -
using
SQLTRACE and
TKPROF
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 -
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.
Tuesday, May
09, 2006
Finding Nearby
Rows. Three
methods of
solving similar
requirements.
Monday,
August 01,
2005
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, 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?
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?
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.
// 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
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
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.
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://www.niall.litchfield.dial.pipex.
com/
ARCHIVES
AS
BEGIN
in_value := 3; ❍ LIST ALL ARTICLES
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 ❍
April 2007
reference for an OUT or IN OUT
❍
May 2007
parameter. When you change a
❍
June 2007
NOCOPY parameter, it changes right ❍
DBMS_OUTPUT.PUT_LINE(the_value);
the_value := 3;
InterProc(the_value);
DBMS_OUTPUT.PUT_LINE(the_value);
END;
1 NoCopyProc
2
3 CopyProc
3
1 row created.
EXEC MyProc('Monday');
EXEC MyProc('Blingday');
http://www.amazon.com/exec/
obidos/ASIN/0596003811/
qid=1117039808/sr=2-1/
ref=pd_bbs_b_2_1/102-9543590-
3979349
http://asktom.oracle.com/~tkyte/
Misc/Random.html
http://asktom.oracle.com/pls/ask/f?
p=4950:8:::::
F4950_P8_DISPLAYID:831827028200
http://www.psoug.org/reference/
dbms_random.html
AS
random_value number(2,0);
BEGIN
random_value := dbms_random.value
(0,20);
random_value := dbms_random.value
(1,21);
random_value := dbms_random.value
(1,21);
random_value := MOD(random_value,
20) + 1;
--------------------
@utlraw
@prvtrawb.plb
@dbmsoctk
@prvtoctk.plb
@dbmsrand
exec ValuePlacer(1000);
Thanks!
ERROR at line 1:
ORA-00957: duplicate column name
ERROR at line 1:
ORA-02256: number of referencing
columns must match referenced
columns
Table altered.
Table altered.
2005 0 comments
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:
DECLARE
x VARCHAR2(32); -- test_constants.
MAX_LEN = 32
Table created.
DECLARE
x TEST_CONSTANTS.MAX_LEN%TYPE;
BEGIN
x := 'Test';
dbms_output.put_line(x);
END;
Steven Feuerstein on
Refactoring
Refactoring for PL/SQL Developers
By Steven Feuerstein
http://www.oracle.com/technology/
oramag/oracle/05-jan/o15plsql.html
My additional thoughts on
Refactoring:
1. Inline documentation
1. utl_file_constants
2. compare_latest_read
1. VARCHAR2 length
2. Procedures vs Functions
Conclusion:
Table created.
1 row created.
1 row created.
1 row created.
2 AS
3 BEGIN
4 DBMS_OUTPUT.PUT_LINE
(some_value);
5 NULL;
6 END;
7/
Procedure created.
oreilly.com/catalog/optoraclep/
chapter/ch01.pdf
Thumbs up.
http://www.coug.ab.ca/Resources/
BookReviews/MillsapsOOPByRVollman.
htm
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
●
Steven Feuerstein
OVER (PARTITION
●
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
December 2005
Schemas:
❍
January 2006
Page 68, section
❍
February 2006
4-28 on Oracle's
❍
March 2006
sample HR ❍
December 2006
first name. I urge
❍
January 2007
you to do the ❍
// 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
Anonymous :
Thursday, 23
February, 2006
Post a
Comment
<< Home
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.
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.
some_variable NUMBER(10),
)
INSTANTIABLE -- Or "NOT INSTANTIABLE" if this is a base class only
NOT FINAL -- Or "FINAL" if this class will NOT have a sub-class
;
composed_object some_object
);
);
-- It will automatically return self, don't even try to return anything else
RETURN;
END some_object;
END;
END;
-- Test!
DECLARE
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.
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.
Table created.
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
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = C:\oracle\ora92)
(SID_NAME = srv_name)
)
5. Test connection
sqlplus username/password@srv_name
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.
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.
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.
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.
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:
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:
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?
TO_DATE('
---------
01-JUN-05
"Today, in june, to_date(2005) returns 01-jun, last month, same function, same
inputs - would return 01-may"
Tom also clarified that the following function would be deterministic and therefore
eligible for a function-based index:
That, of course, would force it to choose January no matter what time of year you
called the function.
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...
This is because they are used in other tables to reference a single row.
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
Synthetic/Surrogate 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
Decode allows you to do if/elseif/else logic within an SQL query, similar to a CASE
WHEN statement in a PL/SQL procedure.
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.
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:
Table created.
1 row created.
1 row created.
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
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
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.
abcde
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
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.
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://tkyte.blogspot.com/2005/05/why.html
Loosely Related:
http://vollman.blogspot.com/2005/04/roberts-tips-on-asking-for-help-1.html
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.
If there is a logical link between these two fields, we can use referential integrity
constraints (thanks "hsheehan"):
Table created.
Table altered.
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)
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));
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
Check Constraints can NOT contain subqueries, so forget about doing it that way.
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.
Table created.
6 END;
7/
Trigger created.
1 row created.
Related links:
http://thinkoracle.blogspot.com/2005/05/enum-in-oracle.html
Bind variables are already very well explained, here are my favourite links on the
subject:
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.
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://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.
DECLARE
v_cur sys_refcursor;
BEGIN
OPEN v_cur FOR 'select 1 from dual where 1=2';
CLOSE v_cur;
END;
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:
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.
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
aint integer
);
It thinks "aint integer" is a new command. What is the problem? Repeat this test
using SQLPlus at a prompt:
10 /
Procedure created.
Table created.
But eventually I took a closer look and arrived at the correct solution. Here it is.
Table created.
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.
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
"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.
No rows selected.
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:
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:
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
Pretty bizarre, eh? Starting to understand the behaviour of NULL? Starting to see
why misunderstanding NULL can lead to application errors?
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.
LAST_NAME
------------
Smith
2 rows selected.
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.
2 rows selected.
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
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.
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
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.
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
❍
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
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
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.
http://thinkoracle.blogspot.com/2005/07/use-views.html
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
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.
http://thinkoracle.blogspot.com/2005/07/extra-columns-in-
group-by.html
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:
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.
Perfect.
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
So instead, let me give you a just a really quick primer from my own
experience, and a couple of treats.
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.
Using this method (only), you can't reference other columns in the
table in your check constraint. Try it:
It is also not obvious what name the constraint takes so it's more
difficult to alter it later. But here is how:
CONSTRAINT_NAME
------------------------------
SYS_C007536
Example:
Doing it this way allows you to reference other columns in the table:
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.
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/06/variable-constraints.html
(By the way, that's the other way to find out the name of your
constraint: violate it!)
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:
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
What is a View?
Here are two definitions from Oracle, along with references to the
key documents on Views to review.
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*.
*This is true in general. Some Views can't be updated, and you can
make a View READONLY.
I use them for many reasons, here are the most common situations
where I will advocate their use:
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.
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.
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!
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.
Table created.
1 row created.
View created.
Table altered.
'Hello');
1 row created.
MYNUMBER
----------
1
2
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.
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE('SQLCODE: ' || SQLCODE);
END BoolProc;
http://asktom.oracle.com/pls/ask/f?
p=4950:8:2109566621053828525::NO::F4950_P8_DISPLAYID,
F4950_P8_CRITERIA:6263249199595
Niall Litchfield has one of the first Oracle blogs I read. He has
interesting posts on a variety of topics including htmldb, and Oracle
10g.
http://www.niall.litchfield.dial.pipex.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/
Lisa Dobson, an Oracle DBA whose brand new blog focuses on the
Newbie perspective.
http://newbiedba.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!
You are logged into your default session (example: sqlplus scott/
tiger with no @instance)
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:
Also, I know some people who put this directly into their sqlplus
prompt.
http://thinkoracle.blogspot.com/2005/06/asking-for-help.html
http://tkyte.blogspot.com/2005/07/rtfm.html
Which begs the F'n question. Where are the F'n manuals? Which
http://www.oracle.com/technology/documentation/index.html
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:
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:
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/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!
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;
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;
/
http://thinkoracle.blogspot.com/2005/05/null-vs-nothing.html
"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."
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
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:
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;
/
Table altered.
1. I only blog about what I'm currently working on and studying, and
2. I use Oracle 9.
http://www.oracle.com/technology/oramag/webcolumns/
2003/techarticles/rischert_regexp_pt1.html
http://www.psoug.org/reference/regexp.html
END;
Procedure created.
Enjoy!
My problem:
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.
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.
http://www.oracledba.co.uk/tips/9i_first_last.htm
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.
2 rows selected.
http://thinkoracle.blogspot.com/2005/05/enum-in-oracle.html
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.
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
❍
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
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
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.
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
Hopefully these blogs will make up for my lack of content ● Dizwell Oracle Wiki
recently! ● My Personal Blog
Aggregators
Brian Duff's OraBlogs
❍
Oracle's Bloglist
Let's say you wanted to write a query that contained an
❍
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
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
http://oraclesponge.blogspot.com/2005/08/list-ways-to-
scan-table-faster.html
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.
First off, here is an easy way to create a nice, big test table.
40763
38000
2763
http://thinkoracle.blogspot.com/2005/07/use-views.html
Nice.
http://thinkoracle.blogspot.com/2005/08/union-all.html
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.
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;
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.
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
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;
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!
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
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
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
But you also want to check out the Oracle SQL Reference,
Chapter 8: SQL Queries and Subqueries.
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://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):
It was very easy using the import (IMP) and export (EXP)
http://www.oracle.com/technology/documentation/index.
html
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.
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.
http://thinkoracle.blogspot.com/2005/05/nocopy-hint.html
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.
2. Now split that stored procedure into two (or more) parts, and a master
proc
...etc!
3. With stats on, call that first stored procedure that does everything,
and then run TKPROF to analyse it.
performance.html
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.
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
DECLARE
out_val NUMBER;
BEGIN
HelperProc('EMPNO', out_val);
DBMS_OUTPUT.PUT_LINE(out_val);
END;
2. Static SQL
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.
ID;...;SALARY;HOURLY;BONUS;DIVIDEND
1;...;60;NULL;NULL;NULL
2;...;100;NULL;NULL;20
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.
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!
http://htmldb.oracle.com/pls/otn/f?p=2853:4:1727923121986559057::
NO::P4_QA_ID:246
http://www.phpbbserver.com/phpbb/viewtopic.php?
t=458&mforum=dizwellforum
http://www.oracle.com/technology/products/jdev/101/
howtos/extools/subversion.html
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
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."
3. Turn on tracing
Note: 00:44:50.07
8. Drop ReallyBigTable
Elapsed: 00:45:21.04
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.
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.
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.
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.
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.
http://thinkoracle.blogspot.com/2005/07/specifying-insert-columns.
html
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.
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
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
http://thinkoracle.blogspot.com/2005/06/decode.html
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
http://thinkoracle.blogspot.com/2005/06/oop-in-plsql-yep.html
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.
COMM
----------
300
500
1400
0
14 rows selected.
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
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.
p=4950:8:16663421538065257584::NO::
F4950_P8_DISPLAYID,F4950_P8_CRITERIA:766825833740
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
What we want:
A table showing each of these 4 teams and their point tables for these 3
seasons.
Step 1/2: We are using season, so we don't need to create our own
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);
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;
Tiger-Cats 15 2 19
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
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.
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
Oracle WTF
Another great way to learn Oracle is to study mistakes.
http://oracle-wtf.blogspot.com/
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?" :)
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.
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
❍
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
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
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.
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:
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
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.
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.
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:
By the way, to use packages, just prefix the package name using dot notation
But also check out UTL_FILE, DBMS_PIPE, DBMS_ALERT and the DBMS_XML stuff.
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;
3 DBMS_OUTPUT.PUT_LINE('Disabled');
4 DBMS_OUTPUT.ENABLE;
5 DBMS_OUTPUT.PUT_LINE('Enabled');
6 END;
7/
Enabled
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
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
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.
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> DECLARE
2 l_bool BOOLEAN;
3 BEGIN
4 l_bool := TRUE;
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
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
There is one thing all these questions have in common: the answer involves either
ROWNUM or 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
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:
Whoops! Turns out ROWNUM is assigned before results are ordered, not after.
Knowing that, we can write it like this:
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.
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.
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/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
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
**Note: I did this about 15-20 times to get a really big table.
The DECODE version completed twice as quickly, because it only need to make one
pass through the data instead of 2.
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
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.
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
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
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.
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).
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);
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;
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.
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 let me give you an example of the type of minor annoyance you have to deal
with when using RAW datatypes.
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;
BEGIN
test_ass(SYS_GUID()) := 1;
test_ass(SYS_GUID()) := 2;
test_ass(SYS_GUID()) := 3;
END;
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.
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.
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 In, XML Out by Jonathan Gennick for Oracle Magazine May/June 2003
http://www.oracle.com/technology/oramag/oracle/03-may/o33xml.html
-
X
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).
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:
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/
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
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
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
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!
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
For more about the Oak Table Network, visit their web site:
http://www.oaktable.net/main.jsp
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
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
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.
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.")
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.
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
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 of mine here:
http://thinkoracle.blogspot.com/2005/05/optimizing-oracle-performance-millsap.
html
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.
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.
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.
"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 -
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.
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.
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.
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
❍
Top Blogs
❍ Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
❍ Data Warehouser David Aldridge
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
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.
http://www.computerworld.com/blogs/node/1466?source=nlt_blg
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.
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
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
4. High-Hit Posts
There were two posts that, for various reasons, seem to have higher hit-
counts than the others. Here they are:
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:
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!
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.
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.
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
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:
6. How do you see the errors from your recently created view/procedure?
show errors;
SQLPlus:
More Advanced:
performance.html
Bonus:
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
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.
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.
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:
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
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!
There are books written on the efficiency gain of preferring SQL over PL/
SQL.
Generally servers are more powerful and built for this type of work. You
also want to minimise trips back and forth to the server.
Not just for performance reasons, but also for security (thwart SQL
injection). I think Tom Kyte made his living off this topic for awhile.
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.
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.
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.
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
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()) {
http://www.orafaq.com/faqperl.htm
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
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.
Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
● Connor McDonald
Aggregators
Brian Duff's OraBlogs
❍
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
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007
❍ Current Posts
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.
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.
Techniques
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!
What's Next?
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.
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
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
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
Ask Tom
Driving Tables
Introduction to Analytical Functions
Batch Processing
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
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:
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.
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.
"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 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!
A Final Plea
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.
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.
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;
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;
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
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);
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
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
Dr. Tim Hall has some several good write-ups with good examples:
http://www.oracle-base.com/articles/8i/BulkBinds8i.php
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
From Others:
11. Don't hesitate to throw away bad code, rewriting can be better
than refactoring.
15. Don't comment your SQL to override the optimizer plan unless
you are sure.
19. Don't expect the same database on two different hosts to work
exactly the same.
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.
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.
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
❍ 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
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.
written, Oracle used a rule-based optimizer (RBO), which ● Steve Adams and Ixora
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.
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
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
❍
❍ 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
Oracle Packages:
Top 20 Lists:
Book Reviews:
Templates:
Great Debates:
NULLs:
Gotchas!
How-To Guides:
TKPROF
Import Export
Other:
this approach.
Notes:
1. By doing things in order of business importance
So what is an exception?
EXCEPTION
WHEN ONE_KIND_OF_ERROR THEN
-- Do something here
WHEN OTHERS THEN
-- Handle all left over cases here
END
BEGIN
BEGIN
-- Do task one.
EXCEPTION
-- Handle it!
END
-- Do task two
-- Do task three ...
EXCEPTION
-- Handle exceptions from task two, three, ...
END
A word on rollback
comments
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.
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.
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.
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.
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.
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.
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)
--------------------------------------------------------------------------------
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?
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 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.
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.
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.
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
❍
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
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007
❍ Current Posts
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.
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.
Quick, find me the average of a value for all rows in a table. No problem,
right? Use the analytic function AVG.
AVG(VOTES)
----------------------
357315.2307692307692307692307692307692308
Great. Now, find me that average only for a certain range of data, say from
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:
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.
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
values).
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.
Putting the partitioning clause and the windowing clause together is like
mixing chocolate and peanut butter. Alone, they're great, together they're
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.
By using the order by clause within the context of the analytic function,
we can create rolling averages.
--
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);
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.
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.
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.
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?
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.
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.
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.
LOC
--------------------
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
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');
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.
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
❍
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
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ October 2007
❍ Current Posts
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.
● Oracle Docs
An iterative function includes a loop, which ● Dan Morgan and PSOUG
Oracle's Bloglist
RETURN fib3;
❍
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
resources until there are none left, possibly ❍ DBA Coskan Gundogar
crashing the system. ❍ Oracle WTF
October 2005
and recursion, but, based on the topic I chose
❍
November 2005
for the sample code, knowledge that I saw "Da ❍
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
❍
❍ Current Posts
comments
7. Recalculate Statistics
That's it!
comments
questions. :)
2006 2 comments
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.
understand the execution plans you see in the DBA Don Seiler
❍
❍ 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?
2006 2 comments
C:\temp>echo %CLASSPATH%
.;c:\oracle\product\10.1.0\db\jdbc\lib
\ojdbc14.jar
import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;
Create an OracleDataSource
Query Away!
javac JdbcVersion.java
java JdbcVersion
That's it!
comments
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
●
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
Zsolt:
In my
experience the
Aggregators
overhead of Brian Duff's OraBlogs
❍
January 2006
NULL;
❍
February 2006
END calculate;
❍
March 2006
BEGIN ❍
December 2006
nLoops LOOP
❍
January 2007
calculate();
❍
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
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.
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 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
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
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();
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');
htp.init();
END;
/
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
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
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.
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.
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.
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.
Reason #1 Protection
The programmers wish to protect their code from theft, misuse or
alteration (among other things).
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;
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.
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.
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
(garbage removed)
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.
About Me
http://thinkoracle.blogspot.com/2006_09_01_archive.html (5 of 8)1/9/2008 2:50:29 AM
OracleBlog: September 2006
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.
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
❍
Top Blogs
❍Oracle's Ask Tom Kyte
❍ Oracle Guru Jonathan Lewis
❍ Blogger of the Year Eddie Awad
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
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.
● 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
1. Credentials
A stellar education with
Aggregators
prestigious degrees, Brian Duff's OraBlogs
❍
January 2006
Criteria? Well the criteria
❍
February 2006
are fairly subjective, but
❍
March 2006
from what I know of ❍
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
❍
Reviewing Burleson's
Three Criteria
1. Credentials
accumulate without
attaining a thorough
understanding of Oracle,
we need to measure it
based upon the actual
understanding.
2. Communicating Their
Knowledge
3. Attitude
elaborated further.
Wrapping Up
// posted by Robert
Vollman @ Tuesday, October
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 ...
SELECT username,
password FROM
dba_users WHERE
username = 'SCOTT';
or deliberately) changed
using ALTER USER.
$ORACLE_HOME/rdbms/
admin/utlpwdmg.sql
password from 8
characters to 9 can
make the different
between 2 days and 57
for a brute force attack!
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
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.
orapwd file=filename
password=syspassword
entries=maxsysdbas
force=Y
maximum number of
users. Use this utility to
increase your limit.
Finally ...
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
// posted by Robert
Vollman @ Monday, October
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
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
CREATE TABLE
MyProcCalls
(caller_name VARCHAR2
(100), line_number
NUMBER(8));
INSERT INTO
MyProcCalls
(caller_name,
line_number) VALUES
(caller_name,
line_number);
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.
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.
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.
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.
Summary
// posted by Robert
Vollman @ Thursday, October
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
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.
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.
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-
// posted by Robert
Vollman @ Tuesday, October
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
●
Perhaps that
makes my work
ARCHIVES
LIST ALL ARTICLES
more accessible.
❍
May 2005
The complexities
❍
June 2005
of Oracle often
❍
❍ July 2005
❍ 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
❍
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
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.
ERROR at line 1:
ORA-02270: no
matching unique
or primary key
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
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.
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.
View altered.
SQL> GRANT
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
In fact that is
precisely the
advice that
Oracle ACE
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).
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
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,
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
regexp_like
(address_ip,'((^([2][0-
Aggregators
5]{2}\.|[2][0-4][0-9] Brian Duff's OraBlogs
❍
Doug Burns
in advance... ❍
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
❍
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
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}'||
'([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
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.
● 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
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,
❍
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, ❍
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 ❍
If so, now you're ready for one of Ask Tom's more complex
examples.
Pivot 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.
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 ●
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
❍
I think your
ARCHIVES
keyboard might be ❍ LIST ALL ARTICLES
on the fritz? ❍ May 2005
Vowels are ❍ June 2005
disappearing left ❍ July 2005
❍ 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
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)
BONUS:
7. Fast Refresh is
Taking Longer
Than Complete
Refresh of
Materialized View
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
10. Designing
Tables
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?
Oracle Database
// posted by Robert
Vollman @ Monday,
February 26, 2007 6
comments
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.
Top Blogs
"Trust, but Verify."
Trust in Tom's
wisdom, but check Oracle's Ask Tom Kyte
the context of his
❍
❍ 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
February 2006
utilities that call
❍
March 2006
nothing and are
❍
May 2007
SQL as you would for
❍
June 2007
any other language
❍
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
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
Refresh on
Materialized View
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.
DBMS_JOB Package
This is one of Tom's
favourite comebacks
to someone saying "it
doesn't work."
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.
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
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
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.
Steven Feuerstein
that recommendation, I
●
Jonathan Lewis
make it clear that this ●
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
❍
Chris Foot
views could be enforced.
❍
❍ July 2005
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 ❍
May 2007
far superior to others
❍
June 2007
RDBMS, but I agree there's
❍
McDonald's 19 suggestions
(what, he couldn't think of
1 more to make a round
number?)
// posted by Robert
Vollman @ Thursday, April 05,
2007 5 comments
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
●
ERROR at line 1:
ORA-00933:
SQL command
Aggregators
not properly Brian Duff's OraBlogs
❍
table
(column1, ARCHIVES
column2) ❍ LIST ALL ARTICLES
VALUES ❍ May 2005
(value1, ❍ June 2005
value2); ❍ July 2005
❍ August 2005
November 2005
of Laurent
❍
December 2005
Schneider (see
❍
January 2006
the ❍
October 2006
INSERT ALL
❍
November 2006
INTO table ❍
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.
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
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.
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 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.
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.
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
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
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.
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
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;
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 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.
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.
"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.
Not everyone
has really
enjoyed
moving from
the traditional
join syntax to
ANSI syntax,
including Doug
Burns and Jeff
Moss.
got a crash
course on the
different types
of ANSI joins,
but of course,
that type of
information
you can find
almost
anywhere.
// posted by
Robert
Vollman @ Friday,
May 04, 2007 7
comments
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
●
Top Blogs
were
nevertheless
remarkably Oracle's Ask Tom Kyte
effective ways
❍
May 2005
their SQL. This
❍
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 ❍
department
that has a
higher
combined
salary than
mine?
Intermediate
Questions
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
- 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
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.
"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.
"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
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.
"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."
"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.
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."
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.
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
❍
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
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
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.
"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.
"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
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.
"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."
"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.
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."
First I ask the candidate how they would personally rate their own
understanding of SQL. I'm also curious what databases and tools
they've used to write their SQL. This gives me a good idea where I
should begin my questioning.
Basic Questions
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?
Advanced Questions
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
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.
ERROR at line 1:
ORA-00933: SQL command not properly ended
1 row created.
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.
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.
1. Accuracy
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
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.
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 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.
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 have to stop following because the author stopped blogging
regularly? (Edit: List removed because it was easily misunderstood as
criticism)
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.
7. Googlability.
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
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.
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.
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 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.
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."
Incidentally, if the columns are named differently, you'd use this syntax
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."
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.
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.
Best Links
http://thinkoracle.blogspot.com/ (14 of 16)1/9/2008 2:51:03 AM
OracleBlog
Aggregators
Brian Duff's OraBlogs
❍
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
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
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.
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
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)/ ●
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), ❍
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
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;
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
Sloppy!!!
Peter,
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;
Cheers,
Robert
# posted by Robert Vollman : Saturday, 25 February, 2006
Anonymous,
Lycovian,
Anonymous,
Robert
# posted by Robert Vollman : Tuesday, 07 March, 2006
Regards,
# posted by Roy Brokvam : Thursday, 09 March, 2006
RETURN tmp;
END;
/
Post a Comment
<< Home
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, ●
January 2006
at getting to
❍
February 2006
the heart of the
❍
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
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.
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"
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
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.
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
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!
Robert
# posted by
Robert
Vollman : Tuesday,
21 February, 2006
Post a
Comment
<< Home
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?
●
Top Blogs
opposed to
large,
proprietary ❍ Oracle's Ask Tom Kyte
applications Oracle Guru Jonathan Lewis
that do
❍
Chris Foot
The notion of
❍
ARCHIVES
shared task is
also sometimes
referred to as ❍ LIST ALL ARTICLES
grid computing. ❍ May 2005
June 2005
Everyone knows
❍
❍ July 2005
December 2005
is essentially a
❍
January 2006
collection of
❍
February 2006
such services, ❍
January 2007
contained
❍
February 2007
service
❍
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
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
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, 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
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
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
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.
(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
●
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
❍
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.
latest stuff.
- blogreader
# posted by Anonymous : Friday, 17 February, 2006
Post a Comment
<< Home
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.
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
❍
❍ 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
December 2006
represents a special code
❍
January 2007
in your company where
❍
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:
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));
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.
scott@Robert>
SELECT
TRANSLATE
('abc123',
'0123456789',
'') FROM DUAL;
T
-
scott@Robert>
SELECT
TRANSLATE
('abc123',
'$0123456789',
'$') FROM
DUAL;
TRA
---
abc
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
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.
// posted by Robert
Vollman @ Tuesday, February 07,
2006
Comments:
Great article.
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?
Rob,
Thanks,
LewisC
# posted by LewisC : Sunday,
19 February, 2006
Post a Comment
<< Home
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
Doug Burns
plsqlgenpkg/
❍
January 2006
to various IDEs (like
❍
February 2006
Eclipse). I've seen
❍
March 2006
Java programs that ❍
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,
Comments:
Here is a handy link:
oracle.com/
technology/
community/
opensource_projects.
html
# posted by Eddie
Awad : Thursday, 02
February, 2006
Post a Comment
<< Home
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.
Doug Burns
parameters setup
❍
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? ❍
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
More Advanced:
analyze itself.
Pre-10g: Must be logged in with
privileges:
execute DBMS_STATS.
GATHER_SCHEMA_STATS
('SCOTT');
Bonus:
com/2005/08/import-export.
html
// posted by Robert
Vollman @ Tuesday, December 20, 2005
Comments:
On #9 what is getdate()? Do you
mean sysdate?
Cheers
# posted by Robert Vollman :
Tuesday, 20 December, 2005
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.
Q16)
Q7.)
DBMS_OUTPUT.PUT_LINE
("Hello.");
Cheers.
# posted by Robert Vollman :
Wednesday, 21 December, 2005
http://www.computerworld.
com/blogs/node/1466?
source=nlt_blg
http://thinkoracle.blogspot.
com/2005/12/thomas-kyte-
effect.html
# posted by Robert Vollman :
Wednesday, 21 December, 2005
Post a Comment
<< Home
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.
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 ●
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
❍
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
❍
http://tkyte.blogspot.
com/2005/05/why.html
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,
cheers!
Mark
# posted by Mark : Saturday,
18 June, 2005
http://www.catb.org/~esr/
faqs/smart-questions.html
# posted by Robert Vollman :
Monday, 20 June, 2005
http://tkyte.blogspot.
com/2005/06/how-to-
ask-questions.html
# posted by Robert Vollman :
Friday, 24 June, 2005
http://newbiedba.
blogspot.com/2005/08/
how-to-be-good-newbie.
html
# posted by Robert Vollman :
Thursday, 18 August, 2005
Post a Comment
<< Home
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
Top Blogs
index.html
Chris Foot
Installer, the
❍
ARCHIVES
recommendations
for which F'n
manuals to read. ❍ LIST ALL ARTICLES
May 2005
Being an
❍
June 2005
application ❍
❍ July 2005
June 2007
com/pls/db92/
❍
October 2007
db92.docindex?
❍
remark=homepage
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
// posted by Robert
Vollman @ Thursday,
Comments:
The "F" is for
"Fine" of course.
# posted by
Thomas Kyte :
Thursday, 14 July,
2005
Thanks for
compiling it in
one shot..These
link go right into
my bookmarks as
well
# posted by
Anonymous :
Thursday, 14 July,
2005
As eddie stated
Oracle Paradise
http://tahiti.
oracle.com
Post a
Comment
<< Home
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.
Best Links
write fast mass insert/
deletes like a pro?
Ask Tom Kyte
I have found you the
●
Top Blogs
backed up by references
and proven tests. His
article about OWA_UTIL. Oracle's Ask Tom Kyte
WHO_CALLED_ME is no
❍
❍ 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, ❍
❍ 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.
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.
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.
As database
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.
Summary
// posted by Robert
Vollman @ Thursday, October
19, 2006
Comments: Post a
Comment
<< Home
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.
February 2006
and session variables,
❍
March 2006
and promote overall
❍
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.
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.
Refresh on Materialized
View
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.
DBMS_JOB Package
This is one of Tom's
favourite comebacks to
someone saying "it
doesn't 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....
CPU Utilization
Q: How can I reduce
CPU utilization of
Oracle database?
A: shutdown abort
works well ;)
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!
For example:
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
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.
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
My Personal Blog
http://asktom.oracle.com/pls/ask/f?
●
p=4950:8:::::
F4950_P8_DISPLAYID:1163635055580.
August 2005
probably dealing with a very small set
❍
September 2005
of SQL statements and are specifically ❍
❍ 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
14, 2005
<< Home
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
●
Steven Feuerstein
gathering ●
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. ❍
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
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
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.
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
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
// posted by Robert
Vollman @ Tuesday,
Comments:
Robert Vollman
said....
A requirement is
based on a specific
business-driven
need that is
necessary to
accomplish the
stated project vision.
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
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.
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
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
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:
❍
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
March 2006
code falls into this category, and wrap it in its own, ❍
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
A word on rollback
Comments:
This post has been removed by a blog administrator.
# posted by Thomas Kyte : Thursday, 02 March, 2006
begin p; end;
ops$tkyte@ORA10GR2> rollback;
Rollback complete.
X
----------
2
100
See how you totally changed the behavior - you have half
of P's work now - ugh.
Tom said:
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 ...
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 --
c) partitally
Showing the when others then null and calling it the null
exception - I actually think of that as "irresponsible".
Tom,
But I have had situations where this was the case. Just
because something doesn't matter doesn't mean you
shouldn't do it.
Rob
# posted by Robert Vollman : Thursday, 02 March, 2006
Can you post a real world example where you didn't care
if
:)
The day that email didn't show up, what does that poor
analyst do?
....
Incidentally, here is what the "do nothing" (edit or "hide
the error") option looks like:
.........
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,
Use Constraints
Variables in Constraints
Rob
# posted by Robert Vollman : Sunday, 05 March, 2006
Post a Comment
<< Home
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.
Best Links
sufficient level of
experience, this is
successful quite Ask Tom Kyte
often with minimal
●
Oracle Docs
effort. But there
●
Top Blogs
Millsap's influence
in this approach.
Oracle's Ask Tom Kyte
1. Rank the most
❍
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 ❍
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.
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
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,
Comments:
I think this
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
evaluation
independent of the
business analysis
to see these things.
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,
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
One thing I do
here, that is a
slight departure
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
When I was
referring to the
"common
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.
Cheers,
Robert
# posted by Robert
Vollman : Wednesday,
22 March, 2006
Depends on your
definition of
"broke." :-)
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.
four interesting
points in his
Modern
Performance Myths
paper at orapub.
# posted by Joel
Garry : Thursday, 23
March, 2006
Post a Comment
<< Home
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
Oracle Docs
often overlooked way ●
Doug Burns
version of this table. ❍
Oracle WTF
all data.
❍
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
❍
SELECT SUM(object_id)
FROM ReallyBigTable
WHERE object_id * 2
NOT IN
(SELECT object_id
FROM ReallyBigTable);
Time Elapsed:
00:11:42.09
CREATE TABLE
ReallyBigTable_Archive
AS SELECT * FROM
ReallyBigTable
WHERE object_id <
40000;
38000
CREATE TABLE
ReallyBigTable_Active
AS SELECT * FROM
ReallyBigTable
WHERE object_id >=
40000;
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
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!
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
INSERT INTO
ReallyBigTable
(object_id) VALUES
(NULL);
ORA-01732: data
manipulation
operation not legal on
this view
SELECT SUM(object_id)
FROM ReallyBigTable
WHERE object_id * 2
NOT IN
(SELECT object_id
FROM ReallyBigTable);
Time Elapsed:
00:08:18.02
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.
http://thinkoracle.
blogspot.
com/2005/08/union-
all.html
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
SELECT SUM
(object_id) FROM
ReallyBigTable_Active
WHERE object_id * 2
NOT IN
(SELECT object_id
FROM ReallyBigTable);
Time Elapsed:
00:00:54.05
Wrap-up:
// posted by Robert
Vollman @ Wednesday,
Comments:
... and partitioning is
an even better way of
achieving the same
thing!
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
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
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
Cheers,
Doug
# posted by Doug
Burns : Thursday, 18
August, 2005
Post a Comment
<< Home
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. ●
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
December 2005
have all the details
❍
January 2006
and logic behind
❍
February 2006
the package. Often ❍
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."
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.
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.
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.
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
notation
It includes
UTL_HTTP and
DBMS_OUTPUT
http://thinkoracle.
blogspot.
com/2005/08/
utlhttp.html
http://thinkoracle.
blogspot.
com/2005/10/
dbmsoutputputline.
html
// posted by Robert
Vollman @ Monday,
Comments:
Hi...I have a
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.
# posted by
Manish : Monday,
16 April, 2007
Post a Comment
<< Home
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.
Steven Feuerstein
for in an INSERT
●
Jonathan Lewis
statement.
●
❍ 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
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 ❍
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
SCOTT.
INSERTINTOMYTABLE
is invalid
ORA-06550: line 1,
column 7:
PL/SQL: Statement
ignored
CREATE OR
REPLACE
PROCEDURE
InsertIntoMyTable
(InValue IN NUMBER)
AS
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.
Table altered.
SQL> EXEC
InsertIntoMyTable
(3);
Inserting 3 into
MyTable
PL/SQL procedure
successfully
completed.
// posted by Robert
Vollman @ Monday, July
11, 2005
Comments: Post
a Comment
<< Home
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.
My additional
thoughts on
Refactoring: Aggregators
1. One of the Brian Duff's OraBlogs
❍
Doug Burns
to re-testing and re- ❍
My additional
imperfections in the ARCHIVES
unfactored code ❍ LIST ALL ARTICLES
sample: ❍ May 2005
❍ June 2005
1. Inline ❍ July 2005
October 2005
point out the most
❍
November 2005
egregious
❍
December 2005
transgression: lack of ❍
November 2006
documentation, but
❍
December 2006
didn't draw any
❍
My comments on the
refactored version:
1. utl_file_constants
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?
2. compare_latest_read
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.
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
3. Cleanup: closing an
unopened file
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.
Conclusion:
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
Comments:
Regarding your
question:
2. Procedures vs
Functions
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);
. end loop;
.
.
end;
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
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.
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
❍
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);
http://thinkoracle.blogspot.
com/2005/06/variable-
constraints.html
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
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
Post a Comment
<< Home
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.
● FAQ
Nothing could be easier. Here: ● Connor McDonald
Oracle's Bloglist
Likewise, any changes to the base
❍
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:
❍
❍ 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 ❍
❍ 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 ❍
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.
5. Rename a column
Table created.
1 row created.
View created.
Table altered.
1 row created.
MYNUMBER
----------
1
2
MYNUMBER MYSTRING
----------
--------------------------------
1
2 Hello
25, 2005
Comments:
Nice write up, only thing you might
explore later is "are views generaly
Anonymous,
Robert
# posted by Robert Vollman : Tuesday, 09
May, 2006
Post a Comment
<< Home
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
Top Blogs
lesser than
another, but
also by what Oracle's Ask Tom Kyte
number of
❍
Some
ARCHIVES
LIST ALL ARTICLES
developers
❍
December 2006
not the least of
❍
January 2007
which is
❍
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.
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
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
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
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,
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)
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
# 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)
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
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
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.
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;
3 DBMS_OUTPUT.PUT_LINE('Disabled');
4 DBMS_OUTPUT.ENABLE;
5 DBMS_OUTPUT.PUT_LINE('Enabled');
6 END;
7/
Enabled
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
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
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.
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> DECLARE
2 l_bool BOOLEAN;
3 BEGIN
4 l_bool := TRUE;
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
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
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
And a follow-up to Doug's comment, here is a quote from the Oracle 10gR2
documentation:
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
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.
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
Aggregators
Brian Duff's OraBlogs
❍
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
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ 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.
What is DBMS_PIPE?
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).
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);
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;
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:
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
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.
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
❍
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
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
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.
My Personal Blog
Yahoo Finance. Using UTL_HTTP.
●
❍ 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, ❍
June 2007
-- If we find it, add 52 (magic,
❍
October 2007
Yahoo-specific number)
❍
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;
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
Post a Comment
<< Home
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.
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
Oracle WTF
they are cool.
❍
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 ❍
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
15, 2006
<< Home
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
●
Aggregators
follow along with
me in my
adventures.
Brian Duff's OraBlogs
❍
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
March 2006
help.
❍
April 2006
The primary
❍
March 2007
so many places
❍
April 2007
to search for
❍
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.
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
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
http://
thinkoracle.
blogspot.
com/2005/07/
use-constraints.
html
http://
thinkoracle.
blogspot.
com/2005/07/
use-views.html
http://
thinkoracle.
blogspot.
com/2005/08/
keeping-tables-
small.html
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/08/
utlhttp.html
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
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
fairly typical of
Oracle docs?
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
Post a
Comment
<< Home
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.
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
●
Chris Foot
rather than patching something
❍
❍ 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
❍
Comments:
Rob,
http://oracledoug.blogspot.
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.
Regards
Karl
# posted by Karl r. : Tuesday, 20 December,
2005
Karl,
Doug:
Post a Comment
<< Home
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 ●
Aggregators
up for courses
and, more
importantly,
Brian Duff's OraBlogs
giving them
❍
Chris Foot
resist the urge. ❍
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
January 2006
become
❍
February 2006
(legitimate or
❍
March 2006
not) obstacles ❍
December 2006
but not too
❍
January 2007
current
❍
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/
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-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
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.
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
excellent
advice. ALong
the lines of "so
obvious
everybody
knows it, and
nobody does
it".
# posted by
Harry :
Thursday, 19
October, 2006
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
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
Post a
Comment
<< Home
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-
●
VARIABLE ARCHIVES
room_name ❍ LIST ALL ARTICLES
VARCHAR2(25) ❍ May 2005
EXEC :room_name : ❍ June 2005
= 'Room A' ❍ July 2005
❍ August 2005
-- If the count September 2005
comes back 0, the
❍
October 2005
room is yours
❍
November 2005
SELECT COUNT (*)
❍
December 2005
FROM schedules ❍
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
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."
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"
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
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,
Comments:
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.
I think we need a
#3 there....
(personally)
# posted by Thomas
Kyte : Thursday, 23 June,
2005
Post a Comment
<< Home
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.
FAQ
occasionally being wrong.
●
Connor McDonald
Cary Millsap (of the Oak
●
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
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 ❍
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
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
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
blog:
Top Blogs
http:// Oracle's Ask Tom Kyte
❍
❍ May 2005
For more about ❍ June 2005
the Oak Table ❍ July 2005
April 2006
essays from a
❍
May 2006
very talented and ❍
April 2007
performance/
❍
May 2007
tuning and
❍
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
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.
Chapter 2: You
Probably Don't
Tune Right, by
Mogens Norgaard
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.
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
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 7:
Compulsive
Tuning Disorder,
by Gaja Krishna
Vaidyanatha
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
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
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.
Chapter 10:
Design Disasters,
by 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.
development
project.
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
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
Post a
Comment
<< Home
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.
●
I really like
Aggregators
Steven Brian Duff's OraBlogs
❍
❍ May 2005
Connor ❍ June 2005
McDonald of ❍ July 2005
January 2006
presense. His
❍
February 2006
site is
❍
November 2006
Oracle PL/SQL:
❍
December 2006
Practical
❍
January 2007
Solutions ❍
// posted by Robert
Vollman @ Thursday,
Comments:
Post a
Comment
<< Home
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.
● 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
some_variable NUMBER
(10),
MEMBER FUNCTION
Aggregators
member_function Brian Duff's OraBlogs
❍
Doug Burns
IN NUMBER DEFAULT 1) ❍
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
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
❍
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;
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;
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
-- 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
2006
Post a Comment
<< Home
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.
Jonathan Lewis
pointer (pass by reference) -
●
FAQ
faster.
●
Top Blogs
DEFAULT 1)
-- The following says it is
independent of anything Oracle's Ask Tom Kyte
calling it (eg: rollbacks, etc)
❍
November 2005
"off" the Read Only
❍
December 2005
-- SET TRANSACTION
❍
January 2006
ISOLATION LEVEL READ ❍
October 2006
BlockName.v_datetime FROM
❍
November 2006
dual;
❍
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;
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
Comments: Post a
Comment
<< Home
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.
This is because they are used in other tables to reference a single row.
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
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
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
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.
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
forum discussion).
Last_name: Gretzky
First_name: Wayne
DOB: 26-Jan-61
ID: Gretzky_Wayne_260161
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).
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
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.
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
No, not in this context. A natural key isn't necessarily all that natural: it's a value in
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.
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
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
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ 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.
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
●
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 ❍
January 2006
be from several
❍
February 2006
tables, spread all
❍
January 2007
will be joined,
❍
February 2007
and which
❍
March 2007
indexes will be ❍
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
take advantage
of it.
// posted by Robert
Vollman @ Wednesday,
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
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?!
the word
verification
seems sort of
ironic: uiokj (or
am I just
paranoid?)
# posted by Peter
Lewis : Wednesday,
29 March, 2006
c'est la vie, I
guess.
LewisC
# posted by
LewisC :
Wednesday, 29
March, 2006
Post a
Comment
<< Home
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.
Steven Feuerstein
t=458&mforum=dizwellforum
●
● Jonathan Lewis
To sum up their positions: ● FAQ
● Connor McDonald
packages
- These packages should be
ARCHIVES
❍ LIST ALL ARTICLES
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 ❍
Post a Comment
<< Home
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
●
February 2006
night dreaming
❍
March 2006
of fewer errors/
❍
February 2007
to accept greater
❍
March 2007
ease of
❍
April 2007
development and ❍
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.
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
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.
// posted by Robert
Vollman @ Wednesday,
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
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
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
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
is a real issue, so
they haven't had
to learn the
mistake in their
approach the
hard way.
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://www.
kudzufiles.com/
archives/000749.
html
This, IMHO, is
why so many
commercial off-
the-shelf (COTS)
solutions
perform so
poorly. They are
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
premium, when
life-cycle costs
and performance
are considered.
# posted by David
Aldridge : Thursday,
19 January, 2006
sPh
# posted by
Anonymous :
Friday, 20 January,
2006
"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
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
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,
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
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
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.
● 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
❍
❍ Oracle's Bloglist
a96540.pdf ❍ Oracle Base Aggregator
ARCHIVES
// posted by Robert Vollman @ Friday,
❍ 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
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.
SELECT * FROM dual WHERE NULL <> ● Cary Millsap and Hotsos
NULL; ● Steve Adams and Ixora
Anjo Kolk and OraPerf
No rows selected.
●
❍ 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
August 2005
behaviour of NULL, check out this
❍
September 2005
other case, kindly provided by Tom ❍
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
❍
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
LAST_NAME
------------
Smith
2 rows selected.
LAST_NAME
------------
Smith
[NULL]
2 rows selected.
nvl(expr_1, expr_2)
Returns expr_2 if expr_1 is null and
expr_1 otherwise.
2 rows selected.
LAST_NAME
---------------
Y: Smith
N
2 rows selected.
http://sybasease.blogspot.
com/2005/05/nulls-in-sybase-ase.
html
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
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
http://www.oracledba.co.uk/tips/
plsql_nvl_costs.htm
http://www.oracle.com/technology/
oramag/oracle/05-jul/o45sql.html
# posted by Robert Vollman : Monday, 27
June, 2005
http://www.phpbbserver.com/phpbb/
viewtopic.php?
t=220&mforum=dizwellforum
# posted by Robert Vollman : Wednesday,
29 June, 2005
reduces to
IF NULL THEN
something
ELSEIF NULL
something else
END IF;
Post a Comment
<< Home
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.
● Connor McDonald
My Personal Blog
Smith John
●
Oracle's Bloglist
*
❍
Oracle WTF
--------------------------------
❍
----------
Smith John ARCHIVES
Smith John 0 ❍ LIST ALL ARTICLES
❍ 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 ❍
6/
Procedure created.
completed.
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)!
COUNT(*)
----------
14
COUNT(*)
----------
0
Regards
HJR
# posted by Howard J. Rogers : Wednesday,
18 May, 2005
http://thinkoracle.blogspot.
com/2005/05/dynamically-
assigning-size-of-varchar2.html
*
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
May, 2005
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.
*
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
Post a Comment
<< Home
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
●
It thinks "aint
integer" is a
new
Aggregators
command. Brian Duff's OraBlogs
❍
Top Blogs
SQLPlus at a
prompt:
Oracle's Ask Tom Kyte
SQL> create
❍
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 );
Table created.
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,
Comments:
Thank you for
Post a
Comment
<< Home
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.
Connor McDonald
a_id1 varchar2
●
Doug Burns
ON DELETE SET
❍
Oracle WTF
columns
❍
December 2005
FOREIGN KEY
❍
January 2006
(a_id1)
❍
February 2006
REFERENCES ❍
September 2006
btable
❍
October 2006
ADD ❍
Note: Monday is
a holiday in
Canada, no
update until
Tuesday.
// posted by Robert
Vollman @ Friday,
Comments:
Post a
Comment
<< Home
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.
CREATE TABLE
LogTable (logString Best Links
VARCHAR2(128)); ● Ask Tom Kyte
Oracle Docs
CREATE OR REPLACE
●
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
Oracle WTF
for a workaround.
❍
December 2005
errString := SQLCODE
❍
January 2006
|| ' ' || SQLERRM;
❍
February 2006
INSERT INTO ❍
September 2006
up SQLCODE and
❍
October 2006
SQLERRM in the PL/ ❍
Enjoy!
// posted by Robert
Vollman @ Monday, July
04, 2005
Comments:
Same for update's
too.
So as usual has to
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
declare
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
Post a Comment
<< Home
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.
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
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."
3. Turn on tracing
Note: 00:44:50.07
8. Drop ReallyBigTable
Elapsed: 00:45:21.04
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.
Comments:
max_dump_file_size seems a little "conservative" there Robert ;)
... at the moment. It seems that you could also wrap up this series of
commands in a neat little procedure also.
The part about not being able to SQL trace a raw password value is not
exactly true:
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.
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
❍
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
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
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.
FAQ
increasingly
●
Connor McDonald
often I run into ●
Top Blogs
the past few
years. They
would instead ❍ Oracle's Ask Tom Kyte
write that Oracle Guru Jonathan Lewis
query like this:
❍
January 2006
readable, too,
❍
February 2006
as do those
❍
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,
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.
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.
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.
Not everyone
has really
enjoyed
moving from
the traditional
join syntax to
ANSI syntax,
including Doug
Burns and Jeff
Moss.
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.
least be aware
of it, and know
how to use it.
// posted by
Robert
Vollman @ Friday,
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.
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,
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
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
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.
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
August, 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
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.
"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.
DECLARE
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;
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
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);
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
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
Dr. Tim Hall has some several good write-ups with good examples:
http://www.oracle-base.com/articles/8i/BulkBinds8i.php
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
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.
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
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
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.
❍ May 2005
❍ June 2005
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
❍
ID;...;SALARY;HOURLY;BONUS;
DIVIDEND
1;...;60;NULL;NULL;NULL
2;...;100;NULL;NULL;20
ID;VALUE;TYPE
1;60;'SALARY'
2;100;'SALARY'
2;20;'DIVIDEND'
http://thinkoracle.blogspot.
com/2005/07/use-views.
html
http://thinkoracle.blogspot.
com/2005/09/pivot-and-
crosstab-queries.html
// posted by Robert
Vollman @ Thursday, September 22,
2005
Comments:
Rob,
Cheers,
Doug
# posted by Doug Burns : Friday,
23 September, 2005
Cheers,
Doug
# posted by Doug Burns : Friday,
23 September, 2005
Post a Comment
<< Home
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.
Oracle Docs
VARCHAR2(32));
●
* Connor McDonald
●
Oracle's Bloglist
* ❍
Chris Foot
btable_name VARCHAR2(32));
❍
July 2005
because sometimes there is no such
❍
August 2005
relationships between columns. You may ❍
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:
❍
2005
<< Home
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.
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
❍ 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
Comments:
scott@ORA10GR1> select decode( grouping_id(ename), 1,
'Subtotal' ) tag,
17 rows selected.
# posted by Thomas Kyte : Wednesday, 24 August, 2005
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
I love the way you even changed your emp table to make
me the President, too!!
Hi there!
I just answered a similar question on otn a few minutes ago:
Re: Display Grand Total on the same line.See output
Kindest regards
# posted by Laurent Schneider : Wednesday, 31 August, 2005
Post a Comment
<< Home
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.
❍ Oracle's Bloglist
This is an interesting example, but it is just ❍ Oracle Base Aggregator
Top Blogs
one use of these features.
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???
❍
Post a Comment
<< Home
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.
My Personal Blog
com/2005/05/null-vs-nothing.html
●
http://thinkoracle.blogspot.
com/2005/06/nulls-in-oracle.html
❍ 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://oracledoug.com/decode.html
Cheers,
Doug
# posted by Doug Burns : Tuesday, 04 July,
2006
Post a Comment
<< Home
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.
D
-
X
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).
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:
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/
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
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
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
Comments:
Can we truncate dual table?
# 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.
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
❍
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
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ 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.
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?
● 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
-- Anonymous
Top Blogs
block Oracle's Ask Tom Kyte
❍
Doug Burns
put_line(x); ❍
❍ July 2005
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 ❍
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,
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
$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
One problem is
the following:
create table
atable (
acol types.
identifier_type
);
ORA-00902:
invalid datatype
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
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
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
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.
Best Links
application.
Oracle Docs
and months, or
●
❍ 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
December 2005
BEGIN
❍
January 2006
DBMS_OUTPUT.PUT_LINE
❍
February 2006
(in_col); ❍
May 2007
you can (check
❍
June 2007
comments for any
❍
http://www.amazon.
com/exec/obidos/
ASIN/0596003811/
qid=1117039808/
sr=2-1/
ref=pd_bbs_b_2_1/102-
9543590-3979349
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.
// posted by Robert
Vollman @ Wednesday, May
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.
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
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.
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
---------
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 ❍
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 ❍
March 2007
it is salary, in our case, it will be
❍
April 2007
'effective'.
❍
SELECT * FROM
CURRENT_ASSIGNMENTS;
2 rows selected.
http://thinkoracle.blogspot.
com/2005/05/enum-in-oracle.html
2005
Comments:
In simple situations, here is the
"normal" way of doing it:
Post a Comment
<< Home
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.
Although there are many different variations on this central theme, in order to solve problems of this nature, you'll need to
know:
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.
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.
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.
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?
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.
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.
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.
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
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.
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)
);
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.
ACCOUNTING,RESEARCH,SALES,OPERATIONS
Thank you
Khurram Naseem
# posted by Khurram Naseem : Saturday, 10 November, 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.
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
❍
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
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
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
●
http://www.
oracle.com/
Aggregators
Brian Duff's OraBlogs
technology/
❍
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
❍
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
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 ❍
C:\> IMP
USERID=scott/
tiger FILE=scott.
dmp FULL=Y
As a final note,
here is a good
FQ, by Frank
Naude:
http://www.
orafaq.com/
faqiexp.htm
// posted by Robert
Vollman @ Monday,
Comments:
Word of caution:
Think twice
before using
IMP/EXP as your
back-up
strategy on
large, complex
databases.
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://
laurentschneider.
blogspot.
com/2005/09/
migrate-
database-with-
imp-exp.html
# posted by
Robert Vollman :
Thursday, 01
September, 2005
Post a
Comment
<< Home
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
●
ERROR at line
1:
ORA-00933:
Aggregators
Brian Duff's OraBlogs
SQL command
❍
❍ September 2005
1 row created. ❍ October 2005
November 2005
Edit: Courtesy ❍
❍ 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
...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,
Comments:
insert all
into table1
(column1,
column2)
values(1,2)
into table1
(column1,
column2)
values(3,4)
into table1
(column1,
column2)
values(5,6)
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,
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
colleague's
textbook.
I would LOVE
to have it ...
# posted by
Robert
Vollman : Monday,
28 May, 2007
Post a
Comment
<< Home
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.
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 WTF
CREATE OR REPLACE PROCEDURE
NoCopyProc (in_value IN OUT ARCHIVES
NOCOPY number) ❍ LIST ALL ARTICLES
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
❍
the_value := 3;
InterProc(the_value);
DBMS_OUTPUT.PUT_LINE(the_value);
END;
1 NoCopyProc
2
3 CopyProc
3
fails early.
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
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.
Connor McDonald
WHEN OTHERS
●
ya really
# posted by Anonymous : Tuesday, 07
ARCHIVES
❍ LIST ALL ARTICLES
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
❍
Post a Comment
<< Home
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.
http://thinkoracle.blogspot.com/2005/07/use-views.html
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
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.
http://thinkoracle.blogspot.com/2005/07/extra-columns-in-
group-by.html
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:
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.
Perfect.
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
<< 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.
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
❍
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
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ 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.
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
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
<< 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.
Best Links
http://thinkoracle.blogspot.com/2005/06/oracle-client.html (2 of 4)1/9/2008 2:54:16 AM
OracleBlog: Oracle Client
Aggregators
Brian Duff's OraBlogs
❍
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
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
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.
Top Blogs
Set your PATH
Oracle WTF
Java tools, search the ❍
October 2005
older version, you'll
❍
November 2005
want something like
❍
December 2005
classes12.jar instead. ❍
October 2006
thing that seems to ❍
CLASSPATH%
.;c:\oracle\product
\10.1.0\db\jdbc\lib
\ojdbc14.jar
import java.sql.*;
import oracle.jdbc.
pool.
OracleDataSource;
Create an
OracleDataSource
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!
Statement stmt =
conn.createStatement
();
ResultSet rset = stmt.
executeQuery("select
'Hello World' from
dual");
while (rset.next())
System.out.println
(rset.getString(1));
You'll need to
compile your
application before
you execute.
javac JdbcVersion.java
java JdbcVersion
Exception in thread
"main" java.lang.
NoClassDefFoundError
That's it!
For more
information, review
the documentation to
which the README
file points you:
white paper
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 :
Post a Comment
<< Home
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.
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?
●
Chris Foot
allow more users SYSDBA
❍
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
❍
May 2007
cleaner example of restoring an
❍
June 2007
encrypted password.
❍
❍ October 2007
Your Oracle Password Policy
$ORACLE_HOME/rdbms/admin/
utlpwdmg.sql
orapwd file=filename
password=syspassword
entries=maxsysdbas force=Y
Finally ...
around this?
Comments:
I'm honored to be just below Tom
AND Jonathan :)
# posted by Eddie Awad : Monday, 30
October, 2006
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.
identified by mineisdirty;
User created.
User created.
User created.
USERNAME PASSWORD
------------------------------
------------------------------
COAL 6FCDA69BF440408F
COALMINE 6FCDA69BF440408F
COALMINER 0753A36B9F404829
SQL@O9.2.0.7>
Post a Comment
<< Home
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.
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()) {
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
<< 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.
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
❍
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
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
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.
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.
●
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
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,
❍
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,
❍
July 2005
DECODE (season, 2002, points, NULL) Yr2002,
❍
August 2005
DECODE (season, 2003, points, NULL) Yr2003,
❍
September 2005
DECODE (season, 2004, points, NULL) Yr2004 ❍
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;
http://thinkoracle.blogspot.com/2005/06/decode.html
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.
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
Jonathan Gennick
http://www.oracle.com/technology/oramag/oracle/02-
sep/o52sql.html
Laurent Schneider
http://laurentschneider.blogspot.com/2005/08/pivot-
table.html
Comments:
Thanks, Robert! This article helped me today.
# posted by John : Wednesday, 23 August, 2006
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
Post a Comment
<< Home
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.
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.
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.
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)
--------------------------------------------------------------------------------
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?
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 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.
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.
<< 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.
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
❍
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
❍ October 2006
❍ November 2006
❍ December 2006
❍ January 2007
❍ February 2007
❍ March 2007
❍ April 2007
❍ May 2007
❍ June 2007
❍ 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.
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 ●
I assume there is at
least some
overhead to calling
PL/SQL procedures.
Aggregators
I mean, if the Brian Duff's OraBlogs
❍
If it's already in
Top Blogs
Oracle's Ask Tom Kyte
memory, there ❍
Doug Burns
com/2005/05/
❍
May 2005
something more
❍
June 2005
conclusive after ❍
❍ July 2005
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;
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;
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-
performance.html
// posted by Robert
Vollman @ Friday,
Comments:
you'll want to avoid
procedure calls
Hi.
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.
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>
Cheers
Tim...
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. :-)
DECLARE
nLoops CONSTANT
NUMBER :=
10000000;
nStart NUMBER;
PROCEDURE
calculate IS
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
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. :-)
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.
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 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.
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
((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
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();
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;
/
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');
htp.init();
END;
/
My results were:
time: 23.7 s
time: 23.27 s
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
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.
Doug Burns
FOR i IN 1..nLoops LOOP ❍
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
November 2005
was:
❍
December 2005
time: 4.33 s ❍
September 2006
which is 66% in this case).
❍
October 2006
Of course this is nothing ❍
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 := nTemp + 1;
END LOOP;
dbms_output.put_line
('time: ' || ROUND
((dbms_utility.get_time() -
nStart)/100, 3) || ' s');
END;
/
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
((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
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
calculate(sTemp);
END LOOP;
dbms_output.put_line
('time: ' || ROUND
((dbms_utility.get_time() -
nStart)/100, 3) || ' s');
htp.init();
END;
/
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');
htp.init();
END;
/
My results were:
time: 23.7 s
time: 23.27 s
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
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).
thnx
rich
# posted by Anonymous :
Sunday, 12 August, 2007
Post a Comment
<< Home
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.
Aggregators
AS
random_value number(2,0);
BEGIN
Brian Duff's OraBlogs
random_value := dbms_random.
❍
Top Blogs
Plus you're not getting very many
20s. So you do this instead
Oracle's Ask Tom Kyte
random_value := dbms_random.
❍
❍ 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
❍
ARCHIVES
Will there be the right number of 1s
and 20s?
2. Is there a better way? ❍ LIST ALL ARTICLES
❍ 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
❍
exec ValuePlacer(1000);
Thanks!
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:
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
<< Home
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.
Jonathan Lewis
depending on the character set (by
●
FAQ
import/export, for example). More ●
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.
❍
ARCHIVES
like Perl, that is what they are called
2. "Index-by tables": because they
are declared just like nested tables ❍ LIST ALL ARTICLES
September 2005
instead of the %ROWTYPE you would ❍
June 2006
test_ass(SYS_GUID()) := 2;
❍
July 2006
test_ass(SYS_GUID()) := 3; ❍
February 2007
VARCHAR2 in order to use it, using
❍
March 2007
RAWTOHEX. You can use HEXTORAW
❍
---
Related Info:
Comments:
This post has been removed by a
blog administrator.
# posted by Anonymous : Saturday, 26
November, 2005
Hi
Great,info on RAW datatype,
How about it using it in DBI(Perl) for
binding raw values?
If i am right SQL_BINARY or
SQL_VARBINARY are bound as RAW
in Oracle when using DBD::Oracle
(Oracle Driver).
Post a Comment
<< Home
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.
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
❍
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:
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
FIBONACCI_REC(35)
-----------------
9227465
FIBONACCI_IT(35)
----------------
9227465
SQL>
# posted by Mennan : Sunday, 01 October, 2006
"Pure disinformation?"
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;
}
return fibonacci[n];
}
http://thinkoracle.blogspot.com/2006/08/
plsql-procedure-call-overhead-re.html
http://en.wikipedia.org/wiki/
Fibonacci_number#Closed_form_expression
Post a Comment
<< Home
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.
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.
●
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
❍
❍ 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.
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)
7. Recalculate Statistics
That's it!
// posted by Robert
Vollman @ Tuesday, June 13, 2006
Comments:
Rob,
LewisC
# posted by LewisC : Tuesday, 13
June, 2006
I am a bit confused:
Please comment.
Thanks.
# posted by Anonymous :
Saturday, 17 June, 2006
Thanks,
Robert
# posted by Robert Vollman :
Monday, 19 June, 2006
Post a Comment
<< Home
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.
There is one thing all these questions have in common: the answer
involves either ROWNUM or 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.
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.
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.
Comments:
Can I use rowid as a primary key
Table created.
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
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
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.
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
salaries".
# posted by Peter K : Friday, 07 October, 2005
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,
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
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;
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;
Sandeep,
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
select a1
from a
where a1 in (select b.b1 from b)
# posted by laxman : Thursday, 16 August, 2007
abcd
1xyz
1abc
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.
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
❍
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
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
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.
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.
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
❍
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
❍
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
But you also want to check out the Oracle SQL Reference,
Chapter 8: SQL Queries and Subqueries.
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.
Post a Comment
<< Home
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.
* ● 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.
●
Table created.
Aggregators
This will take the Brian Duff's OraBlogs
❍
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:
❍
Chris Foot
"TABLE" ("NUMBER"
❍
ARCHIVES
// posted by Robert
Vollman @ Monday,
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.
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
**Note: I did this about 15-20 times to get a really big table.
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.
against
What surprised me about your results is the increase in disk. I'd expect
Cheers,
Doug
# posted by Doug Burns : Wednesday, 05 October, 2005
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,
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?
You also don't strictly need the NULLs in there at all as they're implicit.
Cheers,
Doug
# posted by Doug Burns : Wednesday, 05 October, 2005
Thanks Doug:
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."
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
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.
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
Aggregators
Brian Duff's OraBlogs
❍
Top Blogs
Oracle's Ask Tom Kyte
❍
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
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.
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
❍
Chris Foot
VALUES (1);
❍
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
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
●
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
❍ August 2005
Have you done ❍ September 2005
something ❍ October 2005
wrong? ❍ November 2005
December 2005
No. You've come ❍
February 2007
constraints on
❍
March 2007
views through ❍
(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
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.
View altered.
SQL> GRANT
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
In fact that is
precisely the
advice that
Oracle ACE
Andrew "Arfur
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
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
(as I believe)
solution - two
tables with the
"shared" same id
column. I.e.:
as necessary.
Post a
Comment
<< Home
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.
Connor McDonald
around at similar ●
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:
❍
Oracle's Bloglist
org/reference/
❍
❍ 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
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
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.
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.
Quick, find me the average of a value for all rows in a table. No problem,
right? Use the analytic function AVG.
AVG(VOTES)
----------------------
357315.2307692307692307692307692307692308
Great. Now, find me that average only for a certain range of data, say from
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:
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.
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
values).
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.
Putting the partitioning clause and the windowing clause together is like
mixing chocolate and peanut butter. Alone, they're great, together they're
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.
By using the order by clause within the context of the analytic function,
we can create rolling averages.
--
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);
<< 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.
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
❍ 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
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.
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?
Oracle Database
Comments:
Ok, I laughed out loud at this myself.
Hmmmmmm
# posted by Thomas Kyte : Monday, 26 February, 2007
I always liked:
Thanks.
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
<< Home
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.
Steven Feuerstein
that recommendation, I
●
Jonathan Lewis
make it clear that this ●
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
❍
Chris Foot
views could be enforced.
❍
❍ July 2005
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 ❍
May 2007
far superior to others
❍
June 2007
RDBMS, but I agree there's
❍
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";
McDonald's 19 suggestions
(what, he couldn't think of
1 more to make a round
number?)
// posted by Robert
Vollman @ Thursday, April 05,
2007
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
or just
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???
(for example)..
Valentine
# posted by valentine :
Thursday, 23 August, 2007
Post a Comment
<< Home
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.
2. Communicating Their
Knowledge
Via insightful blogs,
publishing opportunities, and
Aggregators
polished communications Brian Duff's OraBlogs
❍
❍ 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
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.
2. Communicating Their
Knowledge
definition of a guru I
reviewed, it would seem like
educating others is a
necessary qualification.
3. Attitude
Wrapping Up
// posted by Robert
Vollman @ Tuesday, October 31,
2006
Comments:
Q: what makes an Oracle guru?
A: Knowledge, and lots of it,
http://kevinclosson.
wordpress.com/
:-)
# posted by Kevin Closson :
Tuesday, 31 October, 2006
Just kidding! :)
# posted by Robert Vollman :
Wednesday, 01 November, 2006
http://radiofreetooting.
blogspot.com/2005/11/how-
to-be-good-guru.html
# posted by Steve Karam :
Wednesday, 01 November, 2006
http://radiofreetooting.
blogspot.com/2006/11/
oracle-guru-is-it-you.html
Cheers, APC
# posted by APC : Thursday, 02
November, 2006
Gu = darkness
Ru = light
So he could be a myth
buster ;) Reminds me of Tom
Kyte and JL.
- Naresh
# posted by Anonymous : Sunday,
05 November, 2006
http://www.dba-oracle.com/
t_how_to_become_oracle_guru.
htm
Cheers
Tim...
# posted by Tim... : Friday, 08
December, 2006
Post a Comment
<< Home
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.
Best Links
on the team, to
participate briefly
in the interview to ● Ask Tom Kyte
gauge this Oracle Docs
individual's
●
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
Top Blogs
interview time.
Let me save you
the latter! ❍ Oracle's Ask Tom Kyte
Oracle Guru Jonathan Lewis
First I ask the
❍
❍ 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
❍ 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 ❍
Intermediate
Questions
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
- 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
// posted by Robert
Vollman @ Sunday,
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.
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?
declare
x BOOLEAN;
begin
x := (null=null);
if (x)
then
dbms_output.
put_line
('NULL=NULL IS
TRUE');
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
completed.
# posted by RGT :
Sunday, 03 June, 2007
Hahaha, definitely
RGT!!!
# posted by Robert
Vollman : Sunday, 03
June, 2007
Understanding
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
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
Quick question:
where did I saying
anything about
DBAs?
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".
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
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
I strongly URGE
people who feel
the same way to
visit that first link
(http://
thinkoracle.
blogspot.
com/2006/02/
oracle-interview-
questions.html).
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,
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.
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....
Regards,
Valentine M.
# posted by
valentine :
Saturday, 01
September, 2007
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
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
●
Aggregators
you'll find that
each of them
share the same
Brian Duff's OraBlogs
core qualities
❍
May 2005
be accurate!
❍
June 2005
Indeed, if your ❍
January 2006
make sure
❍
February 2006
everything you
❍
March 2006
write is fully ❍
October 2006
off-topic
❍
November 2006
article can be a ❍
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 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.
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.
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
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
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.
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
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,
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
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?
# posted by M.
Moore : Friday, 25
May, 2007
Great
metablog!
It was meant
as praise, not
criticism. I
wouldn't mind
decreased
blogging if
they weren't
such fine blogs.
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
Good post,
good timing !
I'm starting
blogging again
- as of
yesterday in
fact! Hopefully
I'll keep going
a little longer
this time. I've
got a few
subjects
planned to get
me started.
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
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
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
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
great post
Robert and
thank you for
including mine
too :)
Keep blogging
# posted by
Coskan
Gundogar :
Monday, 28 May,
2007
Post a
Comment
<< Home
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.
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)
●
2. Oracle magazine
has great articles, Aggregators
especially Ask Tom Brian Duff's OraBlogs
❍
❍ 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
❍
❍ 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
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,
●
ARCHIVES
<< Home
❍ 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
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
●
Oracle's Bloglist
spectrum of
❍
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
❍
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
January 2006
his posts. His
❍
February 2006
passionate
❍
March 2006
Oracle rants ❍
April 2007
design and
❍
May 2007
maintenance. He
❍
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
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/
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,
Comments:
Thanks to Nuno:
Anjo Kolk
http://oraperf.
blogspot.com/
Thanks to
"Captain
Obvious":
Sue Harper's
Blog:
http://www.
groundside.com/
blog/content/
SueHarper/
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,
Happy blogging!
# posted by Bill
S. : Friday, 22 July,
2005
http://
laurentschneider.
blogspot.com/
http://www.adp-
gmbh.ch/
# posted by
Anonymous :
Wednesday, 31
August, 2005
Post a
Comment
<< Home
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.
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
●
http://www.oracle.
Top Blogs
Oracle's Ask Tom Kyte
com/technology/
❍
❍ December 2005
05, 2005 ❍ January 2006
❍ February 2006
❍ March 2006
Comments:
April 2006
i have implemented
❍
May 2006
the oracle regexp in
❍
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.
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;
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://asktom.
oracle.com
Hi Robert,
still running Oracle
9i?
;-)
Flavio
# posted by Byte64 :
Post a Comment
<< Home
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
Aggregators
Schneider. He is
one of my
favourite
Brian Duff's OraBlogs
posters from the
❍
com/2005/08/
pivot-table.html
ARCHIVES
❍ LIST ALL ARTICLES
There are a few ❍ May 2005
other changes: ❍ June 2005
❍ July 2005
March 2006
Rusinov has a
❍
April 2006
new blog, which
❍
April 2007
up for my lack
❍
May 2007
of content
❍
Comments:
And here is the
blogging
community on
OTN
# posted by
Eddie Awad :
Monday, 29 August,
2005
Post a
Comment
<< Home
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.
FAQ
not included
●
Connor McDonald
because they
●
Aggregators
me to
Feedburner. It
converts your
Brian Duff's OraBlogs
feed from one
❍
❍ 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
❍
Chris Foot
2) Select
❍
ARCHIVES
list of options.
May 2005
my first post
❍
January 2006
today. Instead,
❍
February 2006
just like a bad
❍
March 2006
80s sitcom, I ❍
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 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:
Post a
Comment
<< Home
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
●
Aggregators
a good home. I
will pay for
shipping costs
Brian Duff's OraBlogs
to Canada, and
❍
Top Blogs
Many thanks!
// posted by
Oracle's Ask Tom Kyte
Robert
❍
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
Cheers,
Doug
# posted by
Doug Burns :
Wednesday, 21
September, 2005
Post a
Comment
<< Home
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.
Best Links
misunderstandings of Oracle:
http://oracle-wtf.blogspot.
Ask Tom Kyte
com/
●
● Oracle Docs
Dan Morgan and PSOUG
It's written by William ●
❍ 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
❍ 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
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.
http://www.dbspecialists.
com/presentations.
html#perf_bottleneck Aggregators
Brian Duff's OraBlogs
The articles on their site are ❍
Top Blogs
"Database Mysteries" courtesy
of Chris Lawson:
Oracle's Ask Tom Kyte
http://www.dbspecialists.
❍
ARCHIVES
Post a Comment ❍ LIST ALL ARTICLES
❍ May 2005
❍ 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.
Jonathan Lewis
http://www.dbazine.com/oracle/or-
●
FAQ
articles/kyte1/
●
Connor McDonald
●
My Personal Blog
Dave Ensor
●
http://www.dbazine.com/oracle/or-
articles/ensor6
May 2006
"Supersizing your PGA"
❍
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
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
Oracle Docs
writers out there
●
Exploiting and
Protecting Oracle
Top Blogs
Oracle's Ask Tom Kyte
by Pete Finnigan for
❍
ARCHIVES
What, Where, When,
Why - Selecting
Oracle LIST ALL ARTICLES
Development Tools
❍
May 2005
by Ken Atkins from
❍
June 2005
ODTUG 2001
❍
❍ July 2005
April 2006
http://www.
❍
May 2006
miracleas.dk/tools/
❍
June 2006
Miracle_1_statspack.
❍
❍ July 2006
pdf
❍ August 2006
September 2006
SQL Tuning With
❍
Planning Extents by
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,
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,
Doug
# posted by Doug
Burns : Saturday, 12
November, 2005
Post a Comment
<< Home
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
●
❍ 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
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
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 WTF
picks, too. ❍
❍ July 2005
❍ 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 ❍
November 2006
publication, it
❍
December 2006
will likely be on
❍
com/2005/10/
using-decode-to-
exploit-countnull.
html
2. Best Practises
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
Analyzing Query
Performance:
http://
thinkoracle.
blogspot.
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.
Doug Burns:
http://
oracledoug.
blogspot.com
Eddie Awad:
http://awads.net/
wp
Warning to Doug
and Eddie: You
might experience
the first ever
Robert Vollman
Effect!
// posted by Robert
Vollman @ Wednesday,
December 21, 2005
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....
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
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
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.
FAQ
Dave Warnock's Response
●
● Connor McDonald
Aggregators
Brian Duff's OraBlogs
❍
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
❍
Neat Tricks
ARCHIVES
Some time ago I posted an article on ❍ LIST ALL ARTICLES
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.
❍
My FORALL
Yas' BULK COLLECT
Ask Tom
Driving Tables
Introduction to Analytical Functions
Batch Processing
Finally
Eddie Awad
Steven Feuerstein is a nut?
20, 2006
<< Home
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.
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.
Hall
recompilation is really necessary, and will also
UKOUG's Andrew (Arfur C.) Clarke
look for optimizations within your code. I
❍
overhead to check for things, but faster ❍ Coffee-Drinking DBA Jon Emmons
results, especially for inexperienced ❍ Chris Foot
programmers. ❍ The Pythian DBA Team 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.
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
●
Chris Foot
Myers, Tom Kyte,
❍
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
❍ 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
❍
January 2007
browsing the ❍
Post a
Comment
<< Home
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,
●
# posted by
● Steve Adams and Ixora
● Anjo Kolk and OraPerf
Eddie Awad :
● Dizwell Oracle Wiki
Tuesday, 25 July, ● My Personal Blog
2006
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
❍
ARCHIVES
December, 2006
❍ May 2005
I didn't find ❍ June 2005
out how to ❍ July 2005
post question ❍ August 2005
❍ February 2007
❍ March 2007
Post a ❍ April 2007
Comment ❍ May 2007
❍ June 2007
<< Home ❍ 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.
Oracle Documentation
Best Links
● Ask Tom Kyte
Oracle Docs
I love Oracle documentation. I can usually find
●
Aggregators
Brian Duff's OraBlogs
❍
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
❍
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 ❍
May 2007
still haven't found the information you're ❍
Comments:
Robert,
Cheers,
Doug
# posted by Doug Burns : Wednesday, 19 July, 2006
Post a Comment
<< Home
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
●
So go do it now.
Aggregators
Brian Duff's OraBlogs
❍
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
❍
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
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.
Reason #1 Protection
The programmers wish to protect their code from theft, misuse or
alteration (among other things).
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;
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.
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.
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.
(garbage removed)
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.
Comments:
Hi Robert,
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.
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
cheers
pete
# posted by Pete Finnigan : Monday, 04 September, 2006
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
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.
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
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
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
●
Aggregators
and its about the
same cost, but
maybe a few
Brian Duff's OraBlogs
hundred bucks
❍
Top Blogs
Maybe for a warm-
up I'd finally meet
up with Dan Oracle's Ask Tom Kyte
Morgan at the
❍
❍ 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
❍
December 2005
PL/SQL-specific
❍
January 2006
OPP 2007, for 2
❍
February 2006
days in February/ ❍
December 2006
my first Oracle
❍
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
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
Post a Comment
<< Home
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
●
I wonder why
people are
Aggregators
Brian Duff's OraBlogs
reading my
❍
Top Blogs
like every other
Oracle blogger
knows this ❍ Oracle's Ask Tom Kyte
material far Oracle Guru Jonathan Lewis
better than I.
❍
May 2005
expert like,
❍
June 2005
say, Laurent ❍
July 2005
Schneider or
❍
❍ August 2005
January 2006
accessible. The
❍
February 2006
complexities of
❍
November 2006
some of you
❍
December 2006
started on your
❍
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
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
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
topics, to the
point - i'll be
back.
# posted by
gazza :
Wednesday, 15
November, 2006
Post a
Comment
<< Home
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,
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
regexp_like
(address_ip,'((^([2][0-
Aggregators
5]{2}\.|[2][0-4][0-9] Brian Duff's OraBlogs
❍
Doug Burns
in advance... ❍
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
❍
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
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}'||
'([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,
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]')
I noticed
performance issues
when using
regexp_like in
10.2.0.2. It didn't
use index on
2.7billion partitioned
table.
I like regexp_*
commands, but I am
slightly weary to use
them in my code.
raj
# posted by Rjamya :
Tuesday, 05 December,
2006
Post a Comment
<< Home
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.
● 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
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,
❍
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, ❍
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 ❍
If so, now you're ready for one of Ask Tom's more complex
examples.
Pivot Tables
Comments:
Pivoting in SQL using the 10g Model :)
Table created
1 row inserted
1 row inserted
1 row inserted
1 row inserted
1 row inserted
1 row inserted
SQL> commit;
Commit complete
ID DES T
– —- ———-
A a1 12
A a2 3
A a3 1
B a1 10
B a2 23
C a3 45
6 rows selected
I A1 A2 A3
– ———- ———- ———-
C 0 0 45
B 10 23 0
A 12 3 1
DABC
—- ———- ———- ———-
a1 12 10 0
a3 1 0 45
a2 3 23 0
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
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 |
—————————————————————————-
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
Post a Comment
<< Home
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.
"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.
"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
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.
"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."
"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.
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."
Comments:
I like that style. Thanks Robert.
# posted by Oracloid : Friday, 26 October, 2007
Thank you for coming back with your style of making excellent reading.
# posted by Coskan Gundogar : Tuesday, 30 October, 2007
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
~ 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.
Best Links
● Ask Tom Kyte
● Oracle Docs
● Dan Morgan and PSOUG
● Steven Feuerstein
● Jonathan Lewis
● FAQ
Connor McDonald
●
Aggregators
Brian Duff's OraBlogs
❍
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