有d:\test.sql
spool d:\tables.txt
select * from t_test where rownum<10;
spool offsqlplus下执行@d:\test.sql可以导出t_test表中的数据到d:\tables.txt以上都没问题现在我想实现定时导出,知道可以用job来做,可是不知道如何用job执行,请高手详细指点,先谢谢各位。

解决方案 »

  1.   

    如果在Windows上,可以设置计划任务如果Linux,也可以添加定时任务导出是由外部控制的,Oracle内置的JOB不能用
      

  2.   

    写文件举例
    -- 环境 windows 2000 server + oracle 8.1.7
    -- 先在 init.ora中的参数utl_file_dircreate or replace procedure write_txtfile( -- 写一个字符串到指定文本文件中
    path   in varchar2,
    name   in varchar2,
    pstr   in varchar2
    )
    as
    l_output   utl_file.file_type;
    str        varchar2(1000);
    begin
    l_output:=utl_file.fopen(path,name,'a',2000); -- 每行最大字节数最多为32K bytes
    --l_output:=utl_file.fopen(path,name,'a'); -- 每行最大字节数最多为1023 bytes
    utl_file.put_line(l_output,pstr);
    utl_file.fclose(l_output);
    exception
    when utl_file.invalid_path then
    raise_application_error(-20001,'INVALID_PATH!');
    when utl_file.invalid_mode then
    raise_application_error(-20002,'INVALID_MODE!');
    when utl_file.invalid_filehandle then
    raise_application_error(-20003,'INVALID_FILEHANDLE!');
    when utl_file.invalid_operation then
    raise_application_error(-20004,'INVALID_OPERATION!');
    when utl_file.read_error then
    raise_application_error(-20005,'READ_ERROR!');
    when utl_file.write_error then
    raise_application_error(-20006,'WRITE_ERROR!');
    when utl_file.internal_error then
    raise_application_error(-20007,'INTERNAL_ERROR!');
    when others then
    str:=sqlerrm(sqlcode);
    dbms_output.put_line(str);
    end;
    /
    --SQL> execute write_txtfile('e:\','njhart2003.txt','hello oracle,i like oracle!');--PL/SQL 过程已成功完成。
    放到job里就行了
      

  3.   

    问楼上的朋友:写文件举例
    -- 环境 windows 2000 server + oracle 8.1.7
    -- 先在 init.ora中的参数utl_file_dir???????????
      

  4.   

    在9i中可以不在init.ora中增加utl_file_dir目录
      

  5.   

    to leborety(那只螃蟹):你这种方案会直接把数据导出到数据库服务器上啊,哪能这么做呢?9i里面可以 CREATE DIRECTORY ... 但也是在服务器上才能用
      

  6.   

    如果要导出文件到本地,可以用pro*c,但我不会,给个参考,要麻烦楼主自己去查了