我正在使用Oracle SQL Developer在Oracle12c中編寫過程。我需要做的是檢查一張表以查看是否存在記錄。如果確實如此,那麼我需要對其進行編輯。如果沒有,那麼我需要添加它。Oracle IF/ELSE語句
所以,我的 「僞」 邏輯將是這個樣子:
If (Select * from MyTable where MyValue = 0) has more than one record, then
This will be an EDIT line of code
else
This will be an ADD line of code
end
我怎麼會寫在Oracle SQL Developer中?
編輯:
目前我的代碼看起來是這樣的,我需要添加一塊要更新的記錄。如果Line_ID存在,我需要更新記錄。如果不是,我需要添加它。
create or replace PROCEDURE CST_WRITE_FEEDBACK (
v_AuditID IN NUMBER,
v_BenefitID IN NUMBER,
v_Network1 IN VarChar,
v_Network2 IN VarChar,
v_Network3 IN VarChar,
v_Network4 IN VarChar,
v_Issue1 IN NUMBER,
v_Issue2 IN NUMBER,
v_Issue3 IN NUMBER,
v_Issue4 IN NUMBER,
v_Resolution1 IN NUMBER,
v_Resolution2 IN NUMBER,
v_Resolution3 IN NUMBER,
v_Resolution4 IN NUMBER,
v_Status IN NUMBER,
v_Comment IN VarChar,
v_LineID IN NUMBER,
v_EmpID IN NUMBER
)
AS
BEGIN
IF
INSERT INTO F_AUDIT_LINE ("AUDIT_ID", "BENEFIT_ID", "NETWORK", "NETWORK2", "NETWORK3", "NETWORK4",
"ISSUE_ID", "ISSUE_ID2", "ISSUE_ID3", "ISSUE_ID4",
"RESOLUTION_ID", "RESOLUTION_ID2", "RESOLUTION_ID3", "RESOLUTION_ID4",
"LINE_STATUS")
VALUES (v_AuditID, v_BenefitID, v_Network1, v_Network2, v_Network3, v_Network4,
v_Issue1, v_Issue2, v_Issue3, v_Issue4,
v_Resolution1, v_Resolution2, v_Resolution3, v_Resolution4,
v_Status
);
END CST_WRITE_FEEDBACK;
只需使用Oracle上的合併功能 –
您可以在此擴展嗎? –
我已經刪除了SQL Developer的標籤,因爲代碼不依賴於您使用的編輯器。 – Kacper