使用 PL/SQL 过程转储 Oracle 10g 中的表
您好,需要立即回复,
我想从架构中转储一些选定的表,任何人都可以告诉我这是否可能? 任何人都可以通过执行来提供我们可以转储的程序。
例如,我有模式、测试用户和表(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于您使用的是 10g,因此可以使用 执行此操作数据泵API。您需要对映射到目标操作系统目录的目录对象具有读写访问权限。
在以下示例中,我将两个表 EMP 和 DEPT 导出到 DATA_PUMP_DIR 标识的目录中名为 EMP.DMP 的文件。
@DerekMahar 问道:
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.
@DerekMahar asks:
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.
您应该尝试使用 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
使用此命令,您将获得二进制 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
如果您必须使用 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.