create table cdi(comp_id varchar2(3),pk_key varchar2(2000));
insert into cdi values('abc','empno,ename,job');
insert into cdi values('pqr','empno,job,mgr');
insert into cdi values('cde','empno,mgr,sal');
commit;
create table emp_test(empno integer,ename varchar2(200),job varchar2(200),mrg integer,sal integer);
insert into emp_test values(1,'Gaurav Soni','DB',12,12000);
insert into emp_test values(2,'Niharika Saraf','Law',13,12000);
insert into emp_test values(2,'Niharika Saraf','Law',13,12000);
insert into emp_test values(3,'Saurabh Soni',null,12,12000);
commit;
In cdi
table comp_id
is primary key
create or replace procedure test(p_comp_id IN cdi.comp_id%TYPE
,p_empno IN emp_test.empno%TYPE
)
IS
TYPE ref_cur is ref cursor;
v_cur ref_cur;
v_pk_key cdi.pk_key%TYPE;
BEGIN
OPEN v_cur is select pk_key from cdi where comp_id =p_comp_id;
fetch v_cur into v_pk_key;
--now this list v_pk_key is primary key for that comp_id
--so following things need to be done
--1.check the emp_test table with this column list (v_pk_key )
--2. whether for that emp_no the primary key is null eg.
-- incase of comp_id cde ...empno,mgr,sal value should be not null
--if any of the value is null raise an error
--3.If there are two rows for that primary also raise an error.
-- for eg comp_id=abc two rows are fetched from emp_test
close v_cur;
END;
I am not sure of the approach what should i do to,first i think of concatenating the v_pk_key
like empno||ename||job
and then used this in select query ,but not able to check for null values ,i am confused what to do .
EDIT
what i have tried was to convert the list v_pk_key to
NVL(empno,'$')||NVL(ename,'$')||NVL(job,'$') and then
select v_pk_list from emp_test where empno=p_empno;
and then check for $ in the result if there is no $ in the result i ll check for more than one row,but i am not finding this as an efficient solution
if anyone give me a jist of it ,i will solve this .