I have a SQL query which selects only four columns from a table and adds to it another column which will be the result of a function. The function is to produce dates, it takes a number as parameter and adds it to SYSDATE to produce future days:
CREATE OR REPLACE FUNCTION future(p_day NUMBER)
RETURN DATE
IS
--
v_date DATE;
--
BEGIN
--
v_date := SYSDATE + p_day;
RETURN v_date;
--
END;
The feature of the SQL column selections are:
- first three columns are unique combination and this this is done by grouping by SELECT a, b, c FROM table GROUP BY a, b, c;
- the fourth column (h) is numeric values for ease I just say 1-10
so currently in the original table each unique combination of a, b, c has 1 to 10
assigned:
-+----+----+----+----+-
| a | b | c | h | <----Column names
-+----+----+----+----+-
| a1 | b1 | c1 | 1 |
-+----+----+----+----+-
| a1 | b1 | c1 | 2 |
-+----+----+----+----+-
| a1 | b1 | c1 | 3 |
-+----+----+----+----+-
| a1 | b1 | c1 | 4 |
-+----+----+----+----+-
: : : :
: : : :
-+----+----+----+----+-
| a1 | b1 | c1 | 9 |
-+----+----+----+----+-
| a1 | b1 | c1 | 10 |
-+----+----+----+----+-
| a1 | b1 | c2 | 1 |
-+----+----+----+----+-
| a1 | b1 | c2 | 2 |
-+----+----+----+----+-
: : : :
: : : :
so now I have to add dates between column c and h by using my function(or any other methods that will do the same job) which will be 7 days in the future and the column should change so that for each day there is a unique combination and 10 numeric values. Thant means if there are 50 a, b, c combination the rows of the query will be 50*7*10 = 3500. now I don't know how to insert the seven days. I thought about the FOR i IN 1..7 LOOP but still can't figure it out. Please give me some advice