I have three tables:
CUSTOMER Columns (Tracking)
Reference Columns (Ref_Tracking, Project)
PROJECT Columns(Project)
我需要检查 Reference 以查看来自 CUSTOMER 的列 (Tracking) 中的记录是否存在于 Reference (Ref_Tracking) 中。然后检查参考(项目)中的关联记录是否存在于项目(项目)中。
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;