删除 Oracle 10g 中创建的所有内容

发布于 2024-12-11 05:54:42 字数 49 浏览 0 评论 0原文

是否有一个命令可以删除 Oracle 10g 中创建的所有内容,以便我可以重新开始?

Is there a command that can delete everything ever created in Oracle 10g so I can start again?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一笑百媚生 2024-12-18 05:54:42

清除模式的最简单方法是以 DBA 身份登录并删除用户:

drop user apc cascade
/

但如果您确实只想删除对象,则需要部署一些动态 SQL。

declare
    stmt varchar2(2000);
begin
    for r in ( select object_type, object_name
               from user_objects
               where object_type in 
                   ( 'TYPE', 'PACKAGE', 'FUNCTION', 'PROCEDURE', 
                      'SEQUENCE', 'VIEW', 'TABLE', 'MATERIALIZED VIEW')
              _
    loop
         stmt :=  'drop '||r.object_type||' '||r.object_name;
         -- to avoid failures due to foreign keys
         if r.object_type = 'TABLE' then
             stmt := stmt || ' cascade constraints';
         end if;
         execute immediate stmt;
     end loop;
end;

在大多数情况下,这应该会强制删除架构中的每个对象。但它有可能会失败(例如,如果其他会话锁定了某个对象)。此外,它不处理由于 TYPE 继承而导致的依赖关系。因此,有明显的方法可以改进它:自动重新运行、异常处理等。但它提供了十个启动器。


在现实世界中,与学术界的象牙塔相反,不应该需要这样的程序。每个数据库构建脚本都应该有一个相等且相反的回归脚本。遗憾的是,情况往往并非如此。


“我不知道架构是什么”

模式是用户拥有的所有对象。它与用户没有区别,因为它们共享相同的名称,并且当我们创建用户时会隐式创建一个空模式。然而,严格来说它们是两个不同的东西。 了解更多

The easiest way to clear out a schema would be to log in as a DBA and drop the user:

drop user apc cascade
/

But if you really want to just drop the objects, you'll need to deploy some dynamic SQL.

declare
    stmt varchar2(2000);
begin
    for r in ( select object_type, object_name
               from user_objects
               where object_type in 
                   ( 'TYPE', 'PACKAGE', 'FUNCTION', 'PROCEDURE', 
                      'SEQUENCE', 'VIEW', 'TABLE', 'MATERIALIZED VIEW')
              _
    loop
         stmt :=  'drop '||r.object_type||' '||r.object_name;
         -- to avoid failures due to foreign keys
         if r.object_type = 'TABLE' then
             stmt := stmt || ' cascade constraints';
         end if;
         execute immediate stmt;
     end loop;
end;

This should force the dropping of every object in your schema in most scenarios. But there is a possibility that it will fail (say if some other session has a lock on an object). Also it doesn't handle dependencies due to TYPE inheritance. So there are obvious ways it can be improved: automatic re-running, excpetion handling, etc. But it provides a starter for ten.


In the real world, as opposed to the ivory towers of Academe, there should be no need for a procedure like this. Every database build script should have an equal and opposite regression script. Sadly this is frequently not the case.


"I dont know what a schema is"

A schema is all the objects owned by a user. It is indistinguishable from the user in that they share the same name and an empty schema is implicitly created when we create a user. However, strictly they are two different things. Find out more.

药祭#氼 2024-12-18 05:54:42

在 Mac 10.5.8 上,要删除与 Oracle 10g 数据库实例相关的每个文件,请删除以下目录:
- oracle(安装过程生成的目录)
- oraInventory(系统上所有 oracle 安装的公共目录)
- /var/opt/oracle(包含设置 oraInventory 目录位置的文件)
- db(是从oracle网站下载安装文件解压后的目录)
- db.zip(从 oracle 站点下载用于安装的文件)

现在您可以在 Mac 上全新安装新的 oracle 数据库。至少,这对我有用。

我在此处和<找到了有用的信息一个href="http://blog.rayapps.com/2009/04/12/how-to-install-oracle-database-10g-on-mac-os-x-intel/" rel="nofollow">此处< /a>.

On a mac 10.5.8, to delete each and every file regarding oracle 10g db instance delete these dirs:
- oracle (the dir generated from the installation procedure)
- oraInventory (common directory for all oracle installation on your system)
- /var/opt/oracle (contains the file that sets the oraInventory dir location)
- db (is the dir unzipped from the file downloaded from oracle site for installation)
- db.zip (the file downloaded from oracle site for intallation)

Now you can fresh install a new oracle database on your mac. At least, this worked for me.

I found useful information here and here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文