2015-05-28 54 views

回答

0

您可以使用EXTRACT

SELECT * 
FROM CUSTOMERS 
WHERE EXTRACT(MONTH FROM dateofbirth) < EXTRACT(MONTH FROM SYSDATE) 
OR  ( EXTRACT(MONTH FROM dateofbirth) = EXTRACT(MONTH FROM SYSDATE) 
     AND EXTRACT(DAY FROM dateofbirth) <= EXTRACT(DAY FROM SYSDATE)) 

,或者您可以使用TO_CHARMMDD日年格式的

SELECT * 
FROM CUSTOMERS 
WHERE TO_CHAR(dateofbirth, 'MMDD') <= TO_CHAR(SYSDATE, 'MMDD') 
+0

這是爲什麼downvoted?我目前正在使用EXTRACT來獲得我需要的東西 –

0
select to_char(to_date('27-01-1966','DD-MM-YYYY'),'MMDD'),to_char(sysdate,'MMDD'), 
CASE WHEN to_char(to_date('27-01-1966','DD-MM-YYYY'),'MMDD') > to_char(sysdate,'MMDD') 
    THEN 'No' 
    ELSE 'Yes' 
END 
from dual; 

所以

WHERE to_char(dateofbirth,'MMDD') < to_char(sysdate,'MMDD') 
1

我提出了以下解決方案

SELECT 
    name, 
    TO_CHAR(dob,'mm') MONTH, 
    TO_CHAR(dob,'dd') DAY 
FROM 
    target_table 
WHERE 
    TO_CHAR(sysdate,'yyyy') =2015 
AND 
    (
    to_number(TO_CHAR(dob,'mm'))<to_number(TO_CHAR(sysdate,'mm')) 
    OR 
    (
     TO_CHAR(dob,'mm') =TO_CHAR(sysdate,'mm') 
    AND TO_CHAR(dob,'dd')<=TO_CHAR(sysdate,'dd') 
    ) 
); 

我寫的代碼基於我的表中的數據...... DOB出生

tartget_table的= =日期所需的表