How to update a column using control file in oracle? - oracle

I want to update a column in a table if it satisfies a condition. This should happen while loading the data into the table using sqlldr. Below is the control file i have written for this. I am facing some issue while executing this through sqlldr.
options (SKIP=1,bindsize=1048576, rows=500, errors=100)
LOAD DATA
INFILE '/home/x069291/appln/ncisdr/inbound/ExternalUserMasterNCI.TXT'
APPEND
INTO TABLE OMS_DP_EXTERNAL_USERS
FIELDS TERMINATED BY ";"
trailing nullcols
(STATUS,
USER_NAME,
FIRST_NAME,
MIDDLE_NAME,
LAST_NAME,
CMPNY_NM,
EMAIL,
MAILING_ADDRESS,
CITY,
STATE_PROVINCE,
ZIP_POSTALCODE,
COUNTRY,
PRIMARY_PHONE_NUMBER,
FAX_NUMBER,
BH_AFFILIATE,
USER_TYPE "CASE when USER_TYPE='NCIF' THEN 'G' ELSE USER_TYPE END'",
DPRTMT_NM,
TITLE,
CREATED_DATE "to_timestamp(:created_date,'YYYY-MM-DD HH24:MI:SS.FF')",
MODIFIED_DATE "to_timestamp(:modified_date,'YYYY-MM-DD HH24:MI:SS.FF')"
)
Below is the data in the file
STATUS;USER_ID;FIRST_NAME;MIDDLE_NAME;LAST_NAME;COMPANY;EMAIL;MAILING_ADDRESS;CITY;STATE_PROVINCE;ZIP_POSTALCODE;COUNTRY;PHONE;FAX;AFFLIATE;USER_TYPE;Code;Fleet_Account_Type;CREATED_DT;UPDATED_DT
Active;XD429895;DPTesttt;M;Fleet;Hertz;;1 Nissan way;Franklin;TN ;37067;CA;231-231-2312;;NCI;NCIF;R01_FTP02;E01010101;24-APR-17 03.27.52.542000 PM;24-APR-17 03.27.52.542000 PM
Active;XD961792;DPTesttttt;M;NCIfleet;Enterprise;;1 Nissan way;Franklin;TN ;37067;CA;123-123-1231;;NCI;NCIF;E01_12102;R01010101;24-APR-17 03.28.58.337000 PM;24-APR-17 03.28.58.337000 PM
Below is the table structure i am using for this.
Name Null Type
Name Null Type
-------------------------- ---- ------------------
STATUS VARCHAR2(10 CHAR)
USER_NAME VARCHAR2(60 CHAR)
FIRST_NAME VARCHAR2(60 CHAR)
MIDDLE_NAME VARCHAR2(60 CHAR)
LAST_NAME VARCHAR2(60 CHAR)
POSITION CHAR(3 CHAR)
TITLE VARCHAR2(60 CHAR)
DEALER_EMPLOYEE_NUMBER VARCHAR2(60 CHAR)
HIRE_DATE DATE
DATE_OF_BIRTH DATE
LMS_PERSON_ID VARCHAR2(60 CHAR)
EID VARCHAR2(60 CHAR)
LANGUAGE VARCHAR2(50 CHAR)
DOCUMENT_SENSITIVITY_LEVEL VARCHAR2(50 CHAR)
EMAIL VARCHAR2(120 CHAR)
EMAIL2 VARCHAR2(120 CHAR)
EMAIL3 VARCHAR2(120 CHAR)
PRIMARY_PHONE_NUMBER VARCHAR2(50 CHAR)
ALTERNATE_PHONE_NUMBER VARCHAR2(50 CHAR)
FAX_NUMBER VARCHAR2(50 CHAR)
MAILING_ADDRESS VARCHAR2(100 CHAR)
CITY VARCHAR2(50 CHAR)
STATE_PROVINCE VARCHAR2(15 CHAR)
ZIP_POSTALCODE CHAR(20 CHAR)
COUNTRY VARCHAR2(50 CHAR)
APPLICATION_ROLE VARCHAR2(120 CHAR)
FUNCTIONAL_ROLE VARCHAR2(50 CHAR)
PARTSNET_REGISTRATION VARCHAR2(50 CHAR)
DEALER_NUMBER VARCHAR2(20 CHAR)
DEALER_NAME VARCHAR2(50 CHAR)
BH_AFFILIATE VARCHAR2(50 CHAR)
BH_CHANNEL_CODE VARCHAR2(25 CHAR)
BH_DIVISION_NAME VARCHAR2(50 CHAR)
SALES_REGION_CODE CHAR(3 CHAR)
SALES_REGION_NAME VARCHAR2(50 CHAR)
SALES_DISTRICT_CODE CHAR(3 CHAR)
SALES_DISTRICT_NAME VARCHAR2(50 CHAR)
USER_TYPE CHAR(3 CHAR)
CREATED_DATE TIMESTAMP(6)
MODIFIED_DATE TIMESTAMP(6)
CMPNY_NM VARCHAR2(50 CHAR)
DPRTMT_NM VARCHAR2(50 CHAR)
and i am previously facing the error ORA-00984: column not allowed here
After including Boeinst changes i got the error
SQL*Loader-350: Syntax error at line 23.
Expecting "," or ")", found "USER_TYPE".
USER_TYPE USER_TYPE "DECODE(:user_type, 'NCIF', 'G', :user_type)",

