这是基于我的另一个问题。。请参见在oracle中更新表集合列等于选择id在查询外部匹配的位置
是否可以使用循环或光标来更新我的表snp\u faculty\u census,其中person\u skey值在snp\u faculty\u census和vpaa\u ppaggenl\u fis中匹配?
我之所以问这个问题,是因为我有一个update语句,当我显式定义id列(person_skey)时,它工作得非常好,例如:
WHERE V.PERSON_SKEY = 12345
但是,如果我使用从另一个表中获取值的where子句
WHERE V.PERSON_SKEY = SNP_FACULTY_CENSUS.PERSON_SKEY
update语句没有正确地更新列(我认为它对max(oir\u degree\u hierarchy)使用了错误的值)
以下是我的代码,我希望在这里循环使用snp\u faculty\u census中不同的person\u skey值:
WITH HIGHES_DEG_VALUE AS (
SELECT max(D.OIR_DEGREE_HIERARCHY) AS MAX_DEG
FROM VPAA_PPAGGENL_FIS V
JOIN DIM_DEGREE_CROSSWALK D
ON V.VPAA_FACULTY_DEGREE_CODE =
D.VPAA_DEGREE_CODE
WHERE V.PERSON_SKEY = 189444) --CHANGE TO = SRC.PERSON_SKEY
SELECT
CASE
WHEN MAX_DEG = 30
THEN --CHECK IF EXIST ON CROSSWALKS AND USE THAT VALUE IF IT DOES
(CASE
WHEN EXISTS (SELECT V.VPAA_FACULTY_DEGREE_CODE, --IF ON SUBJ CODE CROSSWALK
V.VPAA_FACULTY_SUBJECT_CODE
FROM VPAA_PPAGGENL_FIS V
JOIN DIM_DEGREE_CROSSWALK D
ON V.VPAA_FACULTY_DEGREE_CODE = D.VPAA_DEGREE_CODE
INNER JOIN SUBJ_CODE_CROSSWALK S
ON V.VPAA_FACULTY_DEGREE_CODE = S.VPAA_FACULTY_DEGREE_CODE
and S.VPAA_FACULTY_SUBJECT_CODE = V.VPAA_FACULTY_SUBJECT_CODE
WHERE V.PERSON_SKEY =189444 ----CHANGE TO = SRC.PERSON_SKEY
)
THEN (SELECT DISTINCT -- USE TERMINAL VALUE FROM SUBJ CODE
CASE
WHEN s.OIR_TERMINAL_DEGREE_STATUS =
'Terminal'
THEN
'Yes'
WHEN s.OIR_TERMINAL_DEGREE_STATUS =
'Not terminal'
THEN
'No'
ELSE
'Unknown'
END
FROM SUBJ_CODE_CROSSWALK S
INNER JOIN VPAA_PPAGGENL_FIS V
ON V.VPAA_FACULTY_DEGREE_CODE =
S.VPAA_FACULTY_DEGREE_CODE
AND S.VPAA_FACULTY_SUBJECT_CODE =
V.VPAA_FACULTY_SUBJECT_CODE
WHERE V.PERSON_SKEY = 189444 )----CHANGE TO = SRC.PERSON_SKEY )
WHEN EXISTS (SELECT DISTINCT V.VPAA_FACULTY_DEGREE_CODE, --IF ON CLIC INSTRUCTORS CROSSWALK
V.VPAA_FACULTY_SUBJECT_CODE,
I.OIR_EMPLOYEE_DEPARTMENT_HOME_ORG
FROM VPAA_PPAGGENL_FIS V
INNER JOIN CLIC_INSTRUCTORS_CROSSWALK C
ON V.VPAA_FACULTY_DEGREE_CODE = C.VPAA_FACULTY_DEGREE_CODE
AND V.VPAA_FACULTY_SUBJECT_CODE = C.VPAA_FACULTY_SUBJECT_CODE
INNER JOIN IPEDS_REPORT_DETAILS I ON V.PIDM = I.HR_PIDM
WHERE V.PERSON_SKEY = 189444 ----CHANGE TO = SRC.PERSON_SKEY
AND (I.OIR_EMPLOYEE_DEPARTMENT_HOME_ORG = '396000'
OR I.OIR_EMPLOYEE_DEPARTMENT_HOME_ORG = '396010')
)
THEN (SELECT DISTINCT
CASE
WHEN C.OIR_TERMINAL_DEGREE_STATUS =
'Terminal'
THEN
'Yes'
WHEN C.OIR_TERMINAL_DEGREE_STATUS =
'Not terminal'
THEN
'No'
ELSE
'Unknown'
END
FROM CLIC_INSTRUCTORS_CROSSWALK C
INNER JOIN VPAA_PPAGGENL_FIS V
ON C.VPAA_FACULTY_DEGREE_CODE =
V.VPAA_FACULTY_DEGREE_CODE
AND C.VPAA_FACULTY_SUBJECT_CODE =
V.VPAA_FACULTY_SUBJECT_CODE
WHERE V.PERSON_SKEY = 189444 )----CHANGE TO = SRC.PERSON_SKEY)
ELSE --USE DIM DEGREE CROSSWALK NORMALLY
(SELECT DISTINCT
CASE
WHEN D.OIR_TERMINAL_DEGREE_STATUS =
'Terminal'
THEN
'Yes'
WHEN D.OIR_TERMINAL_DEGREE_STATUS =
'Not terminal'
THEN
'No'
ELSE
'Unknown'
END
FROM DIM_DEGREE_CROSSWALK D
JOIN VPAA_PPAGGENL_FIS V
ON V.VPAA_FACULTY_DEGREE_CODE =
D.VPAA_DEGREE_CODE
WHERE V.PERSON_SKEY = 189444 ----CHANGE TO = SRC.PERSON_SKEY)
ORDER BY OIR_DEGREE_HIERARCHY DESC
FETCH FIRST ROW ONLY )
END) --USE DIM DEGREE CROSSWALK FOR THE TERMINAL VALUE FOR THE MAX DEG THERE
WHEN MAX_DEG != 30
THEN
(SELECT DISTINCT
CASE
WHEN D.OIR_TERMINAL_DEGREE_STATUS =
'Terminal'
THEN
'Yes'
WHEN D.OIR_TERMINAL_DEGREE_STATUS =
'Not terminal'
THEN
'No'
ELSE
'Unknown'
END
FROM DIM_DEGREE_CROSSWALK D
JOIN VPAA_PPAGGENL_FIS V
ON V.VPAA_FACULTY_DEGREE_CODE =
D.VPAA_DEGREE_CODE
WHERE V.PERSON_SKEY = 189444 ----CHANGE TO = SRC.PERSON_SKEY)
ORDER BY OIR_DEGREE_HIERARCHY DESC
FETCH FIRST ROW ONLY )
ELSE NULL
END
FROM HIGHES_DEG_VALUE
暂无答案!
目前还没有任何答案,快来回答吧!