我有一个成功编译的程序。更新docmeta表并在记录流入temp_pay_term表后插入updatehistory表。问题是代码需要两个修复1)当它们是temp_pay_term表中的多个记录时,删除命令at在下面的代码中的第65行,只删除temp_term表的一个记录而不是全部。我希望在此过程完成其全部工作后删除temp_pay_term表的所有记录。我是否必须在循环内使用循环来实现这一目标。如果是,那怎么样?请告诉我代码。 2)现在这困扰了我一段时间。从下面代码中的第28-34行,当我更新docmeta表以设置XPAYMENTTERM值时,因为此后的条件是子查询,所以我只能得到一行。出于这个原因,我想通过paytermtimestamp desc返回记录pid = d.xProject_id AND rownum< = 1 order。但order by子句不适用于此处并抛出错误。如何在此处应用order by子句来获取最新记录。
CREATE OR REPLACE
PROCEDURE TERMUPDATE
IS
RecordCount INT;
varDID NUMBER(38);
varpaymentterm VARCHAR2(200 CHAR);
varprojectID VARCHAR2(30 CHAR);
BEGIN
RecordCount :=0;
SELECT COUNT(1)
INTO RecordCount
FROM temp_pay_term;
IF RecordCount > 0 THEN
FOR X IN
(SELECT DISTINCT r.ddocName
FROM temp_Pay_Term p,
docMeta d,
revisions r
WHERE TO_CHAR(p.pid) = d.xproject_id
AND r.did = d.did
)
LOOP
SELECT MAX(did)
INTO varDid
FROM revisions r
WHERE r.ddocname = X.ddocName
GROUP BY r.ddocname;
UPDATE docmeta d
SET XPAYMENTTERM =
(SELECT paymentterm
FROM temp_pay_term
WHERE pid = d.xProject_id
AND rownum <= 1
)
WHERE d.did = vardid returning xpaymentterm,
xProject_id
INTO varpaymentterm,
varprojectID;
INSERT
INTO updatehistory
(
UPDATEID,
DID,
UPDATETIME,
METADATAFIELD,
NEWVALUE,
OLDVALUE,
UPDATEDBY
)
VALUES
(
(SELECT MAX(updateid)+1 FROM updatehistory
)
,
(SELECT did FROM revisions WHERE did = vardid
),
systimestamp,
'Payment term',
varpaymentterm,
( SELECT oldpaymentterm FROM temp_pay_term WHERE pid = varprojectID
),
'sysadmin'
);
END LOOP;
DELETE FROM temp_Pay_Term WHERE pid = varprojectID;
COMMIT;
END IF;
END TERMUPDATE; -- PL SQL code