oracle PLS-00103发生在Toad上的PL/SQL中

at0kjp5o  于 2023-05-06  发布在  Oracle
关注(0)|答案(2)|浏览(137)

我是PL/SQL过程的新手,并试图从Java中接收一些变量。我遇到PLS-00103错误说遇到符号“SELECT”和“)”在SELECT语句之间的“是”和“开始”和遇到符号“生命周期结束”的分号结束后请给予我一些线索,这个错误,想知道为什么会发生这种情况。代码如下:

CREATE OR REPLACE PROCEDURE P_SYS_APPL_TEMP_SAVE2 
(
  P_C_CD IN GEN3200.C_CD%TYPE
, P_APPL_ID IN GEN3200.APPL_ID%TYPE
, P_ITEM_CD IN GEN3200.ITEM_CD%TYPE
, P_SEQ_NO IN GEN3200.SEQ_NO%TYPE
, P_ITEM_SIZE_CD IN GEN3200.ITEM_SIZE_CD%TYPE
, P_APPL_CNT IN GEN3200.APPL_CNT%TYPE
, P_ORDER_YMD IN GEN3200.ORDER_YMD%TYPE
, P_OFFER_YMD IN GEN3200.OFFER_YMD%TYPE
, P_MOD_USER_ID IN GEN3200.MOD_USER_ID%TYPE
, P_MOD_YMDHMS IN GEN3200.MOD_YMDHMS%TYPE
)
IS

APPL_TYPE VARCHAR2(20) := 
(SELECT T1.APPL_TYPE 
  FROM SY7010 T1
     , GEN3200 T2
 WHERE T1.C_CD = T2.C_CD
   AND T2.C_CD = P_C_CD
   AND T1.APPL_ID = T2.APPL_ID
   AND T2.APPL_ID = P_APPL_ID);
   
   
EMP_ID VARCHAR2(20) :=
(SELECT T1.APPL_EMP_ID EMP_ID
  FROM SY7010 T1
     , GEN3200 T2
 WHERE T1.C_CD = T2.C_CD
   AND T2.C_CD = P_C_CD
   AND T1.APPL_ID = T2.APPL_ID
   AND T2.APPL_ID = P_APPL_ID);

BEGIN

SELECT CASE WHEN PERIOD_CD IS NULL THEN 'Y'
            WHEN (CK_CNT + P_APPL_CNT) <= LIMIT_CNT THEN 'Y' 
            ELSE 'N' END AS CK_YN
  FROM (
        SELECT SUM(CASE WHEN T3.PERIOD_CD = '1' AND TO_CHAR(TO_DATE(T1.APPL_YMD, 'YYYYMMDD'), 'YYYY') = TO_CHAR(SYSDATE, 'YYYY') THEN T2.APPL_CNT
                    WHEN T3.PERIOD_CD = '2' AND TO_CHAR(TO_DATE(T1.APPL_YMD, 'YYYYMMDD'), 'MM') = TO_CHAR(SYSDATE, 'MM') THEN T2.APPL_CNT 
                    WHEN T3.PERIOD_CD = '3' AND T1.APPL_YMD = TO_CHAR(SYSDATE, 'YYYYMMDD') THEN T2.APPL_CNT 
                    ELSE 0 END) AS CK_CNT
             , T3.PERIOD_CD
             , T3.LIMIT_CNT
          FROM SY7010 T1
             , GEN3200 T2
             , GEN3100 T3
         WHERE T1.C_CD = P_C_CD
           AND T1.APPL_TYPE = APPL_TYPE
           AND T1.TRG_EMP_ID = EMP_ID
           AND TO_CHAR(TO_DATE(T1.APPL_YMD, 'YYYYMMDD'), 'YYYY') = TO_CHAR(SYSDATE, 'YYYY')
           AND T2.C_CD = T1.C_CD
           AND T2.APPL_ID = T1.APPL_ID
           AND T2.ITEM_CD = P_ITEM_CD
           AND T2.SEQ_NO = P_SEQ_NO
           AND T3.C_CD = T2.C_CD
           AND T3.ITEM_CD = T2.ITEM_CD
           AND T3.SEQ_NO = T2.SEQ_NO
         GROUP BY T3.PERIOD_CD, T3.LIMIT_CNT );

