Repository navigation
Expand file tree
/
Copy pathcol-diff.sql
More file actions
61 lines (46 loc) · 1.37 KB
/
Copy pathcol-diff.sql
File metadata and controls
61 lines (46 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- col-diff.sql
-- originally from https://renenyffenegger.ch
-- and modified to accept variable names
-- [email protected] - 2022
@clears
col v_owner new_value v_owner noprint
col v_tab_a new_value v_tab_a noprint
col v_tab_b new_value v_tab_b noprint
prompt 'Owner: '
set term off feed off
select upper('&1') v_owner from dual;
set term on
prompt 'Table A:'
set term off
-- change V$ to V_$ for data dictionary lookup
select replace(upper('&2'),'V$','V_$') v_tab_a from dual;
set term on
prompt 'Table B:'
set term off
select replace(upper('&3'),'V$','V_$') v_tab_b from dual;
set term on
col col_name format a30
col IN_A format a4
col IN_B format a4
set linesize 200 trimspool on
set pagesize 100
prompt
prompt A: &v_tab_a
prompt B: &v_tab_b
prompt
with
a as (select * from dba_tab_columns where owner = '&v_owner' and table_name = '&v_tab_a'),
b as (select * from dba_tab_columns where owner = '&v_owner' and table_name = '&v_tab_b')
select
coalesce(a.column_name, b.column_name) col_name,
-- the decode and case are equivalent
decode(a.column_id,null,'','X') in_a,
--case when a.column_id is not null then 'X' else '' end in_a,
case when b.column_id is not null then 'X' else '' end in_b
from a
full outer join b on a.column_name = b.column_name
order by
--coalesce (a.column_name, b.column_name) -
-- named columns works from at least 10gR2
col_name
/