Oracle ORA-04063: table "TABLE" has errors - oracle

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

Related

Not enough values while trying to insert data from table 1 to table 2

I want to add one column in table but I get error that table needs to be empty.
I create backup table using following command
CREATE TABLE attachments_backup
AS
SELECT * FROM attachments
When I create a backup table I insert data from attachments to attachments_backup
INSERT INTO attachments SELECT * FROM attachments_backup
Then I delete data from table 1 (attachments)
DELETE FROM attachments
I add column which I need to add in table attachment
ALTER TABLE attachments
ADD ChildrenDirectory VARCHAR(50) DEFAULT NULL
Right here problem occure. Since I add new column right now I can insert data from table 2 (attachment_backup) to table 1 (attachments)
I try something like this
INSERT INTO attachments VALUES (AtaId,Belongs_To,ClientId,File_path,Id,Image_Path,Lock_,Name,Project_Id,Type,Category) SELECT * FROM attachments_backup
But this solution doesn't work since I get error message "Not enought values"
SQL Error: ORA-00947: not enough values
00947. 00000 - "not enough values"
Does anyone now how to solve this kind of issue since I have no more idea ?
Attachments table
ATAID NUMBER(10,0)
BELONGS_TO NUMBER(10,0)
CLIENTID NUMBER(10,0)
FILE_PATH VARCHAR2(255 CHAR)
ID NUMBER(10,0)
IMAGE_PATH VARCHAR2(255 CHAR)
ISDELETED NUMBER(10,0)
LOCK_ CHAR(1 CHAR)
NAME VARCHAR2(255 CHAR)
PROJECT_ID NUMBER(10,0)
TYPE VARCHAR2(4000 CHAR)
CATEGORY VARCHAR2(20 BYTE)
CHILDRENDIRECTORY VARCHAR2(50 BYTE)
Attachments_backup
ATAID NUMBER(10,0)
BELONGS_TO NUMBER(10,0)
CLIENTID NUMBER(10,0)
FILE_PATH VARCHAR2(255 CHAR)
ID NUMBER(10,0)
IMAGE_PATH VARCHAR2(255 CHAR)
ISDELETED NUMBER(10,0)
LOCK_ CHAR(1 CHAR)
NAME VARCHAR2(255 CHAR)
PROJECT_ID NUMBER(10,0)
TYPE VARCHAR2(4000 CHAR)
CATEGORY VARCHAR2(20 BYTE)
Basically, you're doing it wrong.
Except for quick and dirty selects, don't use asterisk *. Something like this:
insert into a select * from b
just waits for error to happen. Always name all columns involved. Yes, it requires some more typing, but is safe. So:
insert into a (empno, ename, job, sal)
select empno, ename, job, sal
from b;
Welcome,
You can add new column to an existing table using an alter command, even if the table is not empty
To insert from table "A" to table "B" or vice-versa, you need to have exact number of columns to perform "select * " type insert

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",

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

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;

Delete tables from table based on table size

I use this table to store messages. I would like to delete rows by date if the size of the table is bigger than 10 MB. Is this possible in Oracle?
CREATE TABLE EVENTS(
EVENTID INTEGER NOT NULL,
SOURCE VARCHAR2(50 ),
TYPE VARCHAR2(50 ),
EVENT_DATE DATE,
DESCRIPTION VARCHAR2(100 )
)
/

Resources