如何在 where 子句中包含 USER_VIEWS.TEXT 列

发布于 2024-10-30 07:38:22 字数 398 浏览 3 评论 0原文

这似乎应该是一件很容易弄清楚的事情,但我正在努力寻找任何答案。

我希望能够查询 Oracle 中的 USER_VIEWS 表以查找使用特定表的其他视图。

像这样的东西:

从用户视图中选择视图名称、文本 WHERE 文本 LIKE'%MY_TABLE%'

我收到错误: ORA-00932:数据类型不一致:预期的 NUMBER 为 LONG

TEXT 的数据类型为 LONG,在 TOAD 中显示为 WIDEMEMO。

我尝试过将其转换为 to_char 并连接。我尝试创建另一个仅包含 TEXT 数据的表,结果出现 ORA-00997:非法使用 LONG 数据类型。

有什么想法吗?

谢谢!

This seems like it should have been an easy thing to figure out but I am struggling to find any answers.

I want to be able to query against the USER_VIEWS table in Oracle to find other views that are using a particular table.

Something like:

SELECT view_name, text FROM user_views
WHERE text LIKE'%MY_TABLE%'

I get the error:
ORA-00932: inconsistent datatypes: expected NUMBER got LONG

The datatype for TEXT is LONG and in TOAD it shows WIDEMEMO.

I have tried casting it, to_char and concatenating. I tried creating another table with just the TEXT data and I get ORA-00997: illegal use of LONG datatype.

Any ideas?

Thanks!

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

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

发布评论

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

评论(3

树深时见影 2024-11-06 07:38:22

从技术上讲,您可以使用 DBMS_METADATA 包获取 CLOB 中视图的 DDL,然后解析它以查找对表的引用。但还有比查看视图定义更简单的解决方案。

Oracle 在 USER_DEPENDENCIES 视图(或 ALL_DEPENDENCIESDBA_DEPENDENCIES)中维护有关对象依赖关系的信息,具体取决于您的权限级别以及是否尝试跟踪依赖关系跨模式)。使用这些视图效果会更好。

SQL> create table base_table (
  2    col1 number
  3  );

Table created.

SQL> create view my_view
  2  as
  3  select *
  4    from base_table;

View created.

SQL> select name, type
  2    from user_dependencies
  3   where referenced_name = 'BASE_TABLE';

NAME                           TYPE
------------------------------ ------------------
MY_VIEW                        VIEW

如果您使用USER_DEPENDENCIES 视图,您还可以使用依赖对象树执行更复杂的操作。如果我创建依赖于第一个视图的第二个视图,我可以很容易地看到两个视图最终都使用基表。

SQL> create view my_view2
  2  as
  3  select *
  4    from my_view;

View created.

SQL> ed
Wrote file afiedt.buf

  1  select level, name, type
  2    from user_dependencies
  3  start with referenced_name = 'BASE_TABLE'
  4* connect by referenced_name = prior name
SQL> /

     LEVEL NAME                           TYPE
---------- ------------------------------ ------------------
         1 MY_VIEW                        VIEW
         2 MY_VIEW2                       VIEW

Technically, you could use the DBMS_METADATA package to get the DDL for the view in a CLOB and then parse that looking for a reference to your table. But there are far easier solutions than looking at the view definition.

Oracle maintains information about object dependencies in the USER_DEPENDENCIES view (or ALL_DEPENDENCIES or DBA_DEPENDENCIES depending on your privilege levels and whether you're trying to track dependencies across schemas). You're far better off using those views

SQL> create table base_table (
  2    col1 number
  3  );

Table created.

SQL> create view my_view
  2  as
  3  select *
  4    from base_table;

View created.

SQL> select name, type
  2    from user_dependencies
  3   where referenced_name = 'BASE_TABLE';

NAME                           TYPE
------------------------------ ------------------
MY_VIEW                        VIEW

If you're using the USER_DEPENDENCIES view, you can also do more sophisticated things with the tree of dependent objects. If I create a second view that depends on the first, I can easily see that both views eventually use the base table.

SQL> create view my_view2
  2  as
  3  select *
  4    from my_view;

View created.

SQL> ed
Wrote file afiedt.buf

  1  select level, name, type
  2    from user_dependencies
  3  start with referenced_name = 'BASE_TABLE'
  4* connect by referenced_name = prior name
SQL> /

     LEVEL NAME                           TYPE
---------- ------------------------------ ------------------
         1 MY_VIEW                        VIEW
         2 MY_VIEW2                       VIEW
最冷一天 2024-11-06 07:38:22

您不能将 LIKE 与 LONG 列一起使用。不过,您可以编写自己的自定义函数来执行搜索 - 请参阅 http://www. techonthenet.com/oracle/questions/long_value.php
您还可以创建一个表并将 LONG 列转换为 CLOB 列:

create table my_tab as
select to_lob(text) from user_views;

另请参阅 http:// /www.dba-oracle.com/oracle_news/2005_5_9_converting_long_lob_data_types.htm

You cannot use LIKE with LONG columns. You could write your own custom function to perform the search, though - see http://www.techonthenet.com/oracle/questions/long_value.php
You could also create a table and convert the LONG column to a CLOB column:

create table my_tab as
select to_lob(text) from user_views;

see also http://www.dba-oracle.com/oracle_news/2005_5_9_converting_long_lob_data_types.htm

脱离于你 2024-11-06 07:38:22

如果您只想在 TOAD 的数据网格中查看它,那么您可以打开预览:

View =>蟾蜍选项=>数据网格 =>数据=> [x] 预览 CLOB 和 LONG 数据

我正在使用 TOAD 10.5.1.3

If you just want to see it in TOAD's datagrid then you can turn on the preview:

View => Toad Options => Data Grids => Data => [x] Preview CLOB and LONG data

I'm using TOAD 10.5.1.3

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