PL SQL Oracle中的零迭代计数

PL SQL Oracle中的零迭代计数,oracle,plsql,oraclereports,Oracle,Plsql,Oraclereports,我正在编写一个查询,它应该基于IF语句执行不同的select语句。以前没有在Oracle中执行过任何IFs,我也不确定出了什么问题,但是我得到了错误,零迭代计数,它指向第一行代码。我包含了很多代码,但是你只需要关注IFs IF :p_sales_type = 'all_cancel' THEN SELECT TO_DATE(SUBSTR(Transaction_Date,1,10), 'MM/DD/YYYY'),Item_Number, REGEXP_REPLACE(

我正在编写一个查询,它应该基于IF语句执行不同的select语句。以前没有在Oracle中执行过任何IFs,我也不确定出了什么问题,但是我得到了错误,零迭代计数,它指向第一行代码。我包含了很多代码,但是你只需要关注IFs

IF :p_sales_type = 'all_cancel' THEN



  SELECT 
   TO_DATE(SUBSTR(Transaction_Date,1,10), 'MM/DD/YYYY'),Item_Number, 
    REGEXP_REPLACE(SUBSTR(Item_Or_Adj_Description,1,50),'([^[:print:]])',' ') AS Item_Or_Adj_Desctription, 
    Customer_Type, Document_ID, Dealer_ID, Sales_Type, Item_Quantity, Total_Fee, State_Fee, Transaction_Fee, AO_Fee, WDFW_Fee 
  FROM 
  ( 
    -- Sales Transactions 
   SELECT /*+ index(IT ITEM_X4) */ 
      TO_CHAR(IT.it_status_set_date - 2/24, 'MM/DD/YYYY HH24:MI:SS') AS Transaction_Date,  -- Pacific Time
      TO_NUMBER(IT.ic_rcn) AS Item_Number, IT.it_descr AS Item_Or_Adj_Description, 
      DT.di_name AS Customer_Type, IT.it_docid AS Document_ID, IT.ag_id AS Dealer_ID, 
      CASE WHEN UPPER(IST.is_name) = 'ACTIVE' THEN 'SALE' ELSE IST.is_name END AS Sales_Type, 
      NVL(IT.it_quantity * CASE WHEN IT.is_id = 'AC' THEN 1 WHEN IT.is_id = 'DU' THEN 1 ELSE -1 END, 0) AS Item_Quantity,  -- Dups = 1
      NVL(IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) + 
    NVL(IT.it_other_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) AS Total_Fee, 
      NVL(IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) AS State_Fee, 
      NVL(IT.it_other_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) AS Transaction_Fee, 
      CASE WHEN IT.it_other_fee IS NULL OR IT.it_other_fee = 0.00 THEN 0.00 
        ELSE ROUND(IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END * (:p_ao_trx_fee / 100), 2) 
      END AS AO_Fee, 
      CASE WHEN IT.it_other_fee IS NULL OR IT.it_other_fee = 0.00 THEN 0.00 
        ELSE (IT.it_other_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END) - 
          ROUND((IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END * (:p_ao_trx_fee / 100)), 2) 
      END AS WDFW_Fee 
   FROM ITEM IT 
   JOIN DISCOUNT_TYPE DT ON DT.di_id = IT.di_id 
   JOIN ITEM_STATUS_TYPE IST ON IST.is_id = IT.is_id 
   WHERE IT.it_status_ind = 'A' -- Include active ITEM rows only. 
   AND (IT.is_id IN ('AC','DC','SC') OR (IT.is_id = 'DU' AND NVL(IT.it_state_fee, 0) != 0)) -- Exclude voids, exchanges, and false duplicates.
   AND IT.ic_rcn != '999' -- Exclude Dealer Fees. 
   AND IT.it_status_set_date BETWEEN :P_beg_dt  -- Pacific Time
                 AND :P_end_dt
    AND (:p_discount_type IS NULL OR DT.di_id = :p_discount_type)
  -- AND IST.is_name = :SalesType
   UNION ALL

   -- Item Adjustments
   SELECT 
      TO_CHAR(AJ.aj_adjustment_date - 2/24, 'MM/DD/YYYY HH24:MI:SS') AS Transaction_Date,  -- Pacific Time
      TO_NUMBER(IT.ic_rcn) AS Item_Number, AJ.aj_comment AS Item_Or_Adj_Description, 
      DT.di_name AS Customer_Type, IT.it_docid AS Document_ID, AJ.ag_id AS Dealer_ID, 
      AJ.ajt_adjustment_type_name AS Sales_Type, 
      0 AS Item_Quantity, 
      NVL(AJ.aj_state_adj_amt, 0.00) + NVL(AJ.aj_other_adj_amt, 0.00) AS Total_Fee, 
      NVL(AJ.aj_state_adj_amt, 0.00) AS State_Fee, 
      NVL(AJ.aj_other_adj_amt, 0.00) AS Transaction_Fee, 
      CASE WHEN AJ.aj_other_adj_amt IS NULL OR AJ.aj_other_adj_amt = 0.00 THEN 0.00 
    ELSE ROUND(NVL(AJ.aj_state_adj_amt, 0.00) * (:p_ao_trx_fee / 100), 2) END AS AO_Fee, 
      CASE WHEN AJ.aj_other_adj_amt IS NULL OR AJ.aj_other_adj_amt = 0.00 THEN 0.00 
    ELSE AJ.aj_other_adj_amt - ROUND(NVL(AJ.aj_state_adj_amt, 0.00) * (:p_ao_trx_fee / 100), 2) END AS WDFW_Fee 
   FROM ADJUSTMENT AJ 
   JOIN ITEM IT ON IT.it_id = AJ.it_id 
   JOIN DISCOUNT_TYPE DT ON DT.di_id = IT.di_id 
   WHERE AJ.aj_status_ind = 'A' -- Include active adjustments only. 
   AND AJ.it_id IS NOT NULL -- Include Item Adjustments only; rows with a foreign key to the ITEM table are Item Adjustments. 
   AND AJ.ajt_id != '0' -- Unreturned Doc Charge is not an Item Adjustment, it's a Lump Sum Adjustment to the Dealers account. 
   AND IT.ic_rcn != '999' -- Exclude Dealer Fees. 
   AND AJ.aj_adjustment_date BETWEEN :P_beg_dt  -- Pacific Time
                 AND :P_end_dt
    AND (:p_discount_type IS NULL OR DT.di_id = :p_discount_type)
   --AND AJ.Ajt_Adjustment_Type_Name = :SalesType
  ) ReportDetails 

  WHERE-- Sales_Type = :SalesType
                 (:p_ic_rcn is null OR :p_ic_rcn = Item_Number)
                 AND (:p_dealer_id IS NULL OR Dealer_ID = :p_dealer_id)
                 AND Sales_Type in ('DEALER CANCEL', 'STATE CANCEL')



  ORDER BY TO_DATE(SUBSTR(Transaction_Date,1,10), 'MM/DD/YYYY'), Item_Number,  -- Transaction Date, RCN (numerical order), order RCN was purchased. 
       TO_CHAR(TO_DATE(Transaction_Date, 'MM/DD/YYYY HH24:MI:SS'), 'SSSSS');


  ELSE IF :p_sales_type = 'item_adjustment' THEN


   -- Item Adjustments
   SELECT 
      TO_CHAR(AJ.aj_adjustment_date - 2/24, 'MM/DD/YYYY HH24:MI:SS') AS Transaction_Date,  -- Pacific Time
      TO_NUMBER(IT.ic_rcn) AS Item_Number, AJ.aj_comment AS Item_Or_Adj_Description, 
      DT.di_name AS Customer_Type, IT.it_docid AS Document_ID, AJ.ag_id AS Dealer_ID, 
      AJ.ajt_adjustment_type_name AS Sales_Type, 
      0 AS Item_Quantity, 
      NVL(AJ.aj_state_adj_amt, 0.00) + NVL(AJ.aj_other_adj_amt, 0.00) AS Total_Fee, 
      NVL(AJ.aj_state_adj_amt, 0.00) AS State_Fee, 
      NVL(AJ.aj_other_adj_amt, 0.00) AS Transaction_Fee, 
      CASE WHEN AJ.aj_other_adj_amt IS NULL OR AJ.aj_other_adj_amt = 0.00 THEN 0.00 
    ELSE ROUND(NVL(AJ.aj_state_adj_amt, 0.00) * (:p_ao_trx_fee / 100), 2) END AS AO_Fee, 
      CASE WHEN AJ.aj_other_adj_amt IS NULL OR AJ.aj_other_adj_amt = 0.00 THEN 0.00 
    ELSE AJ.aj_other_adj_amt - ROUND(NVL(AJ.aj_state_adj_amt, 0.00) * (:p_ao_trx_fee / 100), 2) END AS WDFW_Fee 
   FROM ADJUSTMENT AJ 
   JOIN ITEM IT ON IT.it_id = AJ.it_id 
   JOIN DISCOUNT_TYPE DT ON DT.di_id = IT.di_id 
   WHERE AJ.aj_status_ind = 'A' -- Include active adjustments only. 
   AND AJ.it_id IS NOT NULL -- Include Item Adjustments only; rows with a foreign key to the ITEM table are Item Adjustments. 
   AND AJ.ajt_id != '0' -- Unreturned Doc Charge is not an Item Adjustment, it's a Lump Sum Adjustment to the Dealers account. 
   AND IT.ic_rcn != '999' -- Exclude Dealer Fees. 
   AND AJ.aj_adjustment_date BETWEEN :P_beg_dt  -- Pacific Time
                 AND :P_end_dt
    AND (:p_discount_type IS NULL OR DT.di_id = :p_discount_type)
    WHERE-- Sales_Type = :SalesType
                 (:p_ic_rcn is null OR :p_ic_rcn = Item_Number)
                 AND (:p_dealer_id IS NULL OR Dealer_ID = :p_dealer_id)
                 AND Sales_Type = 'ADJUSTMENT'

    ORDER BY TO_DATE(SUBSTR(Transaction_Date,1,10), 'MM/DD/YYYY'), Item_Number,  -- Transaction Date, RCN (numerical order), order RCN was purchased. 
       TO_CHAR(TO_DATE(Transaction_Date, 'MM/DD/YYYY HH24:MI:SS'), 'SSSSS');

  ELSE IF :p_sales_type IS NULL 


  SELECT 
   TO_DATE(SUBSTR(Transaction_Date,1,10), 'MM/DD/YYYY'),Item_Number, 
    REGEXP_REPLACE(SUBSTR(Item_Or_Adj_Description,1,50),'([^[:print:]])',' ') AS Item_Or_Adj_Desctription, 
    Customer_Type, Document_ID, Dealer_ID, Sales_Type, Item_Quantity, Total_Fee, State_Fee, Transaction_Fee, AO_Fee, WDFW_Fee 
  FROM 
  ( 
    -- Sales Transactions 
   SELECT /*+ index(IT ITEM_X4) */ 
      TO_CHAR(IT.it_status_set_date - 2/24, 'MM/DD/YYYY HH24:MI:SS') AS Transaction_Date,  -- Pacific Time
      TO_NUMBER(IT.ic_rcn) AS Item_Number, IT.it_descr AS Item_Or_Adj_Description, 
      DT.di_name AS Customer_Type, IT.it_docid AS Document_ID, IT.ag_id AS Dealer_ID, 
      CASE WHEN UPPER(IST.is_name) = 'ACTIVE' THEN 'SALE' ELSE IST.is_name END AS Sales_Type, 
      NVL(IT.it_quantity * CASE WHEN IT.is_id = 'AC' THEN 1 WHEN IT.is_id = 'DU' THEN 1 ELSE -1 END, 0) AS Item_Quantity,  -- Dups = 1
      NVL(IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) + 
    NVL(IT.it_other_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) AS Total_Fee, 
      NVL(IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) AS State_Fee, 
      NVL(IT.it_other_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) AS Transaction_Fee, 
      CASE WHEN IT.it_other_fee IS NULL OR IT.it_other_fee = 0.00 THEN 0.00 
        ELSE ROUND(IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END * (:p_ao_trx_fee / 100), 2) 
      END AS AO_Fee, 
      CASE WHEN IT.it_other_fee IS NULL OR IT.it_other_fee = 0.00 THEN 0.00 
        ELSE (IT.it_other_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END) - 
          ROUND((IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END * (:p_ao_trx_fee / 100)), 2) 
      END AS WDFW_Fee 
   FROM ITEM IT 
   JOIN DISCOUNT_TYPE DT ON DT.di_id = IT.di_id 
   JOIN ITEM_STATUS_TYPE IST ON IST.is_id = IT.is_id 
   WHERE IT.it_status_ind = 'A' -- Include active ITEM rows only. 
   AND (IT.is_id IN ('AC','DC','SC') OR (IT.is_id = 'DU' AND NVL(IT.it_state_fee, 0) != 0)) -- Exclude voids, exchanges, and false duplicates.
   AND IT.ic_rcn != '999' -- Exclude Dealer Fees. 
   AND IT.it_status_set_date BETWEEN :P_beg_dt  -- Pacific Time
                 AND :P_end_dt
    AND (:p_discount_type IS NULL OR DT.di_id = :p_discount_type)
  -- AND IST.is_name = :SalesType
   UNION ALL

   -- Item Adjustments
   SELECT 
      TO_CHAR(AJ.aj_adjustment_date - 2/24, 'MM/DD/YYYY HH24:MI:SS') AS Transaction_Date,  -- Pacific Time
      TO_NUMBER(IT.ic_rcn) AS Item_Number, AJ.aj_comment AS Item_Or_Adj_Description, 
      DT.di_name AS Customer_Type, IT.it_docid AS Document_ID, AJ.ag_id AS Dealer_ID, 
      AJ.ajt_adjustment_type_name AS Sales_Type, 
      0 AS Item_Quantity, 
      NVL(AJ.aj_state_adj_amt, 0.00) + NVL(AJ.aj_other_adj_amt, 0.00) AS Total_Fee, 
      NVL(AJ.aj_state_adj_amt, 0.00) AS State_Fee, 
      NVL(AJ.aj_other_adj_amt, 0.00) AS Transaction_Fee, 
      CASE WHEN AJ.aj_other_adj_amt IS NULL OR AJ.aj_other_adj_amt = 0.00 THEN 0.00 
    ELSE ROUND(NVL(AJ.aj_state_adj_amt, 0.00) * (:p_ao_trx_fee / 100), 2) END AS AO_Fee, 
      CASE WHEN AJ.aj_other_adj_amt IS NULL OR AJ.aj_other_adj_amt = 0.00 THEN 0.00 
    ELSE AJ.aj_other_adj_amt - ROUND(NVL(AJ.aj_state_adj_amt, 0.00) * (:p_ao_trx_fee / 100), 2) END AS WDFW_Fee 
   FROM ADJUSTMENT AJ 
   JOIN ITEM IT ON IT.it_id = AJ.it_id 
   JOIN DISCOUNT_TYPE DT ON DT.di_id = IT.di_id 
   WHERE AJ.aj_status_ind = 'A' -- Include active adjustments only. 
   AND AJ.it_id IS NOT NULL -- Include Item Adjustments only; rows with a foreign key to the ITEM table are Item Adjustments. 
   AND AJ.ajt_id != '0' -- Unreturned Doc Charge is not an Item Adjustment, it's a Lump Sum Adjustment to the Dealers account. 
   AND IT.ic_rcn != '999' -- Exclude Dealer Fees. 
   AND AJ.aj_adjustment_date BETWEEN :P_beg_dt  -- Pacific Time
                 AND :P_end_dt
    AND (:p_discount_type IS NULL OR DT.di_id = :p_discount_type)
   --AND AJ.Ajt_Adjustment_Type_Name = :SalesType
  ) ReportDetails 

  WHERE         (:p_ic_rcn is null OR :p_ic_rcn = Item_Number)
                 AND (:p_dealer_id IS NULL OR Dealer_ID = :p_dealer_id)



  ORDER BY TO_DATE(SUBSTR(Transaction_Date,1,10), 'MM/DD/YYYY'), Item_Number,  -- Transaction Date, RCN (numerical order), order RCN was purchased. 
       TO_CHAR(TO_DATE(Transaction_Date, 'MM/DD/YYYY HH24:MI:SS'), 'SSSSS');


ELSE

  SELECT 
   TO_DATE(SUBSTR(Transaction_Date,1,10), 'MM/DD/YYYY'),Item_Number, 
    REGEXP_REPLACE(SUBSTR(Item_Or_Adj_Description,1,50),'([^[:print:]])',' ') AS Item_Or_Adj_Desctription, 
    Customer_Type, Document_ID, Dealer_ID, Sales_Type, Item_Quantity, Total_Fee, State_Fee, Transaction_Fee, AO_Fee, WDFW_Fee 
  FROM 
  ( 
    -- Sales Transactions 
   SELECT /*+ index(IT ITEM_X4) */ 
      TO_CHAR(IT.it_status_set_date - 2/24, 'MM/DD/YYYY HH24:MI:SS') AS Transaction_Date,  -- Pacific Time
      TO_NUMBER(IT.ic_rcn) AS Item_Number, IT.it_descr AS Item_Or_Adj_Description, 
      DT.di_name AS Customer_Type, IT.it_docid AS Document_ID, IT.ag_id AS Dealer_ID, 
      CASE WHEN UPPER(IST.is_name) = 'ACTIVE' THEN 'SALE' ELSE IST.is_name END AS Sales_Type, 
      NVL(IT.it_quantity * CASE WHEN IT.is_id = 'AC' THEN 1 WHEN IT.is_id = 'DU' THEN 1 ELSE -1 END, 0) AS Item_Quantity,  -- Dups = 1
      NVL(IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) + 
    NVL(IT.it_other_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) AS Total_Fee, 
      NVL(IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) AS State_Fee, 
      NVL(IT.it_other_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END, 0.00) AS Transaction_Fee, 
      CASE WHEN IT.it_other_fee IS NULL OR IT.it_other_fee = 0.00 THEN 0.00 
        ELSE ROUND(IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END * (:p_ao_trx_fee / 100), 2) 
      END AS AO_Fee, 
      CASE WHEN IT.it_other_fee IS NULL OR IT.it_other_fee = 0.00 THEN 0.00 
        ELSE (IT.it_other_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END) - 
          ROUND((IT.it_state_fee * CASE WHEN IT.is_id IN ('DC','SC') THEN -1.00 ELSE 1.00 END * (:p_ao_trx_fee / 100)), 2) 
      END AS WDFW_Fee 
   FROM ITEM IT 
   JOIN DISCOUNT_TYPE DT ON DT.di_id = IT.di_id 
   JOIN ITEM_STATUS_TYPE IST ON IST.is_id = IT.is_id 
   WHERE IT.it_status_ind = 'A' -- Include active ITEM rows only. 
   AND (IT.is_id IN ('AC','DC','SC') OR (IT.is_id = 'DU' AND NVL(IT.it_state_fee, 0) != 0)) -- Exclude voids, exchanges, and false duplicates.
   AND IT.ic_rcn != '999' -- Exclude Dealer Fees. 
   AND IT.it_status_set_date BETWEEN :P_beg_dt  -- Pacific Time
                 AND :P_end_dt
    AND (:p_discount_type IS NULL OR DT.di_id = :p_discount_type)
  -- AND IST.is_name = :SalesType
   UNION ALL

   -- Item Adjustments
   SELECT 
      TO_CHAR(AJ.aj_adjustment_date - 2/24, 'MM/DD/YYYY HH24:MI:SS') AS Transaction_Date,  -- Pacific Time
      TO_NUMBER(IT.ic_rcn) AS Item_Number, AJ.aj_comment AS Item_Or_Adj_Description, 
      DT.di_name AS Customer_Type, IT.it_docid AS Document_ID, AJ.ag_id AS Dealer_ID, 
      AJ.ajt_adjustment_type_name AS Sales_Type, 
      0 AS Item_Quantity, 
      NVL(AJ.aj_state_adj_amt, 0.00) + NVL(AJ.aj_other_adj_amt, 0.00) AS Total_Fee, 
      NVL(AJ.aj_state_adj_amt, 0.00) AS State_Fee, 
      NVL(AJ.aj_other_adj_amt, 0.00) AS Transaction_Fee, 
      CASE WHEN AJ.aj_other_adj_amt IS NULL OR AJ.aj_other_adj_amt = 0.00 THEN 0.00 
    ELSE ROUND(NVL(AJ.aj_state_adj_amt, 0.00) * (:p_ao_trx_fee / 100), 2) END AS AO_Fee, 
      CASE WHEN AJ.aj_other_adj_amt IS NULL OR AJ.aj_other_adj_amt = 0.00 THEN 0.00 
    ELSE AJ.aj_other_adj_amt - ROUND(NVL(AJ.aj_state_adj_amt, 0.00) * (:p_ao_trx_fee / 100), 2) END AS WDFW_Fee 
   FROM ADJUSTMENT AJ 
   JOIN ITEM IT ON IT.it_id = AJ.it_id 
   JOIN DISCOUNT_TYPE DT ON DT.di_id = IT.di_id 
   WHERE AJ.aj_status_ind = 'A' -- Include active adjustments only. 
   AND AJ.it_id IS NOT NULL -- Include Item Adjustments only; rows with a foreign key to the ITEM table are Item Adjustments. 
   AND AJ.ajt_id != '0' -- Unreturned Doc Charge is not an Item Adjustment, it's a Lump Sum Adjustment to the Dealers account. 
   AND IT.ic_rcn != '999' -- Exclude Dealer Fees. 
   AND AJ.aj_adjustment_date BETWEEN :P_beg_dt  -- Pacific Time
                 AND :P_end_dt
    AND (:p_discount_type IS NULL OR DT.di_id = :p_discount_type)
   --AND AJ.Ajt_Adjustment_Type_Name = :SalesType
  ) ReportDetails 

  WHERE        Sales_Type = :p_sales_type
                AND (:p_ic_rcn is null OR :p_ic_rcn = Item_Number)
                 AND (:p_dealer_id IS NULL OR Dealer_ID = :p_dealer_id)




  ORDER BY TO_DATE(SUBSTR(Transaction_Date,1,10), 'MM/DD/YYYY'), Item_Number,  -- Transaction Date, RCN (numerical order), order RCN was purchased. 
       TO_CHAR(TO_DATE(Transaction_Date, 'MM/DD/YYYY HH24:MI:SS'), 'SSSSS');

  END IF;

我不确定您所说的“零迭代计数”是什么意思,但您需要一个
INTO
子句来选择结果,并使用
ELSIF
而不是
elseif

IF :p_sales_type = 'all_cancel' 
THEN
   SELECT col_list
     INTO variable_list
     FROM tables
    WHERE <where_clause>;
ELSIF :p_sales_type = 'item_adjustment' 
THEN 
   SELECT col_list
     INTO variable_list
     FROM tables
    WHERE <where_clause>;
ELSIF :p_sales_type IS NULL  
THEN
   SELECT col_list
     INTO variable_list
     FROM tables
    WHERE <where_clause>;
ELSE
   SELECT col_list
     INTO variable_list
     FROM tables
    WHERE <where_clause>;
END IF;
IF:p\u sales\u type='all\u cancel'
然后
选择col_列表
进入变量列表
从桌子上
哪里
ELSIF:p_销售类型='项目调整'
然后
选择col_列表
进入变量列表
从桌子上
哪里
ELSIF:p_sales_type为空
然后
选择col_列表
进入变量列表
从桌子上
哪里
其他的
选择col_列表
进入变量列表
从桌子上
哪里
如果结束;
您的
p\u sales\u type
变量/参数前面有一个冒号。 最后,可能值得将
p_sales_type
包装在
UPPER
中,如
UPPER(p_sales_type)=“ALL_CANCEL”
中,以确保没有任何意外的不匹配(当然,除非您确定值的情况)


希望它有帮助…

实际的错误代码和语句是什么?在PL/SQL上下文中,像这样的SQL语句需要一个
SELECT。。进入..
或其他处理结果集的方法。您得到的错误号是多少?如果我理解正确,您执行的是单个语句,它们都正常工作。然后添加了IF以选择要执行的正确语句,并开始出现错误。这就是发生的事情吗?@BobJarvis是的,这是正确的。@rageq这个SQL在Oracle报告中的事实改变了这个问题。除了本机SQL之外,您可能无法在Oracle报表查询块中使用这样的PL/SQL条件。您可以使用beforeReport触发器或执行所需SQL块的条件布局。另一个选项是在Oracle报表SQL块中,您可以使用
UNION all
连接所有三条语句,然后在
WHERE
子句中包含互斥参数,这样只有一条语句返回值。冒号是因为它是Oracle报表中的一个参数,在我添加IFs@OllieFair之前,它工作得很好,如果冒号是Oracle Reports变量,则需要保留冒号。