Search code examples
oracle-databaseoracle-apex

Oracle Apex. SQL Workshop. ORA-01400: cannot insert NULL into


I'm using Oracle Database 23c Free - VirtualBox Appliance for Developers.

Created two tables using the Apex Object Browser. First table - table1 (id, name). I inserted rows from a pre-prepared set into one table.

After this, if I try to insert a row through the Apex Object Browser, I get ORA-01400: cannot insert NULL into table1.id.

I decided that i was out of sequence and ran this command

ALTER TABLE table1 MODIFY id GENERATED BY DEFAULT AS IDENTITY (START WITH LIMIT VALUE);

But it didn't solve the problem. I got ORA-01400: cannot insert NULL into table1.id.

I inserted row with command INSERT INTO table1 (name) VALUES ('test'). The row has been added and ID has the correct (following) value.

If i try to insert a row through the Apex Object Browser, I again get ORA-01400: cannot insert NULL into table1.id.

In the second table I can insert a row through the Apex Object Browser without any problems.

What should I do to solve this problem?


Solution

  • Use the 'on null' clause in the identity column definition

    ...id generated by default on null as identity start with limit value

    You'll find APEX is constructing an insert statement with null as the value, as nothing has been defined for that column. The DDL will ensure a value is given.

    The use a process to fetch the sequence value will also work, but I think this would be cleaner.