In the Before Insert trigger, I am using a sequence (MySeq.Nextval) to generate a unique number for a not null field. This trigger is working fine, but when the user is exported and imported into different user, the first instance of writing an insert statement in that table is getting a not null constraint error. After, when I again tried to insert, it worked. What could be the reason the insert failed for first time?
I'm not exactly sure what your problem is. But I did find that there are numerous bugs that are similar to your problem for both the 8i and 9i releases. Please make sure that your database is patched to the latest patch set and check it again. This problem should not be happening, and it definitely looks like a bug. The question that remains is whether or not Oracle knows about it. If a patch set does not fix your problem, you'll have to file a TAR with Oracle Support. In the meantime, a workaround is to insert a "dummy" row and then delete it so that the trigger works properly.
For More Information
- Dozens more answers to tough Oracle questions from Brian Peasland are available.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
Dig Deeper on Oracle database design and architecture
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.