select from_unixtime(unix_timestamp(concat(substr(add_months(current_date(),-1),1,7),'-01'),'yyyy-mm-dd'),'yyyymmdd') as ymd from xxxx limit 1;
select concat(substr(regexp_replace(add_months(current_date(),-1),'-',''),1,6),'01') as ymd from xxxx limit 1;
輸出均爲20191001
兩種方法都是用add_month 方法獲得 yyyy-mm-dd 格式,分別通過 unix_time 方法、替換字符串的方法 得到 yyyymmdd 的格式
oracle 實現相關功能就簡單了
trunc(current_date(), 'mm')
即可