问题
I have a table as follow:
|----------|----------|
| DT | FLAG |
|----------|----------|
| 2015-MAY | E |
| 2015-JUN | H |
| 2015-OCT | E |
| 2016-FEB | E |
|----------|----------|
That I would like to transform as follow:
|----------|----------|
| DT | FLAG |
|----------|----------|
| 2015-MAY | E |
| 2015-JUN | H |
| 2015-JUL | V |
| 2015-AUG | V |
| 2015-SEP | V |
| 2015-OCT | E |
| 2015-NOV | V |
| 2015-DEC | V |
| 2016-JAN | V |
| 2016-FEB | E |
|----------|----------|
Missing months are inserted with the FLAG V
Is there an easy way to that that ?
Thanks!
回答1:
Thanks jspcal for the link that inspired this answer.
Got it work with
CREATE OR REPLACE PROCEDURE FILL_DATE_GAP AS
BEGIN
INSERT INTO DUMMY_DATES
SELECT to_date(add_months(date '2015-01-01', level - 1), 'yyyy-mm-dd') mth,
'V'
FROM DUAL
connect by level <= 14
MINUS
SELECT DT,
FLAG
FROM DUMMY_DATES;
END FILL_DATE_GAP;
Demo
来源:https://stackoverflow.com/questions/50439903/sql-inserting-row-for-missing-months