我对Oracle很陌生。
当我尝试实现以下逻辑时,我才陷入困境。我在oracle中创建一个sql脚本,它将帮助我生成一个报告。这个脚本每天运行两次,所以下次运行时我不应该选择相同的文件。
1)当作业运行时,运行查询并保存结果setand将订单ID存储在临时表中@ 11 Am 2)第二次运行查询@ 3 pm检查临时表并返回不在临时表中的结果集。
以下查询将生成结果集,但不确定如何创建临时表并在运行时有效。
select
rownum as LineNum,
'New' as ActionCode,
ORDER_ID,
AmountType,
trun(sysdate),
trun(systime)
from crd.V_IVZ_T19 t19
where
(t19.acct_cd in
(select fc.child_acct_cd
from cs_config fc
where fc.parent_acct ike 'G_TRI_RPT'))
and t19.date>= trunc(sysdate)
and t19.date<= trunc(sysdate);
任何帮助非常感谢。我不知道如何只获得时间戳。
答案 0 :(得分:1)
TEMP表不是这里的想法,导致临时表数据不会长时间存储数据(仅用于会话),您只需要创建一个普通表。希望它会对你有所帮助:
--- table for storing ORDER_ID for further checking, make a correct DataType, you also can add date period in the table to control expired order_ids';
CREATE TABLE order_id_store (
order_id NUMBER,
end_date DATE
);
--- filling the table for further checking
INSERT INTO order_id_store
SELECT ORDER_ID, trunc(sysdate)
FROM crd.V_IVZ_T19 t19
WHERE t19.order_id NOT IN (SELECT DISTINCT order_id FROM order_id_store)
AND t19.date>= trunc(sysdate)
AND t19.date<= trunc(sysdate);
--- delete no need data by date period, for example for last 2 days:
DELETE FROM order_id_store WHERE end_date <= trunc(SYSDATE - 2);
COMMIT;
---- for select report without already existed data
SELECT
rownum as LineNum,
'New' as ActionCode,
ORDER_ID,
AmountType,
trun(sysdate),
trun(systime)
FROM crd.V_IVZ_T19 t19
WHERE
(t19.acct_cd in
(select fc.child_acct_cd
from cs_config fc
where fc.parent_acct ike 'G_TRI_RPT'))
AND t19.order_id NOT IN (SELECT DISTINCT order_id FROM order_id_store)
AND t19.date>= trunc(sysdate)
AND t19.date<= trunc(sysdate);
我不确定你的&#34; t19.date&gt; =&#34;和&#34; t19.date&lt; =&#34;,导致关闭持续时间,如果不是那么正确。