Solved

Oracle DB Trigger

Posted on 2013-11-18
3
424 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
Comment Utility
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)
Comment Utility
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
Comment Utility
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.

Join & Write a Comment

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to recover a database from a user managed backup

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now