【问题标题】:View to determine if a LOB column is NULL through a database link通过数据库链接查看以确定 LOB 列是否为 NULL
【发布时间】:2020-05-16 23:40:10
【问题描述】:

一个新列(BLOB 类型)已添加到远程数据库表中。我维护的应用程序通过一个视图读取该表,该视图是数据库链接上的简单选择语句。我需要更新视图,以便可以访问新列。

显然,您无法通过数据库链接读取 LOB 列:

ORA-22992: 无法使用从远程表中选择的 LOB 定位器

到目前为止,我只需要知道行是否有数据。此查询完美无缺:

select foo_id, foo_name, foo_date,
case
    when foo_binary is not null then 1
    else 0
end as has_foo_binary_data
from remote_table@remote_database;

但除非删除 case 表达式,否则我无法创建视图:

create view remote_foo as
select foo_id, foo_name, foo_date,
case
    when foo_binary is not null then 1
    else 0
end as has_foo_binary_data
from remote_table@remote_database;

RA-22992:无法使用从远程表中选择的 LOB 定位器

DBMS_LOB.GETLENGTH(foo_binary) 开始可爱的 catch-22:

ORA-02069:此操作的 global_names 参数必须设置为 TRUE

alter session set global_names = true`;
create view ...

ORA-02085: 数据库链接 remote_database 连接到 remote_sid

原因:数据库链接连接到具有不同名称的数据库。连接被拒绝。

操作:创建一个与其连接的数据库同名的数据库链接,或设置 global_names=false。

不知道我是不是碰壁了,或者我只是在犯愚蠢的错误。有什么方法可以获取关于视图中工作的 CLOB(不是 blob 数据)的任何信息?

【问题讨论】:

  • 我猜你必须用 case 表达式在 remote db 上定义一个视图。

标签: oracle oracle11g


【解决方案1】:

你已经发布了很多信息,所以我不会重复。

这是您可能要考虑的一个选项;不是完美的,它取决于它是否可以。无论如何:

更改远程数据库中的表并添加新列:

alter remote_table add foo_binary_length number;

将其填充到数据库触发器中:

create or replace trigger trg_biu_remtab
  before insert or update on remote_table
  for each row
begin
  :new.foo_binary_length := dbms_lob.getlength(:new.foo_binary);
end;
/

现在在本地数据库中创建视图是一项简单的任务:

create view remote_foo as
select foo_id, foo_name, foo_date,
case
    when foo_binary_length > 0 then 1      --> this
    else 0
end as has_foo_binary_data
from remote_table@remote_database;

【讨论】:

  • 我明白了...如果我要获得已经发送的信息,我可以只获得一个使用 case 表达式创建的虚拟列。无论如何都不确定它有多可行(非常企业化的环境,有很多官僚作风)。 叹息
  • 对,一个虚拟列——出于某种原因(我无法解释),我相信它是在 12c 中引入的。更好的是,您不需要“昂贵”的触发器。
猜你喜欢
  • 2010-11-13
  • 1970-01-01
  • 2022-01-17
  • 2015-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-01
相关资源
最近更新 更多