Oracle 11g 数据库上的 Oracle ORA-01805

发布于 2024-12-08 16:20:29 字数 989 浏览 3 评论 0原文

我们的 Oracle 10g 数据库最近升级到了 11g。该数据库在 Windows Server 2003 X64 计算机上运行。在来自 .NET 应用程序访问具有 TIMESTAMP (6) WITH TIME ZONE 数据列的表的 SQL 查询中,我收到以下异常。

System.Data.OracleClient.OracleException:ORA-01805:日期/时间操作中可能出现错误

针对例外情况的建议操作是确保客户端和服务器版本相同:

ORA-01805: 日期/时间操作中可能出现错误 原因:客户端和服务器上的时区文件不匹配。根据本地时区文件,操作可能会导致错误的结果。 操作:请确保客户端和服务器时区版本相同。

我运行了以下查询来检查相关数据库的时区。我还没有找到有关如何为客户端设置时区(或更改时区文件)的信息。

SELECT dbtimezone FROM DUAL;
select * from v$timezone_file;

DBTIMEZONE 
---------- 
+00:00     

FILENAME             VERSION                
-------------------- ---------------------- 
timezlrg_14.dat      14     

我假设客户端指的是我安装的即时客户端,版本为 11_2?我通过 .NET Framework 提供的 System.Data.OracleClient.OracleConnection 运行查询。 UI 假设“时区版本”指的是时区文件版本。我没有看到即时客户端哪里有时区文件。任何建议都表示赞赏。

Our Oracle 10g database was recently upgraded to 11g. The database is running on a Windows Server 2003 X64 machine. In SQL queries from a .NET application that access a table that has a TIMESTAMP (6) WITH TIME ZONE data columns, I am getting the following exception.

System.Data.OracleClient.OracleException : ORA-01805: possible error in date/time operation

The suggested action for the exception is to ensure that the client and server are the same version:

ORA-01805: possible error in date/time operation
Cause: The timezone files on client and server do not match. Operation can potentially result in incorrect results based on local timezone file.
Action: Please ensure client and server timezone versions are same.

I've ran the following queries to check the timezone on the database in question. I haven't found information on how I set the timezone (or change the timezone file) for the client.

SELECT dbtimezone FROM DUAL;
select * from v$timezone_file;

DBTIMEZONE 
---------- 
+00:00     

FILENAME             VERSION                
-------------------- ---------------------- 
timezlrg_14.dat      14     

I assume the client is referring to the Instant Client I have installed, which is version 11_2? I'm running the queries through a System.Data.OracleClient.OracleConnection as provided by the .NET Framework. U I assume by "timezone version" it's referring to the timezone file versions. I don't see where the instant client has a timezone file. Any suggestions are appreicated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

手心的海 2024-12-15 16:20:29

我确定我安装了版本 11_2_0_1 的即时客户端。升级到11_2_0_2似乎已经缓解了这个问题。但是,我仍然不清楚即时客户端如何管理它的时区文件,甚至不清楚它在哪里或它是什么。我读过的所有资料都说要确保客户端和服务器具有相同的时区文件版本,但我不清楚客户端上实际上是如何完成的。也许除了使用不同版本的即时客户端之外我无法直接维护它?

I determined that I had version 11_2_0_1 of the instant client installed. Upgrading to 11_2_0_2 seems to have relieved this issue. However, I'm still not clear on how the instant client manages it timezone file, or even where it is or what it is. All the sources I've read say to ensure that the client and server have the same timezone file version, but it's not clear to me how that is actually done on the client. Perhaps it's not something I can directly maintain beyond using a different version of the instant client?

扶醉桌前 2024-12-15 16:20:29

使用“genezi -v”了解时区文件版本。

这是我的 Linux 盒子中的一个示例:

$ genezi -v
Client Shared Library 32-bit - 11.2.0.2.0

System name:    Linux
Release:    2.6.32-34-generic
Version:    #77-Ubuntu SMP Tue Sep 13 19:39:17 UTC 2011
Machine:    x86_64

Operating in Instant Client mode.
Small timezone file = timezone_14.dat
Large timezone file = timezlrg_14.dat

Use "genezi -v" to know the timezone file version.

Here is a sample in my Linux box:

$ genezi -v
Client Shared Library 32-bit - 11.2.0.2.0

System name:    Linux
Release:    2.6.32-34-generic
Version:    #77-Ubuntu SMP Tue Sep 13 19:39:17 UTC 2011
Machine:    x86_64

Operating in Instant Client mode.
Small timezone file = timezone_14.dat
Large timezone file = timezlrg_14.dat
酒解孤独 2024-12-15 16:20:29

除了其他原因之外,当您进行时区转换并使用版本比数据库高得多的 cx-Oracle 库时,使用 python3.6 也会出现该问题。

它解释了“Manuel Pinot”的评论。当他评论 TZ 转换线时,它就起作用了。

