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;
在cdi
表中comp_id
是主键
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;
我不确定我应该做什么,首先我想到连接v_pk_key
类似empno||ename||job
然后在选择查询中使用它,但无法检查空值,我很困惑该怎么做。
编辑
我尝试过的是将列表 v_pk_key 转换为
NVL(empno,'$')||NVL(ename,'$')||NVL(job,'$') and then
select v_pk_list from emp_test where empno=p_empno;
然后检查结果中的 $ 如果结果中没有 $ 我会检查不止一行,但我发现这不是一个有效的解决方案
如果有人给我一个jist,我会解决这个问题。