00904. 00000 - "%s: invalid identifier" [duplicate] - oracle

This question already has an answer here:
Invalid Identifier SQL
(1 answer)
Closed 5 years ago.
Going crazy with this code. Can Anybody put me on the right track? I am using SQL Develope 3.1.07. Thanks.
SELECT
PHA.PO_HEADER_ID,
PRLA.ATTRIBUTE1 As "REQUISITION_NUMBER",
PHA.SEGMENT1 As PO_NUMBER,
DECODE (nvl(REG.DOCUMENT_TYPE, '-'),
'APW', 'Agreement for Performance of Work',
'APWEMER', 'Agreement for Performance of Work - Emergency',
'CONS', 'Consultant',
'CONCEMER', 'Consultant - Emergency',
'DFC', 'Direct Financial Contribution',
'FELLOW', 'Fellowship',
'GENEXT', 'General External Services',
'IMPRESTCC', 'Imprest/Credit Card',
'IS', 'Internal Services',
'LOA', 'Letter of Agreement',
'TSA', 'Technical Service Agreement') as DOCUMENT_TYPE,
HAOU.NAME As BUDGET_CENTRE,
PHA.CREATION_DATE As PO_CREATION_DATE,
PHA.AUTHORIZATION_STATUS,
PHA.APPROVED_DATE,
PHA.COMMENTS,
PHA.CLOSED_DATE,
PHA.CLOSED_CODE,
PDA.PO_DISTRIBUTION_ID,
AIDA.INVOICE_ID,
AIA.INVOICE_TYPE_LOOKUP_CODE AS INVOICE_TYPE,
AIA.REMIT_TO_SUPPLIER_NAME AS SUPPLIER_NAME,
AIA.REMIT_TO_SUPPLIER_ID AS SUPPLIER_ID,
AIA.INVOICE_DATE, AIA.INVOICE_NUM,
AIA.INVOICE_AMOUNT,
AIA.INVOICE_CURRENCY_CODE AS INVOICE_CURRENCY,
AIA.GL_DATE,
AIA.PAYMENT_CURRENCY_CODE AS PAYMENT_CURRENCY,
AIA.PAYMENT_CROSS_RATE_DATE AS PAYMENT_DATE,
AIA.DESCRIPTION, AIA.EXCHANGE_DATE,
AIA.EXCHANGE_RATE,
AIA.BASE_AMOUNT AS FUNCTIONAL_CURRENCY_AMOUNT
FROM
po_headers_all pha,
po_distributions_all pda,
ap_invoice_distributions_all aida,
ap_invoices_all aia,
po_requisition_lines_all prla,
po_req_distributions_all prda,
hr.hr_all_organization_units haou,
pa.pa_projects_all ppa
LEFT JOIN
xxwrp.xxwrp_service_reg_all reg
ON
reg.po_header_id = pha.po_header_id
WHERE
1=1
AND pha.segment1 = '201251390'
AND pda.req_distribution_id = prda.distribution_id
AND prda.requisition_line_id = prla.requisition_line_id
AND pha.po_header_id = pda.po_header_id
AND pda.po_distribution_id = aida.po_distribution_id
AND aida.invoice_id = aia.invoice_id
AND pda.project_id = ppa.project_id
AND haou.organization_id=ppa.carrying_out_organization_id
AND pha.creation_date > aia.invoice_date
GROUP BY
PHA.PO_HEADER_ID, PRLA.ATTRIBUTE1, PHA.SEGMENT1, REG.DOCUMENT_TYPE, HAOU.NAME, PHA.CREATION_DATE, PHA.AUTHORIZATION_STATUS, PHA.APPROVED_DATE, PHA.COMMENTS, PHA.CLOSED_DATE, PHA.CLOSED_CODE, PDA.PO_DISTRIBUTION_ID, AIDA.INVOICE_ID, AIA.INVOICE_TYPE_LOOKUP_CODE, AIA.REMIT_TO_SUPPLIER_NAME, AIA.REMIT_TO_SUPPLIER_ID, AIA.INVOICE_DATE, AIA.INVOICE_NUM, AIA.INVOICE_AMOUNT, AIA.INVOICE_CURRENCY_CODE, AIA.GL_DATE, AIA.PAYMENT_CURRENCY_CODE, AIA.PAYMENT_CROSS_RATE_DATE, AIA.DESCRIPTION, AIA.EXCHANGE_DATE, AIA.EXCHANGE_RATE, AIA.BASE_AMOUNT
When I run it, it returns this error:
ORA-00904: "PHA"."PO_HEADER_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 50 Column: 21

