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!

Help in Execute Immediate - Invalid relational Operator

AceNoviceJul 25 2012 — edited Jul 26 2012
I am trying to find rows from a table which has unexpected records. for that i have created a exception table..

Table Name = ABC
TABLE_NAME	COLsUMN_NAME	COL_VALUES
------------	-----------	-----------
CUSTOMER	DEPARTMENT	0
CUSTOMER	DEPARTMENT	NULL
It says, if Department column of Customer table contains value 0 or NULL, notify concerned team. There are many other tables on which we need to perform same.

I have created a procedure which will run after daily load.
CREATE OR REPLACE PROCEDURE EXCP_TEST
AS


BEGIN
	FOR TableList IN (SELECT DISTINCT TABLE_NAME FROM ABC)
	LOOP
		FOR ColumnList IN (SELECT COLUMN_NAME, COL_VALUES FROM ABC WHERE TABLE_NAME = TableList.TABLE_NAME)
		LOOP
			/* below code will create dynamic WHERE Condition. (as NULL requires Column_name 'IS NULL' and other value requires columna_name = '0' */

			IF ColumnList.COL_VALUES = 'NULL'
			THEN
				v_where = ' IS NULL ';
			ELSE
				v_where := ' = ' ||''''||ColumnList.COL_VALUE||'''';
			END IF;

			/* below code is to check if any record exists. Here is an issue. WHile executing Dynamic SQL it gives an error. */
			/* Error is : Invalid relational Operator

			EXECUTE IMMEDIATE 'SELECT COUNT(1) FROM ' || v_tabname || ' WHERE ' || v_colname  || ' :a ' into v_cnt using v_where;
		END LOOP
	END LOOP;
END;
Can comeone help me to find solution for the same...?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 23 2012
Added on Jul 25 2012
15 comments
590 views