0% found this document useful (0 votes)
3 views

Example Code

The document contains multiple PL/SQL blocks that perform operations on tables 'testa', 'testb', and 'testc', including data insertion, selection, and comparison. It utilizes cursor loops and dynamic SQL to generate and execute queries based on the results from the 'test_diff' table. Additionally, it handles exceptions and outputs messages for debugging purposes.

Uploaded by

Srikkanth Mani
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Example Code

The document contains multiple PL/SQL blocks that perform operations on tables 'testa', 'testb', and 'testc', including data insertion, selection, and comparison. It utilizes cursor loops and dynamic SQL to generate and execute queries based on the results from the 'test_diff' table. Additionally, it handles exceptions and outputs messages for debugging purposes.

Uploaded by

Srikkanth Mani
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

DECLARE

lv_var1 VARCHAR2(100);
lv_var2 VARCHAR2(100);
lv_var3 VARCHAR2(100);
lv_var4 VARCHAR2(100);
v_select VARCHAR2(1000);
v_insert VARCHAR2(1000);
BEGIN
FOR i IN (
SELECT
/* LISTAGG('A.' || col_name, ',') WITHIN GROUP(
ORDER BY
tab_name
),
LISTAGG('B.' || col_name1, ',') WITHIN GROUP(
ORDER BY
tab_name1
), */
col_name sc_colname,
col_name1 tg_colname,
tab_name AS sr_tab,
tab_name1 AS tg_tab,
tab_name
|| ' A inner join '
|| tab_name1
|| ' B on (a.id=b.id )' tab_name
FROM
test_diff
) LOOP
dbms_output.put_line('Test');
v_select := 'select a.id as sr_id, b.id as tg_id, '''
|| i.sr_tab
|| ''' as sr_tab, '''
|| i.sc_colname
|| ''' as sr_colname, a.'
|| i.sc_colname
|| ' as sr_value , '''
|| i.tg_tab
|| ''' as tg_tab, '''
|| i.tg_colname
|| ''' as tg_colname, b.'
|| i.tg_colname
|| ' as tg_value'
|| ' from '
|| i.tab_name
|| ' where a.'
|| i.sc_colname
|| ' != b.'
|| i.tg_colname;

v_select := 'insert into testc


(sc_id,tg_id,sc_tabname,sc_column,sc_value,tg_tabname,tg_column,tg_value)' ||
v_select;
dbms_output.put_line(v_select);
EXECUTE IMMEDIATE v_select;
COMMIT;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
dbms_output.put_line('Issue' || sqlerrm);
END;

----------

DECLARE
lv_var1 VARCHAR2(100);
lv_var2 VARCHAR2(100);
lv_var3 VARCHAR2(100);
lv_var4 VARCHAR2(100);
v_select VARCHAR2(1000);
v_insert varchar2(1000);
BEGIN
SELECT
LISTAGG('A.' || col_name, ',') WITHIN GROUP(
ORDER BY
tab_name
) ,
LISTAGG('B.' || col_name1, ',') WITHIN GROUP(
ORDER BY
tab_name1
)
INTO
lv_var1,
lv_var2
FROM
test_diff;

for i in (select col_name,col_name1 into lv_var3,lv_var4 from test_diff ) loop


/* v_select := 'select '
|| lv_var1
|| ' from testa a minus select '
|| lv_var2
|| ' from testb b'; */

lv_var3 := i.col_name;
lv_var4 := i.col_name;
v_insert := 'insert into testc (sc_id,sc_value,sc_column) select a.id, '
|| i.col_name
|| ' from testa a minus select b.id, '
|| i.col_name1
|| ' from testb b';

dbms_output.put_line ('Test: '|| v_insert);


execute immediate v_insert;
END loop;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Issue' || sqlerrm);
END;

-----------

select * from testa


/
select * from testb
/
insert into testa values (4,'EE','EEE','EEEE','EEEEE')
/
insert into testb values (4,'EF','EFF','EFFF','EEEEE')
/
update testb set id=5 where name1='EF'
/
select * from test_diff
/
create table testd (name1 varchar2(240),name2 varchar2(240),name3 varchar2(240))
/
select *from testc
/
select * from teste
/
select * from (
select id,name1 from testa
minus
select id, name1 from testb)
/
delete test_diff where col_name='ID'
/
create table teste (id number,name varchar2(100))
/
delete from testc
/
select * from testc
/
select a.id sid,a.name1 sname1,a.name2 sname2,b.id tid,b.name1 tname1,b.name2
tname2 from testa a,testb b
where a.id=b.id
order by a.id asc
/
select * from testc
/
select * from test_diff
/
SELECT
LISTAGG('A.' || col_name, ',') WITHIN GROUP(
ORDER BY
tab_name
) ,
LISTAGG('B.' || col_name1, ',') WITHIN GROUP(
ORDER BY
tab_name1
) ,tab_name ||' A inner join '|| tab_name1 ||' B on (a.id=b.id )'

FROM
test_diff
group by tab_name,tab_name1
/
insert into testc
(sc_id,tab_name,sc_colname,sc_value,tg_id,tg_name,tg_colname,tg_value)select a.id
as sr_id, 'TESTA' as sr_tab, 'NAME1' as sr_colname, a.NAME1 as sr_value , 'TESTB'
as tg_tab, 'NAME1' as tg_colname, b.NAME1 as tg_value from TESTA A inner join
TESTB B on (a.id=b.id ) where a.NAME1 != b.NAME1

/
DECLARE
lv_var1 VARCHAR2(100);
lv_var2 VARCHAR2(100);
lv_var3 VARCHAR2(100);
lv_var4 VARCHAR2(100);
v_select VARCHAR2(1000);
v_insert VARCHAR2(1000);
BEGIN
FOR i IN (
SELECT
/* LISTAGG('A.' || col_name, ',') WITHIN GROUP(
ORDER BY
tab_name
),
LISTAGG('B.' || col_name1, ',') WITHIN GROUP(
ORDER BY
tab_name1
), */
tab_name
|| ' A inner join '
|| tab_name1
|| ' B on (a.id=b.id )'
FROM
test_diff
GROUP BY
tab_name,
tab_name1
) LOOP
dbms_output.put_line('Test');
v_select:=
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Issue' || sqlerrm);
END;
/
alter table testc add tg_tabname varchar2(100)

You might also like