SQL Developer - Bind Variable" prmMediaDate"未申报

时间:2018-01-03 20:45:44

标签: plsql oracle-sqldeveloper

我在SQL Developer中运行下面的PL / SQL块。我收到错误Bind Variable" prmMediaDate"未申报。有人请告诉我们这里缺少什么:

 set serveroutput on;
/* RUN the following as a SCRIPT (F5)    */
DECLARE
  VARIABLE prmMediaDate varchar2(10); 
  VARIABLE prmSchdDiv varchar2(2); 
  VARIABLE prmSchdStore varchar2(4); 
  VARIABLE prmSchdAssoc varchar2(8);

BEGIN
    select '07/17/2017' into :prmMediaDate FROM DUAL;
    select '91'         into :prmSchdDiv FROM DUAL;    
    select '91916559'   into :prmSchdAssoc FROM DUAL; 


SELECT
       NVL(ODIV,LA.LABORLEV1NM)                               AS "schd_division"
      ,NVL(OLOC,LA.LABORLEV4NM)                              AS "schd_location"
      ,NVL(OZONE,LA.LABORLEV5NM)                            AS "schd_dept"
      ,NVL(O.ORGPATHTXT,LA.LABORLEV1NM||'-'||LA.LABORLEV4NM||'-'||LA.LABORLEV5NM)       AS "orgpath_of_shift"                            
      ,SA.SHIFTASSIGNID                                             AS "shiftassignid"                                                                     
      ,SA.SHIFTCODEID                                                AS "shiftcodeid"                                                                      
      ,SA.ENTEREDONDTM                                           AS "assignmnt_add_dtm"                                                                    
      ,ST.ENTEREDONDTM                                           AS "assignmnt_edit_dtm"                                                                   
      ,CASE WHEN ST.ACTIONTYPEID IS NULL THEN SA.ENTEREDONDTM ELSE ST.ENTEREDONDTM  END as "last_action_dt"      
      ,ST.ACTIONTYPEID                                              AS "last_action_cd"                                                                    
      ,AT.SHORTNM                                                    AS "last_action_descr"                                                                
      ,SA.DELETEDSW                                                 AS "deletedsw"                                                                         
      ,TRUNC(SA.SHIFTSTARTDATE)                            AS "shift_start_date"
      ,TRUNC(SA.SHIFTENDDATE)                                AS "shift_end_date"
      ,TO_CHAR(SA.SHIFTSTARTDATE, 'HH24:MI:SS')   AS "shift_start_time"
      ,TO_CHAR(SA.SHIFTENDDATE, 'HH24:MI:SS')        AS "shift_end_time"
      ,CASE SA.SHIFTTYPEID WHEN  1 THEN 'WORK SHIFT' WHEN  2 THEN 'UNAVAIL' WHEN  3 THEN 'HIDE SHFT' WHEN  4 THEN 'SCHD PAYCD EDIT' WHEN  5 THEN 'HIDE WRK SHFT' WHEN 6 THEN 'HIDE UNAVAIL DAY'  ELSE 'UNDEFINED' END as "segment"
      ,NVL(LA.LABORLEV2DSC,'9999')                             AS "sell_nonsell"  
      ,P.PERSONNUM                                                     AS "assoc_nbr"
      ,SA.ENTEREDONDTM                                             AS "entered_on_dtm"
from         PERSON                             P             
        JOIN SHIFTASSIGNMNT               SA          on SA.EMPLOYEEID              =  P.PERSONID                    
        JOIN COMBHOMEACCT                HA          on (P.PERSONID                  = HA.EMPLOYEEID)
        LEFT JOIN SHFTSEGORGTRAN     SSOT      on SSOT.SHIFTASSIGNID     =  SA.SHIFTASSIGNID             
        LEFT JOIN ORGX                         O            on O.ORGIDSID                   =  SSOT.ORGIDSID  
        LEFT JOIN SHFTASGNMNTTRC     ST          on  ST.SHIFTASSIGNID       = SA.SHIFTASSIGNID
        LEFT JOIN ACTIONTYPE               AT          on AT.ACTIONTYPEID          = ST.ACTIONTYPEID
        LEFT JOIN LABORACCT                LA           on (LA.LABORACCTID          = HA.LABORACCTID)
WHERE             
    TRUNC(SA.SHIFTSTARTDATE) = :prmMediaDate                                                         
    AND :prmMediaDate BETWEEN HA.EFFECTIVEDTM AND (HA.EXPIRATIONDTM - 1)                             
    AND ((:prmMediaDate BETWEEN O.EFFECTIVEDTM AND (O.EXPIRATIONDTM - 1)) OR (O.EFFECTIVEDTM IS NULL))
    AND (SSOT.SEGMENTNUM = 1  OR SSOT.SEGMENTNUM IS NULL)                                             
    AND (TRUNC(SSOT.SHIFTSTARTDATE) = :prmMediaDate OR SSOT.SHIFTSTARTDATE IS NULL)                   
    AND SA.DELETEDSW = 0
    AND (O.ODIV   = :prmSchdDiv OR LA.LABORLEV1NM = :prmSchdDiv)                                      
    AND  P.PERSONNUM  =  :prmSchdAssoc;          
end;
/

我尝试了多种选项,例如将VARIABLE声明为var,设置Scan ON等。但它没有帮助。

1 个答案:

答案 0 :(得分:1)

您需要了解声明是pl / sql和变量是sql * plus程序命令的一部分。

因此,要成功执行该代码,您需要删除DECLARE命令。

Set Serveroutput On;
/* RUN the following as a SCRIPT (F5)    */
--DECLARE
Variable Prmmediadate Varchar2(10); 

Begin
    Select '07/17/2017' Into :Prmmediadate From Dual;          
End;
/
print :Prmmediadate


PL/SQL procedure successfully completed.


PRMMEDIADATE
--------------------------------------------------------------------------------
07/17/2017