Home » SQL & PL/SQL » SQL & PL/SQL » PL/SQL comment bug
PL/SQL comment bug [message #391557] Thu, 12 March 2009 10:10 Go to next message
happyjoshua777
Messages: 33
Registered: February 2009
Location: United States
Member
i have the following code (below)
i commented out a line of code and then realised that i was being promted for v_my_name variable twice.
once i delete the '&' operator in the comment it does not prompt to input value for v_my_name variable again.
i have searched on the internet for PL/SQL comments intricacies and could not find any info. except for the basic syntax.
the same thing is happening if i use a /**/ type fo a comment.

please tell me why this is happening and why does PL/SQL still prompt for a variable value when there is a '&' operator WITHIN the comment.
thank you:)

set serveroutput on
declare 
	v_my_name VARCHAR(15);
begin
	v_my_name := 'ELENA';
	
	dbms_output.put_line('My name is '||v_my_name);
	
	declare
		v_your_name varchar2(15):= '&sv_your_name';
		
	begin
	
	--v_your_name varchar2(15):= '&sv_your_name';
	
	DBMS_OUTPUT.PUT_LINE('Your name is '||v_your_name);
		exception
			when value_error then
				dbms_output.put_line('Error in the inner block');
				dbms_output.put_line('This name is too long');
	end;
	
	exception
		when value_error then
			dbms_output.put_line('Error in the outer block');
			dbms_output.put_line('This name is too long');
end;
/ 
Re: PL/SQL comment bug [message #391564 is a reply to message #391557] Thu, 12 March 2009 10:30 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Expected and documented behavior.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14238/smtosp.htm#sthref399
Re: PL/SQL comment bug [message #391567 is a reply to message #391557] Thu, 12 March 2009 10:33 Go to previous messageGo to next message
Michel Cadot
Messages: 68718
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
& is a SQL*Plus special character (by default) not a PL/SQL one.
Your code is interpreted by SQL*Plus before being sent to the server to be executed.
SQL*Plus ask for its variable (starting with &) value, replace it in the code and then send it to the server.
The fact it is in PL/SQL comment or not is irrelevant as PL/SQL comment is not SQL*Plus one.

Regards
Michel
Re: PL/SQL comment bug [message #391569 is a reply to message #391567] Thu, 12 March 2009 10:44 Go to previous messageGo to next message
happyjoshua777
Messages: 33
Registered: February 2009
Location: United States
Member
thnak you so much for your reply.
my only question is why would SQL PLUS behave differently from PL/SQL i.e. disregard the fact that there is a comment and interpret '&'? is it not like a potential source of bugs? is there a point in doing it like that? i mean in languages like c++/java a comment is a comment and one can write ANYTHING in it without fearing that a compiler is going to disregard it...
Re: PL/SQL comment bug [message #391587 is a reply to message #391569] Thu, 12 March 2009 11:39 Go to previous message
Michel Cadot
Messages: 68718
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
SQL*Plus has nothing to do with PL/SQL. It is just a tool for writing SQL or PL/SQL like vi/notepad for writing Java or C++.
The only difference is that SQL*Plus send the result to the server for execution, like if vi can send the code to Java compiler and interpreter.

Regards
Michel
Previous Topic: Creating one index for 2 columns or two
Next Topic: sql problem
Goto Forum:
  


Current Time: Tue Dec 03 12:28:47 CST 2024