Need to detect the column while using sqlldr - oracle

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) .

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

Naive approach to finding table size in SQL Developer?

Given a table containing n rows and k bytes per row, can I estimate the size of a table in GB by finding (n x k)/(1024)^3?
For example, I have a table with 21,097,698 rows and the following columns:
ALWAMT NUMBER(11,2)
ALWUNT NUMBER
CLAIMNO VARCHAR2(22 BYTE)
DIAGN1 VARCHAR2(8 BYTE)
DIAGN2 VARCHAR2(8 BYTE)
DIAGN3 VARCHAR2(8 BYTE)
DIAGN4 VARCHAR2(8 BYTE)
MEMAGE NUMBER(20,0)
MEMBNO VARCHAR2(15 BYTE)
PARENT VARCHAR2(4 BYTE)
SEXCOD VARCHAR2(1 BYTE)
SVCDAT NUMBER(20,0)
NAMCOD VARCHAR2(50 BYTE)
NAMKEY VARCHAR2(30 BYTE)
DIAGNOSISCAT VARCHAR2(80 BYTE)
LOC_DESC VARCHAR2(40 BYTE)
SVCCOD_DESC VARCHAR2(50 BYTE)
ALWAMT_CATG VARCHAR2(20 BYTE)
The table does not contain an index nor is it partitioned.
The above formula yields a table size of 7.78 GB. Is this an accurate estimate (knowing it's an estimate of the maximum size since most fields will only be partially filled or may be null)?

How to update a column using control file in 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",

Oracle Trigger to loop and update field based on sysdate

I would like to make a trigger that can update a field (‘STATUS’) to Inactive when a vaccine is past its expiration date (‘EXPIRATION_DATE’).
Here is the current table structure:
**CREATE TABLE WAREHOUSE.VACCINE_INVENTORY (
VACCINE VARCHAR2(200 BYTE) NOT NULL,
RECEIPT_DATE DATE NOT NULL,
CONTAINER_SIZE VARCHAR2(200 BYTE),
QUANTITY NUMBER(6, 0),
REQUISITION NUMBER(6, 0),
FISCAL_YEAR NUMBER(4, 0),
RECEIVED_BY VARCHAR2(50 BYTE),
EXPIRATION_DATE DATE,
LOT_NUMBER VARCHAR2(30 BYTE) NOT NULL,
VENDOR VARCHAR2(200 BYTE),
STATUS VARCHAR2(10 BYTE),
CATALOG_NUMBER NUMBER(5, 0),
CONSTRAINT PK_VACC PRIMARY KEY (VACCINE, RECEIPT_DATE, LOT_NUMBER) USING INDEX TABLESPACE WAREHOUSE STORAGE**
So the idea is that if SYSDATE > EXPIRATION_DATE the expiration date should be changed from Active to Inactive.
I would assume I would need to create a Loop so that when the trigger is run, it will loop through all the records in the table and set each expired vaccine to Inactive.
I would greatly appreciate any help…
Thanks,
Matthew
Create an additional view to provide fields that depend on table columns and sysdate, e.g.
CREATE TABLE VACCINE_INVENTORY(VACCINE VARCHAR2(200 BYTE) NOT NULL,
-- ---
EXPIRATION_DATE DATE NOT NULL
-- ...
);
CREATE view VACCINE_INVENTORY_VW AS
select v.*,
case
when v.expiration_date < sysdate then
'I'
else
'A'
end as status
from VACCINE_INVENTORY v;

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