I am writing an INSERT Statement to insert one row into the table in a PL/SQL block. If this insert fails or no row is inserted then I need to rollback the previously executed update statement.
I want to know under what circumstances the INSERT statement could insert 0 rows. If the insert fails due to some exception, I can handle that in the exception block. Are there cases where the INSERT might run successfully but not throw an exception where I need to check whether SQL%ROWCOUNT < 1?
If your
INSERTstatement is structured as anINSERT ... VALUES, then it will either successfully insert exactly one row or generate an exception. There would be no need to check theSQL%ROWCOUNT.If your
INSERTstatement is structured as anINSERT ... SELECT, then it is possible that theSELECTstatement will return 0 rows, theINSERTstatement will insert 0 rows, and no exception will be thrown. If you consider that to be an error, you would need to check theSQL%ROWCOUNTafter theINSERTstatement runs.