Solved

Oracle DB Trigger

Posted on 2013-11-18
3
432 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
3 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 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 76

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

825 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