Skip to content
Advertisement

Oracle SQL Errors

I am very new to SQL and my class is using Oracle cloud as of now. I have created tables and I am trying to insert data into it. I keep receiving the error ORA-02291: integrity constraint violated when I try to insert data into my semester table. Any help would be extremely appreciated. Thank you!

Advertisement

Answer

Check if there are trailing spaces in the SCHOOLID column

You would most likely see length as 10 instead of 3 :


A good explanation is below ( quoting Tom Kyte here )

A varchar2 datatype, when stored in a database table, uses only the space allocated to it. If you have a varchar2(1999) and put 50 bytes in the table, we will use 52 bytes (leading length byte).

A char datatype, when stored in a database table, always uses the maximum length and is blank padded. If you have char(1999) and put 50 bytes into it, it will consume 2001 bytes (leading length field is present on char’s as well).

In the database — a CHAR is a VARCHAR that is blank padded to its maximum length.

There are great differences between a char(1999) and varchar2(1999) as the CHAR is always 1999 characters long physically AND logically. the varchar is physically 1999 bytes but logically can be any size in between 0 and 1999. The char is always blank padded, not so for the varchar.


See if the error persists when you define columns as varchar2, as follows ..

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement