Этот блок кода работал для меня.Здесь необходимо использовать динамический SQL.
Пример данных:
create table table_name(abc, efg, hij, klm) as (
select '1234', '5678', 'PQR', 'XYZ' from dual union all
select '1221', '8688', 'ABQ', 'ZAA' from dual
);
alter table table_name add constraint tn_pk primary key (abc, efg);
Блок кода:
declare
v_flt varchar2(4000);
v_val varchar2(1000);
v_sql varchar2(4000);
begin
for r in (select rowid rwd from table_name where rownum <= 2) loop
v_flt := '';
for con in (select column_name col
from all_constraints cons
join all_cons_columns cols using (owner, table_name, constraint_name)
where owner = 'SCOTT'
and table_name = 'TABLE_NAME'
and constraint_type = 'P')
loop
v_sql := 'select '||con.col||' from table_name where rowid = '''||r.rwd||'''' ;
execute immediate v_sql into v_val;
v_flt := v_flt ||con.col||' = '''||v_val||''' AND ';
end loop;
dbms_output.put_line(v_flt);
end loop;
end;
Результат:
ABC = '1221' AND EFG = '8688' AND
ABC = '1234' AND EFG = '5678' AND