俺终于明白你的意思 这样好了 先从旧的系统查阅这些注释信息 select comments from user_tab_comments; select comments from user_col_comments;comment on table aa is 'DNA表' SQL> select comments from user_tab_comments where table_name='AA';COMMENTS -------------------------------------------------------------------------------- DNA表comment on column aa.name is '基因名' SQL> select comments from user_col_comments where table_name='AA';COMMENTS -------------------------------------------------------------------------------- 基因名
--这个程序是根据当前用户的所有表的表注释,去更新另一个用户的所有同名表的表注释的程序 --更新字段注释原理也一样的,你可以自己改改 create or replace procedure comm is cursor table_name is select table_name from user_tables; type ref_cursor is ref cursor; cursor_comm ref_cursor; tablename varchar2(100); my_comments varchar2(200); my_sql varchar2(200); my_update varchar2(200); begin open table_name; loop fetch table_name into tablename; exit when table_name%notfound; my_sql := 'select comments from user_tab_comments where table_name='''||tablename||''''; open cursor_comm for my_sql; loop fetch cursor_comm into my_comments; exit when cursor_comm%notfound; --下面这行可以修改一下,把tablename改成另一个用户的tablename,比如用户2.tablename,就可以了 --如果是两台机器上的,那么有要建立DBLINK my_update := 'comment on table '||tablename||' is '||''''||my_comments||''''; -- if (lengthb(my_comments) != 0) then execute immediate my_update; end if; end loop; close cursor_comm; end loop; close table_name; end comm; /
对了,俺对那些变量定义的时候宽度可能不够 你自己最好写成 %type的形式
如果有sys.com$表的插入更新权限,可以直接对这个表进行插入更新,注意不要把obj#搞错了.^_^[code] SQL> create table t (t1 int );Table created.SQL> select object_id from obj where object_name = 'T'; OBJECT_ID ---------- 5871SQL> conn / as sysdba Connected. SQL> insert into com$ values(5871,null,'这只是一个做测试的临时表而已^_^');1 row created.SQL> commit;Commit complete.SQL> conn jfdata/jf Connected. SQL> select * from user_tab_comments where table_name = 'T';TABLE_NAME TABLE_TYPE -------------------- -------------------- COMMENTS ------------------------------------------------------------------------------------------------------------------------ T TABLE 这只是一个做测试的临时表而已^_^ SQL> conn / as sysdba Connected. SQL> update com$ set comment$ = 'this is just a test for test the comment adding' 2 where obj# = 5871 and col# is null;1 row updated.SQL> commit;Commit complete.SQL> conn jfdata/jf Connected. SQL> select * from user_tab_comments where table_name = 'T';TABLE_NAME TABLE_TYPE -------------------- -------------------- COMMENTS ------------------------------------------------------------------------------------------------------------------------ T TABLE this is just a test for test the comment adding SQL> [/code]
除非你修改了table
数据字典是oracle自动维护的
要不然还不乱了套了
数据字典是不能更改的
如果新建了一张表
那么在数据字典user_tables里就会自动增加一条记录,记录了你刚才增加的表的表名等信息
如果你这时候,把user_tables里面的这条记录手工删除了(事实上你没法删除,因为你不能对数据字典进行此类操作,除了一些特殊情况)这算什么意思呢?
也就是实际的表是存在的,但是却没有在数据字典里面记录也就是你是学校的学生,每天来上课
但是班级的学生名单里却没有你。。
为什么要修改数据字典?因为我们的前期数据库设计工作没有做好文档,一些字段定义,表名做了定义,好多都没有,这样后来的人看不懂,所以现在是逆向做ER工作,为了充分利用已经做了得数据字典,我猜想着这样做的。希望各位高手继续关注中!
楼主好倔强,看来是非把oracle RDBMS自行维护的data dictionary改了不可^_^你的一张表假如有10个字段,那么在数据字典USER_COLS_COMMENTS里面就会自动记录这张表的
10个字段名,假如这时候,你又对这张表添加了一个字段
alter table table_name add new_field varchar2(8);
那么,你在USER_COLS_COMMENTS里面就可以查到这张表有11个字段你还要修改数据字典干吗?真不明白楼主说的数据字典是什么
建议楼主看看Oracle的数据字典方面的定义。。我想我说了多了,
这样好了
先从旧的系统查阅这些注释信息
select comments from user_tab_comments;
select comments from user_col_comments;comment on table aa is 'DNA表'
SQL> select comments from user_tab_comments where table_name='AA';COMMENTS
--------------------------------------------------------------------------------
DNA表comment on column aa.name is '基因名'
SQL> select comments from user_col_comments where table_name='AA';COMMENTS
--------------------------------------------------------------------------------
基因名
就是先从旧的系统查阅注释信息,
然后把查到的信息
再到新系统去更新
用 comment命令
更新表注释user_tab_comments和字段注释user_col_comments
那就是怪事了。。你一个一个手工commnet当然慢了
你可以写一个程序,从user_tab_comment和user_col_comments里面select记录
然后把检索到的记录改写成comment的形式,并保存到一个SQL脚本
然后执行这个脚本不就OK了?
--更新字段注释原理也一样的,你可以自己改改
create or replace procedure comm
is
cursor table_name is select table_name from user_tables;
type ref_cursor is ref cursor;
cursor_comm ref_cursor;
tablename varchar2(100);
my_comments varchar2(200);
my_sql varchar2(200);
my_update varchar2(200);
begin
open table_name;
loop
fetch table_name into tablename;
exit when table_name%notfound;
my_sql := 'select comments from user_tab_comments where table_name='''||tablename||'''';
open cursor_comm for my_sql;
loop
fetch cursor_comm into my_comments;
exit when cursor_comm%notfound;
--下面这行可以修改一下,把tablename改成另一个用户的tablename,比如用户2.tablename,就可以了
--如果是两台机器上的,那么有要建立DBLINK
my_update := 'comment on table '||tablename||' is '||''''||my_comments||'''';
--
if (lengthb(my_comments) != 0) then
execute immediate my_update;
end if;
end loop;
close cursor_comm;
end loop;
close table_name;
end comm;
/
你自己最好写成 %type的形式
SQL> create table t (t1 int );Table created.SQL> select object_id from obj where object_name = 'T'; OBJECT_ID
----------
5871SQL> conn / as sysdba
Connected.
SQL> insert into com$ values(5871,null,'这只是一个做测试的临时表而已^_^');1 row created.SQL> commit;Commit complete.SQL> conn jfdata/jf
Connected.
SQL> select * from user_tab_comments where table_name = 'T';TABLE_NAME TABLE_TYPE
-------------------- --------------------
COMMENTS
------------------------------------------------------------------------------------------------------------------------
T TABLE
这只是一个做测试的临时表而已^_^
SQL> conn / as sysdba
Connected.
SQL> update com$ set comment$ = 'this is just a test for test the comment adding'
2 where obj# = 5871 and col# is null;1 row updated.SQL> commit;Commit complete.SQL> conn jfdata/jf
Connected.
SQL> select * from user_tab_comments where table_name = 'T';TABLE_NAME TABLE_TYPE
-------------------- --------------------
COMMENTS
------------------------------------------------------------------------------------------------------------------------
T TABLE
this is just a test for test the comment adding
SQL>
[/code]
弄得不好,破坏了数据的完整性
你还可以去改数据字典来修改列名呢。。
但是俺从不这么做除了俺在数据字典改过字符集外,还有哪个AUDIT_TRAIL