forked from tanelpoder/tpt-oracle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cons.sql
52 lines (48 loc) · 1.48 KB
/
cons.sql
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
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
column cons_constraint_name heading CONSTRAINT_NAME format a30
column cons_column_name heading COLUMN_NAME format a30
column cons_owner heading OWNER format A30
column cons_table_name heading TABLE_NAME format A30
column constraint_name for a30
column r_constraint_name for a30
prompt Show constraints on table &1....
select
co.owner cons_owner,
co.table_name cons_table_name,
co.constraint_name cons_constraint_name,
co.constraint_type,
co.r_constraint_name,
cc.column_name cons_column_name,
cc.position,
co.status,
co.validated
from
dba_constraints co,
dba_cons_columns cc
where
co.owner = cc.owner
and co.table_name = cc.table_name
and co.constraint_name = cc.constraint_name
and upper(co.table_name) LIKE
upper(CASE
WHEN INSTR('&1','.') > 0 THEN
SUBSTR('&1',INSTR('&1','.')+1)
ELSE
'&1'
END
)
AND co.owner LIKE
CASE WHEN INSTR('&1','.') > 0 THEN
UPPER(SUBSTR('&1',1,INSTR('&1','.')-1))
ELSE
user
END
order by
cons_owner,
cons_table_name,
constraint_type,
cons_constraint_name,
position,
column_name
/