使用 PL/SQL 过程转储 Oracle 10g 中的表

发布于 2024-08-14 12:38:57 字数 152 浏览 7 评论 0原文

您好,需要立即回复,

我想从架构中转储一些选定的表,任何人都可以告诉我这是否可能? 任何人都可以通过执行来提供我们可以转储的程序。

例如,我有模式、测试用户和表(T1、T2、T3、T5、T9),我想转储 T1 和 T1。仅限 T5。

提前致谢

Hi Required immediate response,

I want to take dump of some selected tables from schema, can any body tell me is it possible?
Can anybody provide procedure by executing that we can take dump.

e.g. I have schema, testuser, and tables (T1,T2,T3,T5,T9), i want to take dump of T1 & T5 only.

Thanks in advance

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

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

发布评论

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

评论(4

疯到世界奔溃 2024-08-21 12:38:57

由于您使用的是 10g,因此可以使用 执行此操作数据泵API。您需要对映射到目标操作系统目录的目录对象具有读写访问权限。

在以下示例中,我将两个表 EMP 和 DEPT 导出到 DATA_PUMP_DIR 标识的目录中名为 EMP.DMP 的文件。

SQL> declare
  2      dp_handle       number;
  3  begin
  4      dp_handle := dbms_datapump.open(
  5      operation   => 'EXPORT',
  6      job_mode    => 'TABLE');
  7
  8    dbms_datapump.add_file(
  9      handle    =>  dp_handle,
 10      filename  => 'emp.dmp',
 11      directory => 'DATA_PUMP_DIR');
 12
 13    dbms_datapump.add_file(
 14      handle    => dp_handle,
 15      filename  => 'emp.log',
 16      directory => 'DATA_PUMP_DIR',
 17      filetype  => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);
 18
 19    dbms_datapump.metadata_filter(
 20      handle => dp_handle,
 21      name   => 'NAME_LIST',
 22      value  => '''EMP'',''DEPT''');
 23
 24    dbms_datapump.start_job(dp_handle);
 25
 26    dbms_datapump.detach(dp_handle);
 27  end;
 28  /    

PL/SQL procedure successfully completed.

SQL> 

@DerekMahar 问道:

“是否有类似的数据泵工具或
可供执行的 API
客户端”

DataPump、PL/SQL API 和操作系统实用程序都写入 Oracle 目录。Oracle 目录必须代表数据库可见的操作系统目录。通常这是服务器上的目录,尽管我认为它是理论上可以将 PC 驱动器映射到网络,您必须说服网络管理员这是一个好主意,但很难推销,因为它不是……

旧的 IMP 和 EXP 实用程序可以读取和写入。从客户端目录,因此理论上可以将本地转储文件导入到远程数据库中,但我认为这不是一种实用的方法,因为转储文件的本质往往很大,因此通过网络导入速度很慢。压缩转储文件,将其复制到服务器并从那里导入是一个更好的解决方案。

As you are on 10g you can do this with the Data Pump API. You need to have read and write access on a directory object which maps to the destination OS directory.

In the following example I am exporting two tables, EMP and DEPT, to a file called EMP.DMP in a directory identified by DATA_PUMP_DIR.

SQL> declare
  2      dp_handle       number;
  3  begin
  4      dp_handle := dbms_datapump.open(
  5      operation   => 'EXPORT',
  6      job_mode    => 'TABLE');
  7
  8    dbms_datapump.add_file(
  9      handle    =>  dp_handle,
 10      filename  => 'emp.dmp',
 11      directory => 'DATA_PUMP_DIR');
 12
 13    dbms_datapump.add_file(
 14      handle    => dp_handle,
 15      filename  => 'emp.log',
 16      directory => 'DATA_PUMP_DIR',
 17      filetype  => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);
 18
 19    dbms_datapump.metadata_filter(
 20      handle => dp_handle,
 21      name   => 'NAME_LIST',
 22      value  => '''EMP'',''DEPT''');
 23
 24    dbms_datapump.start_job(dp_handle);
 25
 26    dbms_datapump.detach(dp_handle);
 27  end;
 28  /    

PL/SQL procedure successfully completed.

SQL> 

@DerekMahar asks:

"Is there a similar data pump tool or
API available for execution from the
client side"

DataPump, both the PL/SQL API and the OS utility, write to Oracle directories. An Oracle directory must represent an OS directory which is visible to the database. Usually that is a directory on the server, although I suppose it is theoretically possible to map a PC drive to the network. You'd have to persuade your network admin that this is a good idea, it is a tough sell, because it isn't...

The older IMP and EXP utilities read and wrote from client directories, so it is theoretically possible possible to IMP a local dump file into a remote database. But I don't think this is a practical approach. By their nature dump files tend to be big, so importing across a network is slow and prone to failure. It is a much better solution to zip the dump file, copy it to the server and import it from there.

柠檬色的秋千 2024-08-21 12:38:57

您应该尝试使用 DATAPUMP api (EXPDP/IMPDP)。它具有更多功能并具有 PLP/SQL API。 DATAPUMP 是 exp 和 imp 的替代品,并在 10g 中得到支持。

http://www.orafaq.com/wiki/Datapump#Invoking_from_PL.2FSQL

You should try using the DATAPUMP api's (EXPDP/IMPDP). It has a lot more capabilities and has PLP/SQL APIs. DATAPUMP is a replacement for exp and imp and is supported in 10g.

http://www.orafaq.com/wiki/Datapump#Invoking_from_PL.2FSQL

£烟消云散 2024-08-21 12:38:57

使用此命令,您将获得二进制 Oracle 转储:
exp scott/tiger file=mydump.dmp table=(T1,T5)

我推荐此链接: http:// /www.orafaq.com/wiki/Import_Export_FAQ

With this command you'll get a binary Oracle dump:
exp scott/tiger file=mydump.dmp tables=(T1,T5)

I recommend this link: http://www.orafaq.com/wiki/Import_Export_FAQ

飘过的浮云 2024-08-21 12:38:57

如果您必须使用 PL/SQL,并且您正在尝试创建文件,那么您需要定义一个目录,并授予您的用户授予写入权限。这是 DBA 可以做的事情。请参阅“创建目录”命令。

此时,您可以 (1) 调用 UTL_FILE 打开文件并向其中写入行,或者 (2) 创建“外部表”并将信息复制到其中,或者 (3) 使用 DBMS_XMLGEN 或 (4) 使用以下几种中的任何一种将数据从数据库实际写入文件的其他方法。所有这些都在 Oracle 文档中。 PL/SQL 包和类型手册在此类事情上是你的朋友。

请注意,实际的文件系统目录必须位于数据库所在的服务器上。因此,您可能需要访问该服务器来复制您的文件,或者让某人设置安装或其他什么。

或者,您可以设置一个 plsql Web 服务,您可以调用该服务来获取数据。

但是,就我个人而言,我只会使用 exp。或者,如果不可用,可以使用 Toad 或其他一些前端工具(甚至 SQL*Plus),您可以在其中编写简单的 SQL 脚本并保存结果。

如果您这样做是为了完成家庭作业,我猜他们会需要 UTL_FILE 解决方案。

If you must use PL/SQL, and you're trying to create a file, then you'll need to have a directory defined with write access granted to your user. That's something your DBA can do. See the "create directory" command.

At that point, you can (1) call UTL_FILE to open a file and write rows to it or (2) create an "EXTERNAL TABLE" and copy the information to it or (3) use DBMS_XMLGEN or (4) use any of several other ways to actually write the data from the database to the file. All of these are in the Oracle docs. The PL/SQL Packages and Types manual is your friend for things like this.

Note that the actual file system directory has to be on the server where the database is located. So you may need to get access to that server to copy your file, or have somebody set up a mount or whatever.

Alternatively, you could set up a plsql web service that you could call to get your data.

But, personally, I'd just use exp. Or, if that's not available, Toad or some other front end tool (even SQL*Plus) where you can just write a simple SQL script and save the results.

If you're doing this for a homework assignment, my guess is they'll want a UTL_FILE solution.

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