Oracle: insert without column specification

I have an oracle table with a sequence and a trigger to automatically create a column. Now I want to do an insert. Usually I should write:

INSERT INTO table (column1, column2,...) VALUES (value1, value2) 

but I just want to insert a record with no default values. How to do it in Oracle?

 `Mysql`: INSERT INTO table () VALUES () `Mssql`: INSERT INTO table default VALUES `Oracle:` INSERT INTO table (column1, column2,...) VALUES (default, default,...) 

Is this the only way? Do I need to list all columns?

+7
source share
4 answers
 INSERT INTO table (column1) VALUES (default); 

The rest will be by default!

+7
source

Is this the only way? Do I need to list all columns?

Yes. And good practice: always specify all columns in the INSERT statement for which you want to specify values.

+4
source

In Oracle, you do not need to specify columns, but this will not cause you to open for errors, how and when the table definition changes.

You can insert:

INSERT VALUES (value1, value2, value3);

This assumes table t has three columns

It is much better and convenient to embed with:

INSERT INTO t (column1, column2, column3) VALUES (value1, value2, value3);

I would not use PL / SQL (if you can help) when you enter context switching from PL / SQL to SQL, and then return to PL / SQL again.

+3
source

I skipped this part on first reading:

I have an oracle table with a sequence and a trigger for auto-increment column.

So, I assume that the sequence is populated on the PK column, and the rest all have default values. Given this, I would do the following:

 INSERT INTO table (pk_column) VALUES (NULL); 

The trigger will override the NULL value (and if this is not for any reason, the insert will not be executed); and the rest of the columns will be filled using the default values.

+3
source

All Articles