I have a For loop in plsql and a procedure. Inside the procedure I have IF block :
IF c.payer='GCC' and c.dataset='SAME' then
EMPID:=REGEXP_SUBSTR(c.hitablename,'[^_]+',1,4);
vbquery:='
Insert /*parallel(unk_codes)*/ into unk_codes(act_nbr, hitablename, groupid, payer)
select /* parallel(a,4) */ distinct '''||EMPID||'0100'' as unknown_codes,'''||c.hitablename||''' as hitablename,
REGEXP_SUBSTR('''||c.hitablename||''',''[^_]+'',1,4) as groupid,'''||c.payer||''' as payer from HI0777777.'||c.hitablename||' a
where '''||EMPID||'0100'' in (select NVL(b.ACC_NUM,''NOT'') from group_abc b where
'''||EMPID||'0100'' = b.ACC_NUM
AND
REGEXP_SUBSTR('''||c.hitablename||''',''[^_]+'',1,4)=b.group_id)';
BEGIN
EXECUTE IMMEDIATE vbquery;
EXCEPTION WHEN OTHERS THEN
Dbms_Output.put_line('GCC SAME block'||SQLERRM||vbquery||c.ai_table);
END;
END IF;
I want to pass EMPID inside the vbquery string but I am getting ORA-00936: missing expression error.
I tried to debugged and see what is the problem and I found EMPID value not getting replaced inside vbquery.
My vbquery is being printed as:
ORA-00936: missing expression
Insert /*parallel(unk_codes)*/ into unk_codes(act_nbr, hitablename, groupid, payer)
select /* parallel(a,4) */ distinct unknown_codes,'HI_SAME_GCC_MPD' as hitablename,
REGEXP_SUBSTR('HI_SAME_GCC_MPD','[^_]+',1,4) as groupid,'GCC' as payer from HI0777777.HI_SAME_GCC_MPD a
where not exists (select 1 from group_abc b where b.acc_num= and
REGEXP_SUBSTR('HI_SAME_GCC_MPD','[^_]+',1,4)=b.group_id)
My EMPID may be 'ABCD'. So my expected output was:
Insert /*parallel(unk_codes)*/ into unk_codes(act_nbr, hitablename, groupid, payer)
select /* parallel(a,4) */ distinct 'ABCD0100' unknown_codes,'HI_SAME_GCC_MPD' as hitablename,
REGEXP_SUBSTR('HI_SAME_GCC_MPD','[^_]+',1,4) as groupid,'GCC' as payer from HI0777777.HI_SAME_GCC_MPD a
where not exists (select 1 from group_abc b where b.acc_num='ABCD0100' and
REGEXP_SUBSTR('HI_SAME_GCC_MPD','[^_]+',1,4)=b.group_id)
Why is that EMPID value not getting passed in string?
DECLARE v_test VARCHAR2(4000); v_test2 VARCHAR2(4000); BEGIN SELECT REGEXP_SUBSTR('500 Oracle Parkway, Redwood Shores, CA', ',[^,]+,') INTO v_test2 FROM dual; v_test := REGEXP_SUBSTR('500 Oracle Parkway, Redwood Shores, CA', ',[^,]+,'); dbms_output.put_line(v_test); dbms_output.put_line(v_test2); END;- both outputs show up fine