2013-02-11 54 views
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; 

什麼是正確的方法是什麼?

回答

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; 
0
p_description2  IN VARCHAR2; 

你想用這條線做什麼? 如果您想申報變量p_description2,則需要在DECLARE部分內部完成,該部分位於BEGIN之前。 雖然聲明它,但不要使用VARCHAR2,但使用CUR_RULES%ROWTYPE,這就是爲什麼pl/sql功能強大。