是PL SQL的新手,如何在调用过程时解决pls-00306错误的参数数量?
CREATE OR REPLACE PROCEDURE overtime (
Normal_Hours NUMBER ,
Hours_worked NUMBER ,
message VARCHAR2 ,
Overtime IN OUT NUMBER )
AS
Begin
DBMS_OUTPUT.PUT_LINE('ENTER HOURS WORKED' || &hours_worked);
IF hours_worked <=Normal_Hours THEN
DBMS_OUTPUT.PUT_LINE('NO OVETIME WORKED');
ELSE
BEGIN
Overtime := Hours_worked - Normal_Hours;
DBMS_OUTPUT.PUT_LINE('You have worked' || Overtime );
END;
END IF;
END;
/
答案 0 :(得分:1)
错误...使用正确的参数数量和类型调用过程? E.g。
declare
v_overtime number;
begin
overtime(
normal_hours => 8
,hours_worked => 12
,message => 'clever message'
,overtime => v_overtime
);
dbms_output.put_line(v_overtime);
end;
/
请注意,因为第四个参数的传递模式是in out
,所以你需要将它绑定到一个变量中 - 一个常数不会发生。
答案 1 :(得分:1)
创建过程或函数时,声明的参数在调用过程或函数时应该是一致的。
CREATE OR REPLACE PROCEDURE overtime (
Normal_Hours NUMBER ,
Hours_worked NUMBER ,
message VARCHAR2 ,
Overtime IN OUT NUMBER )
由于您在过程中声明了4个参数,因此规则是在调用过程时,还应该传递4个变量/值。
declare
out_overtime number; -- this is the variable that will catch the value passed by the procedure
begin
overtime(8,9,'One Hour overtime', out_overtime);
dbms_output.put_line('Total overtime is '||out_overtime||' hours');
end;