0
DECLARE
PROCEDURE create_rule(
      p_rule_type_key   IN VARCHAR2,
      p_key             IN VARCHAR2,
      p_activation      IN DATE,
      p_termination     IN DATE,
      p_description     IN VARCHAR2
    )
IS
   CURSOR cur_rules (pc_rule_type_key IN VARCHAR2, pc_key IN VARCHAR2)
   IS
      SELECT rule_type_key
      FROM ino_offers.rules
      WHERE rule_type_key = pc_rule_type_key
      AND key             = pc_key;
BEGIN
   OPEN cur_rules (p_rule_type_key, p_key);
   p_description2     IN VARCHAR2;
   FETCH cur_rules INTO p_description2;
   IF (cur_rules%NOTFOUND) THEN
      INSERT
      INTO rules
         (
            RULE_TYPE_KEY,
            KEY,
            ACTIVATION,
            TERMINATION,
            DESCRIPTION,
            CHANGED
         )
         VALUES
         (
            p_rule_type_key,
            p_key,
            p_activation,
            p_termination,
            p_description,
            SYSDATE
         );
   END IF;
   CLOSE cur_rules;
END;
BEGIN
   create_rule(?, ?, ?, ?, ?);
END;

但我得到:

PLS-00103: Encountered the symbol "IN" when expecting one of the following:

   := . ( @ % ;
The symbol ":= was inserted before "IN" to continue.

问题在这里:

OPEN cur_rules (p_rule_type_key, p_key);
       p_description2     IN VARCHAR2;

什么是正确的方法?

4

2 回答 2

1

嗨,你在开始后声明了 p_description2 IN VARCHAR2。你得到了以下错误。你将游标记录提取到 p_description2 变量中,所以它应该是 cur_rules 类型。所以尝试像这样使用 p_description2 cur_rules%ROWTYPE;

DECLARE
PROCEDURE create_rule(
      p_rule_type_key   IN VARCHAR2,
      p_key             IN VARCHAR2,
      p_activation      IN DATE,
      p_termination     IN DATE,
      p_description     IN VARCHAR2
    )
IS
   CURSOR cur_rules (pc_rule_type_key IN VARCHAR2, pc_key IN VARCHAR2)
   IS
      SELECT rule_type_key
      FROM ino_offers.rules
      WHERE rule_type_key = pc_rule_type_key
      AND key             = pc_key;
 p_description2 cur_rules%ROWTYPE;
BEGIN
   OPEN cur_rules (p_rule_type_key, p_key);
   FETCH cur_rules INTO p_description2;
   IF (cur_rules%NOTFOUND) THEN
      INSERT
      INTO rules
         (
            RULE_TYPE_KEY,
            KEY,
            ACTIVATION,
            TERMINATION,
            DESCRIPTION,
            CHANGED
         )
         VALUES
         (
            p_rule_type_key,
            p_key,
            p_activation,
            p_termination,
            p_description,
            SYSDATE
         );
   END IF;
   CLOSE cur_rules;
END;
BEGIN
   create_rule(?, ?, ?, ?, ?);
END;
于 2013-02-12T04:06:02.760 回答
0
 p_description2     IN VARCHAR2;

你到底想用那条线做什么?如果你想声明一个变量p_description2,你需要在DECLARE部件内部,就在BEGIN. 在声明它时,不要使用 a VARCHAR2,而是使用 a CUR_RULES%ROWTYPE,这就是 pl/sql 强大的原因。

于 2013-02-11T16:15:35.263 回答