Show Column: Input will be the column name
select table_name,
column_name,
substr(data_type,1,10) data_type,
CASE WHEN DATA_TYPE IN (‘CHAR’,'VARCHAR2′) THEN char_length ELSE data_length END length,
data_precision,
data_scale
FROM user_Tab_columns
WHERE column_name like upper(‘%&column_name%’)
ORDER BY table_name
/
Show constraints: Input is the table name
select substr(a.constraint_name,1,30),substr(a.column_name,1,30),a.position
from user_cons_columns a, user_constraints b
where a.table_name = upper(‘&table’)
and b.table_name = a.table_name
and b.constraint_name = a.constraint_name
and b.constraint_type in (‘P’, ‘R’, ‘U’)
order by a.constraint_name,a.position
/
select /*+ rule */ b.table_name child_table,
b.constraint_name fk_constraint
from user_constraints a,
user_constraints b
where a.table_name = Upper(‘&table’)
and a.constraint_type = ‘P’
and a.constraint_name = b.r_constraint_name (+)
/
Show Default: Table and Column Names are the two inputs
select data_Default from user_tab_columns
where table_name = upper(‘&table_name’)
and column_name = upper(‘&column_name’)
/
Show Index: Table Name is the input
select substr(index_name,1,30),substr(column_name,1,30),column_position
from user_ind_columns
where table_name = upper(‘&table’)
order by index_name,column_position
/
Show Invalid: Shows invalid status objects and generates the SQLs to COMPILE them (please note that this is just one of the ways to recompile the invalid objects – there are many other simple ways as well that we will cover in a future blog)
select ‘ALTER ‘ || decode(object_type,’PACKAGE BODY’, ‘PACKAGE’,object_Type) ||’ ‘||object_name || ‘ COMPILE;’
from user_objects
where status = ‘INVALID’
and object_name not like ‘BIN$%’
/
Show Space: For tablespace
SELECT owner,SUM(bytes+blocks)/1024/1024 FROM dba_segments
WHERE tablespace_name = UPPER(‘&tablespace_name’)
GROUP BY owner
ORDER BY 2 DESC
/
Show memory usage:
SELECT to_number(decode(SID,65535,NULL,SID)) SID,
operation_Type OPERATION,
trunc(work_area_size/1024) WSIZE,
trunc(expected_size/1024) ESIZE,
trunc(actual_mem_used/1024) MEM,
trunc(max_mem_used/1024) “MAX_MEM”
FROM v$sql_workarea_active
ORDER BY 1,2
/