INSERT INTO GEN3200
(
C_CD
, APPL_ID
, ITEM_CD
, SEQ_NO
, ITEM_SIZE_CD
, APPL_CNT
, ORDER_YMD
, OFFER_YMD
, MOD_USER_ID
, MOD_YMDHMS
)
VALUES 
(
P_C_CD
, P_APPL_ID
, P_ITEM_CD
, P_SEQ_NO
, P_ITEM_SIZE_CD
, P_APPL_CNT
, P_ORDER_YMD
, P_OFFER_YMD
, P_MOD_USER_ID
, P_MOD_YMDHMS
);
COMMIT;

END P_SYS_APPL_TEMP_SAVE2;
/
  • 我在google上搜索了一下,但是找不到解决办法
gev0vcfq

gev0vcfq1#

我没有你的表格来测试,但是:

  • 在过程的DECLARE部分中声明的局部变量不能接受作为select语句结果的值;你必须在过程的可执行部分中输入select ... into。参见演示:
SQL> declare
  2    l_val number := (select 1 from dual);
  3  begin
  4    null;
  5  end;
  6  /
  l_val number := (select 1 from dual);
                   *
ERROR at line 2:
ORA-06550: line 2, column 20:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case for mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge standard time timestamp
interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>

SQL> declare
  2    l_val number;
  3  begin
  4    select 1 into l_val from dual;
  5  end;
  6  /

PL/SQL procedure successfully completed.
  • 下一个select(包含case表达式)需要into;基本上,PL/SQL中的所有选择都需要into子句(有一些例外,例如显式声明的游标,游标for循环,子查询...)
  • 这也意味着你必须声明一个变量来保存这个值

这是你的代码,经过编辑;看看能不能用就像我说的,没有table我没法经营。如果您仍然有问题,请考虑发布CREATE TABLE语句,以便我们可以创建环境来编译该过程。

CREATE OR REPLACE PROCEDURE P_SYS_APPL_TEMP_SAVE2 
(
  P_C_CD IN GEN3200.C_CD%TYPE
, P_APPL_ID IN GEN3200.APPL_ID%TYPE
, P_ITEM_CD IN GEN3200.ITEM_CD%TYPE
, P_SEQ_NO IN GEN3200.SEQ_NO%TYPE
, P_ITEM_SIZE_CD IN GEN3200.ITEM_SIZE_CD%TYPE
, P_APPL_CNT IN GEN3200.APPL_CNT%TYPE
, P_ORDER_YMD IN GEN3200.ORDER_YMD%TYPE
, P_OFFER_YMD IN GEN3200.OFFER_YMD%TYPE
, P_MOD_USER_ID IN GEN3200.MOD_USER_ID%TYPE
, P_MOD_YMDHMS IN GEN3200.MOD_YMDHMS%TYPE
)
IS
  APPL_TYPE VARCHAR2(20);
  EMP_ID VARCHAR2(20);
  l_yn varchar2(1);
BEGIN
SELECT T1.APPL_TYPE into appl_type
  FROM SY7010 T1
     , GEN3200 T2
 WHERE T1.C_CD = T2.C_CD
   AND T2.C_CD = P_C_CD
   AND T1.APPL_ID = T2.APPL_ID
   AND T2.APPL_ID = P_APPL_ID;
      
SELECT T1.APPL_EMP_ID into emp_id
  FROM SY7010 T1
     , GEN3200 T2
 WHERE T1.C_CD = T2.C_CD
   AND T2.C_CD = P_C_CD
   AND T1.APPL_ID = T2.APPL_ID
   AND T2.APPL_ID = P_APPL_ID;

