UTLITeye - 牛牛娱乐

UTLITeye

2019年03月06日12时21分14秒 | 作者: 星鹏 | 标签: 数据,目录,文件 | 浏览: 1395

以SYS用户创立目录dir_dump,文件就保存在这个目录下
SQL create or replace directory dir_dump as /data/cmssdb;windows:F:\app
Directory created.
授权对应的操作帐号读和写的权限,这里是operator
SQL grant read on directory dir_dump to operator;
Grant succeeded.
SQL grant write on directory dir_dump to operator;
Grant succeeded.
以operator用户登陆
SQL connect operator/operation
Error accessing PRODUCT_USER_PROFILE
Warning: Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM
Connected.
创立表BIBI,并参加测试数据
SQL create table bibi(row_id int,row_name varchar2(10));
Table created.
SQL insert into bibi values(1,luochun);
1 row created.
SQL insert into bibi values(2,maihy);
1 row created.
SQL commit;
Commit complete.
/*该进程担任备份数据到DIR_DUMP目录,名称为bibi.csv
DECLARE lv_file_handle UTL_FILE.file_type;
BEGIN
lv_file_handle := UTL_FILE.FOPEN(DIR_DUMP,bibi.csv,a);
FOR x IN (SELECT ROW_ID,ROW_NAME FROM BIBI) LOOP
 UTL_FILE.PUT_LINE(lv_file_handle,x.ROW_ID || , || NVL(x.ROW_NAME,));
END LOOP;
UTL_FILE.FCLOSE(lv_file_handle);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SUBSTR(SQLERRM,1,200));
进程完结,转到DIR_DUMP目录检查生成的文件,数据现已发生
[oracle@qaserver oracle]$ cd /data/cmssdb
[oracle@qaserver cmssdb]$ cat bibi.csv
1,luochun
2,maihy
现在删去BIBI数据,预备将备份的导入
SQL truncate table bibi;
Table truncated.
/*这个进程担任读取文件,并导入数据
DECLARE lv_file_handle UTL_FILE.file_type;
lv_row_text VARCHAR2(2000);
lv_row_id PLS_INTEGER;
lv_row_name VARCHAR2(50);
BEGIN
lv_file_handle := UTL_FILE.FOPEN(DIR_DUMP,bibi.csv,r);
 BEGIN
 UTL_FILE.GET_LINE(lv_file_handle,lv_row_text);
 lv_row_id := SUBSTR(lv_row_text,1,INSTR(lv_row_text,,,1,1) - 1);
 lv_row_name := SUBSTR(lv_row_text,INSTR(lv_row_text,,,1,1) + 1);
 INSERT INTO BIBI VALUES(lv_row_id,lv_row_name);
 EXCEPTION
 WHEN NO_DATA_FOUND THEN
 EXIT;
 END;
END LOOP;
COMMIT;
UTL_FILE.FCLOSE(lv_file_handle);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SUBSTR(SQLERRM,1,200));
数据现已发生
SQL SQL SELECT * FROM BIBI;
 ROW_ID ROW_NAME
 
 1 luochun
 2 maihy
SQL 

 参阅:http://www.blogjava.net/sterning/archive/2009/01/10/250793.html

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表牛牛娱乐立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章

阅读排行

  • 1
  • 2

    UTLITeye

    数据,目录,文件
  • 3
  • 4
  • 5

    java与函数式编程ITeye

    函数,编程,一些
  • 6
  • 7
  • 8
  • 9
  • 10