Solved

Oracle DB Trigger

Posted on 2013-11-18
3
438 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 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 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

Independent Software Vendors: 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

Suggested Solutions

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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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 set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

730 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