Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

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.

Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-