Oracle invalid identifier error 7 - sql

I've looked at multiple questions that have been asked before but they don't seem to fix my problem. I keep getting an invalid identifier error with my following code:
SELECT C.VENDOR_ID, C.VENDOR_SITE_ID, C.AMOUNT, I.AMOUNT AS LINE_AMOUNT, C.BANK_AMOUNT_ID, C.BANK_ACCOUNT_NAME,
C.CHECK_DATE, C.CHECK_ID, C.CHECK_NUMBER, C.CURRENCY_CODE, C.PAYMENT_METHOD_LOOKUP_CODE, C.PAYMENT_TYPE_FLAG,
C.CHECKRUN_NAME, C.STATUS_LOOKUP_CODE, C.CLEARED_AMOUNT, C.CLEARED_DATE, C.CLEARED_BASE_AMOUNT,
C.CLEARED_EXCHANGE_RATE, C.CLEARED_EXCHANGE_DATE, C.EXCHANGE_RATE, C.EXCHANGE_DATE, C.CE_BANK_ACCT_USE_ID,
C.PAYMENT_METHOD_CODE, C.PARTY_ID, C.PARTY_SITE_ID, C.PAYMENT_DOCUMENT_ID, C.REMIT_TO_SUPPLIER_NAME, C.REMIT_TO_SUPPLIER_ID,
C.REMIT_TO_SUPPLIER_SITE_ID, I.INVOICE_ID, I.INVOICE_PAYMENT_ID, I.PERIOD_NAME, I.INVOICE_BASE_AMOUNT, I.PAYMENT_BASE_AMOUNT,
I.REVERSAL_FLAG, I.REVERSAL_INV_PMT_ID, S.ADDRESS_LINE1, S.ADDRESS_LINE_ALT, S.ADDRESS_LINE2, S.ADDRESS_LINE3, S.CITY,
S.STATE, S.ZIP, S.PROVINCE, S.COUNTRY
FROM AP_CHECKS_ALL C
JOIN AP_INVOICE_PAYMENTS_ALL I
ON C.CHECK_ID = I.CHECK_ID
JOIN AP_SUPPLIER_SITES_ALL S
ON C.VENDOR_SITE_ID = S.VENDOR_SITE_ID AND C.VENDOR_ID = S.VENDOR_ID

Check your column names. It's ADDRESS_LINES_ALT, not ADDRESS_LINE_ALT.
Generally speaking, you will get an ORA-00904: invalid identifier when you attempt to select a column from a table that does not contain that column. E.g.,
SELECT not_dummy FROM DUAL;
>>> ORA-00904: "NOT_DUMMY": invalid identifier

Related

Syntax error: Expected end of input but got identifier

I'm trying to run the following query but keep getting the same error
Syntax error: Expected end of input but got identifier "BD_Dictionary"
at [3:1]
My query is:
SELECT
MI.* except(period_date, entity_level, email_access, period_filter)
BD_Dictionary.BD_EMAIL, BD_Dictionary.AREA_LEAD, BD_Dictionary.BD_LEADER
FROM
`mi-trial-365509.Trial.MI` as MI
INNER JOIN
`mi-trial-365509.Trial.BD Dictionary` as BD_Dictionary
ON
A.bd_email = BD_Dictionary.BD_EMAIL
LIMIT
1000
Sorry my bad, i forgot to put a comma in between the table source in SELECT command.
my code is now like this:
SELECT
MI.* except(period_date, entity_level, email_access, period_filter),
BD_Dictionary.BD_EMAIL, BD_Dictionary.AREA_LEAD, BD_Dictionary.BD_LEADER
FROM
`mi-trial-365509.Trial.MI` as MI
INNER JOIN
`mi-trial-365509.Trial.BD Dictionary` as BD_Dictionary
ON
MI.bd_email = BD_Dictionary.BD_EMAIL
LIMIT
1000

Oracle SQL Error : Unable to execute Subquery

I am trying to execute below Oracle SQL query
select m.*, n.region_building_count from
(SELECT
a.BUILDING_ID as "Building Id",
d.Building_name as "Building Name",
d.ADDRESS as "Building Address",
d.REGION as "Region",
d.Country as "Country",
d.State as "State",
d.City as "City"
FROM Company a, LOCATION d
where 1=1
and a.Building_ID like 'BLD-%') m
left JOIN
(select count(building_id) region_building_count, region
from LOCATION l
where l.Building_ID like 'BLD-%' group by region) n
on m.region = n.region
But keep getting error like
Oracle database error 904: ORA-00904: "M"."REGION": invalid identifier
Any idea what I am missing
If you use double-quotes when you define an alias like "Region" (which you should never do!), the alias becomes case-sensitive. When you reference m.region, that is not in double-quotes, the column name is automatically converted to upper-case REGION, which does not match Region.
Just don't use double-quotes around the aliases in the query and this problem will be cured. I didn't check the rest of the query to see if you will run into additional errors.
Alternatively, you could use m."Region" everywhere (in double quotes). Bad practice!

