[英]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.