我有一个带有条目的常规表和几个类型的声明:
create TYPE entity as OBJECT ( attribute1 NUMBER);
create TYPE entity_array as OBJECT of entity;
现在我想在我的表中使用sql工作表连接声明的entity_array
对象:
DECLARE
entity_array_obj entity_array := entity_array(
entity(11111),
entity(22222)
);
BEGIN
select * from mytable as t1
inner join entity_array_obj as t2 on (t1.attribute1 = t2.attribute1);
END;
我收到编译错误:
PL/SQL: ORA-00933: SQL command not properly ended
请建议
答案 0 :(得分:4)
create type entity as object ( attribute1 number);
create type entity_array as table of entity;
create table mytable(attribute1 number);
insert into mytable values (11111);
declare
entity_array_obj entity_array := entity_array(
entity(11111),
entity(22222)
);
v_count number;
begin
select count(*)
into v_count
from mytable t1
join table(entity_array_obj) t2
on t1.attribute1 = t2.attribute1;
dbms_output.put_line('Count: '||v_count);
end;
/
以下是对代码所做的主要更改:
as OBJECT of entity;
更改为as TABLE of entity;
。您可能没有注意到此错误,因为某些IDE会抑制代码编译错误。table()
运算符将集合转换为行源。