Oracle:查询用户定义类型的值

发布于 2024-10-27 09:25:57 字数 1016 浏览 1 评论 0原文

我有一个用户定义的类型:

create or replace type my_message_type 
  as object (relatedid varchar2(50), payload clob);

我以编程方式插入了一条消息。 SQL Developer 将插入的对象呈现为:

SYNESSO.MY_MESSAGE_TYPE('abcdefgh','oracle.sql.CLOB@1dae16a')

How can query against this data using SQL?例如,以下内容似乎很直观:

select count(1) from table_of_my_messages where user_data.relatedid = 'abcdefgh';

但这会导致ORA-00904:“USER_DATA”。“RELATEDID”:无效标识符

然后我发现正确的语法是构造消息类型并使用相等性检查。但是如何构造一个类型的实例,其中一些字段与 any 匹配?:

select * from table_of_my_messages where user_data = my_message_type('abcdefgh', *);
-- ORA-00936: missing expression

select * from table_of_my_messages where user_data = my_message_type('abcdefgh');
-- ORA-02315: incorrect number of arguments for default constructor

select * from table_of_my_messages where user_data = my_message_type('abcdefgh', ?);
-- Missing IN or OUT parameter at index:: 1

I have a user-defined type:

create or replace type my_message_type 
  as object (relatedid varchar2(50), payload clob);

I inserted a message programatically. SQL Developer renders the inserted object as:

SYNESSO.MY_MESSAGE_TYPE('abcdefgh','oracle.sql.CLOB@1dae16a')

How can query against this data using SQL? For example the following seems intuitive:

select count(1) from table_of_my_messages where user_data.relatedid = 'abcdefgh';

But this results in ORA-00904: "USER_DATA"."RELATEDID": invalid identifier.

I then discovered the correct syntax is to construct the message type and use equality checking. But how to construct an instance of the type with some of the fields matched to any?:

select * from table_of_my_messages where user_data = my_message_type('abcdefgh', *);
-- ORA-00936: missing expression

select * from table_of_my_messages where user_data = my_message_type('abcdefgh');
-- ORA-02315: incorrect number of arguments for default constructor

select * from table_of_my_messages where user_data = my_message_type('abcdefgh', ?);
-- Missing IN or OUT parameter at index:: 1

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

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

发布评论

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

评论(1

尤怨 2024-11-03 09:25:57

直观的版本几乎是正确的。我只需要为表添加别名即可使其工作......

select count(1) from table_of_my_messages m 
    where m.user_data.relatedid = 'abcdefgh';

The intuitive version is almost correct. I needed only to alias the table for it to work...

select count(1) from table_of_my_messages m 
    where m.user_data.relatedid = 'abcdefgh';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文