1

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

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
4

1 回答 1

3

直观的版本几乎是正确的。我只需要给表起别名就可以了...

select count(1) from table_of_my_messages m 
    where m.user_data.relatedid = 'abcdefgh';
于 2011-03-28T23:39:14.233 回答