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;
什么是正确的方法?
答案 0 :(得分: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;
答案 1 :(得分:0)
p_description2 IN VARCHAR2;
你想用这条线做什么?
如果您要声明变量p_description2
,则需要在DECLARE
部分内,BEGIN
之前。
在声明它时,不要使用VARCHAR2
,而是使用CUR_RULES%ROWTYPE
,这就是pl / sql功能强大的原因。