Results 1 to 13 of 13

Thread: ORACLE trigger/PLSQL question...hmm

  1. #1
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,508
    Thanks
    336
    Thanked
    320 times in 255 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre

    ORACLE trigger/PLSQL question...hmm

    Ok i'm not very experienced with oracle triggers,PL/SQL etc but I am learning, so bear with me

    I have 2 tables involved in this situation, a source tabled called:

    'dm_audittrail_s' and a destination table called 'rds_monitoring'

    What I want to do is have a trigger on the dm_audittrail_s table to fire when a new record is inserted, and for that trigger to insert a new record on rds_monitoring. Simple yes? Well it gets more complex.
    I want the trigger to only fire when a certain type of record is inserted - that is, there is an attribute in dm_audittrail_s called 'EVENT_NAME', which could be a variety of things but is always a string. I only want the trigger to fire when EVENT_NAME = 'dm_getfile'

    I'm struggling to get it to do that at the moment ;/

    this is the code that I have currently (abridged to only the relavent code)

    Code:
    CREATE OR REPLACE TRIGGER rds_monitor_update
    	AFTER INSERT ON dm_audittrail_s
    
    	REFERENCING NEW AS newRow
    
    	FOR EACH ROW
    	WHEN (newRow.EVENT_NAME='dm_getfile')
    
                 DECLARE <etc etc> BEGIN <etc etc> EXCEPTION <etc etc> END
    The trigger is currently fireing on any event - not just dm_getfile

    anyone got any ideas at all?

    Failing that any links to sites with lots of detail on triggers / plsql would be helpful, particularly with info about the when clause and the for each row clause (the oracle documentation is good, but could use more insight..)

    Cheers in advance for any help

    Spud/Pete

  2. #2
    TiG
    TiG is offline
    Walk a mile in other peoples shoes...
    Join Date
    Jul 2003
    Location
    Questioning it all
    Posts
    6,213
    Thanks
    45
    Thanked
    48 times in 43 posts
    One thing i will say is that if this is firing a large number of events then a trigger (at least in my opinion) is not the way to implement this. Triggers when used on a large scale absolutely hammer DB performance and can cause problems further down the line.

    Its not possible to alter the Stored Proc's or SQL code to add the insert instead of writing this conditional trigger, that will always need to be evaluated?.

    TiG
    -- Hexus Meets Rock! --

  3. #3
    Administrator Moby-Dick's Avatar
    Join Date
    Jul 2003
    Location
    There's no place like ::1 (IPv6 version)
    Posts
    10,665
    Thanks
    53
    Thanked
    385 times in 314 posts
    wo0ho0 1st dev post I've actually understood

    I'm with TiG on this - lots of triggers is bad ( from a DBa point of view )
    my Virtualisation Blog http://jfvi.co.uk Virtualisation Podcast http://vsoup.net

  4. #4
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,508
    Thanks
    336
    Thanked
    320 times in 255 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre
    Sorry maybe i'm not being as clear as I should be

    I can't go into too much detail for various reasons but anyway, it's not lots of triggers, there's only one. All this trigger will do is update a different table when a record is inserted into dm_audittrail_s with the value 'dm_getfile' in the EVENT_NAME attribute/field/whatever you want to call it

    The dm_audittrail_s table is a table to store information about a user and what the use r is doing when they access certain files on our content management system (a customised version of documentum if that means anything to you )

    does that clear it up a bit?

  5. #5
    Member
    Join Date
    Oct 2005
    Posts
    92
    Thanks
    0
    Thanked
    0 times in 0 posts
    The best example I have found that is similar is this (from http://www-db.stanford.edu/~ullman/f...igger%20syntax):
    Code:
    CREATE TRIGGER trig1
        AFTER INSERT ON dm_audittrail_s
        REFERENCING NEW AS newRow
    
        FOR EACH ROW
        WHEN (newRow.EVENT_NAME='dm_getfile')
        BEGIN
            ...blah...;
        END trig1;
    .
    But that does look worryingly like your code (i tweaked the table names to match). Are you sure the compare is correct? I've had a few oddities in SQL Server where EVENT_NAME = null returned true as well. The system I work on has implemented something similar using a call to another sp within each stored proc which inserts into that table.

    I hope this has helped.
    Nick

  6. #6
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,508
    Thanks
    336
    Thanked
    320 times in 255 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre
    Thanks for the suggestions

    It turns out that my code was correct, it was a problem with the application providing the EVENT_NAME thing, causing it to mis-fire
    anyway its sorted now ty

  7. #7
    Senior Member
    Join Date
    May 2005
    Posts
    434
    Thanks
    0
    Thanked
    0 times in 0 posts
    what is "fire" trigger? never came across that in sql b4, im curious 2 know what it does

  8. #8
    Member
    Join Date
    Oct 2005
    Posts
    92
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by jonneymendoza
    what is "fire" trigger? never came across that in sql b4, im curious 2 know what it does
    Triggers allow you to make SQL more event driven. It does have the side effect of slowing down inserts/updates... basically whatever they are tied to. I would generally recommend avoiding them unless you really have to. A better design is to use stored procedures and include whatever extra code you need within a transaction.

    Have a look at the link i posted earlier for more details.

    Nick
    Abit IP-35 Pro, Core 2 Quad Q6600 @ 3Ghz, 8800GTS 512, Zalman Reserator1 External Watercooler, 4GB DDR2, 76GB Raptor 10k, 300GB Seagate Barracuda 7200.10, 2x Maxtor 250GB 7.2k, ViewSonic VP201s & Dell 2408

  9. #9
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,508
    Thanks
    336
    Thanked
    320 times in 255 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre
    By 'Fire' Trigger i mean launch it, execute it, whatever you want to call it, it basically means running it when something happens (an insert, update etc etc). Fire is just a commonly used term to describe it.

  10. #10
    Senior Member
    Join Date
    May 2005
    Posts
    434
    Thanks
    0
    Thanked
    0 times in 0 posts
    o i see so basicly the database or whatever, will do an operation by itself without a user interacting with the database using something that triggers the operation? like for example add a new record to a relational table automaticly when somthing else happens in say another relation table..

    ahh makes sence

  11. #11
    Senior Member
    Join Date
    Apr 2005
    Location
    Bournemouth, Dorset
    Posts
    1,631
    Thanks
    13
    Thanked
    2 times in 2 posts
    hey, iam not very good at SQL nor do i know much about Oracle, but my pa is a genius when it comes to this stuff! hehe
    he said the best person to speak to is this american called Tom whom he has met before, this guy knows every thing there is to know and will answer your questions personally. My dads students use him as one of their main resources when working with ORACLE,
    http://asktom.oracle.com/
    sorry if you already know about this, just thought it may be of some help

  12. #12
    Senior Member
    Join Date
    May 2005
    Posts
    434
    Thanks
    0
    Thanked
    0 times in 0 posts
    i would say i know quit abit of sql, nice link though, will be visiting that quite often

  13. #13
    Member
    Join Date
    Sep 2003
    Posts
    95
    Thanks
    0
    Thanked
    1 time in 1 post
    you could aslso try the forums at technet.oracle.com or metalink.oracle.com (Oracle support contract required)

    HT

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Quick Question: PSU's with 1x120mm fan question
    By philyau in forum PC Hardware and Components
    Replies: 10
    Last Post: 05-09-2005, 02:30 PM
  2. The 78th Annual Hexus Quiz!
    By Stewart in forum General Discussion
    Replies: 19
    Last Post: 23-01-2005, 02:05 PM
  3. Evolution question.
    By Galant in forum General Discussion
    Replies: 22
    Last Post: 10-09-2004, 10:18 PM
  4. A question without an answer....
    By Zak33 in forum Automotive
    Replies: 21
    Last Post: 23-06-2004, 11:39 AM
  5. Oracle SQL
    By Raz316 in forum Software
    Replies: 7
    Last Post: 08-06-2004, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •