473,461 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I make this trigger?

Hello
I work with Oracle 9 database. I want to create a trigger using 2
tables: KEY_SKILLS_STUDENT and KEY_SKILLS. There are fields in
KEY_SKILLS_STUDENT: KEY_SKILLS_ID, PORTFOLIO_RESULT and ACHIEVED. The
trigger should update automatically the field ACHIEVED to TRUE (-1),
when PORTFOLIO_RESULT is updated with strings "Pass" or "Exempt", but
not always. A field KEY_SKILLS_ID is a link to KEY_SKILLS table.
KEY_SKILLS table has got fields KEY_SKILLS_AREA_ID and KEY_SKILLS_ID.
I want the trigger to work, only if KEY_SKILLS_AREA_ID is >3.
I am not very experienced with Oracle triggers. I have made a couple
in my life, but they were much simpler, on a single table. Please
could you post me an example of a code for such trigger, or to point
into a right direction.
Thank you very much.
Jul 19 '05 #1
2 6443
goggle trigger oracle,

or http://groups.google.com/groups?hl=e...1%40wanadoo.fr

could provide some programmatic items you could use.

regards

s.kapitza
ga****@mail.ru (Galina) wrote in message news:<ec*************************@posting.google.c om>...
Hello
I work with Oracle 9 database. I want to create a trigger using 2
tables: KEY_SKILLS_STUDENT and KEY_SKILLS. There are fields in
KEY_SKILLS_STUDENT: KEY_SKILLS_ID, PORTFOLIO_RESULT and ACHIEVED. The
trigger should update automatically the field ACHIEVED to TRUE (-1),
when PORTFOLIO_RESULT is updated with strings "Pass" or "Exempt", but
not always. A field KEY_SKILLS_ID is a link to KEY_SKILLS table.
KEY_SKILLS table has got fields KEY_SKILLS_AREA_ID and KEY_SKILLS_ID.
I want the trigger to work, only if KEY_SKILLS_AREA_ID is >3.
I am not very experienced with Oracle triggers. I have made a couple
in my life, but they were much simpler, on a single table. Please
could you post me an example of a code for such trigger, or to point
into a right direction.
Thank you very much.

Jul 19 '05 #2
> Hello
I work with Oracle 9 database. I want to create a trigger using 2
tables: KEY_SKILLS_STUDENT and KEY_SKILLS.

Hello Galina

I am not that experienced with triggers myself but I have some ideas.
If you considers only UPDATE on KEY_SKILLS_STUDENT I think you
should use AFTER UPDATE on PORTFOLIO_RESULT row-trigger that updates
ACHIEVED after the UPDATE on PORTFOLIO_RESULT.
A row-level trigger with the conditions in a WHEN clause could
be advantegous withsomething like:
WHEN( PORTFOLIO_RESULT IN ('Pass','Exempt' ) AND .....)
To find out the conditions for KEY_SKILLS_AREA_ID in the other
table you can make a variable v_nr and another v_key_skills_id
with the current KEY_SKILLS_ID and use

SELECT COUNT INTO v_nr FROM KEY_SKILLS
WHERE KEY_SKILLS_AREA_ID > 3
AND KEY_SKILLS_ID = v_key_skills_id

To find if there is any records with your desired criteria. Put
AND v_nr > 0 in WHEN conditions so your triggers wont fire if
no corresponding post in KEY_SKILLS is found.

The only problem is to find out the actual KEY_SKILLS_ID. You cannot
use :NEW because KEY_SKILLS_ID is not changed. You cannot make a SELECT
on the same table(KEY_SKILLS_STUDENT) because you get "mutating problems".
When making row-triggers you have to consider "mutating issues" that
happens if you in the trigger makes a SELECT on the same table
that the trigger is defined on. It also happens if you in the
trigger tries to change the primary-key that has a foreign-key
defined on it. I think this could be different in different
Oracle-versions, but I hope it is like this now.
I think you will not see the mutating problems until
you run a statement that invokes the trigger.

If you have a package with all stored code for students or
student skills you can make a global variable with the actual
KEY_SKILLS_ID. To capture it you can make a STATEMENT trigger
BEFORE UPDATE on KEY_SKILLS_STUDENT that sets the global variable.

I must say I haven't made exactly this myself, only been thinking of
it. Perhaps anyone more experienced can give an easier solution for
your problem. I am interested to know myself.
Regards

Folke Larsson
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Darren | last post by:
Hello, I have some 'CREATE TRIGGER' definitions that work when cut/pasted into SQL*Plus worksheet and execute separately but fail with a 'trigger created with compilation errors' when executed...
7
by: Aidan Whitehall | last post by:
Have gone through BOL and Google, but can't find the answer... please help with a simple Q. I'm trying to create a simple cascade delete trigger in SQL Server 7 where deleting "parent" records in...
1
by: Jen S | last post by:
I feel like I'm missing something obvious here, but I'm stumped... I have a stored procedure with code that looks like: INSERT INTO MyTableA ( ...fields... ) VALUES (...values...) IF...
2
by: Juan Jose Costello Levien | last post by:
Hello, I am trying to use a trigger function I wrote in C. Basically what I want to do is to audit a table when a row is inserted into another table by copying the row to the new table. It...
6
by: wugon.net | last post by:
Hi , Anyone know how to monitor db2 trigger activity ? We suffer some trigger issue , and we try to monitor trigger's behavior use event monitor and db2audit, but both tools can not get...
0
by: wugon.net | last post by:
Hi , Anyone know how to monitor db2 trigger activity ? We suffer some trigger issue today and we try to monitor trigger's behavior use event monitor and db2audit, but both tools can not get...
2
by: wugon.net | last post by:
Problem: after inser trigger encounter error sql0348 Env:db2 v8 + fp 13 + win xp Description: we build two after insert triggers DB2.TRG1, DB2.TRG2 on base table DB2.TEST1, insert data into...
5
by: Bruno Rafael Moreira de Barros | last post by:
function test1() { trigger_error('My error'); } application.php //code... test1(); //code...
9
by: Chico Che | last post by:
Have a table that has following fields (pkid, field1, field2, field3, field4). I need to create a trigger that will insert a row into another table with the pkid column that was updated. Any help...
6
by: Marjeta | last post by:
I was trying to compare a particular trigger on multiple servers. First I tried phpMyAdmin to script the trigger code, which unfortunately only worked on one server that has newer version of...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.