0
我寫此查詢,模擬變量被傳遞到服務器端的查詢和它不斷給我這個錯誤「ORA-06550:第11行,第2列: PLS-00428:預期在此SELECT語句中使用INTO子句 「。 甲骨文PLS-00428:INTO子句預計在SELECT語句
這裏是我的查詢
DECLARE
P_CONTRACTS VARCHAR(60) := NULL;
P_START_DATE DATE:='01/01/2010';
P_END_DATE DATE:='05/01/2010';
P_CONTRACT_TYPE VARCHAR(30):='Annual';
P_CONTRACT_STATUS VARCHAR(30):='OPEN';
BEGIN
SELECT DISTINCT
CONTRACT_ID,
SUPPLIER_NAME,
CONTRACT_NUMBER,
CONTRACT_TYPE,
CONTRACT_STATUS,
CONTRACT_DATE,
MONTHLY_COMMITTED_LBS,
PO,
ORDER_TYPE,
PRICING_TYPE,
PURCHASE_VOLUME,
RECEIVED_VOLUME,
INTRANSIT,
(MONTHLY_COMMITTED_LBS - (RECEIVED_VOLUME + INTRANSIT)) AS "NOT_SCHEDULED"
FROM
(
SELECT DISTINCT
ARR.ID AS CONTRACT_ID,
DWPO.SUPPLIER_NAME AS SUPPLIER_NAME,
ARRANGEMENT_NUMBER AS CONTRACT_NUMBER,
DECODE(ARR.CONTRACT_DESIGNATION, 1, 'ANNUAL', 2, 'MINI-SPOT') AS CONTRACT_TYPE,
DECODE(ARR.STATUS, 1, 'OPEN', 2, 'CLOSED', 3, 'CANCELLED') AS CONTRACT_STATUS,
TO_CHAR(TRUNC(LAST_DAY(ADD_MONTHS(ARR.START_DATE,-1))+1), 'MM/DD/YYYY') AS CONTRACT_DATE,
ARRB.QUANTITY AS MONTHLY_COMMITTED_LBS,
P.PO_NUMBER AS PO,
DWPO.PO_TYPE AS ORDER_TYPE,
DWPO.PRICE_CALCULATION_TYPE AS PRICING_TYPE,
NVL(DW_REPORTS_PKG.GET_RECEIVED_BY_PO(P.PO_NUMBER, ARR.START_DATE, ARR.END_DATE, DWPO.PRODUCT_ID),0) AS "PURCHASE_VOLUME",
NVL(DW_REPORTS_PKG.GET_RECEIVED_WEIGHT_BY_PO(P.PO_NUMBER, ARR.START_DATE, ARR.END_DATE, DWPO.PRODUCT_ID),0) AS "RECEIVED_VOLUME",
NVL(DW_REPORTS_PKG.GET_IN_TRANSIT_BY_PO(P.PO_NUMBER, ARR.START_DATE, ARR.END_DATE, DWPO.PRODUCT_ID),0) AS "INTRANSIT"
FROM
APP_ARRANGEMENT ARR
INNER JOIN APP_CONTRACT_SUPPLIER CS
ON (ARR.ID = CS.ARRANGEMENT_ID)
INNER JOIN APP_PO P
ON(P.ARRANGEMENT_ID = ARR.ID)
INNER JOIN DW_PURCHASE_ORDER DWPO
ON (DWPO.PO_NUMBER = P.PO_NUMBER)
INNER JOIN APP_ARRANGEMENT_BUCKET ARRB
ON (ARR.ID = ARRB.ARRANGEMENT_ID)
WHERE
(
(P_CONTRACTS IS NULL OR
(ARR.ARRANGEMENT_NUMBER IN (SELECT * FROM (SELECT TRIM(SUBSTR(TXT, INSTR (TXT, ',', 1, LEVEL) + 1, INSTR(TXT, ',', 1, LEVEL+1) - INSTR (TXT, ',', 1, LEVEL) -1)) AS TOKEN
FROM (SELECT ','|| P_CONTRACTS ||',' AS TXT FROM DUAL)
CONNECT BY LEVEL <= LENGTH(TXT)-LENGTH(REPLACE(TXT,',',''))-1))))
)
AND
(P_CONTRACT_TYPE IS NULL OR DECODE(ARR.CONTRACT_DESIGNATION, 1, 'ANNUAL', 2, 'MINISPOT') IN
(SELECT * FROM (SELECT TRIM(SUBSTR(TXT, INSTR (TXT, ',', 1, LEVEL) + 1, INSTR(TXT, ',', 1, LEVEL+1) - INSTR (TXT, ',', 1, LEVEL) -1)) AS TOKEN
FROM (SELECT ','|| P_CONTRACT_TYPE ||',' AS TXT FROM DUAL)
CONNECT BY LEVEL <= LENGTH(TXT)-LENGTH(REPLACE(TXT,',',''))-1)))
AND
(P_CONTRACT_STATUS IS NULL OR ARR.STATUS IN
(SELECT * FROM (SELECT TRIM(SUBSTR(TXT, INSTR (TXT, ',', 1, LEVEL) + 1, INSTR(TXT, ',', 1, LEVEL+1) - INSTR (TXT, ',', 1, LEVEL) -1)) AS TOKEN
FROM (SELECT ','|| P_CONTRACT_STATUS ||',' AS TXT FROM DUAL)
CONNECT BY LEVEL <= LENGTH(TXT)-LENGTH(REPLACE(TXT,',',''))-1)))
AND
((P_START_DATE IS NULL AND P_END_DATE IS NULL) OR TO_DATE(ARRB.MONTH || '/' || ARRB.YEAR, 'MM/YYYY') BETWEEN P_START_DATE AND P_END_DATE)
);
END;
我可供應樣品DB結構和日期匹配查詢。
以防萬一有人認爲它與子查詢有關是不是我可以運行子查詢沒有問題硬編碼值的日期。
錯誤消息非常明確:在PL/SQL中,如果不將結果存儲在某處,則無法運行SELECT。爲了存儲結果,你需要一個'INTO'子句。有關詳細信息,請參閱手冊:http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/static.htm#LNPLS551 –
「查詢」是一條SQL語句。任何以BEGIN開頭的東西都是PL/SQL塊(在你的情況下是一個「匿名」塊)。塊不是查詢。你沒有寫一個查詢;你寫了一個PL/SQL匿名塊。如果你想了解這個問題,不要閱讀文檔或谷歌的SQL查詢的事情 - 搜索「PL/SQL匿名塊」和類似的。 – mathguy