Wednesday, 14 September 2011

Accessing constants directly in Oracle Forms

Question:
I found your suggestions for improving PL/SQL code very useful. You have inspired me to write better code from initial development on up!
As a first step, I created a container with a list of constants and started using them right away in my server PL/SQL code. I would like to use them in my client PL/SQL code inside Oracle Forms but I receive a compilation error telling me that there is an implementation restriction that disallows direct access to the remote package variables. (I'm using Oracle 10g Forms.) As a workaround, I'm keeping a copy of the constant definitions in a library. Granted, not the ideal, but it will have to do until the code can be refactored.
Does Oracle have plans to implement access to remote package variables?
Answer:
Grettel, I am glad you found my advice useful!
I do not have any news for you about when and if Oracle Forms might start to allow you to directly reference variables and constants directly in a stored package specification. I do, however, have a suggestion to get around this problem (and avoid a duplicate library definition in your Forms library): Move the constants to your package body and provide a function for each constant that returns the value. You can then call the function from Forms. Even better, you can change the value of a constant without recompiling the package specification, thereby avoiding the need to recompile programs that depend on that package.
This is not to say that you should always hide your constants behind a function; certainly, accessing a constant directly will be more efficient than calling a function. So if the value is unlikely to change and no other factors are arguing for a function, by all means stick with a constant

No comments:

Post a Comment