Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Recursive trigger solution

naveenmani912Mar 17 2019 — edited Apr 1 2019

Hi all

I have a requirement to update same table using trigger. I am getting mutating trigger error. I totally understand its poor application design but need a solution or a work around

I have a table like this

create table nvtest

(

ref number,

addr varchar2(400),

mobile number

)

with records as  below:

900CORR7412
900RESID7401668992

I have created a trigger on that table which when we update one row it has to update another row(sorry the requirement). I could totally understand its the recursive call which cause the oracle mutating table error. Kindly help me out with solutions. The package which makes the first update will call only one row, i have to update the other address type too.

CREATE OR REPLACE TRIGGER nvtesttrigger

   BEFORE INSERT OR UPDATE OR DELETE

   ON nvtest

   REFERENCING NEW AS NEW OLD AS OLD

   FOR EACH ROW

DECLARE

   CURSOR lc_get

   IS

      SELECT * FROM nvtest;

BEGIN

   IF UPDATING

   THEN

      IF :old.addrtyp = 'CORR'

      THEN

         UPDATE nvtest

            SET mobile = :new.mobile

          WHERE addrtyp = 'RESID' AND cliref = :old.cliref;

      ELSIF :old.addrtyp = 'RESID'

      THEN

         UPDATE nvtest

            SET mobile = :new.mobile

          WHERE addrtyp = 'CORR' AND cliref = :old.cliref;

      END IF;

   END IF;

EXCEPTION

   WHEN OTHERS

   THEN

      RAISE;

END;

/

Comments

SH_INT

What error are you getting? Are you sure the string you are trying to convert only contains numeric characters? The method you are trying will work so long as the string is just a representation of a number

JanGLi

The value is 100 percent integer (2017). I have confirmed it by logging.

I even tried using this x = int('19') but getting an error.


Unfortunately i don't have python compiler at the moment. Getting just script fail error in log.

These are the classes i have added:

import string

import java.sql as sql

import java.lang as lang

Regards

JohnGoodwin
Answer

This works for me, no need to import java classes

fdmAPI.logDebug("Period Name=:%s" % fdmContext["PERIODNAME"])

fullYear = int("20" + fdmContext["PERIODNAME"][4:])

fdmAPI.logDebug("Full Year Name=:%s" % fullYear)

pastedImage_2.png

or

YearMinus1 = int("20" + fdmContext["PERIODNAME"][4:])-1

fdmAPI.logDebug("Year -1=:%s" % YearMinus1)

pastedImage_3.png

Cheers

John

Marked as Answer by JanGLi · Sep 27 2020
JanGLi

Thanks for help.

Regards

1 - 4

Post Details

Added on Mar 17 2019
9 comments
1,998 views