The issue is in mixing the old Oracle syntax with the ANSI join syntax; for example, say you have these tables:
create table t1(n1 number);
create table t2(n2 number);
create table t3(n3 number);
this is what you get:
SQL> select *
2 from t1,t2
3 left join t3 on t3.n3 = t1.n1
4 where t1.n1 = t2.n2;
left join t3 on t3.n3 = t1.n1
*
ERROR at line 3:
ORA-00904: "T1"."N1": invalid identifier
SQL> select *
2 from t1
3 inner join t2 on t1.n1 = t2.n2
4 left join t3 on t3.n3 = t1.n1;
no rows selected

The problem is your left join. There is probably a column missing; the one you are joining on.
Here is more details on the error you're receiving:
https://www.techonthenet.com/oracle/errors/ora00904.php

Related

Teradata to Oracle Query eaxdata Conversion

I need help with converting the below SQL query in Taradata to Oracle exadata. Not sure how to convert the date, I changed the CAST date function To_Date but get a few errors.
SELECT DISTINCT
pat.pat_id,
pat.pat_mrn_id AS patientmrn,
pat.pat_name AS patientname,
adt_pat_class_c,
pat.death_date AS deathdate,
cast(patenc.hosp_admsn_time AS DATE format 'mm/dd/yyyy') AS
admitdate,
cast(patenc.hosp_disch_time AS DATE format 'mm/dd/yyyy') AS
dischargedate,
extract(year FROM acct.adm_date_time)-extract(year FROM
pat.birth_date) - CASE WHEN acct.adm_date_time (format
'MMDD')CHAR(4))
<pat.birth_date (format 'MMDD') (CHAR(4)) THEN 1 ELSE 0
END AS patage,
adt_billing_type_c,
adt_patient_stat_c,
hosp_admsn_type_c,
acct_basecls_ha_c,
ordproc.order_proc_id AS order_id,
ordproc.ordering_date
FROM patient pat
inner join pat_enc_hsp patenc ON pat.pat_id = patenc.pat_id
inner join hsp_account acct ON acct.prim_enc_csn_id = patenc.pat_enc_csn_id
inner join order_proc ordproc ON acct.prim_enc_csn_id ON
ordproc.pat_enc_csn_id
inner join clarity_ser ser ON ser.prov_id = ordproc.authrzing_prov_id
inner join identity_ser_id idser ON ser.prov_id=idser.prov_id
inner join clarity_loc loc ON loc.loc_id = acct.loc_id
inner join zc_loc_rpt_grp_7 grp7 ON loc.rpt_grp_seven = grp7.rpt_grp_seven
WHERE grp7.name = 'AB'
AND cast(patenc.hosp_disch_time AS DATE format 'mm/dd/yyyy') >= '01/01/2019'
AND admit_conf_stat_c IN (1,4)
AND description LIKE '%CULTURE%'
AND ordproc.lab_status_c = 3
AND adt_pat_class_c IN ('1204','12113')
AND result_time > patenc.hosp_disch_time;
I changed the top part of the query(one with dates) -
select distinct
pat.pat_id,
pat.PAT_MRN_ID as PatientMRN,
pat.PAT_NAME as PatientName,
ADT_PAT_CLASS_C,
pat.DEATH_DATE as DeathDate,
TO_DATE(patenc.HOSP_ADMSN_TIME, 'mm/dd/yyyy') as AdmitDate,
TO_DATE(patenc.HOSP_DISCH_TIME, 'mm/dd/yyyy') as DischargeDate----
I get the below errors -
ORA-12801: error signaled in parallel query server P02G, instance nzcladb01xm.nndc.kp.org:CDB001N41 (1)
ORA-01843: not a valid month
12801. 00000 - "error signaled in parallel query server %s"
*Cause: A parallel query server reached an exception condition.
*Action: Check the following error message for the cause, and consult
your error manual for the appropriate action.
*Comment: This error can be turned off with event 10397, in which
case the server's actual error is signaled instead.

Missing keyword - inner join with where

