Hi ALL,
I have a pl/sql statement. The idea is to update the M_NAME table, with the information in the t_load_con table. The problem I have is that I have 1M records in the t_load_con table. when I run the statement below. It up dates all of the recordsin the M_NAME . I do not understand why, all the records are updated. The idea behind the statement, is that if there are any new information with the the t_load_con table it updates/add to the master record.
Please could an expert try and point me in the correct direction.
Thanks
T
++++++++++++++++++++++++++
++++++++++
++
declare
counter number ;
BEGIN
counter :=0 ;
FOR LOAD IN (SELECT * FROM t_LOAD_con )
LOOP
FOR MAST IN (SELECT * FROM m_name WHERE LAST_NAME=LOAD.LAST_NAME AND
STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and PLZ = LOAD.PLZ )
LOOP
IF (MAST.LAST_NAME=LOAD.LAST_
NAME
and MAST.STREET=LOAD.STREET
and MAST.HSE_NR = LOAD.HSE_NR
and MAST.PLZ = LOAD.PLZ)
THEN UPDATE m_name SET WHERE_FROM='33b' ;
END IF;
IF ( MAST.TOWN is NULL and LOAD.CITY is not NULL )
or ( MAST.TOWN !=LOAD.CITY and LOAD.CITY is not NULL)
THEN UPDATE m_name SET TOWN=LOAD.CITY
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.TELEPHONE_1 is NULL and LOAD.TELEPHONE1 is not NULL )
or ( MAST.TELEPHONE_1 != LOAD.TELEPHONE1 and LOAD.TELEPHONE1 is not NULL)
THEN UPDATE m_name SET TELEPHONE_1=LOAD.TELEPHONE
1
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.TELEPHONE_2 is NULL and LOAD.TELEPHONE2 is not NULL )
or ( MAST.TELEPHONE_2 != LOAD.TELEPHONE2 )
THEN UPDATE m_name SET TELEPHONE_2=LOAD.TELEPHONE
2
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.TELEPHONE_3 is NULL and LOAD.TELEPHONE3 is not NULL )
or ( MAST.TELEPHONE_3 != LOAD.TELEPHONE3 and LOAD.TELEPHONE3 is not NULL)
THEN UPDATE m_name SET TELEPHONE_3=LOAD.TELEPHONE
3
where MAST.LAST_NAME=LOAD.LAST_N
AME AND STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.TELE_TXT_1 is NULL and LOAD.TEL_TEXT1 is not NULL )
OR ( MAST.TELE_TXT_1 != LOAD.TEL_TEXT1 and LOAD.TEL_TEXT1 is not NULL )
THEN UPDATE m_name SET TELE_TXT_1=LOAD.TEL_TEXT1
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.TELE_TXT_2 is NULL and LOAD.TEL_TEXT2 is not NULL )
OR ( MAST.TELE_TXT_2 != LOAD.TEL_TEXT2 and LOAD.TEL_TEXT2 is not NULL )
THEN UPDATE m_name SET TELE_TXT_2=LOAD.TEL_TEXT2
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.TELE_TXT_3 is NULL and LOAD.TEL_TEXT3 is not NULL )
OR ( MAST.TELE_TXT_3 != LOAD.TEL_TEXT3 and LOAD.TEL_TEXT3 is not NULL )
THEN UPDATE m_name SET TELE_TXT_3=LOAD.TEL_TEXT3
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.HOMEPAGE is NULL and LOAD.HOMEPAGE is not NULL )
OR ( MAST.HOMEPAGE != LOAD.HOMEPAGE and LOAD.HOMEPAGE is not NULL )
THEN UPDATE m_name SET HOMEPAGE=LOAD.HOMEPAGE
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.COUNTRY is NULL and LOAD.COUNTRY is not NULL)
OR ( MAST.COUNTRY != LOAD.COUNTRY and LOAD.COUNTRY is not NULL)
THEN UPDATE m_name SET COUNTRY=LOAD.COUNTRY
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.CANTON is NULL and LOAD.CANTON is not NULL)
OR ( MAST.CANTON != LOAD.CANTON and LOAD.CANTON is not NULL )
THEN UPDATE m_name SET CANTON=LOAD.CANTON
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.TITTLE is NULL and LOAD.TITLE is not NULL )
OR ( MAST.TITTLE != LOAD.TITLE and LOAD.TITLE is not NULL)
THEN UPDATE m_name SET TITTLE=LOAD.TITLE
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
IF ( MAST.eMail is NULL and LOAD.EMAIL is not NULL )
Or ( MAST.eMail != LOAD.EMAIL and LOAD.EMAIL is not NULL )
THEN UPDATE m_name SET eMail=LOAD.EMAIL
where MAST.LAST_NAME=LOAD.LAST_N
AME AND MAST.STREET=LOAD.STREET and HSE_NR=LOAD.HSE_NR and MAST.PLZ = load.plz ;
END IF;
counter:=counter+1;
if counter > 10000 then commit ;
counter:=0 ;
end if ; END LOOP;
COMMIT;
END LOOP;
EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(SQLER
RM);
END;
/
Start Free Trial