我想从member_info表格中的DOB表格(出生日期)中选择当前系统日期
DESIGNATION DOB GENDER MARITAL_STATUS
STUDENT 4-Jun-1996 MALE SINGLE
BUSINESS OWNER 13-Sep-1981 MALE MARRIED
BUSINESS OWNER 1-Jan-1959 MALE MARRIED
答案 0 :(得分:1)
在 Oracle 中,您可以使用 SYSDATE 将日期和月份与 TO_CHAR 和正确的格式进行比较。
例如,
SQL> WITH dates AS(
2 SELECT 'Mark' names, to_date('4-Jun-1996', 'DD-Mon-YYYY') dt FROM dual UNION ALL
3 SELECT 'Henry' names, to_date('7-Apr-1981', 'DD-Mon-YYYY') dt FROM dual
4 )
5 SELECT names,
6 CASE
7 WHEN TO_CHAR(dt, 'MM/DD') = TO_CHAR(sysdate, 'MM/DD')
8 THEN 'Happy Birthday'
9 ELSE 'Not today'
10 END is_bday_today
11 FROM dates;
NAMES IS_BDAY_TODAY
----- --------------
Mark Not today
Henry Happy Birthday
SQL>