SELECT CASE WHEN PERIOD_CD IS NULL THEN 'Y'
            WHEN (CK_CNT + P_APPL_CNT) <= LIMIT_CNT THEN 'Y' 
            ELSE 'N' END AS CK_YN
  INTO l_yn
  FROM (
        SELECT SUM(CASE WHEN T3.PERIOD_CD = '1' AND TO_CHAR(TO_DATE(T1.APPL_YMD, 'YYYYMMDD'), 'YYYY') = TO_CHAR(SYSDATE, 'YYYY') THEN T2.APPL_CNT
                    WHEN T3.PERIOD_CD = '2' AND TO_CHAR(TO_DATE(T1.APPL_YMD, 'YYYYMMDD'), 'MM') = TO_CHAR(SYSDATE, 'MM') THEN T2.APPL_CNT 
                    WHEN T3.PERIOD_CD = '3' AND T1.APPL_YMD = TO_CHAR(SYSDATE, 'YYYYMMDD') THEN T2.APPL_CNT 
                    ELSE 0 END) AS CK_CNT
             , T3.PERIOD_CD
             , T3.LIMIT_CNT
          FROM SY7010 T1
             , GEN3200 T2
             , GEN3100 T3
         WHERE T1.C_CD = P_C_CD
           AND T1.APPL_TYPE = APPL_TYPE
           AND T1.TRG_EMP_ID = EMP_ID
           AND TO_CHAR(TO_DATE(T1.APPL_YMD, 'YYYYMMDD'), 'YYYY') = TO_CHAR(SYSDATE, 'YYYY')
           AND T2.C_CD = T1.C_CD
           AND T2.APPL_ID = T1.APPL_ID
           AND T2.ITEM_CD = P_ITEM_CD
           AND T2.SEQ_NO = P_SEQ_NO
           AND T3.C_CD = T2.C_CD
           AND T3.ITEM_CD = T2.ITEM_CD
           AND T3.SEQ_NO = T2.SEQ_NO
         GROUP BY T3.PERIOD_CD, T3.LIMIT_CNT );

INSERT INTO GEN3200
(
C_CD
, APPL_ID
, ITEM_CD
, SEQ_NO
, ITEM_SIZE_CD
, APPL_CNT
, ORDER_YMD
, OFFER_YMD
, MOD_USER_ID
, MOD_YMDHMS
)
VALUES 
(
P_C_CD
, P_APPL_ID
, P_ITEM_CD
, P_SEQ_NO
, P_ITEM_SIZE_CD
, P_APPL_CNT
, P_ORDER_YMD
, P_OFFER_YMD
, P_MOD_USER_ID
, P_MOD_YMDHMS
);
COMMIT;
END P_SYS_APPL_TEMP_SAVE2;
/
xpszyzbs

xpszyzbs2#

这个问题似乎与你代码中的子查询有关。在PL/SQL中,如果要使用子查询为变量赋值,则应将子查询括在括号内。
例如,而不是:

APPL_TYPE VARCHAR2(20) :=
SELECT T1.APPL_TYPE 
  FROM SY7010 T1
     , GEN3200 T2
 WHERE T1.C_CD = T2.C_CD
   AND T2.C_CD = P_C_CD
   AND T1.APPL_ID = T2.APPL_ID
   AND T2.APPL_ID = P_APPL_ID;

您应该用途:

APPL_TYPE VARCHAR2(20);
BEGIN
  SELECT T1.APPL_TYPE 
  INTO APPL_TYPE
  FROM SY7010 T1
     , GEN3200 T2
 WHERE T1.C_CD = T2.C_CD
   AND T2.C_CD = P_C_CD
   AND T1.APPL_ID = T2.APPL_ID
   AND T2.APPL_ID = P_APPL_ID;
END;

相关问题