[오라클]] INLINE VIEW
본문 바로가기
IT. 컴퓨터

[오라클]] INLINE VIEW

by 솔기잇 2020. 6. 29.

 INLINE VIEW 

구글 이미지

 

VIEW?

본다(=간주하다.)라는 뜻인데 , 테이블은 아니지만 SELECT 결과물이 테이블 처럼 나오므로 SELECT 결과물을

마치 테이블처럼 간주해서 보는 것을 VIEW 라고 부른다.

 

 

SELECT T.SANO AS "사원번호",

            T.NAME AS "사원명",

            T.JUBUN AS "주민번호",

            T.GENDER AS "성별",

            T.AGE AS "현재나이",

            TRUNC(T.AGE, -1) AS "연령대",

            T.YEARPAY AS "연봉",

            T.HIREDATE AS "입사일자",

            TO_CHAR(ADD_MONTHS(SYSDATE, (60-T.AGE) * 12) , 'YYYY')

           ||

            TO_CHAR(T.HIREDATE, '-MM-DD')

            AS "정년퇴직일",

            -- 정년퇴직일은 60세가 되는 해의 입사한 .일로 한다.

            --(정년날지금나이)*12 = 남은 , 이걸 달로 나타낸 것을 년도로.

            -–입사일을 ,일로)

 

 

           -- ( T.YEARPAY / 12 ) * 근속년수 = 퇴직금

 

            -- MONTHS_BETWEEN(정년퇴직일, 입사일자)

            -- 13.9개월 --> 1 3개월 20

            -- 13.9 / 12

            -- TRUNC( 13.9 / 12 )

            -- TRUNC( MONTHS_BETWEEN(정년퇴직일, 입사일자)

            --             / 12 )

 

     TRUNC(

     ( T.YEARPAY / 12 ) *

     TRUNC( MONTHS_BETWEEN( TO_DATE( TO_CHAR(

            ADD_MONTHS(SYSDATE, (60-T.AGE) * 12)

                          ,'YYYY') ||

            TO_CHAR(T.HIREDATE, '-MM-DD'), 'YYYY-MM-DD'),

                 T.HIREDATE) / 12 )

      ) AS "퇴직금",

 

     TRUNC( SYSDATE - T.HIREDATE )  AS "근무일수",

 

     TRUNC( TO_DATE(TO_CHAR(

            ADD_MONTHS(SYSDATE, (60-T.AGE) * 12)

                          ,'YYYY') ||

            TO_CHAR(T.HIREDATE, '-MM-DD'),'YYYY-MM-DD')

               - SYSDATE ) AS "남은일수"

 

FROM

(

SELECT SANO, NAME, JUBUN,

 

         CASE

         WHEN SUBSTR(JUBUN, 7, 1) IN ('1','3') THEN ''

         ELSE '' END  AS "GENDER",

 

         EXTRACT(YEAR FROM SYSDATE)

          - (CASE

          WHEN SUBSTR(JUBUN, 7, 1) IN ('1','2')

          THEN TO_NUMBER( SUBSTR(JUBUN, 1, 2) ) + 1900

          ELSE TO_NUMBER( SUBSTR(JUBUN, 1, 2) ) + 2000

          END )

          + 1 AS "AGE",

 

          NVL2(COMM, SAL*12 + COMM, SAL*12) AS "YEARPAY",

 

          HIREDATE

 

FROM TBL_NEWSAWON

) T;

 

/* WHERE T.GENDER = '' AND

           T.AGE BETWEEN 30 AND 39;

*/


close