PLS-00103 在 Oracle 游标中提供参数时 [重复]

Posted

技术标签:

【中文标题】PLS-00103 在 Oracle 游标中提供参数时 [重复]【英文标题】:PLS-00103 When providing parameter in Oracle cursor [duplicate] 【发布时间】:2019-11-22 00:24:04 【问题描述】:

已经找了一段时间了,但是在函数内部的游标中传递参数时,我无法发现以下错误的原因:

LINE/COL ERROR
-------- -----------------------------------------------------------------
10/7     PLS-00103: Encountered the symbol "WHERE" when expecting one of
     the following:
     begin function pragma procedure subtype type <an identifier>
     <a double-quoted delimited-identifier> current cursor delete
     exists prior

我一直在检查代码的结构,但没有运气。这是完整的sql代码:

CREATE TABLE subs (
   subs_list VARCHAR(500)
)
INSERT INTO subs (subs_list)
VALUES(('MOUNTAIN, MOUNT, MT, MTN'));

INSERT INTO subs (subs_list)
VALUES(('VIEW, VU'));

CREATE TABLE subs (
subs_list VARCHAR(500)
)
INSERT INTO subs (subs_list)
VALUES(('MOUNTAIN, MOUNT, MT, MTN'));

INSERT INTO subs (subs_list)
VALUES(('VIEW, VU'));


    SQL> CREATE OR REPLACE FUNCTION replace_synonyms(text IN VARCHAR2)
  2      RETURN VARCHAR2
  3  IS
  4      p_text VARCHAR2(4000) := text;
  5
  6      CURSOR c_subs
  7      IS
  8        SELECT subs_list
  9        FROM subs
 10        WHERE subs_list LIKE '%' ||p_text|| '%';
 11  BEGIN
 12     FOR i IN c_subs
 13      LOOP
 14        dbms_output.put_line(i.subs_list);
 15      END LOOP;
 16
 17     RETURN p_text;
 18  END;
 19  /

【问题讨论】:

【参考方案1】:

虽然您的 INSERT 语句有一个 ;最后,CREATE TABLE 语句不会。 检查前面的所有语句是否都成功完成。

CREATE TABLE subs (subs_list VARCHAR(500));

Table created.

INSERT INTO subs (subs_list)  VALUES(('MOUNTAIN, MOUNT, MT, MTN'));

1 row created.

INSERT INTO subs (subs_list) VALUES(('VIEW, VU'));

1 row created.

CREATE OR REPLACE FUNCTION replace_synonyms(text IN VARCHAR2)
RETURN VARCHAR2
IS
    p_text VARCHAR2(4000) := text;

    CURSOR c_subs
    IS
      SELECT subs_list
      FROM subs
      WHERE subs_list LIKE '%' ||p_text|| '%';
BEGIN
   FOR i IN c_subs
    LOOP
      dbms_output.put_line(i.subs_list);
    END LOOP;

   RETURN p_text;
END;
/

Function created.

【讨论】:

以上是关于PLS-00103 在 Oracle 游标中提供参数时 [重复]的主要内容,如果未能解决你的问题,请参考以下文章

(PLS-00103:在简单声明游标语句和循环选择数据期间遇到符号“;”)

PL/SQL 过程、游标、PLS- 00103 错误

Oracle 错误 PLS-00103

PLS-00103:在 oracle 函数中预期以下之一时遇到符号“IF”

PLS-00103:在 Oracle 11g 中遇到符号“DECLARE”

oracle函数错误pls-00103