post_code is a primary key in the location table and foreign key in job. I am trying to join them, could anyone help.
SELECT job.start_date, job.cust_id, job.veh_id, location.post_code, location.country_name_location
FROM job
INNER JOIN location job.post_code ON location.post_code AND country_name_location = 'France';
SQL Error: ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Your ON is in the wrong position:
SELECT job.start_date, job.cust_id, job.veh_id, location.post_code, location.country_name_location
FROM job
INNER JOIN location ON job.post_code = location.post_code AND country_name_location = 'France';
There is an error in your syntax. The ON keyword is meant to come after you specify the table you are joining with. So the correct query would be:
SELECT job.start_date, job.cust_id, job.veh_id, location.post_code, location.country_name_location
FROM job
INNER JOIN location ON job.post_code = location.post_code AND country_name_location = 'France';

This query runs fine, but as an update statement in Oracle it fails [duplicate]

This question already has answers here:
Update statement with inner join on Oracle
(15 answers)
Closed 5 years ago.
SELECT arinvt.buyer_code_id
FROM arinvt
LEFT JOIN arinvt_vendors
ON arinvt.ID = arinvt_vendors.ARINVT_ID
where arinvt_vendors.vendor_id like 61690
and arinvt_vendors.is_default ='Y'
and arinvt.buyer_code_id is null
update arinvt
set arinvt.buyer_code_id = 66
SELECT arinvt.buyer_code_id
FROM arinvt
LEFT JOIN arinvt_vendors
ON arinvt.id = arinvt_vendors.arinvt_id
(where arinvt_vendors.vendor_id like 61690
and arinvt_vendors.is_default ='Y'
and arinvt.buyer_code_id is null)
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
< *Action:
I looked at the other (duplicate) question before I posted mine and tried this Update:
UPDATE
( SELECT arinvt.buyer_code_id
FROM arinvt
LEFT JOIN arinvt_vendors ON arinvt.id = arinvt_vendors.arinvt_id
where arinvt_vendors.vendor_id like 61690 and arinvt_vendors.is_default ='Y'
and arinvt.buyer_code_id is null
)x
SET arinvt.buyer_code_id = 66
and I get:
Error report -
SQL Error: ORA-00904: "ARINVT"."BUYER_CODE_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
I'm not sure what I'm doing wrong. Can someone help please, we need this to fix our production system.
You have a syntax error here:
arinvt_vendors.is_default 'Y'
I'm guessing you probably meant
arinvt_vendors.is_default = 'Y'

Oracle update statement multiple tables

I am using Oracle (Still a little new to it) and each time i run the update statement below i get the following error message.
SQL Error: ORA-00904: "CH"."CONTRACT_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Here is the query:
UPDATE wr00262_catalogue_201310 ct SET
ct.PORTFOLIO_ID = (SELECT ch.PORTFOLIO_ID
from WR00262_CONTRACT_HEADER ch
WHERE ch.PORTFOLIO_ID = ct.PORTFOLIO_ID)
WHERE ct.NPC in (SELECT ctl.NPC
FROM wr00262_contract_line ctl
WHERE ctl.CONTRACT_ID = ch.CONTRACT_ID);
I think i may need a join but not quite sure where or how. The contract_header table does have a column called CONTRACT_ID.
This is a scoping issue. The columns in one sub-query are not visible to any other sub-query. So try something like this:
UPDATE wr00262_catalogue_201310 ct SET
PORTFOLIO_ID = (
SELECT ch.PORTFOLIO_ID
from WR00262_CONTRACT_HEADER ch
WHERE ch.PORTFOLIO_ID = ct.PORTFOLIO_ID
)
WHERE ct.NPC in (
SELECT ctl.NPC
FROM WR00262_CONTRACT_HEADER ch
join wr00262_contract_line ctl
on ctl.CONTRACT_ID = ch.CONTRACT_ID
WHERE ch.PORTFOLIO_ID = ct.PORTFOLIO_ID
);

Oracle, invalid identifier error

I have this query that should:
create a listing that identifies different items in the inventory
table on the number of colors available for each option
But I'm getting an error saying:
Error at Command Line:167 Column:66 Error report: SQL Error:
ORA-00904: "INV"."ITEM_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
SELECT inv.inv_id,
item1.item_id,
(SELECT COUNT(*)
FROM (SELECT DISTINCT i.color FROM inventory i WHERE i.item_id = inv.item_id))
FROM inventory inv
INNER JOIN item item1
ON item1.item_id = inv.item_id
GROUP BY inv.inv_id, item1.item_id;
It sounds like you just want
SELECT inv.inv_id,
item1.item_id,
COUNT( distinct inv.color )
FROM inventory inv
JOIN item item1 ON (item1.item_id = inv.item_id)
GROUP BY inv.inv_id, item1.item_id
There doesn't seem to be any reason to hit the inventory table again in a subquery.

Resources