Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to properly use comments in SQL?

Blue BirdJul 7 2016 — edited Jul 7 2016

I'm experimenting with variables in SQL and I noticed that once i put comment on the right side of code, comment is allowed and once isn't. I can put comment on the right side of SQL sentence and when I want to display variable value, but not when I define variable wirh DEF command. See below example:

-- Define variables


-- Comment above variable definition IS ALLOWED
def parLastName = Grant;
def parFirstName = Douglas;  -- Here commment is NOT ALLOWED

def parLastName; -- Display current stored Last Name value. Here commment IS ALLOWED

-- Execute SQL sentence with variables
SELECT employee_id, last_name, first_name, salary -- Comment here in SQL sentence IS ALLOWED
FROM employees -- Table name from HR Schema
WHERE LAST_NAME = '&parLastName' and FIRST_NAME = '&parFirstName'
ORDER BY LAST_NAME;

If I run above code with F5 in SQL Dev (or from file script in SQLPlus) return me correctly one record only if I remove comment at the end of line 5. Otherwise return nothing.

Probably is difference between SQL in PL/SQL commands, but why with DEF command once work and once not. Can someone please simply explain me rules for commenting in different scenarios when you write code in Oracle environment?

This post has been answered by BluShadow on Jul 7 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 4 2016
Added on Jul 7 2016
15 comments
2,501 views