Hi all,
I am getting this weird error when trying to create a trigger. Basically it updates a different relationship table on INSERT or UPDATE.
The error I am getting is:
* PL/SQL: ORA-00904: "cid": invalid identifier*
SET SERVEROUTPUT ON
CREATE or REPLACE TRIGGER UPDATE_REL_TABLE
AFTER INSERT OR UPDATE ON XF_PROJECT_CODE
FOR EACH ROW
DECLARE
customer_count NUMBER;
n_cid NUMBER;
BEGIN
-- CHECK if company exist
SELECT COUNT(*) INTO customer_count FROM XF_CLIENTS WHERE UPPER(client_name) = UPPER(:NEW.company);
CASE
WHEN customer_count > 0 THEN
-- GET CUSTOMER ID
select t.cid INTO n_cid FROM XF_CLIENTS t WHERE t.CLIENT_NAME = :NEW.company; // ERROR HERE!!
-- UPDATE relationship table
INSERT INTO XF_CLIENT_CODE_R (PROJECT_CODE_ID, cid) VALUES (:NEW.project_code_id, n_cid);
ELSE
-- customer does not exist
n_cid := XF_CLIENTS_SEQ.NEXTVAL;
-- Create client
INSERT INTO XF_CLIENTS(cid, client_name) VALUES(n_cid, :NEW.company);
-- update relationship table
INSERT INTO XF_CLIENT_CODE_R(project_code_id, XF_cid) VALUES (:NEW.project_code_id, n_cid);
END CASE;
END;
/
SHOW ERRORS;
The column exists and the data type (number) matches. Any help appreciated. bit at loss where I am going wrong.