oracle数据库可否批量导出存储过程
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;
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询