2017-03-04 78 views
-1
相關的行號
create or replace TRIGGER R_TRACKER_TRI 
    before insert on R_TRACKER 
    for each row 
    declare 
    v_number varchar2(15); 
    begin 

     if inserting then 
     :NEW.PROJECT_ID := PROJECT_ID(1); 
     :NEW.PRO_CREATED := LOCALTIMESTAMP; 
     :NEW.PRO_CREATED_BY := nvl(v('APP_USER'),USER); 

     IF :NEW.RECRUITMENT_TYPE= 'New' THEN 

      SELECT ('NEW/'||TO_CHAR(SYSDATE,'YY') || '/' || (NVL(MAX(SUBSTRB(PROJECT_ID,8)),10000)+1)) into v_number 
      FROM R_TRACKER 
      WHERE SUBSTRB(PROJECT_ID,1,3) = 'NEW'; 

      :NEW.PROJECT_ID := v_number; 

      elsif :NEW.RECRUITMENT_TYPE= 'Replacement' THEN 

      SELECT ('REP/'||TO_CHAR(SYSDATE,'YY') || '/' || (NVL(MAX(SUBSTRB(PROJECT_ID,8)),10000)+1)) into v_number 
      FROM R_TRACKER 
      WHERE SUBSTRB(PROJECT_ID,1,3) = 'REP'; 
      :NEW.PROJECT_ID := v_number; 

     end if; 
INSERT INTO R_TRACKER 
      (
       PROJECT_ID, 
       PRO_LOC, 
       DESIGNATION, 
       NO_OF_POSITION, 
       VACANCY_SINCE, 
       STATUS, 
       REMARKS, 
       UPLOAD, 
      RECRUITMENT_TYPE, 
      APPROVAL, 
      ACTION 
      ) 
      VALUES 
      (
       :NEW.PROJECT_ID, 
       :NEW.PRO_LOC, 
       :NEW.DESIGNATION, 
       :NEW.NO_OF_POSITION, 
       :NEW.VACANCY_SINCE, 
       :NEW.STATUS, 
       :NEW.REMARKS 
       :NEW.UPLOAD, 
      :NEW.RECRUITMENT_TYPE, 
      :NEW.APPROVAL, 
      :NEW.ACTION 
      );   
       end if; 
       end; 
+0

感謝您在同我收到PLS-00201的錯誤味精進行補正後洙多Gurv:標識符 'PROJECT_ID' 必須是declaredCompilation失敗,L –

+0

你能確認R_TRACKER裏面有PROJECT_ID嗎? – mmmmmpie

回答

1

查看您的代碼,請閱讀。簡而言之,我想告訴triggertable上的事件。它被創建爲自動插入/更新/刪除該表的列值。在你的情況下,你在表R_TRACKER上創建觸發器,然後再在inserting以下創建觸發器。這是錯誤的。看你如何做到這一點。

--Table 
CREATE TABLE R_TRACKER 
(
    PROJECT_ID   VARCHAR2 (50), 
    PRO_LOC   VARCHAR2 (50), 
    DESIGNATION  VARCHAR2 (50), 
    NO_OF_POSITION  VARCHAR2 (50), 
    VACANCY_SINCE  VARCHAR2 (50), 
    STATUS    VARCHAR2 (50), 
    REMARKS   VARCHAR2 (50), 
    UPLOAD    VARCHAR2 (50), 
    RECRUITMENT_TYPE VARCHAR2 (50), 
    APPROVAL   VARCHAR2 (50), 
    ACTION    VARCHAR2 (50) 
); 

--Trigger上表

CREATE OR REPLACE TRIGGER R_TRACKER_TRI 
    BEFORE INSERT ON R_TRACKER 
    FOR EACH ROW 
DECLARE 
    v_number VARCHAR2 (15); 
BEGIN 
    IF INSERTING 
    THEN 
     :NEW.PROJECT_ID := '1';--PROJECT_ID(1) -- This seems to be a function in your case; 
    --:NEW.PRO_CREATED := LOCALTIMESTAMP; 
    -- :NEW.PRO_CREATED_BY := NVL('APP_USER', USER); 

     IF :NEW.RECRUITMENT_TYPE = 'New' 
     THEN 
     SELECT ( 'NEW/' 
       || TO_CHAR (SYSDATE, 'YY') 
       || '/' 
       || (NVL (MAX (SUBSTRB (PROJECT_ID, 8)), 10000) + 1)) 
      INTO v_number 
      FROM R_TRACKER 
      WHERE SUBSTRB (PROJECT_ID, 1, 3) = 'NEW'; 

     :NEW.PROJECT_ID := v_number; 

     ELSIF :NEW.RECRUITMENT_TYPE = 'Replacement' 
     THEN 
     SELECT ( 'REP/' 
       || TO_CHAR (SYSDATE, 'YY') 
       || '/' 
       || (NVL (MAX (SUBSTRB (PROJECT_ID, 8)), 10000) + 1)) 
      INTO v_number 
      FROM R_TRACKER 
      WHERE SUBSTRB (PROJECT_ID, 1, 3) = 'REP'; 

     :NEW.PROJECT_ID := v_number; 
     END IF; 

    END IF; 
END;