我在使用最新的 cx-Oracle 8.1.0 的 python 3.6 中遇到了同样的问题,但连接到旧数据库 12.1。

  • 使用的python:python3.6
  • 安装了最新的cx-Oracle版本8.1.0(通常用于18-19.x左右的版本)
  • 连接的数据库:12.1.0.2
  • Oracle即时客户端12.2

调用不带时区转换的查询工作正常:

sql='''select cast (sysdate AS TIMESTAMP WITH TIME ZONE) from dual'''
cur.execute(sql)
cur.fetchone()
(datetime.datetime(2020, 12, 28, 17, 7, 52),)

调用类似的查询时区转换失败:

sql='''select cast (sysdate AS TIMESTAMP WITH TIME ZONE) AT TIME ZONE 'UTC' from dual'''
cur.execute(sql)
cur.fetchone()
*** cx_Oracle.DatabaseError: ORA-01805: possible error in date/time operation

我的解决方案:降级到较旧的 cx-Oracle 客户端(Oracle-instant 客户端 12.2 保持不变)

pip install -U cx-Oracle==6.4.1
Collecting cx-Oracle==6.4.1
  Using cached cx_Oracle-6.4.1-cp36-cp36m-manylinux1_x86_64.whl (596 kB)
    Installing collected packages: cx-Oracle
  Attempting uninstall: cx-Oracle
    Found existing installation: cx-Oracle 8.1.0
    Uninstalling cx-Oracle-8.1.0:
      Successfully uninstalled cx-Oracle-8.1.0
Successfully installed cx-Oracle-6.4.1

现在再次测试时区转换:

sql='''select cast (sysdate AS TIMESTAMP WITH TIME ZONE) AT TIME ZONE 'UTC' from dual'''
cur.execute(sql)
cur.fetchone()
(datetime.datetime(2020, 12, 28, 17, 20, 54),)

Beside other reasons, the problem occurs also using python3.6, when you're doing a timezone conversion and using cx-Oracle libraries with much higher version than database.

It explains the comment from "Manuel Pinot". As soon as he comments the TZ conversion line, it works.

I had the same issue with python 3.6 using most recent cx-Oracle 8.1.0, but connected to old database 12.1.

  • Used python: python3.6
  • Installed most recent cx-Oracle Version 8.1.0 (usually for releases around 18-19.x)
  • Connected database: 12.1.0.2
  • Oracle instant client 12.2

Calling a query without timezone conversion works fine:

sql='''select cast (sysdate AS TIMESTAMP WITH TIME ZONE) from dual'''
cur.execute(sql)
cur.fetchone()
(datetime.datetime(2020, 12, 28, 17, 7, 52),)

Calling similar query with timezone conversion fails:

sql='''select cast (sysdate AS TIMESTAMP WITH TIME ZONE) AT TIME ZONE 'UTC' from dual'''
cur.execute(sql)
cur.fetchone()
*** cx_Oracle.DatabaseError: ORA-01805: possible error in date/time operation

Solution in my case: Downgrade to older cx-Oracle client (Oracle-instant client 12.2 keeps unchanged)

pip install -U cx-Oracle==6.4.1
Collecting cx-Oracle==6.4.1
  Using cached cx_Oracle-6.4.1-cp36-cp36m-manylinux1_x86_64.whl (596 kB)
    Installing collected packages: cx-Oracle
  Attempting uninstall: cx-Oracle
    Found existing installation: cx-Oracle 8.1.0
    Uninstalling cx-Oracle-8.1.0:
      Successfully uninstalled cx-Oracle-8.1.0
Successfully installed cx-Oracle-6.4.1

Now testing again with timezone conversion:

sql='''select cast (sysdate AS TIMESTAMP WITH TIME ZONE) AT TIME ZONE 'UTC' from dual'''
cur.execute(sql)
cur.fetchone()
(datetime.datetime(2020, 12, 28, 17, 20, 54),)
明明#如月 2024-12-15 16:20:29

我在 Oracle 11G 中使用 Docker 时遇到了同样的问题,即

ActiveRecord::StatementInvalid (OCIError: ORA-01805: possible error in date/time operation: SELECT  "USERS".* FROM "USERS" WHERE "USERS"."EMAIL" = :a1 ORDER BY "USERS"."ID" ASC FETCH FIRST :a2 ROWS ONLY):

我在 docker-compose.yml 中使用的

    environment:
      - TZ=America/Guatemala

ORA-01505所以只需注释该行即可,一切正常

      environment:
      #- TZ=America/Guatemala

I have the same problem whit ORA-01505 in Oracle 11G using Docker

ActiveRecord::StatementInvalid (OCIError: ORA-01805: possible error in date/time operation: SELECT  "USERS".* FROM "USERS" WHERE "USERS"."EMAIL" = :a1 ORDER BY "USERS"."ID" ASC FETCH FIRST :a2 ROWS ONLY):

I was using in the docker-compose.yml

    environment:
      - TZ=America/Guatemala

So just comment the line and every thing works

      environment:
      #- TZ=America/Guatemala
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文