Oracle:查询用户定义类型的值
我有一个用户定义的类型:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
直观的版本几乎是正确的。我只需要为表添加别名即可使其工作......
The intuitive version is almost correct. I needed only to alias the table for it to work...