现在的位置: 首页 > 综合 > 正文

超级SQL之数据库导入导出——oracle

2013年12月09日 ⁄ 综合 ⁄ 共 1093字 ⁄ 字号 评论关闭
1 SQL:

select 
'alter table ' || a.table_name || ' modify ' || a.column_name || ' VARCHAR2(' || a.DATA_LENGTH || ');' AS modify_col,
'update ' || a.table_name || ' set ' || a.column_name || '=trim(' || a.column_name || ');' update_data 
from user_tab_columns a,user_tables b 
where a.table_name=b.table_name and b.tablespace_name='表空间名全大写' and a.data_type='CHAR'
and a.table_name ='TABLENAME'

功能:查找出字段类行为char的表的名字及字段名,并直接拼成alter语句,注意的是数据库的对象名肯定是全部大写。

2。SQL:

select table_name ,column_name from  user_tab_columns  where table_name)=''TABLENAME'

根据上一句得来的

3.SQL:select 'DROP INDEX "用户名"."' || index_name || '";' from user_ind_columns where table_name='TABLENAME'

查找该用户空间下的索引。select *  from user_ind_columns

select * from user_indexes order by table_name;

4。有个转贴的 select CONSTRAINT_NAME,CONSTRAINT_TYPE,INDEX_NAME from user_constraints

这个可以知道索引类型,是主键还是其他约束。

这个的地址:http://www.eygle.com/archives/2006/02/oracle9i_enhancement_keep_index.html

5。SQL: select text from all_source where owner=user

查找该用户下的用户的存储过程和函数原文。

6。总结一下第一招

如果记录条数非常多,你有没想到如何批量导出导入,就是这直接让他生成SQL,这样只要执行SQL就行了

select distinct 'update tablename set col1=1 where col2=' || col2 ||';' from  tablename

 

就到这里。

抱歉!评论已关闭.