Home > Ask the Oracle Experts > PL/SQL Questions & Answers > Declaring same variable twice in a package
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Declaring same variable twice in a package

Greg Williams EXPERT RESPONSE FROM: Greg Williams

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Oracle tips, scripts, and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 09 October 2006
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?

>
EXPERT RESPONSE
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.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
PL/SQL
Converting Long Raw to Blob
Parsing in Oracle
ORA-01422 error when procedure returns more than one row
Definition of force view
ORA-04082: NEW or OLD references not allowed in table level triggers
Execute SQL statement from table in other schema
Script to revoke access from user
PL/SQL procedure to load CSV file into database table
Finding size of files in BLOB datatype
Expression is of wrong type

Oracle PL/SQL
Oracle's free SQL Developer adds database migration tool
Confused about Oracle certification exams
ORA-01422 error when procedure returns more than one row
Calling procedure inside another procedure in anonymous block
How to import comma-delimited text file to Oracle table
Oracle updates Microsoft developer tools
PLS-00103 errors
PL/SQL do's and don't's: Five questions with Steven Feuerstein
Definition of force view
ORA-04082: NEW or OLD references not allowed in table level triggers

Oracle stored procedures
Stored procedure to autotransfer data between Oracle servers
Insufficient privileges error when creating stored procedure
ORA-01422 error when procedure returns more than one row
Calling procedure inside another procedure in anonymous block
Can I make a second connection to Oracle without losing the first?
How to create an index using a procedure in Oracle
Oracle updates Microsoft developer tools
Procedure compiles but does not execute
Tool in Oracle 10g to keep track of execution of queries
ORA-04082: NEW or OLD references not allowed in table level triggers

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
PL/SQL  (SearchOracle.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts