Skip to Main Content
Oracle PL/SQL for DBAs
book

Oracle PL/SQL for DBAs

by Arup Nanda, Steven Feuerstein
October 2005
Intermediate to advanced content levelIntermediate to advanced
454 pages
14h 44m
English
O'Reilly Media, Inc.
Content preview from Oracle PL/SQL for DBAs

How Oracle Decides To Share

Oracle uses a complex algorithm to decide whether a cursor that is about to be executed may reuse an already compiled version from the shared pool. Here is a simplified presentation of that algorithm:

  1. Calculate the sum of the ASCII values of all characters in the cursor (excluding bind variables). For example, the total ASCII value of the following cursor is 2556:

    SELECT order_date FROM orders

    This is calculated as ASCII(S) + ASCII(E) + ASCII(L)...or 83 + 69 + 76 and so on.

  2. Apply a hash algorithm to the ASCII total.

  3. Peruse the shared pool for a cursor with the same hash value.

  4. If one is found, it may be reused.

Tip

Note that I say “may” be reused. Most of the time, a matching ASCII hash is enough to allow reuse, but not always, as I’ll explain later in this section.

In item 1, I state that the ASCII value of every character is used. Thus, something as low level as mixing uppercase and lowercase has to be considered when planning for cursor reuse. Consider these two cursors run directly in SQL*Plus.

    SQL> SELECT order_date
      2    FROM orders
      3   WHERE order_number = 11;

    ORDER_DAT
    ---------
    03-MAY-05

    SQL> SELECT order_date
      2    FROM orders
      3   WHERE order_numbeR = 11;

    ORDER_DAT
    ---------
    03-MAY-05

The human eye can see that both of these examples do exactly the same thing—select the order date for order number 11. The only difference is that an uppercase R was used in the second one. That’s just enough for Oracle to consider them different, though, so two cursors wind up in ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Oracle PL/SQL Best Practices

Oracle PL/SQL Best Practices

Steven Feuerstein
Expert Oracle PL/SQL

Expert Oracle PL/SQL

Ron Hardman, Michael McLaughlin
Oracle PL/SQL For Dummies

Oracle PL/SQL For Dummies

Michael Rosenblum, Paul Dorsey

Publisher Resources

ISBN: 0596005873Supplemental ContentErrata Page