Insertinto in oracle

Source: Internet
Author: User
Insert statements are also a lot of SQL statements used in oracle. If you want to develop information systems frequently, you must be familiar with the Insertinto syntax. The following is the basic insert syntax Insertintotable [column1, column2.] Values (value1, value2.). You can use this syntax to insert only one row of data at a time. For example

Insert statements are also a lot of SQL statements used in oracle. If you want to develop information systems frequently, you must be familiar with the Insert into syntax. The following is the basic insert syntax Insert into table [column1, column2.] Values (value1, value2.). You can use this syntax to insert only one row of data at a time. For example

Insert statements are also a lot of SQL statements used in oracle. If you want to develop information systems frequently, you must be familiar with the Insert into syntax.
Below are the most basic insert syntax
Insert into table [column1, column2…]
Values (value1, value2 ....);
With this syntax, only one row of data can be inserted at a time.
If you want to use insert into to insert a row of data, the data contains the values of each column in the table. Therefore, you do not need to list each column in the table, but directly give the value to a column in the order defined by the column in the table.
For example
Insert into emp
Values (7935, 'Robin ', 'salesman', 7566, '04-August 8-08', 3000,100, 20 );
Of course, you can also list all columns in the insert clause. You can also disrupt the column order and then give the value you want to assign in the new order.
Once you omit the list items in the insert clause, you must give the values of each column in the table.
If you omit the list items after insert into and want to assign NULL values to some values, you can use the explicit keyword NULL, for example:
Insert into emp
Values (7936, 'linlin', 'salesman', 7566, '03-January 1, May-08 ', 3000, NULL, 20 );
Here we use the NULL key to assign values to the penultimate value.
You can also use the default keyword. The premise is that you have defined the default value when defining your table.
For example:
Create table testtable
(C1 int,
C2 varchar2 (20) default 'unknown ');
After creating a table, we can use the insert statement with default to insert data.
Insert into testtable
Values (1, default );
Then we can view the inserted data. You will find that the data has been automatically written to the unknown.

Note the following when using the insert into statement:
1. Do not violate existing constraints. For example, if this column is not allowed to be empty and you have to insert a null value, an error will certainly occur.
2. DML statements like insert are not automatically submitted. You must use commit to submit the statements before other users can see your changes.
3. The insert statement can also insert multiple rows at a time. This will be introduced later.
4. if some columns are not provided in the list of Columns after insert into, and these columns can be left blank, oracle automatically assigns null values to columns that are not listed.
5. Some pre-defined functions and keywords in oracle can also be used in the insert statement. For example, sysdate.
6. as we mentioned earlier in oracle's nested subqueries, we can use nested subqueries as a variable, therefore, we can also use nested subqueries at any position in the insert into statement here.

Single quotation marks are used for character and date data.

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.