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