oracle数据库可否批量导出存储过程
2个回答
2016-12-21 · 知道合伙人互联网行家
关注
展开全部
Oracle批量导出存储过程
法一:
PL/SQL工具导出
法二:
Sql代码
SET echo off;
SET heading off;
SET feedback off;
spool C:\Documents and Settings\Administrator\桌面\proc.sql;--1、用sys用户等陆的话:
Sql代码
select text from dba_source where owner= 'lingfeng' and type = 'PROCEDURE';--2、用一般用户(要导出其下存储过程的用户):
Sql代码
select text from user_source;
spool off;
法三:(自己写存储过程导出)
1.创建DIRECTORY
Sql代码
create or replace directory PROCE_DIR as 'C:/Documents and Settings/Administrator/桌面';如创建报没权限的错误,则以system的用户登录,给当前用户赋权--赋权语句
Sql代码
grant create any directory to bijian;
--撤权语句
Sql代码
revoke create any directory from bijian;
创建之后可通过如下语句查询是否创建成功
Sql代码
select * from dba_directories;
2.创建导出存储过程
Sql代码
create or replace procedure loadProce(owner varchar2)is
type user_source_table_type is table of user_source.text%TYPE INDEX BY BINARY_INTEGER;user_source_table user_source_table_type;file_handle utl_file.file_type;
stor_text VARCHAR2(4000);
sql_stat varchar2(1000);
sql_stat2 varchar2(1000);
sql_stat3 varchar2(1000);
nCount NUMBER;
i NUMBER;
begin
sql_stat:='select distinct(name) from all_source where owner = ''' || upper(owner) || '''';execute immediate sql_stat bulk collect into user_source_table;file_handle:=utl_file.fopen('PROCE_DIR','test.sql','W');for j in 1..user_source_table.count loop
i:=1;
sql_stat2:='SELECT MAX(LINE) FROM ALL_SOURCE WHERE OWNER=''' || upper(owner) || ''' AND NAME=''' || user_source_table(j) || '''';--dbms_output.put_line(sql_stat2);
execute immediate sql_stat2 into nCount;
WHILE i<=nCount LOOP
sql_stat3:='SELECT TEXT FROM ALL_SOURCE WHERE OWNER=''' || upper(owner) || ''' AND NAME=''' || user_source_table(j) || ''' and line = ' || i;--dbms_output.put_line(sql_stat3);
execute immediate sql_stat3 into stor_text;i:=i+1;
utl_file.put(file_handle,stor_text);
END LOOP;
end loop;
utl_file.fclose(file_handle);
commit;
end loadProce;
3.调用,将TYPE BODY、PROCEDURE、TYPE、FUNCTION、TRIGGER、PACKAGE BODY、PACKAGE保存到桌面的test.sql中Sql代码
begin
loadproce('bijian');
end;
法一:
PL/SQL工具导出
法二:
Sql代码
SET echo off;
SET heading off;
SET feedback off;
spool C:\Documents and Settings\Administrator\桌面\proc.sql;--1、用sys用户等陆的话:
Sql代码
select text from dba_source where owner= 'lingfeng' and type = 'PROCEDURE';--2、用一般用户(要导出其下存储过程的用户):
Sql代码
select text from user_source;
spool off;
法三:(自己写存储过程导出)
1.创建DIRECTORY
Sql代码
create or replace directory PROCE_DIR as 'C:/Documents and Settings/Administrator/桌面';如创建报没权限的错误,则以system的用户登录,给当前用户赋权--赋权语句
Sql代码
grant create any directory to bijian;
--撤权语句
Sql代码
revoke create any directory from bijian;
创建之后可通过如下语句查询是否创建成功
Sql代码
select * from dba_directories;
2.创建导出存储过程
Sql代码
create or replace procedure loadProce(owner varchar2)is
type user_source_table_type is table of user_source.text%TYPE INDEX BY BINARY_INTEGER;user_source_table user_source_table_type;file_handle utl_file.file_type;
stor_text VARCHAR2(4000);
sql_stat varchar2(1000);
sql_stat2 varchar2(1000);
sql_stat3 varchar2(1000);
nCount NUMBER;
i NUMBER;
begin
sql_stat:='select distinct(name) from all_source where owner = ''' || upper(owner) || '''';execute immediate sql_stat bulk collect into user_source_table;file_handle:=utl_file.fopen('PROCE_DIR','test.sql','W');for j in 1..user_source_table.count loop
i:=1;
sql_stat2:='SELECT MAX(LINE) FROM ALL_SOURCE WHERE OWNER=''' || upper(owner) || ''' AND NAME=''' || user_source_table(j) || '''';--dbms_output.put_line(sql_stat2);
execute immediate sql_stat2 into nCount;
WHILE i<=nCount LOOP
sql_stat3:='SELECT TEXT FROM ALL_SOURCE WHERE OWNER=''' || upper(owner) || ''' AND NAME=''' || user_source_table(j) || ''' and line = ' || i;--dbms_output.put_line(sql_stat3);
execute immediate sql_stat3 into stor_text;i:=i+1;
utl_file.put(file_handle,stor_text);
END LOOP;
end loop;
utl_file.fclose(file_handle);
commit;
end loadProce;
3.调用,将TYPE BODY、PROCEDURE、TYPE、FUNCTION、TRIGGER、PACKAGE BODY、PACKAGE保存到桌面的test.sql中Sql代码
begin
loadproce('bijian');
end;
壹寰(深圳)科技文化有限公司
2021-03-27 广告
2021-03-27 广告
不同公司提供的方案也不一样。以上回答如果还觉得不够详细,可以来咨询下壹寰(深圳)科技文化有限公司。91数据恢复是壹寰(深圳)科技文化有限公司旗下专业数据恢复品牌,91数据恢复专注于勒索病毒数据恢复、勒索病毒数据修复、数据库修复、数据库解密恢...
点击进入详情页
本回答由壹寰(深圳)科技文化有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询