Home > Ask the Oracle Experts > Questions & Answers > Assignment operators explained
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Assignment operators explained

Karen Morton EXPERT RESPONSE FROM: Karen Morton

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 18 June 2002
Would you please explain in details with examples 'assignment operators' like (:= ,:=:,=:).These altogether seem to be a little bit confusing in terms of where to use what and how to use them.

>
EXPERT RESPONSE

The assignment operator is simply the way PL/SQL sets the value of one variable to a given value. There is only one assignment operator, := . I'm not sure where you saw the others listed or used, but they are invalid.

Assignment operators are different from a regular equal sign, =, in that they are used to assign a specified value to a PL/SQL variable. For instance, if I wanted to give a variable named V_TEMPERATURE an initial value of 98.6, I'd use the following assignment statement:

set serveroutput on
DECLARE
  v_temperature	number := 98.6 ;
BEGIN
  dbms_output.put_line('The temperature is ' || v_temperature) ;
END ;
/
I could also change the value of v_temperature in the body of my code as well:
set serveroutput on
DECLARE
  v_temperature	number := 98.6 ;
BEGIN
  dbms_output.put_line('The initial temperature is ' || v_temperature) ;

  v_temperature := 100.6 ;
  dbms_output.put_line('The next temperature is ' || v_temperature) ;

  v_temperature := v_temperature - 4 ;
  dbms_output.put_line('The last temperature is ' || v_temperature) ;

END ;
/
Assigning a value is different from just using the equal sign. Whenever you see an = in PL/SQL, it is typically used for comparison purposes:
set serveroutput on
DECLARE
  v_temperature	number := 98.6 ;
BEGIN
  IF v_temperature = 99 THEN
	dbms_output.put_line('You have a slight fever.')
  END IF ;
END ;
/
Notice how the = is used to compare the value of v_temperature (which is 98.6) to the value 99.

That's the key way to differentiate. If you want to compare a value use an equal sign, but if you want to assign a value to a variable, use the := assignment operator.

For More Information


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


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