我尝试使用独立的外部过程从游标中运行,获取变量并将其返回到过程,其中过程将值插入另一个表中。得到错误。
PROCEDURE:
CREATE OR REPLACE PROCEDURE proc_test
(p_inn newtable.totalhours%TYPE) AS
BEGIN
p_inn := p_inn - p_inn + 1;
INSERT INTO proceduretest (value)
VALUES (p_inn);
END proc_test;
/
带游标的代码
SET SERVEROUTPUT ON
DECLARE
v_idno paydata1.idno%TYPE;
v_name paydata1.name%TYPE;
v_hrs paytran1.hourswk%TYPE;
v_hrsT paytran1.hourswk%TYPE;
v_code paydata1.jobcode%TYPE;
v_payh paydata1.payhr%TYPE;
v_sal paydata1.salary%TYPE;
v_OT NUMBER(6,2);
CURSOR payday IS
SELECT idno, name FROM paydata1
ORDER BY idno;
CURSOR paytray IS
SELECT hourswk FROM paytran1
WHERE v_idno = idno
ORDER BY idno;
CURSOR total IS
SELECT idno, name, jobcode, salary, payhr
FROM paydata1
WHERE v_idno = idno;
BEGIN
OPEN payday;
LOOP
FETCH payday INTO v_idno, v_name;
EXIT WHEN payday%NOTFOUND;
IF paytray%ISOPEN THEN
CLOSE paytray;
END IF;
OPEN paytray;
v_hrsT := 0;
LOOP
FETCH paytray INTO v_hrs;
EXIT WHEN paytray%NOTFOUND;
v_hrsT := v_hrsT + v_hrs;
END LOOP;
OPEN total;
FETCH total INTO v_idno, v_name, v_code, v_sal, v_payh;
WHILE total%FOUND LOOP
IF v_code = 'S' THEN
v_sal := v_sal / 52;
DBMS_OUTPUT.PUT_LINE(v_name || ' - Total hours worked is: ' || v_hrsT);
proc_test (v_hrsT); <------------------
ELSE
IF v_hrsT > 40 THEN
v_OT := v_hrsT - 40;
v_OT := v_OT * (v_payh * 1.5);
v_OT := v_OT + (40 * v_payh);
v_sal := v_OT;
ELSE
v_sal := v_hrsT * v_payh;
END IF;
DBMS_OUTPUT.PUT_LINE(v_name || ' - Total hours worked is: ' || v_hrsT);
proc_test (v_hrsT); <---------------
END IF;
FETCH total INTO v_idno, v_name, v_code, v_sal, v_payh;
END LOOP;
CLOSE total;
CLOSE paytray;
END LOOP;
CLOSE payday;
END;
/
SET SERVEROUTPUT OFF
我道歉,一些代码在最后变得凌乱,但是我已经将箭头绘制到调用过程的位置。
错误:
LINE/COL ERROR
-------- -----------------------------------------------------------------
5/1 PL/SQL: Statement ignored
5/1 PLS-00363: expression 'P_INN' cannot be used as an assignment
target
答案 0 :(得分:1)
未定义方向的参数默认为IN。我们不能分配(改变)IN参数的值。您尚未定义P_INN的方向,因此它默认为IN,因此您无法执行此操作
p_inn := p_inn - p_inn + 1;
这是错误消息告诉你的内容。
如果你不需要插入它以外的其他任何操作值,那就这样做....
CREATE OR REPLACE PROCEDURE proc_test
(p_inn newtable.totalhours%TYPE) AS
BEGIN
INSERT INTO proceduretest (value)
VALUES (p_inn - p_inn + 1);
END proc_test;
/
否则使用局部变量:
CREATE OR REPLACE PROCEDURE proc_test
(p_inn IN newtable.totalhours%TYPE)
AS
l_inn newtable.totalhours%TYPE;
BEGIN
l_inn := p_inn - p_inn + 1;
INSERT INTO proceduretest (value)
VALUES (l_inn);
END proc_test;
/