在CURSOR中添加if条件

时间:2017-12-05 09:28:12

标签: oracle11g

我需要用SELECT语句检查相关条件。我只需要这个。

if systemdate is 'Monday' then 
   select statement1(which contains cursor)
else 
   select statement 2(which contains cursor)

这是我的代码:

CURSOR PR_CASHDEPOSITEMAIL IS
    SELECT      B.STR_DEALER_NAME AS DEALERNAME,
                B.STR_BC_BRANCH_CODE AS ASSINGBRANCH,
                A.STRDDH_DEALERCODE AS ICAMDEALERCODE,
                B.STR_DEALER_CODE AS DEALERCODE,
                TO_DATE(A.DTDDH_DPDATE,'DD/MM/YYYY')AS RECEIPTDATE,
                A.NUMDDH_BALANCEAMOUNT AS RECEIPTAMOUNT,
                A.STRDDH_DPSLNO AS DEPOSITNUMBER 
    FROM        GLINFO.TBLDEALERDEPOSITEHEADER A ,
                ADL.REF_DEALER_MASTER B ,
                CORPINFO.TBLBRANCHES C
    WHERE       A.NUMDDH_BALANCEAMOUNT >0 
    AND         A.STRDDH_DEALERCODE=B.STR_COMP_DEALER_CODE
    AND         B.STR_BC_BRANCH_CODE=C.BRN_CODE
    AND         B.str_bc_branch_code =strBranch 
    ORDER BY    B.STR_BC_BRANCH_CODE, B.STR_DEALER_NAME, RECEIPTDATE, DEPOSITNUMBER;

BEGIN

--rest of code

我需要在此select语句中添加前面提到的条件。

1 个答案:

答案 0 :(得分:1)

带参数的游标可以在这里提供帮助。游标声明:

CURSOR PR_CASHDEPOSITEMAIL (p_day varchar2) -- <-- parameter declaration
  IS
    SELECT <...>
    FROM   <...>
    WHERE  <...>
      and to_date(some_date_column, 'Day') = p_day; -- <-- parameter use in query

使用游标:

...
begin
  open PR_CASHDEPOSITEMAIL('Monday'); -- <-- passing value to the cursor
  ...