?
Solved

Oracle DB Trigger

Posted on 2013-11-18
3
Medium Priority
?
448 Views
Last Modified: 2013-11-18
I am receiving data which is too big for one of the database fields. I created a trigger to truncate the data to the correct size:
However, when the field is too big, the error seems to appear before the trigger is invoked. If the field is the correct length, the trigger is clearly executed.

Is this the expected behavior? Am I doing something wrong?
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production    
PL/SQL Release 11.2.0.3.0 - Production                                          
CORE      11.2.0.3.0      Production                                                        
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production                          
NLSRTL Version 11.2.0.3.0 - Production
0
Comment
Question by:TomDarby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 39657184
check constraints  like nullability or upper/lower  and foreign key constraints are applied after triggers fire.

basic structural limits (data type, data size) are applied before triggers fire - by necessity.  
Your trigger couldn't have a ":new.value"  of varchar2(20) with a 50 character string in it.

You will have to correct the length before putting the value in,  or make the column definition bigger.
You could then apply a check constraint to ensure the trigger-modified value was of the appropriate shorter length.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39657194
I believe length and syntax restrictions are checked at the time the statement is parsed which is before it is executed so the trigger isn't going to work.

As a DBA, the question I have is why it would be acceptable to truncate data and therefore lose it.

If someone passes you data, they sort of expect it to be stored.  Don't they?

Can you not change the table to account for the maximum length you can be sent?

If not, maybe load the data into a staging table for processing before adding it into the main table.
0
 

Author Closing Comment

by:TomDarby
ID: 39657212
The routine is being passed a 12 position postal code and it only needs 9 so I was hoping to truncate it. I guess that will not work.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question