You have an extra single quote in there after the END as well as not using bind variables:
USER_TYPE "CASE when USER_TYPE='NCIF' THEN 'G' ELSE USER_TYPE END'",
Change to this:
USER_TYPE "CASE when :USER_TYPE='NCIF' THEN 'G' ELSE :USER_TYPE END",

Related

Oracle ORA-04063: table "TABLE" has errors

I Create a table with UDT type as a column , after some time i needed one more column to add the type, i altered the type using
alter type type_cust_instatus add attribute (sub_status_to varchar2(20)) invalidate
alter type type_cust_instatus compile
After that the table becomes invalid and tried to make the column unused and dropped the the type also and recreaded once again as per before modification.
now in the table defination there is no type fro the column and showing as blank
how to delete the column or recompile
CREATE TABLE KAMSIT.CUSTOMER_TRANSACTION_DATA
(
MSISDN VARCHAR2(13 BYTE),
IMSI VARCHAR2(15 BYTE),
CONNECTION_TYPE NUMBER,
MSTYPE VARCHAR2(6 BYTE),
SUBSCR_NO VARCHAR2(10 BYTE),
ACCOUNT_NO VARCHAR2(10 BYTE),
ALUIN_ACTIVE_DATE DATE,
FIRST_CALL_MADE_TIME DATE,
ACTIVE_DATE DATE,
INACTIVE_DATE DATE,
BILLING_IMSI VARCHAR2(15 BYTE),
CURRENT_STATUS VARCHAR2(1 BYTE) DEFAULT 'C',
ALUIN_IMSI VARCHAR2(15 BYTE),
ALUIN_SUB_STATUS VARCHAR2(50 BYTE),
INSERT_DATE DATE DEFAULT sysdate,
TRANSACTION_TYPE KAMSIT.CUSTOMER_TRANSACTION_TYPE,
TRANSACTION_IMSI KAMSIT.CUST_IMSI_CHANGE,
ALUIN_STATUS VARCHAR2(1 BYTE) DEFAULT 'C',
IMEI VARCHAR2(20 BYTE),
TRANSACTION_INSTATUS
)
NESTED TABLE TRANSACTION_TYPE STORE AS TBL_CUSTOMER_TRANSACTIONS,
NESTED TABLE TRANSACTION_IMSI STORE AS TBL_TRANSACTION_IMSI
how to drop the column or set unused or rebuild the table

Get error ORA-01722: invalid number while test function

