Internet, Please help!
I am using Oracle DB v 12c, where invoice issuing time is stored as unix timestamp in column of type NUMBER + there is also a VARCHAR2(128) column, which defines the timezone where the invoice was issued, eg 'Europe/London'.
So invoices issued on local date '2020-10-10' can be queried like this:
SELECT inv.invoiceID
FROM invoices inv
WHERE TO_CHAR(
FROM_TZ(timestamp '1970-01-01 00:00:00'
+ NUMTODSINTERVAL(inv.INVOICETIME, 'SECOND'), 'UTC') AT TIME ZONE inv.timezoneName,
'YYYY-MM-DD') = '2020-10-10';
But unfortunately this query is not indexable.
The problem is, that this is not working:
CREATE INDEX Invoices_InvoiceDate ON Invoices (
TO_CHAR(
FROM_TZ(timestamp '1970-01-01 00:00:00'
+ NUMTODSINTERVAL(INVOICETIME, 'SECOND'), 'UTC') AT TIME ZONE timezoneName,
'YYYY-MM-DD')
);
Error: ORA-01743: only pure functions can be indexed
Because of using "AT TIME ZONE", what is "pure version" of this operator? Or in other words - how to property convert Unix timestamp to local date in Oracle?