Home > database >  SQL query small white have great god instructs
SQL query small white have great god instructs

Time:10-22

SQL small white, there is problem with please the great god, now there are two fields,
Field 1: "effective date" field value format for the 2020-9-15,
Column 2: "expiration date", the field values for five months,
Now I want to send this two values into a format for "2020/9/15-2021/2/15", how do you write the SQL???????

CodePudding user response:

To_char (to_date (' 2020-9-15 ', '- dd yyyy - mm'), 'yyyy/mm/dd) | |' - '| | to_char (add_months (to_date (' 2020-9-15', '- dd yyyy - mm), 5),' yyyy/mm/dd)

CodePudding user response:

WITH
T1 AS (SELECT the '2020-9-15 s' D FROM DUAL),
T2 AS (SELECT TO_DATE (D, 'YYYY/MM/DD) D1,
ADD_MONTHS (TO_DATE (D, 'YYYY/MM/DD), 5) D2 FROM T1)
The SELECT TO_CHAR (D1, 'YYYY/MM/DD) | |' - '| | TO_CHAR (D2,' YYYY/MM/DD) FROM T2
  • Related