0

我有一个 WITH 子句,它给了我想要的结果,我试图把它放在一个变量中。为简单起见,我省略了代码。最后一行代码是最相关的。

WITH ALL_VE_ERRORS AS (

        SELECT *
        FROM ASN.AN_VALIDATION_ERRORS
        WHERE ...

    ), FILTER_STATUS AS (

        SELECT *
        FROM ALL_VE_ERRORS
        WHERE ...

      ) SELECT UNIT_DISCREPANCY FROM FILTER_STATUS INTO W_UNIT_DISCREPANCY; <-- like this

但这不起作用,编译器不喜欢这样。我也试过把它放在第一位:

SELECT INTO W_UNIT_DISCREPANCY <-- or like this
       WITH ALL_VE_ERRORS AS (...

任何人都知道做这样的事情的正确语法吗?

4

1 回答 1

2

WITH如果您没有我看不到的原因,则您的子句中不需要两个表;你可以这样简化:

WITH ALL_VE_ERRORS AS (    
    SELECT *
    FROM ASN.AN_VALIDATION_ERRORS
    WHERE ...    
)
SELECT UNIT_DISCREPANCY
INTO W_UNIT_DISCREPANCY
FROM ALL_VE_ERRORS
WHERE ...

否则,您可以使用:

WITH ALL_VE_ERRORS AS (    
        SELECT *
        FROM ASN.AN_VALIDATION_ERRORS
        WHERE ...    
    ), FILTER_STATUS AS (    
        SELECT *
        FROM ALL_VE_ERRORS
        WHERE ...    
      )
SELECT UNIT_DISCREPANCY
INTO W_UNIT_DISCREPANCY
FROM FILTER_STATUS 
于 2016-05-03T15:31:30.497 回答