|
Time for the June 2005 Oracle PL/SQL Programming
e-newsletter. Summer approacheth and I hope you all have some relaxing
time planned -- away from your laptops, desktops, Oracle,
PL/SQL and other elements of your digital world. Before that happens,
though, we have the annual
ODTUG (Oracle
Developer Tools User Group) conference in New Orleans. Hope to see you
there! You will find below a Tip of the Month, Useful Code of the
Month, Recent Writings, Upcoming Public Trainings, and a new section:
Help Wanted. And if you haven't yet heard about or checked out the
following, please take a peek:
Oracle PL/SQL
Programming 2005 - a two-day PL/SQL conference to be held on
November 2-3, 2005 in Chicago. Featuring in-depth presentations
by Steven Feuerstein (don't you love it when people mention themselves
in the third person?), Bryn Llewellyn (PL/SQL Product Manager) and
Marchel Kratochvil (Winner of the 2004 Oracle Magazine
PL/SQL
Developer of the Year award), OPP2005 is a prime learning
opportunity for PL/SQL developers. It will also be a birthday
party: we will be celebrating the 10th anniversary of the publication
of
Oracle PL/SQL
Programming! Space is limited, so I encourage you to register
early.
21st Century
PL/SQL Idea Collector - PL/SQL is a mature, robust language, but
that doesn't we don't each have our own list of things we'd like to see
added or changed in PL/SQL to make it even better. Now you have a
way to share your ideas with other developers and with the PL/SQL
development team. The
21st Century
PL/SQL Idea Collector allows you to submit suggestions and rank the
ideas of others. These recommendations will then be presented to
Bryn Llewellyn at the
Oracle PL/SQL
Programming 2005 conference.
Tip of
the Month
When querying multiple rows of data from
Oracle, don't use the cursor FOR loop. Instead, assuming you are
running at least Oracle8i, start using the wonderful, amazing
BULK COLLECT query, which improve query response time very
dramatically. The following statement, for example, retrieves all the
rows in the employee table and deposits them directly into a collection
of records:
DECLARE TYPE employee_aat IS TABLE OF employee%ROWTYPE INDEX BY BINARY_INTEGER;
l_employees employee_aat; BEGIN SELECT * BULK COLLECT INTO l_employees FROM employee; END;
Of course, if your table has 1,000,000 rows in
it, the above block of code will consume enormous amounts of
memory. In this case, you will want to take advantage of the LIMIT
clause of BULK COLLECT as follows:
DECLARE TYPE employee_aat IS TABLE OF employee%ROWTYPE INDEX BY BINARY_INTEGER;
l_employees employee_aat;
CURSOR employees_cur IS SELECT * FROM employee;
BEGIN
OPEN employees_cur;
LOOP
FETCH employees_cur
BULK COLLECT INTO l_employees LIMIT 100;
EXIT WHEN l_employees.COUNT = 0;
-- Process these 100 rows and then
-- move on to next 100.
END LOOP;
END;
Important! When you use BULK COLLECT, Oracle will not raise
NO_DATA_FOUND even if no rows are found by the implicit query. Also,
within the loop (using LIMIT), you cannot rely on cursor%FOUND
to determine if the last fetch returned any rows. Instead, check the
contents of the collection. If empty, then you are done.
For more complete coverage of this topic, check out my
21st Century
PL/SQL seminar materials.
Useful Code of the
Month
Ever need to read
the contents of a file and then execute it as a SQL statement? This
program reads the contents of a file with UTL_FILE, loads
each line into a collection whose type is defined in the DBMS_SQL
package, and then executes the statement. Note that I read the contents
of the file into a collection defined on the DBMS_SQL.VARCHAR2A type,
which was introduced in Oracle Database 10g Release 1. If you
are on an earlier version, use the DBMS_SQL.VARCHAR2S type instead.
This program will only allow you to execute DDL statements, or DML
statements that do not contain any placeholders for bind variables.
This download, by the way, comes from the
Best
Practice PL/SQL column that I author on the Oracle Technology
Network.
Recent PL/SQL Writings of Note
I just completed a whirlwind tour of the
United States presenting "You wrote WHAT?" at Toad User Group
events. This presentation presents a series of common mistakes that
PL/SQL developers might make, and offers suggestions for how to fix the
problems (or upgrade the code to use the latest and greatest in
PL/SQL). It's short (the presentation lasted just an hour), but you
might still find something of interest in it. Click
here
to download the presentation.
Upcoming Public Trainings
UNYOUG Seminar
on June 10 in Rochester, NY:
A day-long presentation of my
21st
Century PL/SQL seminar. Register
here.
ODTUG on June
20 - New Orleans:
Monday at 1:30 PM: Programming Humility: Dealing with the Reality of
Errors; Tuesday at 9:30 AM - Too Much Code, Too Little Time: How QCGU
Can Help.
Help Wanted
I am working with Arup Nanda (Oracle Magazine Oracle DBA of the Year
2004) and Darryl Hurley (longtime reviewer and contributor to my books)
on a new book tentatively titled "Oracle PL/SQL for DBAs". It is
intended to help DBAs take advantage of a variety of DBA-centric
features that require the use of PL/SQL. We are looking for experienced
DBAs to review chapters in the book. If you are interested, please send
a note to Debby
Russell, our O'Reilly Media editor.
|