Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Error: ORA-01403: no data found

Tags:

oracle

when fire update query

update JISPBILCORBILLINGPRD501.TBLMACCOUNTADDRESS set Address1='NehateSir',stateid='STT0002' where accountid='ACC000000068'

that time this error occurs

Error starting at line 4 in command:
update JISPBILCORBILLINGPRD501.TBLMACCOUNTADDRESS set Address1='NehateSir',stateid='STT0002' where accountid='ACC000000068'
Error report:
SQL Error: ORA-01403: no data found
ORA-06512: at "WOM.TRGBILLINGADDRESS", line 10
ORA-04088: error during execution of trigger 'WOM.TRGBILLINGADDRESS'
01403. 00000 -  "no data found"
*Cause:    
*Action: 

bellow is trigger code

create or replace
TRIGGER TRGBILLINGADDRESS AFTER
  INSERT OR
  DELETE OR
  UPDATE ON jispbilcorbillingprd501.TBLMACCOUNTADDRESS FOR EACH ROW
  DECLARE
  add1 varchar2(200) ;
  add2 varchar2(200);
  cityid varchar2(200);
  stateid varchar2(200);
  pincd varchar2(200);
  parlcid varchar2(12);
  BEGIN
    select endbcirclename into parlcid from jispbilcorbillingprd501.tblmaccountprofile where accountid =:NEW.accountid;
    SELECT address1,
      address2,
      city_id,
      state_id,
      pincode
    INTO add1,
      add2,
      cityid,
      stateid,
      pincd
    FROM wom.tbltaddress ta
    WHERE ta.ID IN
      (SELECT vbac.billing_address_id
      FROM wom.vw_billaddresschange vbac,
        wom.tbltaddress ita
      WHERE vbac.billing_address_id = ita.ID
      AND vbac.lcid                 = parlcid
      );
    IF
    add1 = :new.address1 AND add2 = :new.address2 AND cityid = :new.cityid AND stateid = :new.stateid
    AND pincd = :new.zip THEN
    dbms_output.put_line('Address Already Exist in tbltaddress table');
    ELSE
      UPDATE wom.tbltaddress ta
      SET ta.address1 = :new.address1,
        ta.address2   = :new.address2,
        ta.city_id    = :new.cityid,
        ta.country_id = 'CTR0001',
        ta.state_id   = :new.stateid,
        ta.pincode    = :new.zip
      WHERE ta.ID    IN
        (SELECT vbac.billing_address_id
        FROM wom.vw_billaddresschange vbac,
          wom.tbltaddress ita
        WHERE vbac.billing_address_id = ita.ID
        AND vbac.lcid                 = parlcid
        );
    END IF;
END;
like image 229
user714698 Avatar asked Apr 19 '11 12:04

user714698


1 Answers

This query:

SELECT address1,
  address2,
  city_id,
  state_id,
  pincode
INTO add1,
  add2,
  cityid,
  stateid,
  pincd
FROM wom.tbltaddress ta
WHERE ta.ID IN
  (SELECT vbac.billing_address_id
  FROM wom.vw_billaddresschange vbac,
    wom.tbltaddress ita
  WHERE vbac.billing_address_id = ita.ID
  AND vbac.lcid                 = parlcid
  );

does not return anything which causes an exception in PL/SQL.

You should catch this exception:

BEGIN
        SELECT  address1,
                address2,
                city_id,
                state_id,
                pincode
        INTO    add1,
                add2,
                cityid,
                stateid,
                pincd
        FROM    wom.tbltaddress ta
        WHERE   ta.ID IN
                (
                SELECT  vbac.billing_address_id
                FROM    wom.vw_billaddresschange vbac,
                        wom.tbltaddress ita
                WHERE   vbac.billing_address_id = ita.ID
                        AND vbac.lcid = parlcid
                );
EXCEPTION
WHEN no_data_found THEN
        NULL; -- or do anything useful
END;

If you are using Oracle 9i or above, use MERGE statement instead of implementing UPSERT in a trigger.

like image 55
Quassnoi Avatar answered Sep 29 '22 00:09

Quassnoi