Skip to content

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

  1. Don't Over-Comment: Don't explain what is obvious (e.g., v_age := 25; -- Set age to 25).
  2. Explain the "WHY": Explain why you chose a specific logic or why a tax rate is 18%.
  3. Keep them Updated: If you change the code, change the comment too! An outdated comment is worse than no comment.

πŸ“ˆ Learning Path