Problem: Incorrect displaying of time difference (in months) between Python and Oracle

  Kiến thức lập trình

The background of my problem is:

  • there’s SQL query in Python that extracts particular data from Oracle database
  • one column/information that is extracted from Oracle is information about how long a customer has open account by the company (in years)

The particular part of the query:

ROUND(MONTHS_BETWEEN(sysdate, TO_DATE(c.registration_date, ‘dd.mm.yy’)) / 12, 1) AS Years_Client

The problem:

  • when I run the query in Oracle (SQL Developer), I receive correct values
  • BUT when I run the query within Python code, it returns a column that contains both negative values or really high values (e.g. 21), which in the first place is a nonsense and in the second as well (as the company even doesn’t exist that long)

<class ‘pandas.core.series.Series’>

  • checked Oracle documentation
  • tired to run the whole query both in Oracle SQL Developer and Python
  • it works perfectly fine in Oracle, but not in Python

New contributor

Oskar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT