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):
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.
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.
Hi Steven, You have a grammar typo in the following sentence:
ReplyDelete"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".
Thanks, fixed.
ReplyDeleteMany thanks for this post. I like your blog very much and i am a huge fan of it.
ReplyDeleteThis is my first time writing here. I like this so
much that I even shared on Myspace. Thanks again for the excellent post.
Thanks for your kinds words. And myspace, wow! Haven't seen a reference to that in ages.
Delete