Adding a local variable as a day interval to a timestamp column

Database
Enthusiast

Adding a local variable as a day interval to a timestamp column

Just wanted to give this tip as I could not find help online....

If you are struck in a situation to add a variable to a timestamp column, you have to cast that variable to that particular interval day or minute or second.

Eg:

DECLARE v_DAY_INT INTEGER;

SELECT CURRENT_TIEMSTAMP(3)+INTERVAL :v_DAY_INT DAY ; does not work.

SELECT CURRENT_TIEMSTAMP(3)+CAST(:v_DAY_INT AS INTERVAL DAY) will work.

Also, you should know that you cannot cast a timestamp to a date column and then add a day. 

Hopefully this helps someone.

Regards,

SS