-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathddl.sql
More file actions
51 lines (40 loc) · 1.53 KB
/
ddl.sql
File metadata and controls
51 lines (40 loc) · 1.53 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
-- ddl.sql - extract object DDL, modified from Tanel's ddl.sql script
--
-- Luca, Nov 2022
--
-- Usage: @ddl [schema.]<object_name_pattern>
-- @ddl mytable
-- @ddl system.table
-- @ddl sys%.%tab%
-- unclutter the storage options
EXEC DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);
exec dbms_metadata.set_transform_param( dbms_metadata.session_transform,'SQLTERMINATOR', TRUE);
-- use from select
-- example
-- select DBMS_METADATA.GET_DDL('TABLE','AMI_DS_STATE','ATLAS_AMI_DATA22_01') from dual;
--
-- using sqlplus variables
-- var a varchar2(4000)
-- exec :a := DBMS_METADATA.GET_DDL('TABLE','AMI_DS_STATE','ATLAS_AMI_DATA22_01')
-- print :a
select
dbms_metadata.get_ddl( object_type, object_name, owner )
from
all_objects
where
object_type NOT LIKE '%PARTITION' AND object_type NOT LIKE '%BODY'
AND upper(object_name) LIKE
upper(CASE
WHEN INSTR('&1','.') > 0 THEN
SUBSTR('&1',INSTR('&1','.')+1)
ELSE
'&1'
END
)
AND owner LIKE
CASE WHEN INSTR('&1','.') > 0 THEN
UPPER(SUBSTR('&1',1,INSTR('&1','.')-1))
ELSE
user
END
/