티스토리 뷰

Database

[ORACLE]나이구하기쿼리

애플자라 2012. 11. 9. 15:40
반응형

SELECT *
FROM
(
SELECT CUSTOMER_NM,
        SUBSTR(REGIDENT_ID, 7, 1),
        REGIDENT_ID,
        TRANSLATE (SUBSTR(REGIDENT_ID, 0, 2), 'X0123456789', 'X'),
        2012 - TO_NUMBER(DECODE(SUBSTR(REGIDENT_ID, 7, 1), '3', 20, '4', 20, 19) || SUBSTR(REGIDENT_ID, 0, 2)) AS AGE,
        REGISTER_DT
FROM CUSTOMER
WHERE SERVICE_CD1 ='Y'
AND ACTIVE_YN = '1'
AND TRANSLATE (SUBSTR(REGIDENT_ID, 0, 2), 'X0123456789', 'X') IS NULL -- 숫자만 가져오는
--AND TRANSLATE (SUBSTR(REGIDENT_ID, 0, 2), 'X0123456789', 'X') IS NOT NULL
-- 문자만 가져오는
) X
WHERE AGE > 65

 

SELECT DECODE (
          SIGN (
             TRANSLATE ('4312a',
                        '0123456789abcdefghijklmnopqrstuvwxyz',
                        '000000000011111111111111111111111111')),1, '문자','숫자')T
  FROM DUAL;

SELECT TRANSLATE ('123AB', 'X0123456789', 'X') FROM DUAL

반응형
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함