Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Chapter 9 Understanding the Transfer process [Table of Contents] Chapter 11 Using
Destination-Template Transfer

Access Service User's Guide DirectConnect

[-] Chapter 10 Using Bulk Copy Transfer

Chapter 10

Using Bulk Copy Transfer

This chapter describes the bulk copy transfer statement and covers the following topics:

General description of Bulk Copy Transfer

The bulk copy transfer process initiates a direct transfer of data between two databases from the client application. Bulk copy transfer allows you to use SQL statements to:

Use the bulk copy transfer statement to copy large amounts of data between similar tables.

General rules for Bulk Copy Transfer

Generally, when you use a bulk copy transfer statement, the following restrictions apply:

Syntax for Bulk Copy Transfer statements

The required syntax for a bulk copy transfer statement is:

transfer [with
report]
{to | from} 'secondaryname
userid password';
with {insert | replace | truncate} into tablename;
sourceselectstatement

where:

Examples

This section contains some examples of bulk copy transfer statement syntax that are submitted through ISQL. The following table shows the database and user information used in the examples.

Information used for bulk copy transfer examples

Transfer Components

Primary Database

Secondary Database

Database

DB2

Sybase Adaptive Server

User ID

db2user

ssuser

Password

db2pass

sspass

Service Name

db2

ss

Table Names

db2table1, db2table2, db2table3

sstable1, sstable2,sstable3

Column Names

db2col1, db2col2, db2col3,...

sscol1, sscol2, sscol3,...

The following examples assume that the source and target databases are datatype-compatible.

Example #1

Task: Transfer data from DB2 to append to a Adaptive Server table.

c:>isql -Sdb2 -Udb2user -Pdb2pass
1>transfer to 'ss ssuser sspass' ;
2>with insert into sstable1 ;
3>select * from db2table3
4>go

Result: Data from the DB2 table named db2table3 is appended to the SQL Server table sstable1.

Example #2

Task: Transfer data from SQL Server to replace data in D B2.

c:>isql -Sdb2 -Udb2user -Pdb2pass
1>transfer from 'ss ssuser sspass' ;
2>with replace into db2table1 ;
3>select * from sstable3
4>go

Result: Data from the SQL Server table named sstable3 replaces the data in the DB2 table db2table1.

Example #3

Task: Transfer data from two tables in DB2 to a single SQL Server table.

c:>isql -Sdb2 -Udb2user -Pdb2pass
1>transfer to 'ss ssuser sspass' ;
2>with insert into sstable1 ;
3>select a.ssno, a.name2, b.empid
4>from db2table1a, db2table2b
5>where a.ssno=b.ssno
6>go

Result: A social security number (ssno), a name (name2), and an ID (empid) are selected from two DB2 tables, based on a join of social security numbers. The information is appended to the SQL Server table called sstable1.

Processing Bulk Copy transfer from statements

Use transfer from when you want to transfer data from a secondary database, either Sybase Adaptive Server or another database through another access service, to the primary database. The primary database, DB2, is the target and is implied in the transfer statement; the secondary and source database is specified in the transfer statement.

The following figure shows the data flow of one of the preceding transfer from examples, which transfers data from sstable3 in Sybase Adaptive Server to replace data in the DB2 table named db2table1.

Figure 10-1: DB2 bulk copy transfer from statementraster

Datatype conversion for transfer from processing

The access service performs datatype conversions for bulk copy transfer from statements. These conversions are defined within the access service and are not affected by the settings of the datatype conversion configuration properties and set statements.Each access service specification will include specific definitions of datatype mapping for that target DBMS. The access service converts these datatypes into the actual datatypes of the target columns. If the access service cannot convert the columns, the access service ends the transfer with an error.

The access service performs datatype conversions for bulk copy transfers. These conversions are defined within the access service and are not affected by the settings of the datatype conversions configuration properties. Each access service specification includes specific definitions of datatype mapping for that target DBMS.

The following table shows the acceptable Open Server datatypes that the access service can convert into corresponding DB2 datatypes. To save space, the CS_ prefix is removed from Open Server datatypes, and similar DB2 datatypes are combined.

Open Server to DB2 datatype conversions for transfer processing

From Open Server Datatypes (below)

To DB2 Datatypes (across)

CHAR

VARCHAR

INT

SMALLINT

DECIMAL

FLOAT

REAL

DATE

TIME

TIMESTAMP

CHAR FOR BIT DATA

VARCHAR FOR BIT DATA

CHAR

X

X

X

X

X

VARCHAR

X

X

X

X

TEXT

X

X

X

X

X

BINARY

X

X

VARBINARY

X

X

IMAGE

X

X

BIT

X

X

X

SMALLINT

X

X

X

INTEGER

X

X

X

DECIMAL

X

X

X

MONEY

X

X

X

MONEY4

X

X

X

REAL

X

X

