我是pl / sql的新手,我不能让这个查询运行 我希望它找到两个表之间的差异,然后输出这些事务的ID 任何帮助将不胜感激!
SET SERVEROUTPUT ON
DECLARE
diff_id varchar2(50);
diff_id2 varchar2(50);
BEGIN
FOR dcount IN
SELECT
O.transid ,
ABB.transid
into diff_id, diff_id2
FROM
(SELECT *
FROM O.transactions
AND abdate >= trunc(sysdate -3)
) O
FULL OUTER JOIN
(SELECT *
FROM ABB.transactions
AND abdate >= trunc(sysdate -3)
) ABB
ON O.transid = ABB.transid
LOOP
DBMS_OUTPUT.put_line (employee_rec.diff_id);
DBMS_OUTPUT.put_line (employee_rec.diff_id2);
END LOOP;
END;
答案 0 :(得分:0)
我想要的输出是不在两者中的交易的id 表。即375和480
啊,是的,375和480. 832怎么样?
无论如何:你不需要PL / SQL来做到这一点。 SET运营商会有什么好处吗?例如,如果要从第一个表中获取未包含在第二个表中的ID,则使用
select id from first_table
minus
select id from second_table;
两种方式?
select 'in 1st, not in 2nd' what, id
from (select id from first_table
minus
select id from second_table)
union all
select 'in 2nd, not in 1st', id
from (select id from second_table
minus
select id from first_table);
如有必要,请应用其他条件(例如,ABDATE列)。