Global Warning

June 3, 2011 at 5:51 pm | Posted in Oracle Developement | Leave a comment

You’ve just got to be mindful about how you handle global package variables.

Here is a little obstacle I recently stumbled over:

I have a package with a global boolean variable g_flag. I set this variable to TRUE in my package specification.

In one of the packaged procedures I set g_flag to FALSE. Now when I run this package in a new session, g_flag gets set to TRUE in the package specification and my code executes just fine. Even when this flag is set to FALSE along the way, whenever the  package is executed in a new session, the flag gets reset to TRUE again. Great!

But I forgot that the values of global package variables persist during sessions. This bit me in my rear, when I executed the package as part of  along running loop. In my case this loop executed the package every 24 hours.

Of course, somewhere along the way, g_flag was set to FALSE. The next day the package executed again, it started with g_flag being FALSE and not TRUE, as my code originally expected it; then things fell apart.

So: It is prudent, unless otherwise required by your application, to explicitly set your global package variables before you use them.

 

Advertisements

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: