Oracle SQL中的标识符无效

时间:2013-12-20 10:43:01

标签: sql oracle oracle-sqldeveloper

我没有在带双引号的表中创建任何columns(PAYMENTTERM)但是 我仍然得到以下错误:

Error(26,9): PL/SQL: SQL Statement ignored
Error(27,29): PL/SQL: ORA-00904: "P"."PAYMENTTERM": invalid identifier

请指出我在做什么和需要纠正的错误:

CREATE OR REPLACE
PROCEDURE PAYTERMUPDATE
IS
    RecordCount INT;
BEGIN
    SELECT
        count(1) INTO RecordCount 
    FROM 
        docmeta d 
    INNER JOIN temp_pay_term p ON d.XPROJECT_ID = p.PID
    WHERE
        lower(d.PAYMENTTERM) <> lower(p.PAYMENTTERM);

    DBMS_OUTPUT.PUT_LINE('');
    DBMS_OUTPUT.PUT_LINE('There were '
            || to_char(RecordCount)
            || ' records where payment term is mismatch.');
    DBMS_OUTPUT.PUT_LINE('');

    FOR X IN (
        SELECT p.PID, p.PAYMENTTERM
        FROM docmeta d, temp_pay_term p
        WHERE d.XPROJECT_ID = p.PID AND d.PAYMENTTERM <> p.PAYMENTTERM)
    LOOP
       UPDATE docmeta
           SET d.PAYMENTTERM = p.PAYMENTTERM
       WHERE XPROJECT_ID = X.PID;
    END LOOP;

    COMMIT;

EXCEPTION
WHEN OTHERS THEN
      raise_application_error(-1000,
                    'Error occured, No payment term were updated');

END PAYTERMUPDATE;

3 个答案:

答案 0 :(得分:2)

在这一行:

UPDATE docmeta
SET d.PAYMENTTERM = p.PAYMENTTERM
WHERE XPROJECT_ID = X.PID ; 

您必须在docmeta(d)上添加别名,而p.PAYMENTTERM别名必须为X

因此,以这种方式更改您的查询:

UPDATE docmeta d
SET d.PAYMENTTERM = X.PAYMENTTERM
WHERE XPROJECT_ID = X.PID ; 

答案 1 :(得分:1)

在您的情况下,使用循环变量作为PAYMENTTERM的别名X,同时将DOCMETA的别名声明为d

答案 2 :(得分:-1)

试试这个?

LOOP 
    UPDATE docmeta d
    SET d.PAYMENTTERM = p.PAYMENTTERM
    WHERE XPROJECT_ID = X.PID ; 
  END LOOP;