I have three tables:
CUSTOMER Columns (Tracking)
Reference Columns (Ref_Tracking, Project)
PROJECT Columns(Project)
我需要檢查引用以查看引用(Ref_Tracking)中是否存在來自CUSTOMER的列(跟蹤)中的記錄。然後檢查參考文獻(項目)中的相關記錄是否存在於PROJECT(項目)中。記錄處理如果記錄存在PLSQL中的更新,插入
If they exist UPDATE PROJECT
SET PROJECT.NAME = CURSOR VARIABLES
ETC
ETC
If they do not exist
INSERT INTO REFERENCE
VALUES (CURSOR VALUES)
我有一個遊標正在循環與客戶表的所有變量。
我已經在下面嘗試過,但沒有數據正在填充我不知道我做錯了什麼,或者如果有更好的方法來做到這一點。我學習PL/SQL,所以不知道我是否在正確的軌道上。
CREATE OR REPLACE PROCEDURE P1
AS
V_NAME CUSTOMER.NAME%TYPE;
V_TRACKING CUSTOMER.TRACKING%TYPE;
V_ADDRESS CUSTOMER.ADDRESS%TYPE;
V_CITY CUSTOMER.CITY%TYPE;
V_STATE CUSTOMER.STATE%TYPE;
V_NUMBER CUSTOMER.NUMBER%TYPE;
V_ Ref Reference.REF_TRACKING%TYPE := NULL;
V_Project REFERENCE.PROJECT%TYPE := NULL;
V_Project_2 PROJECT.PROJECT%TYPE := NULL;
CURSOR C01
IS
SELECT C.Name,
C.Tracking,
C.Address,
C.City,
C.State,
C.Number
FROM Customer
WHERE C.Number = Another_Table;
BEGIN
FOR fetchc01 IN C01
LOOP
BEGIN
Select Ref_Tracking, R.Project, P.Project
Into V_ Ref, V_Project, V_Project_2
From Customer C, Reference R, Project P
Where R.Project = P.Project
AND Tracking = Ref_Tracking;
EXCEPTION
WHEN TOO_MANY_ROWS
THEN
NULL;
WHEN NO_DATA_FOUND
THEN
NULL;
END;
BEGIN
IF V_Ref = fetch01.Tracking
Then
Insert Into Sample_Project
VALUES (V_Name, V_Tracking, V_Location)
END
END LOOP;
END;
你的問題到底是什麼? – Bohemian
該過程編譯但它不會返回有關插入或更新的任何數據。想知道是否有更有效的做法或我做錯了什麼。謝謝! – user1307149