SQL> CREATE TABLE test_null (id NUMBER);Table created.SQL> INSERT INTO test_null VALUES (1);1 row created.SQL> INSERT INTO test_null VALUES (2);1 row created.SQL> INSERT INTO test_null VALUES (NULL);1 row created.SQL> SELECT * FROM test_null;
ID---------- 1 2 -- The select count(*) shows 3 records SQL> SELECT COUNT(*) FROM test_null; COUNT(*)---------- 3-- select count(*) with a where clause, shows 2 records.SQL> SELECT COUNT(*) FROM test_null WHERE id > 0; COUNT(*)---------- 2-- select count(*) with a where clause, in this case shows one record.SQL> SELECT COUNT(*) FROM test_null WHERE id != 1; COUNT(*)---------- 1When we define a column to be NOT NULL that means it cannot have a NULL value assigned. This eliminates the problem of three valued logic very nicely, but may not always be possible when designing tables.
There are, of course, much more advanced features revolving around tables. Things like partitioning and index-organized tables are some advanced topics that you will want to look into once you are comfortable with the basics. Also, there are other types of constraints that we could deal with like foreign key constraints. Finally, in earlier versions of Oracle you had to deal with physical storage characteristics related to the table. Thankfully, Oracle Database 10g takes care of a number of the physical storage requirements for you. Many other advanced topics exist that you can research in advanced Oracle DBA books.
ID---------- 1 2 -- The select count(*) shows 3 records SQL> SELECT COUNT(*) FROM test_null; COUNT(*)---------- 3-- select count(*) with a where clause, shows 2 records.SQL> SELECT COUNT(*) FROM test_null WHERE id > 0; COUNT(*)---------- 2-- select count(*) with a where clause, in this case shows one record.SQL> SELECT COUNT(*) FROM test_null WHERE id != 1; COUNT(*)---------- 1When we define a column to be NOT NULL that means it cannot have a NULL value assigned. This eliminates the problem of three valued logic very nicely, but may not always be possible when designing tables.
There are, of course, much more advanced features revolving around tables. Things like partitioning and index-organized tables are some advanced topics that you will want to look into once you are comfortable with the basics. Also, there are other types of constraints that we could deal with like foreign key constraints. Finally, in earlier versions of Oracle you had to deal with physical storage characteristics related to the table. Thankfully, Oracle Database 10g takes care of a number of the physical storage requirements for you. Many other advanced topics exist that you can research in advanced Oracle DBA books.
No comments:
Post a Comment