Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Invalid Identifier error when trying to create a trigger

xarg-XrcJul 19 2012 — edited Jul 19 2012
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.
This post has been answered by unknown-7404 on Jul 19 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 16 2012
Added on Jul 19 2012
13 comments
2,898 views