[英]Oracle - using nested table column in where clause
I have a staging table (table_B) with columns using nested table data types: 我有一个临时表(table_B),其中的列使用嵌套表数据类型:
CREATE OR REPLACE TYPE nested_column_type AS OBJECT
(
abc_1 VARCHAR2(100),
abc_2 VARCHAR2(100),
col_id VARCHAR2(100),
tbl_id NUMBER
);
CREATE OR REPLACE TYPE nested_column_tab AS TABLE OF nested_column_type;
CREATE TABLE table_B
(col_id NUMBER,
nested_column NESTED_COLUMN_TAB)
NESTED TABLE nested_column STORE AS column_nested);
I want to use nested_column in the where clause of a delete statement like this: 我想在delete语句的where子句中使用nested_column,如下所示:
DELETE FROM table_A a
WHERE tbl_id = v_tbl_id
AND NOT EXISTS (SELECT col_id
FROM TABLE(SELECT b.nested_column
FROM table_B b
WHERE tbl_id = v_tbl_id)
WHERE col_id = a.col_id);
Table_A is my target table. Table_A是我的目标表。 My goal is to delete records from table_A where table_A.col_id NOT EXISTS in table_B.nested_column.col_id and tbl_id = v_tbl_id. 我的目标是从table_A中删除记录,其中table_B.nested_column.col_id中的table_A.col_id不存在,并且tbl_id = v_tbl_id。
Adding more on what @Ted mentioned, you need to understand object name resolution steps and must use a table alias. 在@Ted提到的内容上添加更多内容,您需要了解对象名称解析的步骤,并且必须使用表别名。 This is mentioned here . 这是提到在这里 。
To avoid inner capture and similar problems resolving references, Oracle Database requires you to use a table alias to qualify any dot-notational reference to subprograms or attributes of objects. 为避免内部捕获和解决引用的类似问题,Oracle数据库要求您使用表别名来限定对子程序或对象属性的任何点符号引用。
In your case the query becomes: 在您的情况下,查询变为:
DELETE FROM table_A a
WHERE tbl_id = v_tbl_id
AND a.col_id NOT IN (SELECT b.col_id
FROM table_B b
WHERE (SELECT tb.tbl_id
FROM TABLE (b.nested_column) tb) =a.tbl_id);
I think the below will put you in the right path: 我认为以下内容将使您走上正确的道路:
select t.primary_id, nt.*
from table_b t, table (t.nested_column) nt
For any further clarifications please don't hesitate to contact me again here. 如有任何其他澄清,请随时在这里与我联系。
Ted 摊晒
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.