plsql导入excel数据(plsql命令窗口导入sql文件)


如果SQL语句的结果太大,通过plsql developer无法显示所有的结果,这个时候,我们可以通过一段代码来完成,下面是一个例子:

select last_name, salary, department_id
from employees
order by department_id
的结果显示到excel
下面是具体例子:
create or replace procedure out_excel(dir in varchar2,
filename in varchar2) is
file utl_file.file_type;
cursor empc is
select last_name, salary, department_id
from employees
order by department_id;
begin
file := utl_file.fopen(dir, filename, ‘w’);
utl_file.put_line(file, ‘report: generated on ‘ || sysdate);
utl_file.new_line(file);
utl_file.put_line(file,
‘department_id’ || chr(9) || ‘name’ || chr(9) ||
‘salary’);
FOR emp_rec IN empc LOOP
UTL_FILE.PUT_LINE(file,
nvl(emp_rec.department_id, ”) || chr(9) ||
emp_rec.last_name || chr(9) || emp_rec.salary);
END LOOP;
UTL_FILE.PUT_LINE(file, ‘*** END OF REPORT ***’);
UTL_FILE.FCLOSE(file);
EXCEPTION
WHEN
UTL_FILE.INVALID_FILEHANDLE THEN
RAISE_APPLICATION_ERROR(-20001, ‘Invalid File.’);
WHEN UTL_FILE.WRITE_ERROR THEN
RAISE_APPLICATION_ERROR(-20002, ‘Unable to write to file’);
when
utl_file.invalid_operation then
RAISE_APPLICATION_ERROR(-20003, ‘file operate invalid’);
END out_excel;
execute sal_status(dir =>’DIR_FILE’,filename => ‘outexcel.xls’);

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发表评论

登录后才能评论