dbTalk Databases Forums  

PL/SQL removes comments from SQL statements

comp.databases.oracle.server comp.databases.oracle.server


Discuss PL/SQL removes comments from SQL statements in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ca111026
 
Posts: n/a

Default PL/SQL removes comments from SQL statements - 08-31-2010 , 03:05 AM






I've notices that PL/SQL removes comments from SQL statements

For example if I execute folloing SQL

select /* MyComment */ count(*) from big_table;

and while it is running try to find it in V$SQL then the comment is
visible

select hash_value, sql_text from V$SQL where sql_text like '%MyComment
%'

However if I create stored procedure

create or replace procedure commenttest as
l_count number;
begin
select /* MyComment */ count(*) into l_count from big_table;
end;
/

then execute it

exec commenttest;

and check V$SQL from another session then the comment isn't visible, I
get

select count(*) from big_table;

It is still visible in DBA_SOURCE, but this isn't what I need.

It seems that there are only two ways to keep comments in SQL
statements executed from PL/SQL:
- Trick PL/SQL into thinking that the comment is a hint by adding "+".
Howedver this is kind of dirty method as it could confuse the
Optimizer.
- Use Dynamic SQL

Anything else?

Reply With Quote
  #2  
Old   
joel garry
 
Posts: n/a

Default Re: PL/SQL removes comments from SQL statements - 08-31-2010 , 12:34 PM






On Aug 31, 1:05*am, ca111026 <ca111... (AT) gmail (DOT) com> wrote:
Quote:
I've notices that PL/SQL removes comments from SQL statements

For example if I execute folloing SQL

select /* MyComment */ count(*) from big_table;

and while it is running try to find it in V$SQL then the comment is
visible

select hash_value, sql_text from V$SQL where sql_text like '%MyComment
%'

However if I create stored procedure

create or replace procedure commenttest as
l_count number;
begin
select /* MyComment */ count(*) into l_count from big_table;
end;
/

then execute it

exec commenttest;

and check V$SQL from another session then the comment isn't visible, I
get

select count(*) from big_table;

It is still visible in DBA_SOURCE, but this isn't what I need.

It seems that there are only two ways to keep comments in SQL
statements executed from PL/SQL:
- Trick PL/SQL into thinking that the comment is a hint by adding "+".
Howedver this is kind of dirty method as it could confuse the
Optimizer.
Any hint that is not exactly correct will be ignored, there will only
be confusion if your comment happens to be an exactly correct hint.

Quote:
- Use Dynamic SQL

Anything else?
How exactly PL handles comments and white space does vary by version.
There are also different compilation methods.

jg
--
@home.com is bogus.
http://www.signonsandiego.com/news/2...with-qualcomm/

Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.