Null Objects in a PL/SQL Block
DECLARE
emp EMPLOYEE_TYP; -- emp is atomically null
BEGIN
IF emp IS NULL THEN
dbms_output.Put_line('emp is NULL #1');
END IF;
IF emp.employee_id IS NULL THEN
dbms_output.Put_line('emp.employee_id is NULL #1');
END IF;
emp.employee_id := 330;
IF emp IS NULL THEN
dbms_output.Put_line('emp is NULL #2');
END IF;
IF emp.employee_id IS NULL THEN
dbms_output.Put_line('emp.employee_id is NULL #2');
END IF;
emp := Employee_typ(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,Address_typ(NULL,NULL,NULL,NULL));
-- emp := NULL; -- this would have made the following IF statement TRUE
IF emp IS NULL THEN
dbms_output.Put_line('emp is NULL #3');
END IF;
IF emp.employee_id IS NULL THEN
dbms_output.Put_line('emp.employee_id is NULL #3');
END IF;
EXCEPTION
WHEN access_into_null THEN
dbms_output.Put_line('Cannot assign value to NULL object');
END;
/
OUTPUT:-
emp is NULL #1
emp.employee_id is NULL #1
emp is NULL #2
emp.employee_id is NULL #3
PL/SQL procedure successfully completed.
0 comments:
Post a Comment