DB2LOAD Stored Procedure

转自:

http://www-01.ibm.com/support/docview.wss?uid=swg21201292

 

 

Abstract

You can access the LOAD utility via a stored procedure in DB2 UDB V8.2 for Linux, Unix and Windows.
 
Content
Overview
Starting with DB2 UDB V8.2 IBM is shipping another interface to the LOAD utility. The LOAD stored procedure, SYSPROC.DB2LOAD, is implemented on the server and it allows any application able to connect to DB2 UDB server and execute the SQL CALL statement to run the DB2 LOAD utility. The stored procedure is automatically cataloged in the system tables (SYSCAT.PROCEDURES) at database creation time. One of the input parameters to the stored procedure is the CLP syntax of the load command. A cursor definition must be supplied as an input parameter in order to run a LOAD from CURSOR.

The benefits of using DB2LOAD stored procedure to access the utility are:
  • Simpler programmable interface than the db2Load API.
  • Utility is accessible to applications that cannot utilize DB2 UDB administrative APIs but can execute the SQL CALL statement.

Stored procedure definition

CREATE PROCEDURE SYSPROC.DB2LOAD 

    IN version_number INTEGER,
    IN cursor_statement VARCHAR(32672),
    IN load_command VARCHAR(32672),
    OUT sqlcode INTEGER,
    INOUT sqlmessage VARCHAR(2048),
    OUT rows_read BIGINT,
    OUT rows_skipped BIGINT,
    OUT rows_loaded BIGINT,
    OUT rows_rejected BIGINT,
    OUT rows_deleted BIGINT,
    OUT rows_committed BIGINT,
    OUT rows_part_read BIGINT,
    OUT rows_part_rejected BIGINT,
    OUT rows_part_partitioned BIGINT,
    INOUT mpp_load_summary VARCHAR(32672)

SPECIFIC DB2LOAD 
LANGUAGE C 
PARAMETER STYLE DB2SQL 
NOT FENCED 
MODIFIES SQL DATA 
PROGRAM TYPE MAIN 
EXTERNAL NAME 'system_routine~db2load!db2load'

Parameter Description

ParameterDescription
version_numberVersion number of the DB2LOAD stored procedure. Current version number is 1.
cursor_statementDeclaration of the cursor which is to be used during a LOAD from CURSOR operation. This parameter must be specified when loading from CURSOR via DB2LOAD stored procedure.
load_commandLOAD command to be executed.
sqlcodeSQLCODE returned by the LOAD utility. If a nonzero value is returned by the LOAD utility, an SQLCA populated with SQL0462W will be returned by the SQL CALL statement, with the third token indicating either a 'LOAD WARNING' or a 'LOAD ERROR'.
sqlmessageSQL message associated with the above LOAD return SQLCODE.
rows_readNumbers of rows processed by the LOAD utility, including the MPP specific processing done by the partitioning agent. These values correspond to the contents of db2LoadOut API structure and to a subset of the contents of db2PartLoadOutAPI structures.
rows_skipped
rows_loaded
rows_rejected
rows_deleted
rows_committed
rows_part_read
rows_part_rejected
rows_part_partitioned
mpp_load_summaryAbbreviated MPP LOAD summary. Displays a subset of information otherwise contained in thedb2LoadAgentInfo API structure in a character format.

Current restrictions
  • CLIENT option is not supported. Hence all file and directory paths specified as a part of the load command have to refer to existing paths on the DB2 server.
  • When called by a DRDA client following a two phase commitprotocol, the stored procedure can not commit data under the transaction manager control. A call to DB2LOAD stored procedure will fail with SQL30090 (Reason Code 2) if any of the following is true:
    1. Current transaction has executed any SQL statement that writes a log record.
    2. Current transaction has executed an explicit table lock statement.
    3. Current transaction has opened an with hold cursor.
    4. Current transaction has accessed a federated source.
  • Only SQL types can be used as stored procedure input parameters, hence the amount of information returned to the caller is somewhat limited.
  • Output (numbers of rows) can be truncated since the db2Load API uses 64 bit unsigned integers, but the SP uses SQL type BIGINT which is 64 bit signed.
  • At most 1000 individual sub-agent entries will be displayed in the MPP LOAD summary.
  • Message files are not moved to the client.

We strongly recommend a connection be recycled explicitly before invoking the LOAD stored procedure.

Invocation examples using the sample database
Hide details for CLP exampleCLP example
connect to sample;

create table staff2 like staff;

call db2load(1,'','load from /fully/qualified/path/staff.del of del replace into staff2',?,'',?,?,?,?,?,?,?,?,?,NULL);

call db2load(1,'','load from /fully/qualified/path/staff.asc of asc method l (4 6, 8 20, 22 23, 25 33, 35 36, 39 46, 50 56) messages /fully/qualified/path/staff.400.1 insert into staff2 partitioned db config partitioning_dbpartnums(2) output_dbpartnums(3)',?,'',?,?,?,?,?,?,?,?,?,'');

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值