我写了这个查询来模拟传递给服务器端查询的变量,它不断给我这个错误“ORA-06550:第11行,第2列: PLS-00428:此SELECT语句中需要一个INTO子句 ”。
这是我的查询
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;
我可以提供与查询匹配的示例数据库结构和日期。
以防万一有人认为它与子查询有关,我不能运行子查询没有问题硬编码日期值。
答案 0 :(得分:0)
将您的查询声明为游标并继续编写pl / sql程序;)
声明 光标c是 SELECT DISTINCT ....; 开始 - 您的PL / SQL语句 端;