How can I set relative dates using PL/SQL?
For example: I must load information in a summary table for the period 15 of last month and 16 of the current month. Is there any way to establish that period without the need to use fixed dates and use relative dates?
For example: Do not set with a 《 where period between 12/15/2019 and 01/16/2020 》 but that query can be run dynamically each month without the need to "burn the dates (period)"
Thanks in advance to whoever 《can enlighten me on logic》
you can put the following:
That would make the period go between the current date and 30 days less.
Now, if what you want is for it to be exactly the 15th of the previous month and the 16th of the current month, I would make a function that returns a date, and the function would take the
sysdate
validate how far away it is from the 16th, add or subtract depending on that distance, and subtract 30 from the resulting date, so you could use something like:Where 2 and 1 would be parameters to know if it returns the end date (16th of the month) or the start date (start date - 30).