-- Thanks for the question regarding "Comments instead of whitespace", version 10.1.0
Submitted on 8-Nov-2007 12:36 Central time zone
Last updated 9-Nov-2007 12:16
You Asked
I have found in my organization that some developers don't use whitespace to give visual seperation, instead they use comments.
For example, a package spec might look like this:
CREATE OR REPLACE PACKAGE foo AS
--
FUNCTION bar (baz IN NUMBER) RETURN NUMBER;
--
END foo;
When I asked for an explanation, they said that in the past the compiler would occasionally have an issue with whitespace. They couldn't tell me with what though as it was a practice that had been passed down to them from older developers.
I was just wondering if you or anyone else had any knowledge of this. I'm wondering if this is BS or maybe, if it was an issue back in the old day (or maybe still today?).
Thanks
Kyle
and we said...
Had to get into the way back machine for that one :)
tkyte@DEV716> create or replace package my_pkg
2 as
3
3 function foo return number;
4
4 end;
5 /
Package created.
tkyte@DEV716> set linesize 70
tkyte@DEV716> column text format a50
tkyte@DEV716> select line, text from user_source where name = 'MY_PKG' and type =
2 'PACKAGE' order by line;
LINE TEXT
---------- --------------------------------------------------
1 package my_pkg
2 as
3 function foo return number;
4 end;
ops$tkyte@ORA734> @test
Package created.
LINE TEXT
---------- --------------------------------------------------
1 package my_pkg
2 as
3 function foo return number;
4 end;
ops$tkyte@ORA806> @test
Package created.
LINE TEXT
---------- --------------------------------------------------
1 package my_pkg
2 as
3
4 function foo return number;
5
6 end;
6 rows selected.
but it was sqlplus, not the database - sqlplus was filtering out the blank lines, consider:
$svrmgrl
Oracle Server Manager Release 2.1.3.0.0 - Production
Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
Oracle7 Server Release 7.1.6.2.0 - Production Release
With the distributed, replication and parallel query options
PL/SQL Release 2.1.6.2.0 - Production
SVRMGR> connect /
Connected.
SVRMGR> @test
Statement processed.
LINE TEXT
----------
--------------------------------------------------------------------------------
1 package my_pkg
2 as
3
4 function foo return number;
5
6 end;
6 rows selected.
SVRMGR>
Wayback machine - Line Numbers
November 8, 2007 - 3pm Central time zone
Reviewer: Warwick from Australia
Hi Tom,
The reason given to me for using comments rather than whitespace was to ensure that when a
compilation error occurred, the reported error line was at least close to the physical line in the
file (just everyone used vi then and I still do).
I love the site and have learnt so much from it. Thank you.
Cheers
Warwick
PS do you still enjoy the Prius ?
Followup November 9, 2007 - 11am Central time zone:
that was true over a decade ago if you used sqlplus to compile.
It has not been true since.
Yes, still love my Prius. I would buy it again.
Implications of the filtering
November 8, 2007 - 3pm Central time zone
Reviewer: Kyle
From your examples the filtering seems rather benign and doesn't seem to be an issue in the later
releases (I'm assuming this based on your 8.0.6 example). Is there a situation where it could be
detrimental?
I'm trying to justify continuing this practice in future development and haven't found any reason
not to drop it.
Followup November 9, 2007 - 12pm Central time zone:
I find no reason to keep it.
It was true over a decade ago that sqlplus would remove blank lines. That would change the line number (as demonstrated above).
It is not true anymore. And hasn't been for a long time.
a different story for views
November 9, 2007 - 2am Central time zone
Reviewer: Antony Boucher from Calgary, AB
The only situation when I ever had to use comments instead of blank lines was in a script that created views...
test.sql:
create or replace view v1 as
select *
from dual
/
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> @test
SP2-0042: unknown command "from dual" - rest of line ignored.
select *
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
test.sql:
create or replace view v1 as
select *
--
from dual
/
SQL> @test
View created.
Maybe that's what started the habit?
Followup November 9, 2007 - 12pm Central time zone:
whitespace has not been ignored for a long long long long time - see the versions I was using above....
SQLBLANKLINES
November 11, 2007 - 5pm Central time zone
Reviewer: Gary from Sydney, Aus
The create view example could alternatively be resolved with the SET SQLBLANKLINES command.
08:10:58 HR@XE >
08:10:58 HR@XE > create or replace view v1 as
08:11:06 2 select *
08:11:06 3
08:11:06 HR@XE > from dual
SP2-0042: unknown command "from dual" - rest of line ignored.
08:11:06 HR@XE > /
select *
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
Elapsed: 00:00:00.17
08:11:11 HR@XE > set sqlblanklines on
08:11:13 HR@XE > create or replace view v1 as
08:11:13 2 select *
08:11:13 3
08:11:13 4 from dual
08:11:13 5 /
View created.