X

FLOAT

X

X

X

DATETIME

X

X

DATETIME4

X

X

Processing Bulk Copy transfer to statements

Use the transfer to statement when you want to move data to a secondary database from the primary database. When you execute a bulk copy transfer using transfer to, the secondary database is the target, and the primary database is the source. You can use another access service, an MDI Database Gateway, Open Server, or the CIS functionality in ASE (formerly OmniConnect) as the secondary database.

The following figure shows the data flow of one of the preceding transfer to examples, in which a social security number (ssno), a name (name2), and an ID (empid) are selected from two DB2 tables. The information is appended to the SQL Server table called sstable1. The transfer is based on a join of social security numbers.

Figure 10-2: DB2 bulk copy transfer to statementraster

Datatype conversion for transfer to processing

The access service performs datatype conversions for bulk copy transfer to statements. These conversions are defined within the access service and are not affected by the settings of the datatype conversion configuration properties and set statements.Each access service specification will include specific definitions of datatype mapping for that target DBMS. The access service converts these datatypes into the actual datatypes of the target Open Server columns. If a column does not match, the access service ends the transfer with an error.

The access service performs datatype conversions for bulk copy transfers. These conversions are defined within the access service and are not affected by the settings of the datatype conversions configuration properties. Each access service specification includes specific definitions of datatype mapping for that target DBMS.

The following table shows the DB2 datatypes that the access service can convert into corresponding Open Server datatypes. To save space, the CS_ prefix is removed from the Open Server datatypes, and Open Server datatypes with the same results are combined.

DB2 to Open Server datatype conversion for transfer processing

From DB2 Datatype (below)

To Open Server Datatypes (across)

CHAR

VARCHAR

TEXT

BINARY

VARBINARY

IMAGE

BIT

SMALLINT

INTEGER

DECIMAL

MONEY

MONEY4

REAL

FLOAT

DATE TIME

DATETIME4

CHAR

X

X

X

X

X

X

X

VARCHAR

X

X

X

X

X

X

X

SMALLINT

X

X

X

X

X

INT

X

X

X

X

X

DECIMAL

X

X

X

X

X

FLOAT

X

X

X

X

X

REAL

X

X

X

X

X

DATE

X

X

TIME

X

X

TIMESTAMP

X

X

CHAR FOR BIT DATA

X

X

VARCHAR FOR BIT DATA

X

X

Authorization for transfer to a Sybase Adaptive Server

When you execute a transfer to the Sybase Adaptive Server, you must have create procedure authorization on the tempdb database on the Sybase Adaptive Server; otherwise, you receive the following error message:

create procedure permission denied, database tempdb, owner dbo

Because tempdb is the Adaptive server standard temporary database where CT-Library implements dynamic prepare and execute, the System Administrator must grant create procedure authorization so users can execute transfer to statements to a Sybase Adaptive Server.

To grant create procedure permission to public:

Processing for Bulk Copy transfer statements

Bulk copy transfer processing occurs in the following sequence:

Guidelines for processing

Details of which particular values cause errors are access service-specific.

Bulk Copy values

To avoid errors in the bulk copy transfer process, review the following guidelines that apply to values.

Character datatypes

Character datatypes (CHAR, VARCHAR, TEXT) can be converted to any other datatype. Conversely, every datatype can be converted to character data. However, you must be sure the character string is convertible to the target datatype. For example, the character string "450" can be converted to a numeric datatype such as INTEGER or DECIMAL, but the character string "Hello" causes a value error going to a numeric datatype.

Numeric datatypes

Numeric datatypes can be converted to other numeric datatypes or to character datatypes. However, they cannot be converted to binary or date datatypes.

Additional guidelines are:

Date datatypes

Date datatypes can be converted to other date datatypes or to character strings. However, they cannot be converted to numeric or binary datatypes.

Binary datatypes

Binary datatypes can be converted to other binary datatypes and to character strings. However, they cannot be converted to numeric or date datatypes.

ASCII to EBCDIC translation does not occur if the source column, the destination column, or both source and destination columns are BINARY datatypes.

Errors from data values

The following four tables show the values that cause errors for the access service during bulk copy transfer. These tables are divided into the four major groups of input datatypes:

Each table shows the output datatype and the kind of error that can occur.

Character datatype errors

This table uses the following as the source character datatypes:

The following table shows the errors that can occur when the access service converts the preceding character datatypes to those listed in the Open Server and DB2 Output Datatype column.

In the Output Datatype column of the following four tables, the CS_ prefix is attached to the Open Server datatypes to distinguish them from DB2 datatypes.

Conversion errors: character to output datatypes

Open Server and DB2 Output Datatype

Error Condition

CS_CHAR CS_VARCHAR CS_TEXT CS_BINARY CS_VARBINARY CHAR VARCHAR

The source data is longer than the destination column.

CS_BIT

