Solved

Oracle trigger

Posted on 2013-01-17
15
614 Views
Last Modified: 2013-01-17
I have never created a trigger before in Oracle. I need to update a column when a record gets inserted or updated to be Upper Case. This is what I want to run on Insert/Update

UPDATE OMNI_COMMOM_LOOKUP SET LOOKUP_VALUE_TEXT=UPPER(LOOKUP_VALUE_TEXT) WHERE LOOKUP_KEY LIKE 'TRANSIT_TYPE_%';

I want this done After Update/Insert but when I try to create it I get a message that says it compiles but with warnings. Im using TOAD but cant figure it out. I put the Update statement in the Body tab and click the appropriate check boxes for Insert Update and After but I still cant figure it out.

Please walk me through step by step to create this trigger

Thanks
0
Comment
Question by:jknj72
  • 9
  • 6
15 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 38787817
Untested, just typed in but try something like:

create or replace trigger OMNI_COMMOM_LOOKUP_TRIG
after insert or update on OMNI_COMMOM_LOOKUP
for each row
begin
:new.LOOKUP_KEY  := upper(:new.LOOKUP_KEY);
end;
/
0
 

Author Comment

by:jknj72
ID: 38787879
I ran what you sent me I got the following error.

create or replace trigger ANET.TRG_OMNI_COMMOM_LOOKUP
after insert or update on ANET.OMNI_COMMOM_LOOKUP
for each row
begin
:new.LOOKUP_KEY  := upper(:new.LOOKUP_KEY);
end;
Error at line 2
ORA-00942: table or view does not exist


Also, Im trying to Update the LOOKUP_VALUE_TEXT field not LOOKUP_KEY. No idea why this is happening, any idea?
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 38787904
>>trying to Update the LOOKUP_VALUE_TEXT field not LOOKUP_KEY

Then change the column name.

>>ORA-00942: table or view does not exist

Either the user you are logged into the database with doesn't have permissions to see ANET.OMNI_COMMOM_LOOKUP or the table really doesn't exist.
0
 

Author Comment

by:jknj72
ID: 38788155
hahah, nice answser!!! I just wanted to make sure that I was updating the correct column...

Anyway, I got this error now.

Compilation (1: 26): ORA-04084: cannot change NEW values for this trigger type
0
 

Author Comment

by:jknj72
ID: 38788158
This too when using TOAD tocreate trigger....

Error at line 3
ORA-04082: NEW or OLD references not allowed in table level triggers
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 38788165
>>ORA-04082: NEW or OLD references not allowed in table level triggers

Make sure you have 'for each row'.

>> Compilation (1: 26): ORA-04084: cannot change NEW values for this trigger type

Change it to a before update/insert trigger.
0
 

Author Comment

by:jknj72
ID: 38788274
ok that worked. I just need to script this out for the DBAs. When I script other objects I always include a Synonym and Grants, do I have to worry about this with a Trigger?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 38788289
>>do I have to worry about this with a Trigger?

The only think I can think of and I'm not even sure of that is if, for some odd reason, the trigger is on tables that aren't in the same schema as the trigger and that schema doesn't already have the necessary rights.
0
 

Author Comment

by:jknj72
ID: 38788297
Also, Where is the Where Clause that I need in the Trigger Update?
0
 

Author Comment

by:jknj72
ID: 38788300
ok Thanks. I just need to set the Where clause and Im good to go!!
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 38788311
>>Also, Where is the Where Clause that I need in the Trigger Update?

What 'where' clause?  A trigger fires 'for each row' it is passed.  This is determined by the DML statement issued against the base table.
0
 

Author Comment

by:jknj72
ID: 38788318
ok maybe im a little confused. I only want this to run if the
WHERE LOOKUP_KEY LIKE 'TRANSIT_TYPE_%';


This table is used for multiple apps and I only want this to run for these KEYS
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 38788342
That where clause is part of the update statement that fires the trigger.

As you saying you only want to make LOOKUP_VALUE_TEXT upper case if LOOKUP_KEY LIKE 'TRANSIT_TYPE_%'?

If so, just add an if statement to the trigger.

...
if :new.LOOKUP_KEY LIKE 'TRANSIT_TYPE_%' then
   :new.LOOKUP_VALUE_TEXT:= upper(:new.LOOKUP_VALUE_TEXT);
end if;
...
0
 

Author Comment

by:jknj72
ID: 38788398
ok that worked great, thanks for the help
0
 

Author Closing Comment

by:jknj72
ID: 38788403
thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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.
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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

12 Experts available now in Live!

Get 1:1 Help Now