LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-07-2012, 06:00 AM   #1
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
Oracle PL/SQL dbms_output.put_line Throwing Errors when Using Variable


PHP Code:

SQL
edit
Wrote file afiedt
.buf

  1  
declare
  
2     num1 number := 100;
  
3     num2 number := 300;
  
4  begin
  5     
declare
  
6             sum number(6);
  
7     begin
  8             sum 
:= num1 num2;
  
9             dbms_output.put_line ('Total: ');
 
10     end;
 
11end;
SQL> /
Total:

PL/SQL procedure successfully completed
The same PL/SQL block does not work when I use the variable "sum" in the output statement:

PHP Code:


SQL
edit
Wrote file afiedt
.buf

  1  
declare
  
2     num1 number := 100;
  
3     num2 number := 300;
  
4  begin
  5     
declare
  
6             sum number(6);
  
7     begin
  8             sum 
:= num1 num2;
  
9             dbms_output.put_line ('Total: ' || sum);
 
10     end;
 
11end;
SQL> /
                
dbms_output.put_line ('Total: ' || sum);
                                                      *
ERROR at line 9:
ORA-06550line 9column 41:
PLS-00103Encountered the symbol ")" when expecting one of the following:
(


SQL
Note:

This line is causing the error shown above:

PHP Code:
dbms_output.put_line ('Total: ' || sum); 
I tried using the variable name only and it still did not work:

PHP Code:
dbms_output.put_line (sum); 
 
Old 03-08-2012, 01:58 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Sum is quite likely to be a reserved word (name of a group function). Try v_sum instead.
 
1 members found this post helpful.
Old 03-08-2012, 02:36 AM   #3
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by NevemTeve View Post
Sum is quite likely to be a reserved word (name of a group function). Try v_sum instead.
Before going and running the same code by twisting the variable name, I can definitely say that I have by mistake used a reserved keyword as a variable name!

Let me give it a try now!
 
Old 03-08-2012, 02:41 AM   #4
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
NavemTeve:


Thanks for pointing out that variable name! sum() is a function and I just did not pay enough attention to this fact.

Here's the corrected version of the above problem:

Code:
declare
	num1 number := 100;
	num2 number := 300;
begin
	declare
		v_sum number(6);
	begin
		v_sum := num1 + num2;
		dbms_output.put_line ('Total: ' || v_sum);
	end;
end;
/


SQL> set serveroutput on
SQL> @pl.sql
Total: 400

PL/SQL procedure successfully completed.
Rated you for your contribution and time!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Recoll indexing throwing strange errors on some files. taylorkh Linux - Software 1 12-21-2010 02:28 AM
pygtk configure throwing odd errors. ninja master Linux - Software 2 07-28-2010 03:22 AM
New Cavalry external USB HD throwing errors peter3731 Linux - Hardware 0 02-10-2008 01:26 AM
Kernel 2.6.19 throwing up hd read errors cr9c1 Slackware 6 12-18-2006 04:01 PM
GCC First Pass throwing errors...pls help! chakkaradeepcc Linux From Scratch 2 04-11-2005 01:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration