1:查找某用户(方案)内用到得所有函数:(系统表里)
select OBJECT_NAME from ALL_OBJECTS WHERE OWNER = 'user' AND OBJECT_TYPE = 'FUNCTION'
ORDER BY OBJECT_NAME;
2:查找某用户(方案)内用到得所有过程:(系统表里)
select OBJECT_NAME from ALL_OBJECTS WHERE OWNER = 'user' AND OBJECT_TYPE = 'PROCEDURE'
ORDER BY OBJECT_NAME;
3:查找某用户(方案)内用到得所有表:(系统表里)
select OBJECT_NAME from ALL_OBJECTS WHERE OWNER = 'user' AND OBJECT_TYPE = 'TABLE'
AND (OBJECT_NAME LIKE 'T_%' OR OBJECT_NAME LIKE 'CODE_%' OR OBJECT_NAME LIKE 'D_%' OR OBJECT_NAME LIKE 'E_%')
ORDER BY OBJECT_NAME
4:查找某用户(方案)内用到得所有视图:(系统表里)
select OBJECT_NAME from ALL_OBJECTS WHERE OWNER = 'user' AND OBJECT_TYPE = 'VIEW'
AND OBJECT_NAME LIKE 'V_%' ORDER BY OBJECT_NAME
5:用于查看表空间大小的语句:
SELECT V1.TABLESPACE_NAME "表空间名",
ROUND(NVL(V1.SPACE,0)) "表空间大小(M)",
ROUND(NVL(V1.SPACE,0)-NVL(V2.SPACE,0)) "已经使用空间(M)",
ROUND(NVL(V2.SPACE,0)) "可用空间(M)",
ROUND((NVL(V1.SPACE,0)-NVL(V2.SPACE,0))/NVL(V1.SPACE,0)*100,2) "已用百分比"
FROM (SELECT TABLESPACE_NAME, SUM(BYTES)/1024/1024 SPACE FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) V1,
(SELECT TABLESPACE_NAME, SUM(BYTES)/1024/1024 SPACE FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) V2
WHERE V1.TABLESPACE_NAME = V2.TABLESPACE_NAME(+)
ORDER BY V1.TABLESPACE_NAME
6:用于查找某用户(方案)中所用的表以及表的字段名等相关信息:
SELECT table_name FROM ALL_TAB_COLUMNS WHERE OWNER = 'user' AND TABLE_NAME like 'T_WF_%' group by table_name
7:用于查找当前方案中所用到的函数或存储过程:
1):查找函数:
select name from user_source where type = 'FUNCTION' and name like 'FUN_%' group by name
2):查找存储过程:
select name from user_source where type = 'PROCEDURE' and name like 'PRO_%' group by name
8:列出某方案中某张表的所用字段名以及字段类型和相关约束信息:
SELECT TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_LENGTH,NULLABLE ISNULL, COLUMN_ID SORT FROM ALL_TAB_COLUMNS WHERE OWNER = 'user' AND TABLE_NAME = 'TABLE_NAME' ORDER BY COLUMN_ID
9:用于查找某方案中函数或存储过程的信息(方案名可自行控制)
select name from dba_source where OWNER= 'user' and type = 'FUNCTION' and name like 'FUN_%' group by name
10:用于比较两个方案中某一方案缺少的函数
select * from (select name from dba_source where OWNER= 'user1' and type = 'FUNCTION' and name like 'FUN_%' group by name )
where name not in (
select name from dba_source where OWNER= 'user2' and type = 'FUNCTION' and name like 'FUN_%' group by name
)
11:常用的系统表:
1):找当前方案的表或某方案的表:user_tables,All_tables,dba_tables
2):找当前方案的索引或某方案中的索引:user_indexes,All_indexes,dba_indexes
3):找当前方案的视图或某方案中的视图:user_views,all_views,dba_views
4):找当前方案的函数/存储过程/触发器或某方案中的函数/存储过程/触发器:user_source,all_source,dba_source,user_TRIGGERs
5):找当前数据库作业或某方案中的数据库作业:select LOG_USER,WHAT from user_jobs,select LOG_USER,WHAT from all_jobs,select LOG_USER,WHAT from all_jobs
6):找当前方案中的事务:select * from v$transaction
7):查看数据库字符集的信息情况:select * from V$NLS_PARAMETERS where PARAMETER = 'NLS_CHARACTERSET'
---------------------------------------------------------------------------------------------------------------
要删除表结构的某列时可用如下语句:
alter table TABLE_NAME drop COLUMN COLUMN_NAME CASCADE CONSTRAINTS
此为表名 此为列名 此为约束(卸下约束)
修改表的字段类型:
alter table TABLE_NAME modify (COLUMN_NAME varchar2(60));
重命名字段名称的SQL语句:
-- Add/modify columns
alter table TABLE_NAME rename column COLUMN_NAME to new_COLUMN_NAME ;