When you create a table. Add a NOT NULL constraint to the column, such as the following:
column_name Data_type
[constraint constraint_name] NOT NULL
, constraint constraint_name indicates the name specified for the constraint.
You can also add a NOT NULL constraint to a table that you have created, and you need to use the ALTER TABLE ... modify statement. Forms such as the following:
ALTER TABLE table_name MODIFY COLUMN_NAME [constraint constraint_name] NOT null;
Remove NOT NULL constraint
Suppose you need to remove the NOT NULL constraint for a laceration in the table, still using the ALTER TABLE...MODIFY statement, such as the following:
ALTER TABLE table_name MODIFY COLUMN_NAME NULL;
Detailed actions such as the following:
sql> CREATE TABLE person (
2 PID Number (4) NOT NULL,
3 pname varchar2 (20),
4 Psex char (2)
5);
The table is created.
sql> desc person;
name nbsp Is it empty? Type
--------------------------------------------------------------------
pid not NULL Number (4)
pname  VARCHAR2 (+)
psex &NBSP ; , &NB Sp CHAR (2)
sql> ALTER TABLE person modify pname not null;
The table has changed.
sql> desc person;
is the name empty?
Type
----------------------------------------- -------- ------------------
PID not NULL number (4)
PNAME not NULL VARCHAR2 (20)
Psex CHAR (2)
Sql> INSERT into the person values (1, ' aaa ', ' female ');
1 rows have been created.
Sql> INSERT into the person values (1, ' AAA ', NULL);
1 rows have been created.
sql> INSERT into person values (1,null,null);
INSERT into person values (1,null,null) *
Line 1th error:
ORA-01400: Cannot insert NULL ("SYSTEM". " Person "." PNAME ")
sql> ALTER TABLE person modify PNAME null;
The table has changed.
sql> desc person;
is the name empty? Type
----------------------------------------- -------- ------------------
PID not NULL number (4)
PNAME VARCHAR2 (20)
Psex CHAR (2)
sql> INSERT into person values (1,null,null);
1 rows have been created.
Sql>
Oracle joins NOT NULL constraint