简体   繁体   English

如何使用jdbc将包源从数据库复制到本地计算机?

[英]how I can copy the package source from database to my local machine using jdbc?

I want to copy all the packages's source in my local machine using jdbc. 我想使用jdbc在本地计算机中复制所有软件包的源。

select DBMS_METADATA.GET_DDL('PACKAGE_BODY','COLLECTSTATS','MYSCHEMA') from DUAL;

I have tried this but not getting it 我已经尝试过但没有得到

You can create a custom table with ddl for each objects (packages, procedures, functions) like the following: 您可以为每个对象(包,过程,函数)使用ddl创建一个自定义表,如下所示:

drop table myobjects;
create table myobjects (obj_name varchar2(128), sub_obj_name varchar2(128), obj_type varchar2(128), obj_ddl clob);
set serveroutput on
declare
   uobj_ddl clob;
   cnt number := 1;
begin

   for dt in (select object_name, subobject_name, object_type from user_objects where object_type IN ('FUNCTION','PROCEDURE','PACKAGE')) loop
    --dbms_output.put_line(dt.object_name);
    uobj_ddl := dbms_metadata.get_ddl(upper(dt.object_type), upper(dt.object_name));
    insert into myobjects values (dt.object_name, dt.subobject_name, dt.object_type, uobj_ddl);
    if mod(cnt,100) = 0 then
       commit;
    end if;
    cnt := cnt + 1;
end loop;
commit;
end;
/

Then you can do the select on this from java using jdbc: 然后,您可以使用jdbc从Java上进行选择:

select * from myobjects;

Sample java code: 示例Java代码:

try {
    pStat = con.prepareStatement("select * from myobjects";
    ResultSet rSet = pStat.executeQuery();
    while(rSet.next()){
        objName = rSet.getString(1);
        subObjName = rSet.getString(2);
        objType = rSet.getString(3);
        objDDL = rSet.getClob(4);
    }
    rSet = null;
} catch (SQLException e) {
    e.printStackTrace();
}
pStat = null;

The issue is probably with output size. 问题可能与输出大小有关。 The code of a procedure or package is bigger that 32k which is the varchar2 limitation in PL/SQL. 过程或程序包的代码大于32k,这是PL / SQL中的varchar2限制。

Even the sqlplus buffer may fail with huge packages. 甚至sqlplus缓冲区也可能因大型软件包而失败。

One solution can be using the following query in a cursor: select text from user_source where name = 'COLLECTSTATS' order by line asc; 一种解决方案是在游标中使用以下查询:从user_source选择文本,其中name ='COLLECTSTATS',按asc行排序;

This will work for packages, functions, procedures and triggers. 这将适用于程序包,功能,过程和触发器。 Views are managed differently. 视图的管理方式不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用Apache DDLUtils的情况下使用JDBC将模式从一个数据库复制到另一个数据库? - How can I use JDBC to copy schema from one database to another without using Apache DDLUtils? 如何使用Java将文件从本地计算机上传到Web服务以进行ftp传输? - How can I upload a file from my local machine to a webservice for ftp transfer using java? 如何使用JDBC从Java连接到Access数据库? - How can I connect to an Access database from Java using JDBC? 如何使用angularJS将共享文件夹文件复制到本地计算机 - How can i copy shared folder files into local machine using angularJS 如何使用java jdbc连接到本地SQL数据库 - How do I connect to local SQL database using java jdbc 如何在另一台机器上运行本地Maven项目? - How can I run my local maven project on another machine? 如何在ant构建文件中从源文件夹中排除我的测试包? - How can I exclude my tests package from source folder in an ant build file? 如何使用变量将数据放入jdbc表? - How can I put data into my jdbc table using a variable? 如何在GUI上显示jdbc表的结果? - How can I display results from a jdbc table on my GUI? 有什么方法可以从本地计算机(本地服务器)读取数据库文件并复制到 android 中的资产文件夹? - Is there any way that I can read database file from local computer (local server) and copy to assets folder in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM