The default value of a column in an Oracle table

Source: Internet
Author: User
In Oracle, you can specify a default value for a table column. In this way, when you insert data, if the column does not appear in the insert statement, the default value is assigned to it.

In Oracle, you can specify a default value for a table column. In this way, when you insert data, if the column does not appear in the insert statement, the default value is assigned to it.

In Oracle, you can specify a default value for a table column, so that when you insert data, if the column does not appear in the insert statement, the default value is assigned to it. note that this column does not appear in the insert statement, rather than when the column value is null. see the following table:
Create table test (id number (10), name varchar2 (20) default 'name ')
When the following SQL statement is used to insert rows, the default value is assigned to the name column.
Insert into test (id) values (1)
Query Result: select * from test

IDNAME

1 name

When the following SQL statement is used to insert rows, the default value is not assigned to the name column.
Insert into test values (2, null)
The query result shows that the name value of the row with ID 2 is null: select * from test

IDNAME

1 name

2

Select * from test where name is null can query the row with ID 2.
Similarly, when using JDBC in JAVA code and some ORM frameworks to insert data, you also need to pay attention to the same problem.

In the row inserted by the code above, the name column will not be assigned as the default value, and the value of #1 will be changed to sta. setString (2, ""). Similarly, the inserted value is null ).

For more information about Oracle, see the Oracle topic page? Tid = 12

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.