1

I'm trying to better understand the Oracle Data pump functionality used to export data from one database and import it into a different database in a different location. My goal is to create a SQL script so I can automate most of the work and execute the script anytime I need to transfer data over and reduce dependency on the DBA. I am hoping I would not need to get in touch with the DBA each time (I have some limited admin access over the databases).

From my research so far, I have seen examples where people were writing some PL-SQL scripts and running them in SQL Plus (I think). I read that most PL-SQL scripts can be run in SQL Developer but not sure if Data pump commands work in there. If it is possible, I wonder if I could simply just take the same script and use it in either SQL Plus or SQL Developer interchangeably or I would need to make some minor modifications. I'm not sure if I have access to SQL Plus (still learning about it) so preferably want to use SQL developer.

I did find out that there is some Data pump wizard within SQL developer where you can run it but you would need to do it from the DBA panel in the program which I don't think I have the necessary credentials/permissions for that when I try to add my limited admin account connection in there. Also saw a database copy wizard functionality under the Tools file menu which I could use but looking to see if there are commands I can call within my own script.

Thanks.

4

1 回答 1

2

要做到这一点,您需要正确的许可,但是在您获得许可之后,这很简单

假设您只需要导出 schema ,Oracle 提供了预定义的包来执行此操作,您只需要更新和修改您需要的内容。

declare
  l_dp_handle       number;
begin
  -- Open a schema export job.
  l_dp_handle := dbms_datapump.open(
    operation   => 'EXPORT',
    job_mode    => 'SCHEMA',
    remote_link => NULL,
    job_name    => 'The JOB NAME ( FROM YOUR CHOICE)',
    version     => 'LATEST');

然后你需要指定转储文件名和目录对象名。

 dbms_datapump.add_file(
    handle    => l_dp_handle,
    filename  => 'The Dump name (output).dmp',
    directory => 'The location of the dump ( this should be created before run the job)');

如果您需要创建日志,则可选

dbms_datapump.add_file(
    handle    => l_dp_handle,
    filename  => 'Name of the logs .log',
    directory => 'Same directory as above',
    filetype  => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);

指定要导出的架构。

dbms_datapump.metadata_filter(
    handle => l_dp_handle,
    name   => 'SCHEMA_EXPR',
    value  => '= ''The user should be exported''');

  dbms_datapump.start_job(l_dp_handle);

  dbms_datapump.detach(l_dp_handle);
end;
/

我强烈建议您阅读文档以了解有关包和参数的更多信息这里

于 2021-04-26T17:53:56.153 回答