I am a little bit confuse in this problem and I have no idea what's wrong here.
I have function like this
FUNCTION GET_ARTICLES_ADDIOTION_WORK(p_ataID IN INT)
RETURN SYS_REFCURSOR IS
rc SYS_REFCURSOR;
/*getArticlesAdditionalWork*/
BEGIN
OPEN rc FOR
SELECT
aa.ID,
aa.Name,
aa.Quantity,
aa.Unit,
aa.Price,
aa.Deduct,
aa.Account,
aa.Created
FROM
ata_articles aa
LEFT JOIN
weekly_report wr
ON
aa.wrId = wr.id
WHERE
aa.AtaId = p_ataID
AND
aa.type = 1
AND
(aa.wrId = 0 OR (wr.status = 2 OR wr.status = 5))
ORDER BY Name;
RETURN rc;
END GET_ARTICLES_ADDIOTION_WORK;
Somehow, when I want to test does this function work fine I following statment
SELECT ATA_PACKAGE.GET_ARTICLES_ADDIOTION_WORK(2014) from dual
I get error
ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.
While I also try to run query without function also same error occure.
SELECT
aa.ID,
aa.Name,
aa.Quantity,
aa.Unit,
aa.Price,
aa.Deduct,
aa.Account,
aa.Created
FROM
ata_articles aa
LEFT JOIN
weekly_report wr
ON
aa.wrId = wr.id
WHERE
aa.AtaId = 2116
AND
aa.type = 1
AND
(aa.wrId = 0 OR (wr.status = 2 OR wr.status = 5))
ORDER BY Name;
So far I check in table and ataId is NUMBER, it's not string. I have no idea what is wrong here ?
What couse this problem ? What I miss ? Where the error comes from ?
Ata_Article Table Definition
ACCOUNT VARCHAR2(255 CHAR)
ARTICLEPAYMENTTYPE NUMBER(10,0)
ATAID NUMBER(10,0)
CLIENTCOMMENT VARCHAR2(255 CHAR)
CLIENTEMAIL VARCHAR2(255 CHAR)
CLIENTFINALSTATUS NUMBER(10,0)
CLIENTSTATUS NUMBER(10,0)
CREATED DATE
DEDUCT NUMBER(10,0)
EXTERNAL NUMBER(10,0)
ID NUMBER(10,0)
NAME VARCHAR2(255 CHAR)
PRICE FLOAT
PROJECTID NUMBER(10,0)
QUANTITY VARCHAR2(255 CHAR)
SUPPLIERINVOICEID NUMBER(10,0)
TABLETYPE VARCHAR2(50 CHAR)
TOTAL FLOAT
TYPE VARCHAR2(4000 CHAR)
UNIT VARCHAR2(255 CHAR)
WRID NUMBER(10,0)
Weekly_Report Table Definition
ANSWERDATE DATE
ANSWEREMAIL VARCHAR2(50 CHAR)
ANSWERIP VARCHAR2(50 CHAR)
ATAID NUMBER(10,0)
COMMENT_ VARCHAR2(2000 CHAR)
CREATED DATE
DUEDATE DATE
EXTERNAL NUMBER(10,0)
FINANCEID NUMBER(10,0)
ID NUMBER(10,0)
NAME VARCHAR2(45 CHAR)
PARENT NUMBER(10,0)
PDF_URL VARCHAR2(255 CHAR)
PROJECTID NUMBER(10,0)
SEEN DATE
STATUS NUMBER(10,0)
TOKEN VARCHAR2(50 CHAR)
WEEK NUMBER(10,0)
YEAR NUMBER(10,0)
So after a sort discussion we figurated out that the column aa.type has been defined as varchar2 and is being compared to a number. That was the root cause

Why I get error Invalid identifier since column exist

