table1
上有db1
。我在dbl上通过dbl在plsql过程中使用了另一个表table2
。{db2 . The
table2`。
我已使用游标从table1
获取所有主键,这样我的变量ar_col
就是table1
的PK列表。
现在我想从table2
获取这些值的所有值。如果我在table2
中没有值,我应该在结果中至少从table1
获得pk。
我使用了以下查询,但它返回空白
SELECT t1.col1, t2.col1, t2.col2, t2.col3,
FROM table1 t1
LEFT OUTER JOIN table2@db_link t2
ON t2.col1 = t1.col1
WHERE t2.col1 IN (ar_col);
我想在for循环中使用结果,所以我将在此查询中使用批量收集。 ar_col
是包含table1
P.S:
ar_column
的定义是
TYPE t_column IS TABLE OF TABLE_1.COLUMN_1%TYPE INDEX BY PLS_INTEGER;
ar_column t_column;
P.S2:ar_column
没有所有主键,只根据某些标准选择。
答案 0 :(得分:1)
这样的事情?
select *
from (
SELECT t1.col1,
t2.col1 t2col1,
t2.col2,
t2.col3,
FROM table1 t1, table2@db_link t2
where t1.col1 = t2.col1 (+)
)
WHERE t2col1 in (
select thePrimaryKeyCol (what is the col name here)
from table1
)