Oracle: insert without columns specification Oracle: insert without columns specification oracle oracle

Oracle: insert without columns specification


INSERT INTO table (column1) VALUES (default);

The rest will be defaulted!


In Oracle you don't HAVE to specify the columns but not doing so will leave you open to introducing bugs as and when your table definition changes.

You could insert with:

INSERT INTO t VALUES (value1, value2, value3);

This assumes the table t has three columns

It is far better and supportable to insert with:

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

I wouldn't use PL/SQL (if you can help it) as you introduce context switching from PL/SQL to SQL and then back to PL/SQL again.


I missed this part on the first read:

I have an oracle table with a sequence and a trigger to autoincrement a column.

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

INSERT INTO table (pk_column) VALUES (NULL);

The trigger will override the NULL value (and if it doesn't for some reason, the insert will fail); and the other columns will be populated using defaults.