gpt4 book ai didi

sql - PL/SQL - dbms 输出立即执行的结果

转载 作者:搜寻专家 更新时间:2023-10-30 22:03:40 24 4
gpt4 key购买 nike

我希望能够打印出查询的所有结果(应该由 TableA 中的 PK 过滤)并为 TABLEA 中的每个 PK 执行此操作。这是我到目前为止所拥有的:

 DECLARE
CURSOR Curs IS SELECT DISTINCT PKID FROM TABLEA;
BEGIN
FOR rec IN Curs
LOOP
EXECUTE IMMEDIATE
'SELECT * FROM (
SELECT cola,
FKTABLEA,
colc,
lag (cold,1) OVER (ORDER BY cold) AS cold
FROM tableB
WHERE FKTABLEA = :1)
WHERE colc != cold
order by cola' using Curs.PKID;

DBMS_OUTPUT.PUT_LINE('OUTPUT ALL RESULTS FROM THE QUERY HERE');
END LOOP;
END;

最佳答案

不需要使用 EXECUTE IMMEDIATE。并且只有完全手动的方式来打印所有结果:

DECLARE
CURSOR Curs IS SELECT DISTINCT PKID FROM TABLEA;
BEGIN
FOR rec IN Curs LOOP
FOR r IN (
SELECT * FROM (
SELECT cola,
FKTABLEA,
colc,
lag (cold,1) OVER (ORDER BY cold) AS cold
FROM tableB
WHERE FKTABLEA = rec.PKID)
WHERE colc != cold
order by cola )
LOOP
DBMS_OUTPUT.PUT_LINE(r.cola || ',' || r.colb || ',' || r.colc || ',' || r.cold);
END LOOP;
END LOOP;
END;

关于sql - PL/SQL - dbms 输出立即执行的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6166513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com