Note that there are some explanatory texts on larger screens.

plurals
  1. POIn an Oracle trigger, can I assign new and old to a rowtype variable?
    primarykey
    data
    text
    <p>I've been tasked with implementing several trigger scripts, and I've got examples from coworkers to work from. In those, they use pl-sql conditionals for updating/inserting/deleting, along with gigantic insert statements (in another table). These insert statements do not vary other than whether the values are prefixed with new or old. I thought I would be clever and try to make mine a little more compact, using the following:</p> <pre><code>DECLARE vRow SATURN.SPRCMNT%ROWTYPE; BEGIN IF UPDATING THEN vRow := :NEW; ELSIF INSERTING THEN vRow := :NEW; ELSIF DELETING THEN vRow := :OLD; END IF; -- Not the real insert statement INSERT INTO blah (columns) VALUES (vRow.somecolumns); END; </code></pre> <p>I get the following back from the compile system:</p> <pre><code>10/13 PLS-00049: bad bind variable 'NEW' 13/13 PLS-00049: bad bind variable 'NEW' 16/13 PLS-00049: bad bind variable 'OLD' </code></pre> <p>Obviously it does not like this. Is there something that will achieve what I'm attempting? Are :new and :old just not true rowtypes? It seems dumb to repeat what is essentially the same code 3 times over, and yet I can't figure out a better way. Hell, I think I read that there's some hard limit on the size of triggers too. Any help appreciated.</p> <p>[Edit] Just a thought, is it possible to reference the UPDATING/INSERTING keywords somehow within a DECODE()?</p> <p>For instance, if I could do a DECODE(SOMETHINGVAR, UPDATING, :NEW.column, DELETING, :OLD.column) then I could set the value of each column in vRow with a single statement.</p> <p>I guess it'd be better to check DELETING first, and use the default for the other two.</p> <p>Is this possible?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload