For the below table structure and data, I am trying to get rows that contain at least 1 date within the last 15 months for a column having string groups separated by a pattern.
CREATE TABLE TEMP(nbr NUMBER, dt VARCHAR2(4000));
INSERT INTO TEMP VALUES(1,'22/05/2016');
INSERT INTO TEMP VALUES(2,'22/05/2020##22/01/2020##22/10/2019');
INSERT INTO TEMP VALUES(3,'25/05/2020##22/07/2019##22/11/2019');
INSERT INTO TEMP VALUES(4,'25/05/2015##22/01/2017##22/06/2018');
The query that I have written is :
select nbr,dt from temp
WHERE MONTHS_BETWEEN(SYSDATE,TO_DATE(REGEXP_SUBSTR(dt,'[^##]+',1,LEVEL)))<15
CONNECT BY LEVEL<=REGEXP_COUNT(dt,'[^##]+');
For rows 2 and 3,the value of attribute dt is such that at least 1 of the substrings have a date less than 15 months old. Expected result is :
nbr dt
2 22/05/2020##22/01/2020##22/10/2019
3 25/05/2020##22/07/2019##22/11/2019
The result that I am getting is:https://i.stack.imgur.com/rZ1tp.jpg
I am sure that this query is missing something because of which I am getting all those duplicate rows. This is the first time that I am attempting something of this kind. Can someone point out to me what is that I need to do to correct this?