Oracle
 sql >> база данни >  >> RDS >> Oracle

Актуализирайте колоната на набора от таблици, равна на това да изберете къде ID съвпада извън заявката в Oracle

Когато използвате WITH с UPDATE, трябва да използвате псевдоним за таблицата за актуализиране. Ако не, не работи.

Освен това не можете да извикате АКТУАЛИЗИРАНАТА ТАБЛИЦА в КЛАУЗАТА WITH, в този момент тази таблица е неизвестна, поради което получавате НЕВАЛИДЕН ИДЕНТИФИКАТОР. За да разрешите проблема, трябва да премахнете това условие и да го добавите в края.

Опитайте този, но пиша, без дори да знам модела на данните, така че имайте предвид.

UPDATE SNP_FACULTY_CENSUS SFC
SET OIR_TERMINAL_DEGREE = (
  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  
    LEFT JOIN SNP_FACULTY_CENSUS S 
        ON V.PERSON_SKEY = S.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 = SNP_FACULTY_CENSUS.PERSON_SKEY ----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 = SNP_FACULTY_CENSUS.PERSON_SKEY )----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 = SNP_FACULTY_CENSUS.PERSON_SKEY ----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 = SNP_FACULTY_CENSUS.PERSON_SKEY )----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 = SNP_FACULTY_CENSUS.PERSON_SKEY ----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 = SNP_FACULTY_CENSUS.PERSON_SKEY ----CHANGE TO  = SRC.PERSON_SKEY)
           ORDER BY OIR_DEGREE_HIERARCHY DESC
           FETCH FIRST ROW ONLY )
    ELSE NULL
END 
FROM HIGHES_DEG_VALUE
) WHERE SNP_FACULTY_CENSUS.OIR_FALL_TERM = 'Fall 2019' ;


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Приложението OCCI се срива, когато работи в режим на отстраняване на грешки във Visual Studio 2005

  2. Засегнатите редове на Oracle JDBC batchUpdate винаги са -2 (Statement.SUCCESS_NO_INFO)

  3. Как да импортирате Oracle 11g RMAN backupset на нов сървър на база данни?

  4. Как да върнете дробни секунди от стойност на дата и час в Oracle

  5. Oracle deadlock родител/дете и дете е индексирало FK