I have SELECT statment like this
SELECT a.ATAID,
a.ataComment,
a.Type,
a.AtaNumber,
a.DeviationNumber,
a.ProjectID,
a.Name,
a.StartDate,
a.DueDate,
a.RevisionDate,
a.Status,
a.Ata,
a.Deviation,
a.Locked,
a.PaymentType,
a.BecomeExternalAtaFromInternal,
a.Author,
a.AtaType,
a.DeviationType,
a.PDFUrl,
a.street,
a.city,
a.zip,
a.briefDescription,
a.ConfirmStatus,
a.Token,
a.ParentAta,
a.EmailSent,
a.ClientComment,
a.AnswerEmail,
a.AnswerTime,
a.UserID,
a.FromFortnox,
a.ForFortnox,
a.client_answer_attachment,
debitform.Name as paymentTypeName,
CONCAT(CONCAT(users.Surname, ' '),users.Lastname) AS AuthorName,
NULL AS Description,
NULL AS Reason,
NULL AS Suggestion,
NULL AS State,
'ata' as AtaTable ,
NULL AS WeeklyReports,
NULL AS Attachment,
NULL AS articlesAdditionalWorkFromia,
NULL AS enabledAccounts,
NULL AS DefaultWeeklyReports,
NULL AS articlesMaterialFromia,
NULL AS articlesOtherFromia,
NULL AS WeeklyReportsMomentsPerWeek,
a.becomeFastFromOtherType,
ia.ataComment,
ia.Type,
ia.AtaNumber,
ia.DeviationNumber,
ia.ProjectID,
ia.Name,
ia.StartDate,
ia.DueDate,
ia.RevisionDate,
ia.Status,
ia.Ata,
ia.Deviation,
ia.Locked,
ia.PaymentType,
ia.BecomeExternalAtaFromInternal,
ia.Author,
ia.AtaType,
ia.DeviationType,
ia.PDFUrl,
ia.street,
ia.city,
ia.zip,
ia.briefDescription,
ia.ConfirmStatus,
ia.Token,
ia.ParentAta,
ia.EmailSent,
ia.ClientComment,
ia.AnswerEmail,
ia.AnswerTime,
ia.UserID,
ia.FromFortnox,
ia.ForFortnox,
ia.client_answer_attachment,
debitform.Name as paymentTypeName,
CONCAT(CONCAT(users.Surname, ' '),users.Lastname) AS AuthorName,
ia.Description,
ia.Reason,
ia.Suggestion,
ia.State,
'ata_become_external' as AtaTable,
ia.WeeklyReports,
ia.Documents AS Attachment,
ia.articlesAdditionalWork AS articlesAdditionalWorkFromia,
ia.enabledAccounts,
ia.DefaultWeeklyReports,
ia.articlesMaterial AS articlesMaterialFromia,
ia.articlesOther AS articlesOtherFromia,
ia.WeeklyReportsMomentsPerWeek,
NULL AS becomeFastFromOtherType
FROM
ata a
LEFT JOIN
users
INNER JOIN internal_atas ia
ON (a.ATAID = ia.ATAID AND a.Author = users.UserID)
LEFT JOIN
debitform
ON
debitform.Id = a.PaymentType
WHERE
a.ATAID = 2095
OR ia.ATAID IS NULL
OR
a.ParentAta = 0 OR ia.ParentAta = 0
GROUP BY a.ATAID
The ATAID is column which exist in table ata
a.ATAID
2117
2118
2119
2120
2121
2122
2123
Also AtaID from another table which is called internal_atas
ATAID
no rows selected
When I run query I get error message
ORA-00904: "A"."ATAID": invalid identifier
This line of code throw error
ON a.ATAID = ia.ATAID
I try to change this two part and make inversion like
ON ia.ATAID = a.ATAID
But still have same problem.
What is wrong here ? What I miss ?
Table Definition:
internal_atas
ANSWEREMAIL VARCHAR2(255 CHAR)
ANSWERTIME TIMESTAMP(6)
ARTICLESADDITIONALWORK CLOB
ARTICLESMATERIAL CLOB
ARTICLESOTHER CLOB
ATA NUMBER(10,0)
ATABECOMEEXTERNALID NUMBER(10,0)
ATACOMMENT CLOB
ATAID NUMBER(10,0)
ATANUMBER NUMBER(10,0)
ATATYPE VARCHAR2(255 CHAR)
AUTHOR VARCHAR2(255 CHAR)
BECOMEEXTERNALATAFROMINTERNAL NUMBER(10,0)
BRIEFDESCRIPTION CLOB
CITY VARCHAR2(255 CHAR)
CLIENT_ANSWER_ATTACHMENT VARCHAR2(255 CHAR)
CLIENTCOMMENT VARCHAR2(255 CHAR)
CONFIRMSTATUS NUMBER(10,0)
DEFAULTWEEKLYREPORTS CLOB
DESCRIPTION CLOB
DEVIATION NUMBER(10,0)
DEVIATIONNUMBER VARCHAR2(255 CHAR)
DEVIATIONTYPE VARCHAR2(255 CHAR)
DOCUMENTS CLOB
DUEDATE DATE
EMAILSENT NUMBER(10,0)
ENABLEDACCOUNTS CLOB
EXTERNALATANUMBER VARCHAR2(50 CHAR)
FORFORTNOX NUMBER(10,0)
FROMFORTNOX NUMBER(10,0)
INTERNALATANUMBER VARCHAR2(50 CHAR)
IS_DELETED NUMBER(10,0)
LOCKED NUMBER(10,0)
NAME VARCHAR2(255 CHAR)
PARENTATA NUMBER(10,0)
PAYMENTTYPE VARCHAR2(255 CHAR)
PDFURL CLOB
PROJECTID NUMBER(10,0)
QUANTITY VARCHAR2(255 CHAR)
REASON VARCHAR2(255 CHAR)
REVISIONDATE VARCHAR2(50 CHAR)
STARTDATE DATE
STATE CLOB
STATUS NUMBER(10,0)
STREET VARCHAR2(255 CHAR)
SUGGESTION VARCHAR2(255 CHAR)
TOKEN VARCHAR2(255 CHAR)
TYPE VARCHAR2(255 CHAR)
UNIT VARCHAR2(255 CHAR)
USERID NUMBER(10,0)
WEEKLYREPORTS CLOB
WEEKLYREPORTSMOMENTSPERWEEK CLOB
ATA
ANSWEREMAIL VARCHAR2(255 CHAR)
ANSWERTIME VARCHAR2(255 CHAR)
ATA NUMBER(10,0)
ATACOMMENT CLOB
ATAID NUMBER(10,0)
ATAINTERNALNUMBER VARCHAR2(50 CHAR)
ATANUMBER VARCHAR2(50 CHAR)
ATATYPE VARCHAR2(255 CHAR)
AUTHOR VARCHAR2(255 CHAR)
BECOMEATAFROMDEVIATION NUMBER(10,0)
BECOMEEXTERNALATAFROMINTERNAL NUMBER(10,0)
BECOMEFASTFROMOTHERTYPE NUMBER(10,0)
BRIEFDESCRIPTION VARCHAR2(255 CHAR)
CITY VARCHAR2(255 CHAR)
CLIENT_ANSWER_ATTACHMENT VARCHAR2(255 CHAR)
CLIENTCOMMENT VARCHAR2(255 CHAR)
CONFIRMSTATUS NUMBER(10,0)
CREATED_AT DATE
DEVIATION NUMBER(10,0)
DEVIATIONNUMBER VARCHAR2(50 CHAR)
DEVIATIONTYPE VARCHAR2(255 CHAR)
DUEDATE DATE
EMAILSENT NUMBER(10,0)
FINANCEID NUMBER(10,0)
FORFORTNOX NUMBER(10,0)
FROMFORTNOX NUMBER(10,0)
IS_DELETED NUMBER(10,0)
LOCKED CHAR(1 CHAR)
NAME VARCHAR2(255 CHAR)
PARENTATA NUMBER(10,0)
PAYMENTTYPE NUMBER(10,0)
PDFURL VARCHAR2(255 CHAR)
PROJECTID NUMBER(10,0)
QUANTITY VARCHAR2(50 CHAR)
REASON VARCHAR2(50 CHAR)
REVISIONDATE DATE
STARTDATE DATE
STATUS NUMBER(10,0)
STREET VARCHAR2(255 CHAR)
SUGGESTION VARCHAR2(50 CHAR)
TOKEN VARCHAR2(255 CHAR)
TYPE VARCHAR2(255 CHAR)
UNIT VARCHAR2(50 CHAR)
Since internal_atas table is empty so I dont have any data only in table ata I have data something like
Sorry for separete but I have more then 30 column in table
ANSWEREMAIL ANSWERTIME ATA ATACOMMENT ATAID ATAINTERNALNUMBER ATANUMBER ATATYPE AUTHOR BECOMEATAFROMDEVIATION BECOMEEXTERNALATAFROMINTERNAL BECOMEFASTFROMOTHERTYPE BRIEFDESCRIPTION CITY
email#email.com 2020-05-04 12:05:18 1 NULL 2036 NULL 3 1 197 0 0 0 some text here Zagreb
PART II ATA table
CLIENT_ANSWER_ATTACHMENT CONFIRMSTATUS CREATED_AT DEVIATION DEVIATIONTYPE DUEDATE EMAILSENT FINANCEID FORFORTNOX FROMFORTNOX IS_DELETED LOCKED NAME PARENTATA PAYMENTTYPE
NULL 1 10-JUN-20 3 1 06-APR-20 1 173 1 0 0 0 fffttt 0 1
PART III
PDFURL PROJECTID QUANTITY REASON REVISIONDATE STARTDATE STATUS STREET SUGGESTION TOKEN TYPE UNIT USERID ZIP
someurl.com 261 NULL NULL NULL STARTDATE 2 FoxBox 111 NULL 32aacd4b76628feeece6 1 NULL NULL 2624
Your query has a structural issue, i.e. it is written incorrectly. You have the structural element:
select ...
FROM
ata a
LEFT JOIN
users
INNER JOIN internal_atas ia
ON (a.ATAID = ia.ATAID AND a.Author = users.UserID)
...
This is invalid as it translates to the form "from a join b join c on ... on ..." where the join syntax requires the form "from a join b on ... join c on ...". So you need something like:
select ...
from ata a
left join users on a.author = users.userid
inner join internal_atas ia on a.ataid = ia.ataid
...
I believe this is what #ThomasG war referring to.
I am somewhat surprised at the particular error message you are getting. When I tried your query I got "ORA-00905: missing keyword", but I have long since concluded that when a query contains structurally invalid you can just ignore the specific error message (at that point Oracle is "just guessing") and correct the query, then retry.
BTW. You have an inconsistency in your query as well:
ON (a.ATAID = ia.ATAID AND a.Author = users.UserID)
WHERE
a.ATAID = 2095
OR ia.ATAID IS NULL
Any row that satisfies the ON (a.ATAID = ia.ATAID) condition cannot also satisfy the OR (ia.ATAID IS NULL). And since it MUST satisfy the ON condition the OR is condition is superfluous. Unless it is changed when structural element is corrected.
Suposition:
There is perhaps a plausible explanation for your error. According to the Oracle Documentation
To execute a join of three or more tables, Oracle first joins two of
the tables based on the join conditions comparing their columns and
then joins the result to another table based on join conditions
containing columns of the joined tables and the new table. Oracle
continues this process until all tables are joined into the result.
The optimizer determines the order in which Oracle joins tables based
on the join conditions, indexes on the tables, and, any available
statistics for the tables.
At that point in the parsing perhaps it is attempting to evaluate
users
INNER JOIN internal_atas ia
ON (a.ATAID = ia.ATAID AND a.Author = users.UserID)
At which point table ata is not part of the evaluation and thus the column is not defined. As I said this is "just a guess on my part", but it seems to fit the evidence.

