COUNT Method Works Like COUNT in SQL

You are writing PL/SQL code to provide secure, high performance access to your data and implement business rules. [reference: Why Use PL/SQL?]

Right? Good.

And you use collections (associative arrays, nested tables, arrays) because they offer all sorts of great functionality. [reference: Collections in PL/SQL YouTube playlist]

Right? Good.

So here's a quick reminder about COUNT, one of many methods available for collections (others include DELETE, FIRST, LAST, NEXT, PRIOR, TRIM, EXTEND):

It works pretty much like COUNT in SQL.

If the collection is empty, COUNT returns 0, not NULL.

If you try to "read" an element at an undefined index value, Oracle Database raises NO_DATA_FOUND. Just like a SELECT INTO that identifies no rows.

If you check to see if a collection is empty with a call to COUNT, it doesn't raise NO_DATA_FOUND.

To verify what I've said, and to have a bit of fun while doing it, you can take a quiz on this topic at the Oracle Dev Gym.


  1. Hi Steven, You have a grammar typo in the following sentence:

    "Bf you check to see if a collection is empty with a call to COUNT, it doesn't raise NO_DATA_FOUND."

    The first word should "If" instead "Bf". Replace capital "B" with a capital "I".

  2. Many thanks for this post. I like your blog very much and i am a huge fan of it.
    This is my first time writing here. I like this so
    much that I even shared on Myspace. Thanks again for the excellent post.

    1. Thanks for your kinds words. And myspace, wow! Haven't seen a reference to that in ages.


Post a Comment

Popular posts from this blog

Table Functions, Part 1: Introduction and Exploration

Get rid of mutating table trigger errors with the compound trigger

Quick Guide to User-Defined Types in Oracle PL/SQL