oracle去掉 tab,去除Oracle中所有表、视图和列的注释存储过程
时间: 2024-01-21 19:15:59 浏览: 112
Oracle 删除所有表,视图,序列,函数,存储过程等SQL
5星 · 资源好评率100%
可以使用以下存储过程来删除Oracle数据库中所有表、视图和列的注释,并将tab键替换为空格:
```
CREATE OR REPLACE PROCEDURE remove_comments AS
BEGIN
FOR c IN (SELECT table_name, column_name FROM user_col_comments)
LOOP
EXECUTE IMMEDIATE 'COMMENT ON COLUMN '||c.table_name||'.'||c.column_name||' IS NULL';
END LOOP;
FOR t IN (SELECT table_name FROM user_tab_comments)
LOOP
EXECUTE IMMEDIATE 'COMMENT ON TABLE '||t.table_name||' IS NULL';
END LOOP;
FOR v IN (SELECT view_name FROM user_views)
LOOP
EXECUTE IMMEDIATE 'COMMENT ON VIEW '||v.view_name||' IS NULL';
END LOOP;
FOR p IN (SELECT object_name FROM user_procedures WHERE object_type = 'PROCEDURE')
LOOP
EXECUTE IMMEDIATE 'ALTER PROCEDURE '||p.object_name||' COMPILE PLSQL_WARNINGS => ''ENABLE:ALL''';
END LOOP;
FOR f IN (SELECT object_name FROM user_procedures WHERE object_type = 'FUNCTION')
LOOP
EXECUTE IMMEDIATE 'ALTER FUNCTION '||f.object_name||' COMPILE PLSQL_WARNINGS => ''ENABLE:ALL''';
END LOOP;
FOR p IN (SELECT object_name FROM user_packages)
LOOP
EXECUTE IMMEDIATE 'ALTER PACKAGE '||p.object_name||' COMPILE PLSQL_WARNINGS => ''ENABLE:ALL''';
END LOOP;
FOR b IN (SELECT object_name FROM user_synonyms WHERE table_owner = USER)
LOOP
EXECUTE IMMEDIATE 'DROP SYNONYM '||b.object_name;
END LOOP;
FOR s IN (SELECT object_name FROM user_sequences)
LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE '||s.object_name;
END LOOP;
END;
/
```
使用方法:
1. 在Oracle中运行上述代码创建存储过程。
2. 执行以下代码运行存储过程:
```
EXEC remove_comments;
```
3. 存储过程将删除所有表、视图和列的注释,并将tab键替换为空格。同时,存储过程还会重新编译存储过程、函数和包,并删除用户拥有的同义词和序列。
阅读全文