Skip to main content

PL/SQL NULL Statement 😶

Mentor's Note: In English, a "Placeholder" is a word used when you don't have the real word yet. In PL/SQL, NULL; is a command that tells Oracle: "Do absolutely nothing." It sounds useless, but it's actually required by the grammar of the language in certain situations! 💡


🌟 The Scenario: The Under Construction Sign 🚧

Imagine you are building a house.

  • You have a room marked "Future Gym".
  • Right now, there is nothing in it.
  • But the building inspector says every room must have something inside to pass inspection.
  • You put a sign that says "UNDER CONSTRUCTION". That sign is the NULL; statement.

💻 1. Usage: Placeholder for Logic

PL/SQL requires that every branch of an IF or CASE has at least one statement.

DECLARE
v_job VARCHAR2(20) := 'INTERN';
BEGIN
IF v_job = 'CEO' THEN
Process_Huge_Bonus;
ELSE
-- We don't have a plan for interns yet, but we need a line of code.
NULL; -- 🚧 Placeholder
END IF;
END;

💻 2. Usage: Following a Label

Labels (for GOTO) cannot be the last thing in a block. They must be followed by a statement.

BEGIN
IF some_condition THEN
GOTO end_of_program;
END IF;

-- ... more code ...

<<end_of_program>>
NULL; -- ✅ Required so the label has something to point to
END;

🛡️ 3. Why use it? (Architect's Note)

  1. Readability: Using NULL; shows that you intentionally decided to do nothing. It's better than leaving a gap which might look like a mistake.
  2. Grammar: It satisfies the PL/SQL compiler's requirement for executable statements.

📈 Learning Path

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir