27
1 Oracle Tips Oracle Tips Oracle Tips Oracle Tips, Tricks, Utilities and Resources , Tricks, Utilities and Resources , Tricks, Utilities and Resources , Tricks, Utilities and Resources By George Lewycky By George Lewycky By George Lewycky By George Lewycky Wednesday, February 14, 2007 Wednesday, February 14, 2007 Wednesday, February 14, 2007 Wednesday, February 14, 2007 Two very useful websites & email discussions groups SQL tricks for delimiting data into a spooled file Text Write Excel macro to delimit Excel spreadsheets into ASCII text data with any desired delimiter for SQL*Loader Copying a table Copying a table from another machine Oracle’s SQL*Loader (a.k.a. Bulk Loader) o Intro, Overview, examples, features o Fixed or Delimited??? o DOS Script to automate the load process (DOS) SQL*Loader web sites and references o DOS & Unix Questions

Oracle Tips, Tricks, Utilities and Resources

Embed Size (px)

DESCRIPTION

a

Citation preview

1

Oracle TipsOracle TipsOracle TipsOracle Tips, Tricks, Utilities and Resources, Tricks, Utilities and Resources, Tricks, Utilities and Resources, Tricks, Utilities and Resources

By George LewyckyBy George LewyckyBy George LewyckyBy George Lewycky

Wednesday, February 14, 2007Wednesday, February 14, 2007Wednesday, February 14, 2007Wednesday, February 14, 2007

• Two very useful websites & email discussions groups

• SQL tricks for delimiting data into a spooled file

• Text Write Excel macro to delimit Excel spreadsheets into ASCII text

data with any desired delimiter for SQL*Loader

• Copying a table

• Copying a table from another machine

• Oracle’s SQL*Loader (a.k.a. Bulk Loader)

o Intro, Overview, examples, features

o Fixed or Delimited???

o DOS Script to automate the load process (DOS)

• SQL*Loader web sites and references

o DOS & Unix

• Questions

2

Here are two very useful and (a word Transit likes to hear) websites/email discussion list (also available in digest form).

• You can post your question and reply to other member’s questions and answers.

• Learn and collect many tips and solutions.

• Personally I also collect useful postings in a separate Outlook folder

• You are in direct communication with others in the field that might have had the same problem(s) or experience that you can benefit from rather than METALINK.

HTTP://ORACLE.ITTOOLBOX.COM

ITTOOLBOX contains the following ORACLE RELATED discussion lists, along with various languages, operating systems, ERP’s, 3rd party products, etc oracle-apps-l 5,626 oracle-appserver-l 3,955 oracle-bi-l 4,178 oracle-crm-l 3,724 oracle-db-backup-l 4,635 oracle-db-installs-l 4,787 oracle-db-l 6,180 oracle-db-tuning-l 5,618 oracle-db-upgrades-l 4,614 oracle-dev-l 5,000 oracle-dw-l 3,359 oracle-forms-l 1,136 oracle-fusion-wiki-project 369 oracle-jdeveloper-l 893 oracle-sql-l 1,966

I have been a contributing member since December 2001 and it has benefited our projects tremendously. I learn and shared a lot to/from other programmers and I collect postings for future use and reference!

HTTP://WWW.EXFORSYS.COM/

Exforsys is a community of developers specializing in C, C++, C#, Java, J2EE, .NET, PeopleSoft, SAP, Siebel, Oracle Apps., Data warehousing, Oracle/SQL Server/DB2 and Testing, who have come together to share Source code, Articles, Certification details, Interview questions, Job postings, Trainings and on-line tutorials.

3

SQL tricks for delimiting data into a spooled file filename: xxx.sql set heading off set linesize 100 set pagesize 0 set feedback off spool c:\test.txt

select jobno ||'","',nyctpm ||'","', descr || '","' from jobxref; spool off - - - - - - - - - - output - - - - - - - - - outfile: test.txt 95578"," LIONEL SAINT LOUIS"," CORRECT-FALLING DEBRIS,ICE,WAT"," 95579"," MIRON KUCHUK "," RECONSTRUCTION OF FLUSHING AVE"," 95580"," MIRON KUCHUK "," RESURFACING OF MCDONALD AVENUE","

- - - - - OR THIS MUCH SIMPLER METHOD - - - - - - - -

colsep.sql SET SERVEROUTPUT ON SET ECHO OFF SET VERIFY OFF SET Heading OFF SET LINESIZE 2000 SET NEWPAGE NONE SET PAGESIZE 100 SET Heading OFF

SET COLSEP , <- this saves you the headache of coding each column!!! spool example1.txt select * from jobxref where nyctpm like ('%J.G. SUMMERS%'); spool off SQL> @colsep 97474,J.G. SUMMERS ,TO REPLACE MATERIAL EQUIPMENT, 97479,J.G. SUMMERS ,INSTALL NEW DATA CABLING, A NO 97417,J.G. SUMMERS ,TO REPLACE RADIO FRECUENCY (RF 97418,J.G. SUMMERS ,TO REPLACE MATERIAL HANDLING E 97365,J.G. SUMMERS ,REPLACEMENT-MATERIAL HANDLING 97265,J.G. SUMMERS ,REPLACE MATERIAL HANDLING EQUI 97266,J.G. SUMMERS ,PUR.3 RETRIEVAL MACHINES-ZEREG 7 rows selected. SQL>

NOTE: if any of the columns have ',' embedded in them like the address you might be in a bind.

So you might need a unique delimiter like '|' or ']' You must include tick marks with this delimiter!!! See below line:

SET COLSEP '|' or SET COLSEP ']' Then your file will look something like this: 92877|S SHECTER |EMGINEERING & TECHNICAL FIELD 92881|S SHECTER |ENGINEERING & TECHNICAL FIELD

NOTE: only drawback can beNOTE: only drawback can beNOTE: only drawback can beNOTE: only drawback can be excess trailing excess trailing excess trailing excess trailing / padded / padded / padded / padded spacesspacesspacesspaces

4

Very useful Excel macro to use with an Excel spreadsheet to

delimit your DATA with any Delimiter desired ( “,” “|” “]” )

http://www.smokeylake.com/excel/text_write_program.htm http://www.smokeylake.com/excel/

Text Write Program

The Text Write Program is a Microsoft Excel workbook with a macro program that writes any sheet of any open workbook to a text file with lots of options.

Setup Sheet.

Here you specify your options. There is help on the options. A typical setup sheet:

File Name to write: a.txt, or C:\My Documents\a.txt

Record Delimiter: Code/Character 13,10

Stop if Record Delimiter found in cell?: Yes

Field Delimiter: Code/Character , (comma)

Bracketing Code/Character (text qualifier): " (quotation mark)

Bracket data fields?: Yes

Bracket blank fields also?: No

Skip blank rows?: No

Write entire sheet?: Yes

If no, Expand selection?: No

If no, write rectangular?: No

Then you switch to the sheet to be written (in any open workbook), and press Ctrl-Shift-W. It writes the file, letting you know its progress.

Download Text Write Program

The Text Write Program is now at the 1d level. Text Write Program-1d.xls. There are some fixes and some enhancements.

5

INSTRUCTIONS:

(1) In EXCEL open your “TEXT WRITE” spreadsheet with the macro (2) Enter the filename you want outputted and change delimiter, etc if needed

(3) Staying in EXCEL, open the spreadsheet file that needs delimited

(4) Select/highlight the data/cells you want ported over

(5) Hold these keys down in this sequence until you receive a message telling you how many records

<CTRL> then <SHIFT> then <W> wait a few seconds and let go till you see the following

(6) That’s all ……now just Verify the record counts

6

Creating a duplicate TABLE of an existing Table This isn’t copying the data or entire database but rather making an exact copy of a table’s structure to test a load or copy the data into. Create Table <newtablename> AS Select * from <source or original tablename>; Example:

SQL> create table temp_cust_int

AS Select * from ra_customers_interface;

( Feel free to add a WHERE clause, etc )

COPYING TABLE FROM ONE MACHINE TO ANOTHER

First do a count or delete all your rows

SQL> select count(*) from jobxref; COUNT(*) --------- 4227 SQL> copy from apps/apps@argp -

> replace jobxref - or create jobxref - > using select * from jobxref; Array fetch/bind size is 15. (arraysize is 15) Will commit when done. (copycommit is 0) Maximum long size is 80. (long is 80) Table JOBXREF dropped. Table JOBXREF created. 4255 rows selected from apps@argp. 4255 rows inserted into JOBXREF. 4255 rows committed into JOBXREF at DEFAULT HOST connection. SQL> select count(*) from jobxref; COUNT(*) --------- 4255

NOTE: initially be sure to do “CREATE” NOTE: initially be sure to do “CREATE” NOTE: initially be sure to do “CREATE” NOTE: initially be sure to do “CREATE”

7

SUPERB REFERENCE BOOK BY O’REILLY http://www.oreilly.com/catalog/orsqlloader/index.html http://www.oreilly.com/catalog/orsqlloader/chapter/ch01.html INTRODUCTION

SQL Loader is a tool used to import text formatted data into your database. This makes it easy to import your data from almost any database; all you have to do is export you data to a text file. SQL Loader comes with the Oracle client. SQL Loader with control file requires that you create a control file with the location of the data and how to import your data into Oracle.

DATATYPES

SQL*Loader has a rich palette of datatypes. These datatypes are grouped into portable and nonportable datatypes. Within each of these two groups, the datatypes are subgrouped into length-value datatypes and value datatypes. Nonportable datatypes consist of: VALUE and LENGTH-VALUE datatypes. Portable datatypes consist of: CHAR, DATE, GRAPHIC, GRAPHIC EXTERNAL, Numeric External (INTEGER, FLOAT, DECIMAL, ZONED) and RAW

8

Direct Path Load vs. Conventional Path Load MethodDirect Path Load vs. Conventional Path Load MethodDirect Path Load vs. Conventional Path Load MethodDirect Path Load vs. Conventional Path Load Method SQL*Loader can use one of two methods to load data: conventional path (which uses the bind array) and direct path (which stores data directly into the database). The conventional path loader essentially loads the data by using standard insert statements. The direct path loader (direct=true) loads directly into the Oracle data files and creates blocks in Oracle database block format..

Conventional Path (default) During conventional path loads, multiple data records are read in and placed in a bind array. When the bind array is full (or there is no more data left to read), it is passed to Oracle for insertion. Conventional path uses the Oracle SQL interface with the array option.

Direct Path A direct path load creates data blocks that are already in Oracle database block format. These database blocks are then written directly to the database bypassing most RDBMS processing. This path is much faster than the conventional load, but entails several restrictions. To prepare the database for direct path loads, the script: $ORACLE_HOME/rdbms/admin/catldr.sql.sql must be executed. http://www.remote-dba.net/teas_rem_util18.htm

How to improve the performance of SQL*Loader?

A very simple but easily overlooked hint is not to have any indexes and/or constraints (primary key) on your load tables during the load process. This will significantly slow down load times even with ROWS= set to a high value. Add the following option in the command line: DIRECT=TRUE. This will effectively bypass most of the RDBMS processing. However, there are cases when you can't use direct load. Turn off database logging by specifying the UNRECOVERABLE option. This option can only be used with direct data loads. Run multiple load jobs concurrently.

9

IMPORTANT:

Log file will indicate any errors, constraints, duplication errors that occurred………

Record 8: Rejected - Error on table EMP, --EMPNO null ORA-01400: mandatory (NOT NULL) column is missing or NULL during insert Record 9: Rejected - Error on table EMP. --EMPNO not unique ORA-00001: unique constraint (SCOTT.EMPIX) violated

10

SQL*Loader sometimes called ( Oracle Bulk Loader ) Look for sqlldr.exe (DOS) or sqlldr (UNIX) program in your “BIN” directory You would need to navigate to your bin directory in the oracle home directory to launch sqlldr. the control and data files will exist in the home directory of the logged in user..

Program Operating System

sqlload Unix 8.0 sqlldr Unix 8i sqlldr73.exe Oracle Version 7.3 sqlldr80.exe Oracle Version 8.0 sqlldr.exe Oracle Version 8i & above $ORACLE_HOME/bin/sqlldr username/password@service_name control=name.ctl log=name.log data=filename.txt

(Unix) $ cd $ORACLE_HOME/bin (Unix) $ sqlldr

sqlldr control=load.ctl log=load.log bad=load.log The above thing will work if $oracle_home/bin is mentioned in the path of .profile file. You can customize the filename of your log file and error file or let sqlldr take care of it

Beware of “SQL*LoaderSQL*LoaderSQL*LoaderSQL*Loader----625: Multibyte character error in control file625: Multibyte character error in control file625: Multibyte character error in control file625: Multibyte character error in control file”

You might have pressed backspace or an unprintable character somewhere in your control file. You might want to re-type the lines using NOTEPAD, TEXTPAD or a generic editor –

Don’t use MS WORD or WORDPAD for SQL*Loader files!!!

SQL*Loader: Release 8.1.7.0.0 - Production on Thu May 2 10:07:31 2002 (c) Copyright 2000 Oracle Corporation. All rights reserved. SQL*Loader-625: Multibyte character error in control file.

11

Create a control file. This is a simple text file with the following information:

• The location of the datafile

• The table to import the data into

• How the fields are terminated

• The name and format for the columns to create The following is an example control file: Assuming your table is currently empty, you may begin by making a control file. This example can be custom-tailored to fit your needs.

LOAD DATA infile 'people.txt' INTO TABLE tablename FIELDS TERMINATED BY '|' TRAILING NULLCOLS ( first_name, last_name, age )

The last phrase tells the sqlldr which order the fields are listed in. The terminated keyword tells how the data fields are delimited; in this case the pipe character was used. The file 'people.txt' was used to contain the pipe delimited information, as shown here:

jackie|chan|48 bruce|lee|32 jet|li|39

Once your control and data files are ready, use this line to tell sqlldr which control file to run. If you're importing many records at once, it may pause briefly to report that it's reached a commit point:

UNIX:

unix% sqlldr userid=username control=controlfilename.ctl

DOS:

Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\>cd orant C:\orant>cd oracle9i C:\orant\oracle9i>cd bin C:\orant\oracle9i\bin> sqlldr userid=username control=controlfilename.ctl

12

OTHER EXAMPLES OF SQL*LOADER FEATURES

(1) Divide your amount by 100

This is helpful when you have field that are dollars with implied decimals examples: 10000 = 100.00 05623 = 56.23

LOAD DATA INFILE 'month.dat' INTO TABLE register (tx_type POSITION(1:10), acct POSITION(13:17),

amt POSITION(20:24) ":amt/100" )

(2) How to load a file but SKIP over a field you don’t want

This is a frequently asked question. How can you take a file full of delimited data and load just some of the columns, skipping over fields you don't want. You cannot use POSTION(x:y) because it is stream data, and there are no positional fields -- the next field begins after some delimiter, not in column X. Prior to Oracle8i, release 8.1, SQLLDR cannot do this without some help. In Oracle8i, release 8.1 the keyword FILLER was added to SQLLDR so that: LOAD DATA INFILE * TRUNCATE INTO TABLE T FIELDS TERMINATED BY ',' ( field1,

field2 FILLER, field3 )

BEGINDATA BEGINDATA BEGINDATA BEGINDATA a,b,c d,,g

The results from this The results from this The results from this The results from this control file that would load thcontrol file that would load thcontrol file that would load thcontrol file that would load the values a and c, skipping e values a and c, skipping e values a and c, skipping e values a and c, skipping

over b.over b.over b.over b.

13

(3) Embed the Control card with data instead of having it separate file

Loading Without a Separate Data File

It is possible to use just the control file to load data, instead of using a separate data file. Here is an exampl

We want to load the data into the following table: SQL> CREATE TABLE load_user_positional 2 (username CHAR(30), 3 data1 NUMBER, 4 data2 CHAR(15) ); The control file would look like:

LOAD DATA

INFILE * ����

INTO TABLE load_user_positional (username "USER" data1 POSITION(1:5), data2 POSITION(6:15), )

BEGINDATA ���� 11111AAAAAAAAAA 22222BBBBBBBBBB

The trick is to specify "*" as the name of the data file, and use BEGINDATA to start the data section in the control file. If we run SQL*Loader as username scott: $ SQLLDR scott/tiger load_user_d.ctl Our table data looks like: SQL> SELECT * FROM load_user_positional; USERNAME DATA1 DATA2 -------------- ---------- --------------- SCOTT 11111 AAAAAAAAAA SCOTT 22222 BBBBBBBBBB

14

(4) Loading Constants, Dates, Converting and functions

LOAD DATA INFILE '****.txt' REPLACE INTO TABLE test FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' (

LAST_NAME position(1:7) CHAR "UPPER(:LAST_NAME)", uppercase Last Name FIRST_NAME position(8:15) CHAR "LOWER(:FIRST_NAME)" lowercase First Name astrgk POSITION (37:61) CHAR "UPPER(LTRIM(RTRIM(:astrgk)))", astamm POSITION (62:71) CHAR, aadrplz POSITION (72:77) INTEGER EXTERNAL, ROW_NUMBER SEQUENCE(1,1), Sequencing starting at 1 ACTION_ID CONSTANT 10, Numeric 10 REPORT_DATE CONSTANT '20060305', Oracle will store as “05-MAR-06” filedate constant '24-JUN-02', REPORT_DATE DATE TO_DATE('20060305','YYYYMMDD') username "USER" SQLLDR scott/tiger load_user_d.ctl would store “scott” CREATED_BY CONSTANT "-1", CREATION_DATE SYSDATE, Oracle’s system date ROUTING_DAYS CONSTANT "0" literal “0” )

15

(5) Loading NULLs

Entering NULL Values You may specify NULL values simply by entering fields in your data file without content. Keep in mind that any primary keys or other constraints requiring that values be non-NULL will reject tuples for which those attributes are unspecified. Depending how you have your data delimited two delimiters in sequence means NULL is the value Example: WE HAVE 4 FIELDS/COLUMNS delimited by commas : CITY STATE ZIP CODE COUNTRY

BROOKLYN,NY,10021, - country is NULL

NEW YORK,NY,10004,USA - all fields populated BEVERLY HILLS,,90210,USA - state is NULL BEVERLY HILLS,NULL,90210,USA - state is NULL

HOLLYWOOD,CA,NULL,USA - zip code is NULL Note: for the last record the constant “NULL” was used instead of the comma for zipcode. Either one works as long a field is defined “NOT NULL”

16

Fixed-length vs. delimited files? A fixed-length file has a specified number of bytes for each column in the table. For example, if the specification

is for 50 bytes and there are only 20 bytes in the record's column, 30 blank spaces will be appended. This way Oracle knows which byte range to look at for each column.

Loading Fixed-Format Fields The control file is ulcase2.ctl. LOAD DATA INFILE 'ulcase2.dat' INTO TABLE emp (empno POSITION(01:04) INTEGER EXTERNAL, ename POSITION(06:15) CHAR, job POSITION(17:25) CHAR, mgr POSITION(27:30) INTEGER EXTERNAL, sal POSITION(32:39) DECIMAL EXTERNAL, comm POSITION(41:48) DECIMAL EXTERNAL, deptno POSITION(50:51) INTEGER EXTERNAL)

7782 CLARK MANAGER 7839 2572.50 10 7839 KING PRESIDENT 5500.00 10 7934 MILLER CLERK 7782 920.00 10 7566 JONES MANAGER 7839 3123.75 20 7499 ALLEN SALESMAN 7698 1600.00 300.00 30 7658 CHAN ANALYST 7566 3450.00 20 7654 MARTIN SALESMAN 7698 1312.50 1400.00 30

One BIG drawback is if you have to insert a new field/column or your provider changes your One BIG drawback is if you have to insert a new field/column or your provider changes your One BIG drawback is if you have to insert a new field/column or your provider changes your One BIG drawback is if you have to insert a new field/column or your provider changes your

layout you have to change everything unlike having DELIMITERSlayout you have to change everything unlike having DELIMITERSlayout you have to change everything unlike having DELIMITERSlayout you have to change everything unlike having DELIMITERS where yo where yo where yo where you simplyu simplyu simplyu simply move, add move, add move, add move, add

or delete the column or delete the column or delete the column or delete the column field!!!field!!!field!!!field!!!

Also “tab” delimiting is common but cannot be translated wellAlso “tab” delimiting is common but cannot be translated wellAlso “tab” delimiting is common but cannot be translated wellAlso “tab” delimiting is common but cannot be translated well

A delimited file has a special character (usually a tab, comma, bracket, pipe) separating each column for each

record. The character shouldn't be used within the data, so if there's a text field that might contain tabs, developers generally choose a different character as the delimiter. Non-Oracle products generally use more delimited files than fixed-length files.

LOAD DATA INFILE 'ulcase2.dat'

FIELDS TERMINATED BY '|' TRAILING NULLCOLS INTO TABLE emp (empno, ename, job, mgr, sal, comm, deptno)

7782|CLARK MANAGER|7839|2572.50||10 7839|KING PRESIDENT||5500.00||10 7934|MILLER CLERK|7782|920.00||10 7566|JONES MANAGER|7839|3123.75||20 7499|ALLEN SALESMAN|7698|1600.00|300.00|30 7658|CHAN ANALYST|7566|3450.00||20 7654|MARTIN SALESMAN|7698|1312.50|1400.00|30

17

Loading into Non-Empty Database Tables

SQL*Loader does not update existing records, even if they have null columns. If the tables you are loading already contain data, you have three choices for how SQL*Loader should proceed: INSERT - This is the default option. It requires the table to be empty before loading. SQL*Loader terminates with an error if the table contains rows. APPEND - If data already exists in the table, SQL*Loader appends the new rows to it; if data doesn't already exist, the new rows are simply loaded. REPLACE - All rows in the table are deleted and the new data is loaded. This option requires DELETE privileges on the table. You can create one logical record from multiple physical records using CONCATENATE and CONTINUEIF.

Loading Logical Records into Tables The INTO TABLE clause allows you to tell which table you want to load data into. To load multiple tables, you would include one INTO TABLE clause for each table you wish to load. The INTO TABLE clause may continue with some options for loading that table. For example, you may specify different options (INSERT, APPEND, REPLACE) for each table in order to tell SQL*Loader what to do if data already exists in the table. The WHEN clause appears after the table name, and is followed by one or more field conditions. For example, the following clause indicates that any record with the value ``q'' in the fifth column position should be loaded: WHEN (5) = 'q'

18

STEP BY STEP EXAMPLE:STEP BY STEP EXAMPLE:STEP BY STEP EXAMPLE:STEP BY STEP EXAMPLE: SQL> DESC JOBXREF_UTS Name Null? Type ------------------------------- -------- ---- JOBNO VARCHAR2(5) REIMB VARCHAR2(1) STATUS VARCHAR2(1) DESCR VARCHAR2(50)

In: C:\orant\oracle9i\bin

jobcode_uts.ctl LOAD DATA

infile 'c:c:c:c:\\\\jobjobjobjob_uts.txt_uts.txt_uts.txt_uts.txt' replace INTO TABLE jobxref_uts FIELDS TERMINATED BY '|' ( jobno, reimb, status, descr )

c:\job_uts.txt

00000|N|A|FLAGGING DIVERSIONS COST NOT ACCEPTABLE IN TIMEKEE 00001|N|A|TEST FOR CITY HALL ACCIDENT ON 8/22/95 00002|N|A|UMTA PROJ GRANT # 17-06-0102 SPONSOR'S CONT #TSC- 00010|N|A|TAMPING-ALL LINES-ALL TRACKS 00018|N|A|COSTS INCURRED FOR TRACTION GEL PLUS ANDELECTRAS G 00027|N|A|COSTS ASSOC W/HOURLY/ANNUAL TIMEKEEPING 00031|N|A|INFRASTRUCTURE MATERIAL ACQUISITION 00039|N|A|PARSONS/BRINKERHOFF CONSULTANT STUDY FORSIGNAL MOD 00076|N|A|NORMAL REPLACEMENT (TA POLICY FOR PC PRINTER 00077|N|A|DP SUPPLIES (SOFTWARE MEMORY DISKETTES ETC) DEPT 00078|N|A|COSTS ASSOC WITH IN-BETWEEN STATION CLEANING 00092|N|A|CRANE INSPECTIONS 00093|N|A|MTCE&REPAIR OF 1 TON CRANES 00094|N|A|MTCE&REPAIR OF 3 TON CRANES 00095|N|A|MTCE&REPAIR OF 10 TON CRANES 00096|N|A|MTCE&REPAIR OF TAMPERS 00097|N|A|MTCE REPAIR OF BALLAST REGULATORS

19

In DOS shell or Unix shell:In DOS shell or Unix shell:In DOS shell or Unix shell:In DOS shell or Unix shell:

Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp.

C:\>CD orantCD orantCD orantCD orant\\\\oracleoracleoracleoracle9i9i9i9i\\\\binbinbinbin

C:\orant\oracle9i\bin>SQLLDR APPS/APPS@ARGP JOBCODE_UTSSQLLDR APPS/APPS@ARGP JOBCODE_UTSSQLLDR APPS/APPS@ARGP JOBCODE_UTSSQLLDR APPS/APPS@ARGP JOBCODE_UTS SQL*Loader: Release 9.2.0.1.0 - Production on Fri Jan 19 17:14:28 2007 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Commit point reached - logical record count 64 Commit point reached - logical record count 128 Commit point reached - logical record count 192 Commit point reached - logical record count 256 Commit point reached - logical record count 320 Commit point reached - logical record count 384 Commit point reached - logical record count 448 Commit point reached - logical record count 512 Commit point reached - logical record count 576 Commit point reached - logical record count 640 Commit point reached - logical record count 704 Commit point reached - logical record count 768 Commit point reached - logical record count 832 Commit point reached - logical record count 896 Commit point reached - logical record count 960 Commit point reached - logical record count 1024 Commit point reached - logical record count 1088 Commit point reached - logical record count 1152 Commit point reached - logical record count 1216 Commit point reached - logical record count 1280 Commit point reached - logical record count 1344 Commit point reached - logical record count 1408 Commit point reached - logical record count 1472 Commit point reached - logical record count 1536 Commit point reached - logical record count 1600 Commit point reached - logical record count 1664 Commit point reached - logical record count 1728 Commit point reached - logical record count 1792 Commit point reached - logical record count 1856 Commit point reached - logical record count 1920 Commit point reached - logical record count 1984 Commit point reached - logical record count 2048 Commit point reached - logical record count 2112 Commit point reached - logical record count 2176 Commit point reached - logical record count 2240 Commit point reached - logical record count 2304 Commit point reached - logical record count 2368 Commit point reached - logical record count 2432 Commit point reached - logical record count 2496 Commit point reached - logical record count 2560 Commit point reached - logical record count 2624 Commit point reached - logical record count 2688 Commit point reached - logical record count 2752 Commit point reached - logical record count 2816 Commit point reached - logical record count 2880 Commit point reached - logical record count 2944 Commit point reached - logical record count 3008 Commit point reached - logical record count 3072 Commit point reached - logical record count 3136 Commit point reached - logical record count 3200 Commit point reached - logical record count 3235 C:\orant\oracle9i\bin>

20

In: C:\orant\oracle9i\bin

jobcode_uts.log is automatically generated unless you give it a different filename

SQL*Loader: Release 9.2.0.1.0 - Production on Fri Jan 19 17:14:28 2007 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Control File: JOBCODE_UTS.ctl Data File: c:\job_uts.txt Bad File: job_uts.bad Discard File: none specified (Allow all discards) Number to load: ALL Number to skip: 0 Errors allowed: 50 Bind array: 64 rows, maximum of 256000 bytes Continuation: none specified Path used: Conventional Table JOBXREF_UTS, loaded from every logical record. Insert option in effect for this table: REPLACE Column Name Position Len Term Encl Datatype ------------------------------ ---------- ----- ---- ---- --------------------- JOBNO FIRST * | CHARACTER REIMB NEXT * | CHARACTER STATUS NEXT * | CHARACTER DESCR NEXT * | CHARACTER Table JOBXREF_UTS: 3235 Rows successfully loaded. 0 Rows not loaded due to data errors. 0 Rows not loaded because all WHEN clauses were failed. 0 Rows not loaded because all fields were null. Space allocated for bind array: 66048 bytes(64 rows) Read buffer bytes: 1048576 Total logical records skipped: 0 Total logical records read: 3235 Total logical records rejected: 0 Total logical records discarded: 0 Run began on Fri Jan 19 17:14:28 2007 Run ended on Fri Jan 19 17:14:30 2007 Elapsed time was: 00:00:01.92 CPU time was: 00:00:00.08

21

BELOW IS AN EXAMPLE OF HOW TO SCRIPT AND AUTOMATE

THE LOAD PROCESS

[ RUN THIS SCRIPT IN A DOS SHELL ] uts_comspec.bat ECHO. RE LOAD UTS JOBCODE TABLE ON ARGP ECHO. RE LOAD UTS JOBCODE TABLE ON ARGP ECHO. RE LOAD UTS JOBCODE TABLE ON ARGP echo. - echo. - echo. - c:\uts_comspec.bat echo. - echo. - IGNORE ALL MESSAGES UNLESS THE PROCESS echo. - UNEXPECTEDLY SHOULD STOP PROCESSING echo. - echo. - echo. P R O C E S S S T A R T I N G %comspec% /c load_uts > argp_UTS_JOBCODE.txt echo. - echo. - echo. P R O C E S S C O M P L E T E D echo. - echo. - echo press ENTER to close this window echo. - echo. - pause exit

load_uts.bat echo. echo. UTS Jobocodes LOAD into table jobxref_uts echo. ECHO. DELETING C:\UTS_JOBCODES.TXT echo. del /f c:\uts_jobcodes.txt echo. file is deleted echo. ECHO. starting FTP from security to APPS ftp -s:C:\FTP_commands_uts.txt ECHO. FTP completed echo. echo. starting SQL Loader load cd \ echo. CD orant\oracle9i\bin\ echo. CD orant\oracle9i\bin\ sqlldr apps/apps@argp jobcode_uts cd \ echo. echo. UTS Jobocodes LOAD completed

ftp_commands_uts.txt

open 10.8.37.44 <ACCOUNT> <PASSWORD> pwd dir get job_uts.txt c:\uts_jobcodes.txt pwd quit

jobcode_uts.CTL

LOAD DATA infile 'c:\job_uts.txt' replace INTO TABLE jobxref_uts FIELDS TERMINATED BY '|' ( jobno, reimb, status, descr )

22

C:\ argp_UTS_JOBCODE.txt

C:\>echo. C:\>echo. UTS Jobocodes LOAD into table jobxref_uts UTS Jobocodes LOAD into table jobxref_uts C:\>echo. C:\>ECHO. DELETING C:\UTS_JOBCODES.TXT DELETING C:\UTS_JOBCODES.TXT C:\>echo. C:\>del /f c:\uts_jobcodes.txt C:\>echo. file is deleted file is deleted C:\>echo. C:\>ECHO. starting FTP from security to APPS starting FTP from security to APPS C:\>ftp -s:C:\FTP_commands_uts.txt ftp> Connected to 10.8.37.44. open 10.8.37.44 220-FTP server ready. 220 This is a private system - No anonymous login User (10.8.37.44:(none)): 331 User pcprodar OK. Password required 230-User pcprodar has group access to: finance nyct 230 OK. Current restricted directory is / ftp> Invalid command. ftp> pwd 257 "/" is your current location ftp> dir 200 PORT command successful 150 Connecting to port 3118 -rw-r--r-- 1 pcprodar nyct 197579 Jan 16 09:55 job_uts.txt -rw-r--r-- 1 pcprodar nyct 332820 Jan 15 23:01 jobdesc.txt -rw-r--r-- 1 pcprodar nyct 22713 Dec 27 16:26 jspread.txt -rw-r--r-- 1 pcprodar nyct 159689 Dec 27 16:27 summary.txt -rw-r--r-- 1 pcprodar nyct 8320444 Dec 27 16:27 sysout.txt -rw-r--r-- 1 pcprodar nyct 87966 Jan 15 23:01 xrc.txt 226-Options: -l 226 21 matches total ftp: 1496 bytes received in 0.00Seconds 1496000.00Kbytes/sec. ftp> get job_uts.txt c:\uts_jobcodes.txt 200 PORT command successful 150-Connecting to port 3119 150 192.9 kbytes to download 226-File successfully transferred 226 0.171 seconds (measured here), 1.10 Mbytes per second ftp: 200818 bytes received in 0.20Seconds 989.25Kbytes/sec. ftp> pwd 257 "/" is your current location ftp> quit 221-Goodbye. You uploaded 0 and downloaded 193 kbytes. 221 Logout - CPU time spent: 0.000 seconds. C:\>ECHO. FTP completed FTP completed C:\>echo. C:\>echo. starting SQL Loader load starting SQL Loader load C:\>cd \ C:\>echo. CD orant\oracle9i\bin\ CD orant\oracle9i\bin\ C:\>echo. C:\>CD orant\oracle9i\bin\

