Git Product home page Git Product logo

export-and-import-lob-values's Introduction

Export and Import LOB values

Oracle PL/SQL solution to move LOB data with text files

Why?

Because I did not find any useful and easy solution for exporting and importing LOB data.

The EXP_IMP_LOB package can export and import CLOB, NCLOB, BLOB type column data using simple SQL (text) files.

How?

First of all install the package onto both source and target schemas. To export run this select

select * from table( EXP_IMP_LOB.EXPORT('table_name','lob_column_name','condition') );

where the Table_Name and LOB_Column_Name define the data column and the optional Condition defines the row or rows. If there is no condition, then every row data will be exported row by row.

Example:

select * from table( EXP_IMP_LOB.EXPORT('person','image','id=103' ) );

Result:

/ ******************************************************
    TABLE  :PERSON
    COLUMN :IMAGE
    ROW    :103
****************************************************** /
BEGIN
    EXP_IMP_LOB.IMPORT_NEW;
    EXP_IMP_LOB.IMPORT_APPEND ( 'FFD8FFE000104A464....23232323232');
    EXP_IMP_LOB.IMPORT_APPEND ( '32323232323232323....798999AA2A3');
    .........
    EXP_IMP_LOB.IMPORT_APPEND ( 'B2316524267279AA9....51401FFFD9');
    EXP_IMP_LOB.IMPORT_UPDATE ( 'PERSON','IMAGE','103' ); 
    COMMIT;
END;
/   

So, the export converts the binary data to 400 char length hexa strings and creates a script from it. I used ..... to symbolize many chars, because that is only a sample above. DO NOT ORDER THE RESULT! To import, you only have to install the package onto the target schema too and run this script above in the target schema. That's all.

...more:

  • The source and target table name, column name must be the same!

  • The Table (both source and target) must have Primary key and they must be identical.

  • The EXPORT function can detect the primary key automatically. Theoretically it can manage composed keys too...

  • The size of a hexa string is defined in G_LENGTH global variable. 200 chars means 400 hexa chars.

  • The additional procedures:

  • IMPORT_NEW: resets the package variables to prepare it to accept a new LOB

  • IMPORT_APPEND : converts the hexa string to a binary data and append it the package variable

  • IMPORT_UPDATE : updates the given table, row, column with the package variable

  • DIRECT_SQL : executes the given SQL using the global LOB variable as a parameter. eg:

    EXP_IMP_LOB.DIRECT_SQL( 'insert into ANY_TABLE ( ID, IMAGE ) values ( 123, :1 )' );

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.