Recently, I tried declaring and initializing the same variable twice with different values each time in a PL/SQL package. To my surprise, it got compiled without any errors. I tried the same in a procedure and got a complier error, e.g.:
M_var VARCHAR2(10):= 'HELLO';
M_var VARCHAR2(10):= 'HI';
The package returns the last defined variable. This feature is quite misleading in the package because, from a developer's point of view, he may miss seeing the duplicate variables declared later. Any thoughts on this?
I recently attended a webcast on PL/SQL hosted by Steven Feuerstein. In this webcast Mr. Feuerstein listed several points on what to do and not to do. One of the things he listed on the not-to-do list is to declare and initialize variables. Your case is a prime example of why not to declare and initialize variables. I believe he suggested that you assign values to variables just before you use them.
Personally, I am going to start using this rule of declaration and initialization.
Dig Deeper on Oracle and SQL
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.