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?