Need to detect the column while using sqlldr

OS: WIN
Database target: Oracle 12c
Source is File.
Using : sqlldr
I have a text data in this format. I have pasted the sample data in the description (please copy it to notepad++) i have huge data in this way which i would like to load it into the database table using sqlldr.
let me give you a brief of data TRN is where the transaction starts and TRNEND is where it ends.
The problem is- TRN1111111119134 record line where we have one column missing but that is present in transaction TRN1111111117134 column which is 114115, but my requirement here is to insert null into that column corresponding down to 114115 in first transaction when dealing with the second transaction but everything here is separated by white space(can we convert the white space delimiter to fixed one or other delimited one dynamically ?).
Any advice would really be helpful. Thanks a lot.
TRN1111111117134 211712221635361341111576114115 114115 CLOSE CT J J J JOS
TRNEND11111111181111111111
TRN1111111119134 21171222163536 TOTAL CTT VOUCH J11111111111115221111 J J JOS
TRNEND11111111111111111111
I am trying to use below sqlldr control file command, do i missing something here ?
infile 'D:\Source_files\LOG_07117_2017.DAT'
truncate into table RAW_FILE
fields terminated by WHITESPACE optionally enclosed by '#'
TRAILING NULLCOLS
( col1 ,
col2 "nvl(:col2,'')",
col3 "nvl(:col3,'')",
col4 "nvl(:col4,'')",
col5 "nvl(:col5,'')",
col6 "nvl(:col6,'')",
col7 "nvl(:col7,'')",
col8 "nvl(:col8,'')",
col9 "nvl(:col9,'')",
col10 "nvl(:col10,'')",
col11 "nvl(:col11,'')",
col12 "nvl(:col12,'')",
col13 "nvl(:col13,'')",
col14 "nvl(:col14,'')",
col15 "nvl(:col15,'')",
col16 "nvl(:col16,'')",
col17 "nvl(:col17,'')",
col18 "nvl(:col18,'')",
col19 "nvl(:col19,'')",
col20 "nvl(:col20,'')",
col21 "nvl(:col21,'')",
col22 "nvl(:col22,'')",
col23 "nvl(:col23,'')",
col24 "nvl(:col24,'')",
col25 "nvl(:col25,'')",
col26 "nvl(:col26,'')",
col27 "nvl(:col27,'')",
col28 "nvl(:col28,'')",
col29 "nvl(:col29,'')",
col30 "nvl(:col30,'')")
The table definition for this case
CREATE TABLE "RAW_FILE" (
"COL1" VARCHAR2(4000 BYTE),
"COL2" VARCHAR2(4000 BYTE),
"COL3" VARCHAR2(4000 BYTE),
"COL4" VARCHAR2(4000 BYTE),
"COL5" VARCHAR2(4000 BYTE),
"COL6" VARCHAR2(4000 BYTE),
"COL7" VARCHAR2(4000 BYTE),
"COL8" VARCHAR2(4000 BYTE),
"COL9" VARCHAR2(4000 BYTE),
"COL10" VARCHAR2(4000 BYTE),
"COL11" VARCHAR2(4000 BYTE),
"COL12" VARCHAR2(4000 BYTE),
"COL13" VARCHAR2(4000 BYTE),
"COL14" VARCHAR2(4000 BYTE),
"COL15" VARCHAR2(4000 BYTE),
"COL16" VARCHAR2(4000 BYTE),
"COL17" VARCHAR2(4000 BYTE),
"COL18" VARCHAR2(4000 BYTE),
"COL19" VARCHAR2(4000 BYTE),
"COL20" VARCHAR2(4000 BYTE),
"COL21" VARCHAR2(4000 BYTE),
"COL22" VARCHAR2(4000 BYTE),
"COL23" VARCHAR2(4000 BYTE),
"COL24" VARCHAR2(4000 BYTE),
"COL25" VARCHAR2(4000 BYTE),
"COL26" VARCHAR2(4000 BYTE),
"COL27" VARCHAR2(4000 BYTE),
"COL28" VARCHAR2(4000 BYTE),
"COL29" VARCHAR2(4000 BYTE),
"COL30" VARCHAR2(4000 BYTE))
Your input appears to be a fixed format file; try to explain why "TOTAL" is the 4th field and not the 3rd, and it will probably become apparent why.
Replace the fields terminated by WHITESPACE optionally enclosed by '#' with specific positions on each field, such as col3 POSITION (53:62) .

