PL/SQL Comments π¬¶
Mentor's Note: Code is written for computers to run, but it's also written for Humans to read. Comments are notes that the computer ignores but your future self (and your teammates) will value! π‘
π The Scenario: The Hidden Map πΊοΈ¶
Imagine you are building a complex LEGO set. - Without instructions, it's just a pile of bricks. - Comments are the Little Sticky Notes you leave on the model to explain: "This part moves the arm," or "Don't touch this gear."
π» 1. Single-Line Comments¶
Used for short notes. Starts with two dashes --.
DECLARE
v_count NUMBER := 0; -- Initializing the counter
BEGIN
v_count := v_count + 1; -- Incrementing
END;
π» 2. Multi-Line Comments¶
Used for long explanations or headers. Starts with /* and ends with */.
/*
PROJECT: Payroll Calculator
AUTHOR: Vishnu Damwala
DATE: 15-FEB-2026
PURPOSE: This block calculates the monthly tax based on earnings.
*/
BEGIN
NULL;
END;
π‘οΈ 3. The "Disable" Trick (Architect's Note)¶
We also use comments to "Comment Out" code during debugging. If a line is causing an error, don't delete itβjust comment it out so you can bring it back later!
BEGIN
DBMS_OUTPUT.PUT_LINE('Step 1');
-- DBMS_OUTPUT.PUT_LINE('Step 2 - Temporary disabled');
DBMS_OUTPUT.PUT_LINE('Step 3');
END;
π Best Practices¶
- Don't Over-Comment: Don't explain what is obvious (e.g.,
v_age := 25; -- Set age to 25). - Explain the "WHY": Explain why you chose a specific logic or why a tax rate is 18%.
- Keep them Updated: If you change the code, change the comment too! An outdated comment is worse than no comment.