excel - SQL copy rows by date until today -
fyi date format : yyyy.mm.dd , want increment every rows 1 month
i have next sample table in excel:
id date cost 1 2013.01.01 20 2 2014.03.01 30 3 2014.04.01 30 4 2010.01.01 10
i need insert database duplicate rows until today so:
id date cost 1 2013.01.01 20 1 2013.02.01 20 1 2013.03.01 20 1 2013.04.01 20 .... 1 2014.10.01 20 2 2014.03.01 30 ... 2 2014.10.01 30 ... 4 2010.01.01 10 ... 4 2010.10.01 10
can advice me something, first thought java code wich generating dates, java info function not best. , want solve in sql or pl/sql or maybe excel .
assuming info in table, solve if have list of numbers. here 1 solution:
with m ( select trunc(sysdate) - min(date) + 1 numdays tablename t ), n ( select level - 1 n m connect level <= m.numdays + 1 ) select id, date + n.n date, cost tablename t bring together n on date + n.n <= sysdate;
edit:
to month, think next should work:
with m ( select months_between(trunc(sysdate), min(date)) + 1 nummonths tablename t ), n ( select level - 1 n m connect level <= m.nummonths + 1 ) select id, add_months(date, n.n) date, cost tablename t bring together n on add_months(date, n.n) <= sysdate;
sql excel oracle date plsql
No comments:
Post a Comment