23

C:\orant\oracle9i\bin>sqlldr apps/apps@argp jobcode_uts SQL*Loader: Release 9.2.0.1.0 - Production on Tue Jan 16 17:17:25 2007 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Commit point reached - logical record count 64 Commit point reached - logical record count 128 Commit point reached - logical record count 192 Commit point reached - logical record count 256 Commit point reached - logical record count 320 Commit point reached - logical record count 384 Commit point reached - logical record count 448 Commit point reached - logical record count 512 Commit point reached - logical record count 576 Commit point reached - logical record count 640 Commit point reached - logical record count 704 Commit point reached - logical record count 768 Commit point reached - logical record count 832 Commit point reached - logical record count 896 Commit point reached - logical record count 960 Commit point reached - logical record count 1024 Commit point reached - logical record count 1088 Commit point reached - logical record count 1152 Commit point reached - logical record count 1216 Commit point reached - logical record count 1280 Commit point reached - logical record count 1344 Commit point reached - logical record count 1408 Commit point reached - logical record count 1472 Commit point reached - logical record count 1536 Commit point reached - logical record count 1600 Commit point reached - logical record count 1664 Commit point reached - logical record count 1728 Commit point reached - logical record count 1792 Commit point reached - logical record count 1856 Commit point reached - logical record count 1920 Commit point reached - logical record count 1984 Commit point reached - logical record count 2048 Commit point reached - logical record count 2112 Commit point reached - logical record count 2176 Commit point reached - logical record count 2240 Commit point reached - logical record count 2304 Commit point reached - logical record count 2368 Commit point reached - logical record count 2432 Commit point reached - logical record count 2496 Commit point reached - logical record count 2560 Commit point reached - logical record count 2624 Commit point reached - logical record count 2688 Commit point reached - logical record count 2752 Commit point reached - logical record count 2816 Commit point reached - logical record count 2880 Commit point reached - logical record count 2944 Commit point reached - logical record count 3008 Commit point reached - logical record count 3072 Commit point reached - logical record count 3136 Commit point reached - logical record count 3200 Commit point reached - logical record count 3235 C:\orant\oracle9i\bin>cd \ C:\>echo. C:\>echo. UTS Jobocodes LOAD completed UTS Jobocodes LOAD completed

24

BELOW IS AN EXAMPLE OF HOW TO SCRIPT AND AUTOMATE

THE LOAD PROCESS

C:\ argp_UTS_JOBCODE.txt

C:\>echo. C:\>echo. UTS Jobocodes LOAD into table jobxref_uts UTS Jobocodes LOAD into table jobxref_uts C:\>echo. C:\>ECHO. DELETING C:\UTS_JOBCODES.TXT DELETING C:\UTS_JOBCODES.TXT C:\>echo. C:\>del /f c:\uts_jobcodes.txt C:\>echo. file is deleted file is deleted C:\>echo. C:\>ECHO. starting FTP from security to APPS starting FTP from security to APPS C:\>ftp -s:C:\FTP_commands_uts.txt ftp> Connected to 10.8.37.44. open 10.8.37.44 220-FTP server ready. 220 This is a private system - No anonymous login User (10.8.37.44:(none)): 331 User pcprodar OK. Password required 230-User pcprodar has group access to: finance nyct 230 OK. Current restricted directory is / ftp> Invalid command. ftp> pwd 257 "/" is your current location ftp> dir 200 PORT command successful 150 Connecting to port 3118 -rw-r--r-- 1 pcprodar nyct 197579 Jan 16 09:55 job_uts.txt -rw-r--r-- 1 pcprodar nyct 332820 Jan 15 23:01 jobdesc.txt -rw-r--r-- 1 pcprodar nyct 22713 Dec 27 16:26 jspread.txt -rw-r--r-- 1 pcprodar nyct 159689 Dec 27 16:27 summary.txt -rw-r--r-- 1 pcprodar nyct 8320444 Dec 27 16:27 sysout.txt -rw-r--r-- 1 pcprodar nyct 87966 Jan 15 23:01 xrc.txt 226-Options: -l 226 21 matches total ftp: 1496 bytes received in 0.00Seconds 1496000.00Kbytes/sec. ftp> get job_uts.txt c:\uts_jobcodes.txt 200 PORT command successful 150-Connecting to port 3119 150 192.9 kbytes to download 226-File successfully transferred 226 0.171 seconds (measured here), 1.10 Mbytes per second ftp: 200818 bytes received in 0.20Seconds 989.25Kbytes/sec. ftp> pwd 257 "/" is your current location ftp> quit 221-Goodbye. You uploaded 0 and downloaded 193 kbytes. 221 Logout - CPU time spent: 0.000 seconds. C:\>ECHO. FTP completed FTP completed C:\>echo. C:\>echo. starting SQL Loader load starting SQL Loader load C:\>cd \ C:\>echo. CD orant\oracle9i\bin\

