很多事情。
SQL> with test (year, month) as
2 (select '2022', '4' from dual)
3 select to_date(year ||'-'|| lpad(month, 2, '0') || '-01', 'yyyy-mm-dd') result
4 from test;
RESULT
--------------------
01-APR-22
SQL>
不过,由于你似乎想要当月的1号,你可以将其缩短为
SQL> with test (year, month) as
2 (select '2022', '4' from dual)
3 select to_date(year || month, 'yyyymm') result
4 from test;
RESULT
--------------------
01-APR-22
SQL>
这个
LAST_DAY
选项:
SQL> with test (year, month) as
2 (select '2022', '4' from dual)
3 select
4 to_date(year ||'-'|| lpad(month,2,0) ||'-01','YYYY-MM-DD') as firstday,
5 last_day(to_date(year ||'-'|| lpad(month,2,0) ||'-01','YYYY-MM-DD')) as lastday
6 from test;
FIRSTDAY LASTDAY
---------- ----------
01.04.2022 30.04.2022
SQL>