Oracle 1Z0-183 study materials
Oracle 1Z0-183 study resources

Oracle 1Z0-183: Declaring PL/SQL Variables and Writing Executable Statements

Oracle 1Z0-183 · Work through your exam, one topic at a time.

All guide sections

Declaring PL/SQL Variables and Writing Executable Statements

Declaration syntax

The general form is name [CONSTANT] datatype [NOT NULL] {:= | DEFAULT} expression. Every variable starts life as NULL; a NOT NULL variable must be initialised in its own declaration or the block fails to compile. Declare one identifier per line and follow a convention (v_ variable, c_ constant, e_ exception, p_ parameter) so the code reads cleanly.

Scope and shadowing

A variable is visible from its declaration to the end of its block, including nested blocks. If an inner block redeclares the same name, the inner declaration hides the outer one for that block only; the outer value reappears afterwards. Exam questions frequently hinge on this: the outer variable is not modified unless you fully qualify the block with a label (<<outer>>).

Anchoring with %TYPE

Prefer emp.sal%TYPE to repeating a datatype. %TYPE ties the variable to a column, another variable, or a constant, so a column widening is picked up at recompile instead of breaking at run time.

Executable statements

Assignment uses :=; a bare = is a comparison and produces a syntax error in a statement position. PL/SQL VARCHAR2 holds up to 32767 bytes, much larger than the SQL limit of 4000. BOOLEAN (TRUE/FALSE/NULL) exists only inside PL/SQL: it cannot be stored in a table, used in a SQL statement, or passed directly to DBMS_OUTPUT.PUT_LINE.

Rule of thumb: if a value can be NULL, the conversion matters. A BOOLEAN produced by comparing to NULL is itself NULL, and both IF flag and IF NOT flag are then false - so guard before converting to a string.