25

CD orant\oracle9i\bin\ C:\>echo. C:\>CD orant\oracle9i\bin\ C:\orant\oracle9i\bin>sqlldr apps/apps@argp jobcode_uts SQL*Loader: Release 9.2.0.1.0 - Production on Tue Jan 16 17:17:25 2007 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Commit point reached - logical record count 64 Commit point reached - logical record count 128 Commit point reached - logical record count 192 Commit point reached - logical record count 256 Commit point reached - logical record count 320 Commit point reached - logical record count 384 Commit point reached - logical record count 448 Commit point reached - logical record count 512 Commit point reached - logical record count 576 Commit point reached - logical record count 640 Commit point reached - logical record count 704 Commit point reached - logical record count 768 Commit point reached - logical record count 832 Commit point reached - logical record count 896 Commit point reached - logical record count 960 Commit point reached - logical record count 1024 Commit point reached - logical record count 1088 Commit point reached - logical record count 1152 Commit point reached - logical record count 1216 Commit point reached - logical record count 1280 Commit point reached - logical record count 1344 Commit point reached - logical record count 1408 Commit point reached - logical record count 1472 Commit point reached - logical record count 1536 Commit point reached - logical record count 1600 Commit point reached - logical record count 1664 Commit point reached - logical record count 1728 Commit point reached - logical record count 1792 Commit point reached - logical record count 1856 Commit point reached - logical record count 1920 Commit point reached - logical record count 1984 Commit point reached - logical record count 2048 Commit point reached - logical record count 2112 Commit point reached - logical record count 2176 Commit point reached - logical record count 2240 Commit point reached - logical record count 2304 Commit point reached - logical record count 2368 Commit point reached - logical record count 2432 Commit point reached - logical record count 2496 Commit point reached - logical record count 2560 Commit point reached - logical record count 2624 Commit point reached - logical record count 2688 Commit point reached - logical record count 2752 Commit point reached - logical record count 2816 Commit point reached - logical record count 2880 Commit point reached - logical record count 2944 Commit point reached - logical record count 3008 Commit point reached - logical record count 3072 Commit point reached - logical record count 3136 Commit point reached - logical record count 3200 Commit point reached - logical record count 3235 C:\orant\oracle9i\bin>cd \ C:\>echo. C:\>echo. UTS Jobocodes LOAD completed UTS Jobocodes LOAD completed

26

Assorted SQL*Loader links and references

FAQ’s

http://www.orafaq.com/faq/sql_loader Oracle FAQ’s SQL*Loader & A comparative analysis between SQL*LOADER and UTL_FILE utility http://orafaq.com/papers/sqlload.doc Oracle SQL*Loader FAQ http://orafaq.com/faqloadr.htm SOLUTIONS TO COMMON SQL*LOADER QUESTIONS http://www.fors.com/orasupp/rdbms/utils/140121_1.HTM

Oracle SQL*Loader The Definitive Guide (O’Reilly BOOK)

http://www.oreilly.com/catalog/orsqlloader/chapter/ch01.html Oracle SQL*Loader The Definitive Guide (BOOK) http://ftp.ora.com/orsqlloader/ Oracle SQL*Loader: The Definitive Guide Examples (ZIP file) http://www.oreilly.com/catalog/orsqlloader/chapter/ch01.html Chapter 1 Introduction to SQL*Loader

References

http://www.csee.umbc.edu/help/oracle8/server.815/a67792/ch06.htm SQL*Loader Command-Line Reference http://www.csee.umbc.edu/help/oracle8/server.815/a67792/ch05.htm SQL*Loader Control File Reference http://www.csee.umbc.edu/help/oracle8/server.815/a67792/ch04.htm SQL*Loader Case Studies & Examples http://docs.linux.cz/databases/Oracle8/server/a58244/apa.htm SQL Loader Reserved Words http://www.psoug.org/reference/sqlloader.html SQL Loader Version 10.2 http://infolab.stanford.edu/~ullman/fcdb/oracle/or-load.html Using the Oracle Bulk Loader http://www.oracleutilities.com/OSUtil/sqlldr.html

Loading large datasets into oracle 8i tables from unix & windows http://www.cdpr.ca.gov/docs/empm/pubs/sops/data002.00.pdf http://www.dba-oracle.com/t_optimize_sql_loader_sqlldr_performance.htm

Replacing 3GL Data Loading with SQL*Loader and Database Triggers http://www.rumken.com/ioug2000/Paper421.htm

Only UNIX: Oracle » UNIX » Commands » SQL Loader www.rocket99.com/techref/oracle8317.html SQL*Loader Control File Reference (UNIX) http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96652/ch04.htm Unix examples http://www.princeton.edu/~storacle/sqlloader_demo.shtml Oracle Tips http://www.akadia.com/services/ora_important_part_2.html Automating SQL*LDR http://www.oracledbaexpert.com/oracle/oracleSQLLDRAutomation.html

27

NOTES & QUESTIONSNOTES & QUESTIONSNOTES & QUESTIONSNOTES & QUESTIONS By George Lewycky TIS-Financial 646 252 8882 [email protected] Friday, February 02, 2007 Oracle Tips_Pausche 7.1.doc Monday, February 12, 2007 Oracle Tips_Pausche 8.0doc.doc