我在plsql中有要求

时间:2019-12-27 04:54:16

标签: oracle plsql

If you have any sample code for such comparison, could you please share it with me.

Following is the logic my routine is supposed to do:

i) Compare each column values of master table with the Temp table.

ii) If the record is present in the Master table, then do nothing.

iii) If there is a mismatch in data then, Update the master table with the values from temp table and insert the same values in to the another table.

I have tried with the below scenario:

EXECUTE DBMS_ERRLOG.CREATE_ERROR_LOG('Persons1', 'ERR_persons1','@OWNER');

-创建表格(临时)     创建表Persons_temp(PersonID int,         姓氏varchar(255),         名字varchar(255),         地址varchar(255),         City varchar(255));   -插入数据 插入person_temp值(201,“ S”,“ SCOTT”,“ NEW YORK”,“ NEW YORK”);

插入person_temp值(202,“ K”,“ KING”,“ MISSISSIPPI”,“ MISSISSIPPI”);

-创建另一个表(母版)
创建表person1为(从person_temp中选择*);

插入person_temp值(202,“ K”,“ KING”,“ MISSISSIPPI”,“ MISSISSI”);

合并为人1 p     使用person_temp p1     开启(p.personid = p1.personid)     配对时       然后         更新         设置p.LastName = p1.LastName,          p.FirstName = p1.FirstName,          p.Address = p1.Address,          p.City = p1.City     其中p.LastName <> p1.LastName或          p.FirstName <> p1.FirstName或          p.Address <> p1.Address或          p.City <> p1.City     不匹配时             然后             插入(p.personid,p.LastNamep.FirstName,p.Address,p.City)          值(p1.personid,p1.LastName,p1.FirstName,p1.Address,p1.City)

     LOG ERRORS INTO ERR_Persons1 ('MERGE') REJECT LIMIT UNLIMITED;

I have tried with the above scenario, For lesser rows it is working fine, In our tables there are lakhs of records. In that case any better solution is available for this or can I made it any better by using some other approach. suggest the best one, Thanks in advance.

0 个答案:

没有答案