我已经创建了名称更改的过程但是在调用过程时我会收到错误: 错误报告: ORA-06550:第4行,第5栏: PLS-00306:调用'PRODCHANGE_SP'时参数的数量或类型错误 过程:
create or replace
PROCEDURE PRODCHANGE_SP
(
P_PRODID IN bb_product.idproduct%TYPE
, P_NAME IN OUT bb_product.productname%TYPE
) AS
BEGIN
UPDATE bb_product
SET productname = p_name
WHERE idproduct = p_prodid;
COMMIT;
END PRODCHANGE_SP;
BLOCK,调用程序检查是否有效:
DECLARE
lv_pname_txt bb_product.productname%TYPE;
BEGIN
prodchange_sp(1, 'CapressoBar Model #352', lv_pname_txt);
DBMS_OUTPUT.PUT_LINE(lv_pname_txt);
END;
答案 0 :(得分:2)
您需要在更新之前获取旧值。更新后,用旧值覆盖out变量。
create or replace PROCEDURE PRODCHANGE_SP
(
P_PRODID IN bb_product.idproduct%TYPE,
P_NAME IN OUT bb_product.productname%TYPE
) AS
P_NAME_old bb_product.productname%TYPE;
BEGIN
SELECT productname
INTO P_NAME_old
FROM bb_product
WHERE idproduct = p_prodid;
UPDATE bb_product
SET productname = p_name
WHERE idproduct = p_prodid;
COMMIT;
P_NAME := P_NAME_old;
END PRODCHANGE_SP;
您需要传递与IN OUT相同的变量中的值。重写代码以调用过程如下。
DECLARE
lv_pname_txt bb_product.productname%TYPE;
BEGIN
lv_pname_txt := 'CapressoBar Model #352';
prodchange_sp(1, lv_pname_txt);
DBMS_OUTPUT.PUT_LINE(lv_pname_txt);
END;