我有一个用户定义的类型:
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')
如何使用 SQL 查询这些数据?例如以下看起来很直观:
select count(1) from table_of_my_messages where user_data.relatedid = 'abcdefgh';
但这导致ORA-00904: "USER_DATA"."RELATEDID": invalid identifier
.
然后我发现正确的语法是构造消息类型并使用相等检查。但是如何构造一个与某些字段匹配的类型的实例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