Loading multiline columnusing external table in Oracle

Loading a flat file using external table.Some of the fields are being missed out due to multiline values in a column
how can we load all the records including multiline columns?
Data sample:
--first line
56585,0,4032,,1,790035190,,2,2,,1,1,1,06-SEP-07,,,,,0,EUR ,0,06-SEP-07,1,790035190,2,,0,,,,,,,,,,,,2,2,2,,,,,,,,06-SEP-07,,,,,,,,,1,,,,,,,,,,,
--second line
24188,31,4032,This is the Title,1,790035190,,2,2,,1,1,1,06-SEP-07,,,,,0,EUR ,0,06-SEP-07,1,790035190,2,,0,,Value 1
Value 2
Value 3
Value 4,,,,,,,,,,2,2,2,,,,,,,,06-SEP-07,,,,,,,,,1,,,,,,,,,,,1
External table schema:
CREATE TABLE OFFERS_EXT
(
OFFER_ID NUMBER(10) ,
AMENDMENT_ID NUMBER(10) ,
CLIENT_ID NUMBER(10) ,
BUSINESS_UNIT_NAME VARCHAR2(120 BYTE),
RED_FLAG_STATUS NUMBER(10) ,
CREATED_BY VARCHAR2(30 BYTE) ,
RED_FLAG_COMMENTS VARCHAR2(765 BYTE),
OFFER_CATEGORY_ID NUMBER(10) ,
OFFER_PRIORITY_ID NUMBER(10) ,
OFFER_PRIORITY_COMMENTS VARCHAR2(765 BYTE),
OFFER_STATUS_ID NUMBER(10) ,
SOLD_IN NUMBER(10),
END_TYPE_ID NUMBER(10) ,
OFFER_START_DATE DATE,
OFFER_DUE_SUBMITTED_DATE DATE,
VALIDITY_DATE DATE,
CONTRACT_SIGNED_DATE DATE,
CONTRACT_START_DATE DATE,
CONTRACT_DURATION NUMBER(5),
TOTAL_OFFER_VALUE VARCHAR2(57 BYTE),
NUMBER_OF_OFFER_SITES NUMBER(10),
CREATED_TIMESTAMP DATE ,
LANGUAGE_ID NUMBER(10) ,
LAST_UPDATED_BY VARCHAR2(30 BYTE) ,
TIME_RISK_ID NUMBER(10) ,
RISK_COMMENTS VARCHAR2(765 BYTE),
PROBABILITY_OF_WIN NUMBER(5),
PROBABILITY_OF_WIN_DATE DATE,
COMMENTS VARCHAR2(765 BYTE),
ADDRESS_ID NUMBER(10),
WIN_LOSS_PRICE VARCHAR2(3 BYTE),
WIN_LOSS_DESCRIPTION VARCHAR2(3 BYTE),
WIN_LOSS_QUALITY_SERVICE VARCHAR2(3 BYTE),
WIN_LOSS_AVAILABILITY VARCHAR2(3 BYTE),
WIN_LOSS_INCOMPLETE_PORTFOL VARCHAR2(3 BYTE),
WIN_LOSS_REASONS_TEXT VARCHAR2(765 BYTE),
WIN_LOSS_COMMENTS VARCHAR2(765 BYTE),
WIN_LOSS_CONCLUSIONS VARCHAR2(765 BYTE),
SERVICE_RISK_ID NUMBER(10) ,
TECHNICAL_RISK_ID NUMBER(10) ,
FINANCIAL_RISK_ID NUMBER(10) ,
SPECIAL_DISCOUNT NUMBER(5),
SPECIAL_DISCOUNT_INSTALLATIO NUMBER(5),
DISCOUNT_REASONS VARCHAR2(765 BYTE),
DISCOUNT_REPLY VARCHAR2(765 BYTE),
WIN_LOSS_DISCOUNT VARCHAR2(3 BYTE),
WIN_LOSS_OTHER VARCHAR2(3 BYTE),
WIN_LOSS_POLITICAL VARCHAR2(3 BYTE),
LAST_UPDATED_TIMESTAMP DATE ,
ORDER_INST_COUNTRY_ID NUMBER(10),
FM_ORDER_NR VARCHAR2(60 BYTE),
CONTRACT_END_DATE DATE,
BANK_ID NUMBER(10),
BID_TOOL_ID NUMBER(10),
FINANCIAL_RISK_COMMENT VARCHAR2(765 BYTE),
SERVICE_RISK_COMMENT VARCHAR2(765 BYTE),
TECHNICAL_RISK_COMMENT VARCHAR2(765 BYTE),
CONTRACT_CHECK_ID NUMBER(10),
CONTRACT_CHECK_DATE DATE,
CONTRACT_CHECK_BY VARCHAR2(30 BYTE),
CONTRACT_CHECK_COMMENTS VARCHAR2(1536 BYTE),
CONTRACT_CHECK_REPLY VARCHAR2(1536 BYTE),
CONTRACT_PARALLEL_FLAG NUMBER(1),
FRC_FLAG VARCHAR2(3 BYTE),
FRC_OFFER_ID NUMBER(10),
FRC_AMENDMENT_ID NUMBER(10),
FRC_COPYDATAFLAG VARCHAR2(3 BYTE),
CONTRACT_CANCEL_DATE DATE,
REFERS_TO_AMENDMENT NUMBER(10)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY EXTERNAL_DIR_RE
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE CHARACTERSET WE8ISO8859P1
BADFILE REJECT_DIR_RE:'OFFERS_EXT.bad'
LOGFILE REJECT_DIR_RE:'OFFERS_EXT.log'
LOAD WHEN (OFFER_ID != 'FILETRAILER')
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
(
OFFER_ID ,
AMENDMENT_ID ,
CLIENT_ID ,
BUSINESS_UNIT_NAME ,
RED_FLAG_STATUS ,
CREATED_BY ,
RED_FLAG_COMMENTS ,
OFFER_CATEGORY_ID ,
OFFER_PRIORITY_ID ,
OFFER_PRIORITY_COMMENTS ,
OFFER_STATUS_ID ,
SOLD_IN ,
END_TYPE_ID ,
OFFER_START_DATE date "DD-MON-YYYY HH24:MI:SS" ,
OFFER_DUE_SUBMITTED_DATE date "DD-MON-YYYY HH24:MI:SS" ,
VALIDITY_DATE date "DD-MON-YYYY HH24:MI:SS" ,
CONTRACT_SIGNED_DATE date "DD-MON-YYYY HH24:MI:SS" ,
CONTRACT_START_DATE date "DD-MON-YYYY HH24:MI:SS" ,
CONTRACT_DURATION ,
TOTAL_OFFER_VALUE ,
NUMBER_OF_OFFER_SITES ,
CREATED_TIMESTAMP date "DD-MON-YYYY HH24:MI:SS" ,
LANGUAGE_ID ,
LAST_UPDATED_BY ,
TIME_RISK_ID ,
RISK_COMMENTS ,
PROBABILITY_OF_WIN ,
PROBABILITY_OF_WIN_DATE date "DD-MON-YYYY HH24:MI:SS" ,
COMMENTS ,
ADDRESS_ID ,
WIN_LOSS_PRICE ,
WIN_LOSS_DESCRIPTION ,
WIN_LOSS_QUALITY_SERVICE ,
WIN_LOSS_AVAILABILITY ,
WIN_LOSS_INCOMPLETE_PORTFOL ,
WIN_LOSS_REASONS_TEXT ,
WIN_LOSS_COMMENTS ,
WIN_LOSS_CONCLUSIONS ,
SERVICE_RISK_ID ,
TECHNICAL_RISK_ID ,
FINANCIAL_RISK_ID ,
SPECIAL_DISCOUNT ,
SPECIAL_DISCOUNT_INSTALLATIO ,
DISCOUNT_REASONS ,
DISCOUNT_REPLY ,
WIN_LOSS_DISCOUNT ,
WIN_LOSS_OTHER ,
WIN_LOSS_POLITICAL ,
LAST_UPDATED_TIMESTAMP date "DD-MON-YYYY HH24:MI:SS" ,
ORDER_INST_COUNTRY_ID ,
FM_ORDER_NR ,
CONTRACT_END_DATE date "DD-MON-YYYY HH24:MI:SS" ,
BANK_ID ,
BID_TOOL_ID ,
FINANCIAL_RISK_COMMENT ,
SERVICE_RISK_COMMENT ,
TECHNICAL_RISK_COMMENT ,
CONTRACT_CHECK_ID ,
CONTRACT_CHECK_DATE date "DD-MON-YYYY HH24:MI:SS" ,
CONTRACT_CHECK_BY ,
CONTRACT_CHECK_COMMENTS ,
CONTRACT_CHECK_REPLY ,
CONTRACT_PARALLEL_FLAG ,
FRC_FLAG ,
FRC_OFFER_ID ,
FRC_AMENDMENT_ID ,
FRC_COPYDATAFLAG ,
CONTRACT_CANCEL_DATE date "DD-MON-YYYY HH24:MI:SS" ,
REFERS_TO_AMENDMENT
)
)
LOCATION (EXTERNAL_DIR_RE:'OFFERS_EXT.dat')
)
REJECT LIMIT UNLIMITED
NOPARALLEL
NOMONITORING;
You specified "RECORDS DELIMITED BY NEWLINE", i.e. any new line will be treated as new row. If you have multi-line values in your source file you need to use 1) another delimiter for new lines or 2) merge multi-line values into single line before loading using batch script. Is it correct that your multi-line values are not enclosed into double quotes?

Resources