Sunteți pe pagina 1din 2

Page 1 of 2

"> How to use decode function in SQL*Loader to reference fields [ID 1083518.6] Modified 14-OCT-2010 Type HOWTO Status PUBLISHED

HOW TO USE DECODE FUNCTION IN SQL*LOADER TO REFERENCE FIELDS ============================================================ PURPOSE ------How to reference fields using decode function in a SQL*LOADER controlfile. SCOPE & APPLICATION ------------------For users who need a step by step example on how to use decode function in SQL*Loader controlfile.

USING DECODE FUNCTION IN SQL*LOADER ----------------------------------When doing a conventional path load, a SQL string may be applied to column data before it is inserted into the database. A SQL string may be any expression that produces a valid value for an insert statement. To refer to fields in the record, precede the field name with a coln(:). Field values from the current record are substituted. The following example illustrates references to the current field using a decode function.

Format: ====== col <datatype spec> "<sql string>" Example: -----------Control File: ============ The Control file is test.ctl Load data infile * into table testldr fields terminated by ',' optionally enclosed by '"' (test1, test2 "decode(:test1, 'hello', 'goodbye', :test1)") begindata hello,"" goodbye,"" this is a test,"" hello,"" Here the decode function specifies if the data for test1 spells "hello" then loads "goodbye" into test2, otherwise load data from test1.

Invoking SQL*Loader: ==================== sqlldr sys/change_on_install control=test.ctl log=test.log SQL*Loader: Release 8.1.6.0.0 - Production on Mon Apr 10 12:44:57 2000 (c) Copyright 1999 Oracle Corporation. All rights reserved.

Commit point reached - logical record count 4 Log File: ======== test.log SQL*Loader: Release 8.1.6.0.0 - Production on Mon Apr 10 13:05:21 2000 (c) Copyright 1999 Oracle Corporation. All rights reserved.

Commit point reached - logical record count 4 stsun7:/home/skasturi>more test.log SQL*Loader: Release 8.1.6.0.0 - Production on Mon Apr 10 13:05:21 2000 (c) Copyright 1999 Oracle Corporation. Control File: Data File : Bad File : Discard File: test.dat test.dat test.bad none specified All rights reserved.

(Allow all discards) Number to load: Number to skip: Errors allowed: Bind array: Continuation: Path used: ALL 0 50 64 rows, maximum of 65536 bytes none specified Conventional

Table TESTLDR, loaded from every logical record. Insert option in effect for this table: INSERT Column Name Position LenTerm Encl Datatype ------------------------------ ---------- ----- ---- ---- --------TEST1 FIRST * , O(") CHARACTER TEST2 NEXT * , O(") CHARACTER SQL string for column : "decode(:test1, 'hello', 'goodbye', :test1)" Table TESTLDR: 4 Rows successfully 0 Rows not loaded 0 Rows not loaded 0 Rows not loaded

loaded. due to data errors. because all WHEN clauses were failed. because all fields were null.

Space allocated for bind array: 33024 bytes(64 rows) Space allocated for memory besides bind array: 0 bytes Total logical records skipped: Total logical records read: 0 4

https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=HOW... 24/05/2012

Page 2 of 2

Total logical records rejected: Total logical records discarded: Run began on Mon Apr 10 13:05:21 2000 Run ended on Mon Apr 10 13:05:22 2000 Elapsed time was: CPU time was: 00:00:00.25 00:00:00.02

0 0

Data: ===== SVRMGR> select * from testldr; TEST1 ------------------------hello goodbye this is a test hello 4 rows selected. Restrictions: ============= SQL strings are not allowed in the direct load because it bypasses SQL processing. RELATED DOCUMENTS ----------------Oracle8i Utilities Release 8.1.5 Oracle8i Release 2 Utilities Oracle9i Database Utilities TEST2 ------------------------goodbye goodbye this is a test goodbye

Related Products

Oracle Database Products > Oracle Database > Oracle Database > Oracle Server - Personal Edition Oracle Database Products > Oracle Database > Oracle Database > Oracle Server - Enterprise Edition Oracle Database Products > Oracle Database > Oracle Database > Oracle Server - Standard Edition Keywords UTILITY; SQL*LOADER UTILITY

Back to top Copyright (c) 2007, 2010, Oracle. All rights reserved. Legal Notices and Terms of Use | Privacy Statement

https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=HOW... 24/05/2012

S-ar putea să vă placă și