[英]Use for loop after the With Clause in PL/SQL
Im using PL/SQL. 我正在使用PL / SQL。 I am trying to have a for loop right after I define my temporary tables in the with clause.
我正在尝试在with子句中定义临时表之后有一个for循环。 However, Im getting an error to have a SELECT query first.
但是,我首先得到一个SELECT查询错误。
For instance 例如
WITH TMP1 AS (.....), TMP2 AS (......), TMP3 AS (......)
FOR R IN (SELECT DISTINCT ..... FROM TMP1 WHERE .....)
LOOP
SELECT .... FROM TMP2, TMP2 WHERE TMP2.... = R..... ....
How do I go about doing so? 我该怎么做呢?
Thanks 谢谢
You can't access a CTE outside of the whole statement. 您不能在整个声明之外访问CTE。 And you can't access individual parts of a CTE outside of the final SELECT for a CTE.
并且您无法访问CTE的最终SELECT之外的CTE的各个部分。
You need to put the whole CTE (including the final SELECT statement) into the cursor loop: 您需要将整个 CTE(包括最终的SELECT语句) 放入游标循环:
FOR R IN (WITH TMP1 AS (.....),
TMP2 AS (......),
TMP3 AS (......)
SELECT DISTINCT .....
FROM TMP1
JOIN temp2 ON ...
JOIN temp3 ON ...
WHERE .....)
LOOP
-- here goes the code that processes each row of the query
END LOOP;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.