PLS-00357:在此上下文中不允许使用表,视图或序列引用

时间:2015-10-09 16:43:38

标签: database oracle plsql

我想在我的包体中编写更新程序。在我添加这个IF语句之前它工作正常。我想检查一下,只有当新值与旧值不同时,我才更新它。否则,我不会更新它。然后我收到了这个错误:Error(39,22): PLS-00357: Table,View Or Sequence reference 'USER.TABLE_NAME.FIRSTNAME' not allowed in this context。以下是我的程序代码:

PROCEDURE updateTABLE (
  v_code        IN      USER.TABLE_NAME.CODE%TYPE,
  v_id          IN      USER.TABLE_NAME.ID%TYPE,
  v_firstname   IN      USER.TABLE_NAME.FIRSTNAME%TYPE,
  v_lastname    IN      USER.TABLE_NAME.LASTNAME%TYPE,
  v_email       IN      USER.TABLE_NAME.EMAIL%TYPE,
  v_phone       IN      USER.TABLE_NAME.PHONE%TYPE
) IS
BEGIN
IF USER.TABLE_NAME.FIRSTNAME != v_firstname OR
   USER.TABLE_NAME.LASTNAME != v_lastname OR
   USER.TABLE_NAME.EMAIL != v_email OR
   USER.TABLE_NAME.PHONE != v_phone THEN
UPDATE USER.TABLE_NAME
        SET FIRSTNAME = v_firstname,
            LASTNAME = v_lastname,
            EMAIL = v_email,
            PHONE = v_phone,
            SYS_LASTMODF_DTTM = sysdate
  WHERE USER.TABLE_NAME.ID = v_id AND
        USER.TABLE_NAME.CODE= v_code;

END IF;
COMMIT;
END updateTABLE;

想知道我该如何解决它?在这里做了一些搜索,但没找到我需要的东西。

1 个答案:

答案 0 :(得分:0)

答案在评论中,我只是想把它放在这里以防以后有人需要它。

BEGIN 
  UPDATE USER.TABLE_NAME 
    SET FIRSTNAME = v_firstname, 
        LASTNAME = v_lastname, 
        EMAIL = v_email, 
        PHONE = v_phone, 
        SYS_LASTMODF_DTTM = sysdate 
    WHERE USER.TABLE_NAME.ID = v_id 
      AND USER.TABLE_NAME.CODE= v_code 
      AND (USER.TABLE_NAME.FIRSTNAME != v_firstname 
        OR USER.TABLE_NAME.LASTNAME != v_lastname 
        OR USER.TABLE_NAME.EMAIL != v_email 
        OR USER.TABLE_NAME.PHONE != v_phone); 
COMMIT;