#1054 - Unknown column 'Klanten.Klantnummer' in 'on clause'

I know that I have seen a couple of other questions about this error but I'm new to the sql JOIN so plz could you guy explain what I'm doing wrong.
Here's my query
SELECT Klanten.Klantnummer,`Barcode`, `Naam`, `BetaalStatus`, `ScanStatus`, `TijdScan`, `Prijs`
FROM `Klanten`, `kaart`
LEFT JOIN (`Intro`)
ON (Intro.KlantNummer = Klanten.Klantnummer)
WHERE kaart.KlantNummer = Klanten.Klantnummer
This is the Error I get like you have seen in the title
1054 - Unknown column 'Klanten.Klantnummer' in 'on clause'
And the db names are correct
Simple rule: Never use commas in the FROM clause. Always use proper, explicit JOIN syntax. If you did that, you would not have an error:
SELECT Klanten.Klantnummer,`Barcode`, `Naam`, `BetaalStatus`, `ScanStatus`, `TijdScan`, `Prijs`
FROM `Klanten` JOIN
`kaart`
ON kaart.KlantNummer = Klanten.Klantnummer LEFT JOIN
`Intro`
ON Intro.KlantNummer = Klanten.Klantnummer ;
The problem is that the precedence of , and JOIN are different. Hence, the table before the comma is not known to the ON clause.

ORA-00904 on join

I am trying to create the following view:
CREATE OR REPLACE VIEW AlbumDistribution AS
SELECT Album.Album_ID,
Album.title,
HasTrack.tracked,
FinishedTrack.released_title,
SUBSTR(Album.Album_ID, -1) is_distributed_as
FROM Album A
JOIN HasTrack HT
ON HT.Album_ID = A.Album_ID
JOIN FinishedTrack FT
ON HasTrack.OriginatesFrom = FT.OriginatesFrom
AND HasTrack.tracked = FT.version;
but I get the ORA-00904 error:
ERROR at line 6:
ORA-00904: "HASTRACK"."TRACKED": invalid identifier
Which I find very confusing, as I reference HasTrack.tracked before and there's no error. If I change the order of the statements, putting HasTrack.OriginatesFrom = FT.OriginatesFrom last then I get the same error but for HasTrack.OriginatesFrom.
You define an alias for this and other tables. You need to use the alias throughout the query:
CREATE OR REPLACE VIEW AlbumDistribution AS
SELECT A.Album_ID, A.title, HT.tracked,
FT.released_title, SUBSTR(A.Album_ID, -1) is_distributed_as
FROM Album A JOIN
HasTrack HT
ON HT.Album_ID = A.Album_ID JOIN
FinishedTrack FT
ON HT.OriginatesFrom = FT.OriginatesFrom AND
HT.tracked = FT.version;

Oracle SQL Create View invalid identifier

I'm needing to create view where I basically have to combine three tables in order to see when a contact was last verified. This is the code I have so far:
CREATE VIEW P_PHONECONTACT_VERIFICATION_V AS
SELECT OW.LASTNAME, OW.FIRSTNAME, OW.EMAIL,
OP.PHONE_CONTACTID, OP.PHONENUM, OP.PHONETYPE,
OC.LAST_DATE_VERIFIED AS VERIFIED_ON
FROM P_OWNER OW
LEFT JOIN P_OWNERCONTACT OC
ON OW.OWNERID = OC.OWNERID
LEFT JOIN P_OWNERPHONE OP
ON OC.CONTACTID = OP.PHONE_CONTACTID
WHERE VERIFIED_ON IS NULL OR
VERIFIED_ON > SYSDATE-365
ORDER BY LASTNAME;
I keep getting this error and can't figure out why.
Error at Command Line:10 Column:7
Error report:
SQL Error: ORA-00904: "VERIFIED_ON": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
If anyone could help I would greatly appreciate it.
You are using verified_on in the where clause. I think you need last_date_verified instead:
CREATE VIEW P_PHONECONTACT_VERIFICATION_V AS
SELECT
OW.LASTNAME, OW.FIRSTNAME, OW.EMAIL,
OP.PHONE_CONTACTID, OP.PHONENUM, OP.PHONETYPE,
OC.LAST_DATE_VERIFIED AS VERIFIED_ON
FROM P_OWNER OW LEFT JOIN P_OWNERCONTACT OC
ON OW.OWNERID = OC.OWNERID
LEFT JOIN P_OWNERPHONE OP
ON OC.CONTACTID = OP.PHONE_CONTACTID
WHERE OC.LAST_DATE_VERIFIED IS NULL OR
OC.LAST_DATE_VERIFIED > SYSDATE-365
ORDER BY LASTNAME;
You can't use a column alias defined in the select clause in the where clause.