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.
Related
Hi I have been trying to do a subquery using 2 tables and when I try to run the following code:
select t.cantidad_traslado,
(select sum(te.coste)"Coste",
(case when te.nif_emptransporte='F-98987667-R' then'AceSur'
when te.nif_emptransporte='A-98985367-V' then'TransMadrid'
when te.nif_emptransporte='A-97654567-S' then'Perez e Hijos'
when te.nif_emptransporte='A-87684567-B' then'Resur'
when te.nif_emptransporte='A-98987067-V' then'HuelResi'
else 'Indefinido'
end)"Empresa"
from traslado_empresatransportista te
group by te.nif_emptransporte
where t.nif_empresa=te.nif_empresa)
from traslado t
where t.nif_empresa in (select distinct nif_empresa from traslado_empresatransportista)
but when I try to run it oracle shows me the following error:
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 12 Column: 9.
I am pretty sure I have all of my parenthesis right, so I wanted to know if yall could help me.
Edit:
Someone suggestes I swapped the order between the where and group by clause like this:
select t.cantidad_traslado,
(select sum(te.coste)"Coste",
(case when te.nif_emptransporte='F-98987667-R' then'AceSur'
when te.nif_emptransporte='A-98985367-V' then'TransMadrid'
when te.nif_emptransporte='A-97654567-S' then'Perez e Hijos'
when te.nif_emptransporte='A-87684567-B' then'Resur'
when te.nif_emptransporte='A-98987067-V' then'HuelResi'
else 'Indefinido'
end)"Empresa"
from traslado_empresatransportista te
group by te.nif_emptransporte
where t.nif_empresa=te.nif_empresa)
from traslado t
where t.nif_empresa in (select distinct nif_empresa from traslado_empresatransportista)
When I did I was presented the following error:
ORA-00913: too many values
00913. 00000 - "too many values"
*Cause:
*Action:
From Oracle 12, you can use a LATERAL join and then return multiple columns from the joined table:
select t.cantidad_traslado,
te.*
from traslado t
CROSS JOIN LATERAL (
select sum(te.coste) AS "Coste",
case
when te.nif_emptransporte='F-98987667-R' then'AceSur'
when te.nif_emptransporte='A-98985367-V' then'TransMadrid'
when te.nif_emptransporte='A-97654567-S' then'Perez e Hijos'
when te.nif_emptransporte='A-87684567-B' then'Resur'
when te.nif_emptransporte='A-98987067-V' then'HuelResi'
else 'Indefinido'
end AS "Empresa"
from traslado_empresatransportista te
where t.nif_empresa=te.nif_empresa
group by te.nif_emptransporte
) te
After joining three tables, I am unable to call the column "shipping_id" from the "shipment" table.
I've tried re-ordering my joins and other ways of calling the column
SELECT shipment.shipping_id (date_of_delivery-order_date) AS "Length of Delivery",
damaged, inventory.product_id, name_of_product, price
FROM shipment
JOIN orders
ON orders.shipping_id = shipment.shipping_id
JOIN inventory
ON inventory.product_id = orders.product_id
If i remove the first SELECT entry "shipment.shipping_id", the query runs fine. I am receiving this error...
ORA-00904: "SHIPMENT"."SHIPPING_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 1 Column: 8
Missing comman after shipping_id. Since you're joining on shipping_id, there is no need to qualify the reference. There is only a single shipping_id column in the result.
I am trying to find the average number of transactions for every product key for the specified time keys. This is the query in DB2.
select
act.product_key
avg(act.cnt) as avg_transaction
from tb1 as ca
inner join tb2 as act
on ca.base_key = act.base_key and act.time = ca.time and act.product_key = ca.product_key
group by act.product_key, act.time
having act.time in (16476,16516, 16556,16596, 16636,16676,16716, 16756, 16796,16836,16876,16916,16956);
This is the error I am getting for the above query. I am not sure whats going wrong, this is the first time I am querying on DB2. Any suggestions would be great.
Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=(;act.product_key
avg;,, DRIVER=3.66.46
SQLState: 42601
ErrorCode: -104
Error: DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-104;42601;(|act.product_key
avg|,, DRIVER=3.66.46
SQLState: 56098
ErrorCode: -727
The way you describe what you want, you should move the having to a where clause and remove the time key from the group by:
select act.product_key, avg(act.cnt) as avg_transaction
from tb1 ca inner join
tb2 act
on ca.base_key = act.base_key and act.time = ca.time and act.product_key = ca.product_key
where act.time in (16476, 16516, 16556,16596, 16636, 16676, 16716, 16756, 16796, 16836, 16876, 16916, 16956)
group by act.product_key;
I'm not sure if that will fix your problem.
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
I created a view and then I want to update the cost and show the error. But it reterns that virtual column not allowed.
View:
CREATE OR REPLACE VIEW CONCERT_EVENTS1 AS
SELECT CONCERT.CONCERT_ID, EVENT.EVENT_ID, CONCERT.NAME, EVENT.DATE1 , CONCERT.DURATION,
CONCERT.TYPE, TO_CHAR(CONCERT.COST, 'L9,999.99') AS FORMATED_COST
FROM EVENT
INNER JOIN CONCERT
ON CONCERT.CONCERT_ID = EVENT.CONCERT_ID;
Below is the error:
Error starting at line 1 in command:
UPDATE CONCERT_EVENTS1
SET formated_cost = '300.00'
WHERE formated_cost = '200.00'
Error at Command Line:2 Column:5
Error report:
SQL Error: ORA-01733: virtual column not allowed here
01733. 00000 - "virtual column not allowed here"
*Cause:
*Action:
Thanks in advance
FORMATED_COST is probably a calculated field, or in any case the
database cannot infer what change is to be made to the tables
underlying the view based on the change you are requiring.
Include an extra column in your view on CONCERT.COST without the formatting. And update only that new column. The explanation of why this is needed is given by Vignesh Kumar.