基本游标中的独立过程错误 table

Standalone Procedure Error in Cursor to a basic table

我正在尝试使用一个独立的外部过程 运行 从一个游标中获取一个变量并将其扔回该过程,该过程将在该过程中将值插入另一个 table.获取错误。

程序:

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

您的过程需要两个参数,但您用一个参数调用它。

编辑:更改后,您可以像使用变量一样使用参数。这只允许用于 OUT 参数。无论如何,你的计算毫无意义。

为此,请像这样更改您的代码:

CREATE OR REPLACE PROCEDURE proc_test (p_inn IN OUT newtable.totalhours%TYPE) AS

未定义方向的参数默认为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;
/