Suppose you want to read a file from D2k client and want to store its content in Oracle database. But if you will insert row by row from client to server it will take more time and increase lot of network traffic / round trips.

The solution of this problem is to store the content of the text file into an array and then pass it to database procedure and insert record through that procedure. Here is the example step by step:

1)  Create a package in Oracle database.

Create or Replace Package DB_insert
as
Type textrow is table of Varchar2(1000)
    index by binary_integer;

Procedure Insert_into_table (iarray in textrow);
End;
/

Create or Replace Package Body DB_insert 
as
Procedure Insert_into_table(iarray in textrow)
is
Begin
   For i in 1..iarray.count loop
       Insert into Dummytbl values (iarray(i));
       -- you can extract the content from iarray(i) to insert values into multiple fields
       -- e.g. iarray(i).fieldname
       --
   End Loop;
Commit;
End;
/

2)   Now in D2k write a procedure to read text file and store it into array and pass it to that package you crated above.

Procedure Read_File (ifilename in Varchar2)
is
infile Text_IO.File_type;
irow DB_insert.textrow; 
nelm number := 1;
Begin
   infile := text_io.fopen(ifilename, 'r');
Loop
     text_io.get_line(infile, irow(nelm));
     nelm := nelm + 1;
End Loop;
Exception
   when no_data_found then
     -- end of file reached
    text_io.fclose(infile);
   message('Read Completed.'); 
   -- pass it to database
   DB_insert.insert_into_table(irow);
  message('Data saved.');
  when others then
    if text_io.is_open(infile) then
       text_io.fclose(infile);
    end if;
   message(sqlerrm);   
End;

See also: Reading csv files with Text_io
http://foxinfotech.blogspot.com/2013/02/reading-and-importing-comma-delimited.html
   

Using Text_IO To Read Files in Oracle D2k的更多相关文章

  1. Reading Csv Files with Text_io in Oracle D2k Forms

    Below is the example to read and import comma delimited csv file in oracle forms with D2k_Delimited_ ...

  2. Obtaining Query Count Without executing a Query in Oracle D2k

    Obtaining Query Count Without executing a Query in Oracle D2k Obtaining a count of records that will ...

  3. Using Call_Form in Oracle D2k

    Using Call_Form in Oracle D2k CALL_FORM examples/* Example 1:** Call a form in query-only mode.*/BEG ...

  4. Using GET_APPLICATION_PROPERTY in Oracle D2k Forms

    Using GET_APPLICATION_PROPERTY in Oracle D2k Forms DescriptionReturns information about the current ...

  5. DISPLAY_ITEM built-in in Oracle D2k Forms

    DISPLAY_ITEM built-in in Oracle D2k Forms DescriptionMaintained for backward compatibility only. For ...

  6. Pre-Query trigger in Oracle D2k / Oracle Forms

    Pre-Query trigger in Oracle D2k / Oracle Forms DescriptionFires during Execute Query or Count Query ...

  7. Creating List Item in Oracle D2k

    Special Tips for List Items in Oracle D2k In this section, I shall discuss some special tips and tec ...

  8. Creating Object Library OLB in Oracle D2k Form

    With following steps you can create Object Library (OLB) in Oracle D2k Forms.Step - 1Create a form i ...

  9. Creating Timer in Oracle D2k / Forms 6i and Displaying a Clock

    Creating Timer in Oracle D2k / Forms 6i and Displaying a Clock This is about timer in D2k An externa ...

随机推荐

  1. Mysql 查询Hash分区

    select * from information_schema.partitions where table_schema=database() and table_name='table_name ...

  2. HorizontalScrollView水平滑动

    xml布局 <HorizontalScrollView            android:id="@+id/hsv"            android:layout_ ...

  3. selenium+phantomJS学习使用记录

    背景知识: phantomjs是一个基于webkit的没有界面的浏览器,所以运行起来比完整的浏览器要高效. selenium是一个测试web应用的工具,目前是2.42.1版本,和1版的区别在于2.0+ ...

  4. JNI开发流程-JNI/NDK【转】

    本文转载自:http://wiki.jikexueyuan.com/project/jni-ndk-developer-guide/workflow.html 开发流程 JNI 全称是 Java Na ...

  5. 161128、Redis 4.0发布及其新功能介绍

    Redis 4.0-rc1 发布了,这是 4.0 的首个 RC 版.Redis 是一个高性能的key-value数据库.Redis 的出现,很大程度补偿了memcached这类keyvalue存储的不 ...

  6. hadoop之Spark强有力竞争者Flink,Spark与Flink:对比与分析

    hadoop之Spark强有力竞争者Flink,Spark与Flink:对比与分析 Spark是一种快速.通用的计算集群系统,Spark提出的最主要抽象概念是弹性分布式数据集(RDD),它是一个元素集 ...

  7. java面向对象学习笔记

    1.内部类 //外部类HelloWorld public class HelloWorld{ //外部类的私有属性name private String name = "imooc" ...

  8. Windows 7 驱动开发

    本文是对Win7(64)+VS2010+WDK7.1.0(WinDDK\7600.16385.1)开发驱动的小结. 一.系统工具 1.Win7(amd64位)系统 注:已装系统后,管理员身份运行cmd ...

  9. java中方法的参数传递机制(值传递还是引用传递)

    看到一个java面试题: 问:当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,并可返回变化后的结果,那么这里到底是值传递还是引用传递?  答:是值传递.Java 编程语言只有值传递参 ...

  10. [C++]C++标准里 string和wstring

    typedef basic_string<char> string; typedef basic_string<wchar_t> wstring; 前者string是常用类型, ...