Default value

A default value can be defined for a column. When you add a new row to myTable but don't specify the values for the column with default value, those columns are set to the default values.

The following table has a VARCHAR2 with default value set to N/A.


SQL> CREATE TABLE myTable (
  2  id     INTEGER CONSTRAINT default_pk PRIMARY KEY,
  3  status VARCHAR2(20) DEFAULT 'N/A' NOT NULL
  4  );

Table created.

SQL>
SQL> INSERT INTO myTable(id) VALUES (1);

1 row created.

SQL> select * from myTable;

        ID STATUS
---------- --------------------
         1 N/A

SQL>

The following table has a Date type column with SYSDATE default value


SQL> CREATE TABLE myTable (
  2  id INTEGER CONSTRAINT default_pk PRIMARY KEY,
  3  last_modified DATE DEFAULT SYSDATE
  4  );

Table created.

SQL>
SQL> INSERT INTO myTable(id) VALUES (1);

1 row created.

SQL> select * from myTable;

        ID LAST_MODI
---------- ---------
         1 06-JUL-11

SQL>
Home »
Oracle »
Table » 

Default_Value:
  1. Default value
  2. Set a column back to the default using the DEFAULT keyword in an UPDATE statement.
Related: