Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oracle DB Trigger

Posted on 2013-11-18
3
Medium Priority
?
450 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

610 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