The source value cannot be converted to a number, or the resulting value does not equal 0 or 1.

CS_TINYINT

The source value cannot be converted to a number, or the resulting value is not between 0 and 255.

CS_SMALLINT SMALLINT

The source value cannot be converted to a number, or the resulting value is not between -32,768 and +32,767.

CS_INTEGER INTEGER

The source value cannot be converted to a number, or the resulting value is not between -147,483,648 and +2,147,483,647.

CS_DECIMAL DECIMAL

The source value cannot be converted to a number, or the number of digits to the left of the decimal point in the source exceeds the destination decimal's precision minus scale. Digits to the right of the decimal point that exceed the decimal's scale are lost without error.

REAL FLOAT

The source value cannot be converted to a number, or the resulting value is one of the following:

  • Greater than 7.2E+75

  • Less than -7.2E+75

  • Greater than 0 and less than 5.4E-79

  • Less than 0 and greater than -5.4E-79

CS_REAL CS_FLOAT

The source value cannot be converted to a number, or it is out of range. Because the value range is machine-dependent, see the Sybase Adaptive Server documentation for your environment.

CS_MONEY

The source value cannot be converted to a number, or the resulting value is not between -922,337,203,685,477.5807 and +922,337,203,685,477.5807.

CS_MONEY4

The source value cannot be converted to a number, or the resulting value is not between -214,748.3647 and +214,748.3647.

CS_DATE

The source value is not an ISO format (YYYY-MM-DD) date or a valid Sybase Adaptive Server date/time string, or the resulting date has a year prior to 1753.

CS_DATETIME4

The source value is not an ISO format (YYYY-MM-DD) date or a valid Sybase Adaptive Server date/time string, or the resulting date is not between January 1, 1900, and June 6, 2079.

DATETIME TIMESTAMP

The source value is not an ISO format date, time or timestamp, or a valid Sybase Adaptive Server date/time string.

Numeric datatype errors

This section uses the following as source numeric datatypes:

The following table shows the errors that can occur when the access service converts the preceding source numeric datatypes to those listed in the Open Server and DB2 Output Datatype column.

Conversion errors: numeric types to output datatypes

Open Server and DB2 Output Datatype

Error Condition

CS_CHAR CS_VARCHAR CHAR VARCHAR

The destination column is too small to hold the character string to express the value. For example, the source value is 102, and the destination column is CS_CHAR(2).

CS_BIT

The value does not equal 0 or 1.

CS_TINYINT

The value is not between 0 and 255.

CS_SMALLINT SMALLINT

The value is not between -32,768 and +32,767.

CS_INTEGER INTEGER

The value is not between -147,483,648 and +2,147,483,647.

CS_DECIMAL DECIMAL

The number of digits to the left of the decimal point in the source exceeds the destination decimal's precision minus scale. Digits to the right of the decimal point that exceed the decimal's scale are lost without error.

REAL FLOAT

The source value is one of the following:

  • Greater than 7.2E+75

  • Less than -7.2E+75

  • Greater than 0 and less than 5.4E-79

  • Less than 0 and greater than -5.4E-79

CS_REAL CS_FLOAT

The source value is out of range. Because the value range is machine-dependent, see the Sybase Adaptive Server documentation for your environment.

CS_MONEY

The value is not between -922,337,203,685,477.5807 and +922,337,203,685,477.5807.

Because the accuracy of a FLOAT value is 15 digits, a FLOAT value converted to CS_MONEY is accurate only to the nearest dollar.

Because the highest precision of a REAL value is 7 digits, a REAL value converted to CS_MONEY is accurate only to the nearest hundred million dollars.

CS_MONEY4

The value is not between -214,748.3647 and +214,748.3647.

Date datatype errors

This section uses the following as source date datatypes:

The following table shows the errors that can occur when the access service converts the preceding source date datatypes to those listed in the Open Server and DB2 Output Datatype column.

Conversion errors: date types to output datatypes

Open Server and DB2 Output Datatype

Error Condition

CS_CHAR CS_VARCHAR CS_TEXT CHAR VARCHAR

When converted into a character string, the date or time value is too long to fit into the destination column.

CS_DATE

The date has a year prior to 1753.

CS_DATETIME4

The date is not between January 1, 1900, and June 6, 2079.

Binary datatype errors

This section uses the following as source binary datatypes:

The following table shows the errors that can occur when the access service converts the preceding source binary datatypes to those listed in the Open Server and DB2 Output Datatype column.

Conversion errors: binary to output datatypes

Open Server and DB2 Output Datatype

Error Condition

CS_CHAR CS_VARCHAR CS_TEXT CS_BINARY CS_VARBINARY CS_IMAGE CHAR VARCHAR

The source data is longer than the destination column.


Chapter 9 Understanding the Transfer process [Table of Contents] Chapter 11 Using
Destination-Template Transfer