Naive approach to finding table size in SQL Developer? - oracle

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

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

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