I am trying to update some fields in oracle nested table, so I can insert some values, the problem is I am unable to retrieve the results as nested table. The following is the query I am trying to run:
update utilisation_obj
set listerefaccess = (
select ref(a)
from refaccessoireimb a
where a.refaccessoire.accessoire in ('ballon', 'barre')
)
where deref(utilisation_obj.REFTITREDENUM).titreDeNumero = 'Les Zoupalas' and
deref(utilisation_obj.REFUTILISATEUR).nom = 'Louis';
The error is the following:
inconsistent datatypes: expected CIRQUEOR.LISTEREFACCESS_T got : REF CIRQUEOR.REFACCESSOIRE_T
I found this solution but I was hoping for a more dynamic solution since this one would force me to know how many rows I expect to have
INSERT INTO Utilisation_Obj
Select Ref(N), Ref(P), ListeRefAccess_T(RefAccessoire_T(ref(A1)),RefAccessoire_T(ref(A2)))
From Numeros_Obj N, Personnel_Obj P, Accessoire_Obj A1,Accessoire_Obj A2
Where N.TitreDeNumero = 'Les Zoupalas' and P.Nom = 'Louis' and
A1.accessoire = 'ballon' and A2.accessoire = 'barre';
Related
I need to perform an insert into with select, but DBEAVER is returning the following error:
SQL Error [904] [42000]: ORA-00904:" NR_CARTEIRA ": invalid identifier
Does anyone know what can it be ?
INSERT INTO recem_nascido(
DT_ATENDIMENTO ,
CD_DECLARACAO_NASCIDO_VIVO,
cd_atendimento,
CD_MULTI_EMPRESA,
cd_paciente,
nm_paciente,
CD_ATENDIMENTO_PAI,
dt_nascimento,
nm_mae,
cd_convenio,
NR_CARTEIRA )
SELECT
a.DT_ATENDIMENTO ,
c.CD_DECLARACAO_NASCIDO_VIVO,
a.cd_atendimento,
a.CD_MULTI_EMPRESA,
a.cd_paciente,
b.nm_paciente,
a.CD_ATENDIMENTO_PAI,
b.dt_nascimento,
b.nm_mae,
a.cd_convenio,
a.NR_CARTEIRA
FROM
DBAMV.ATENDIME a,
dbamv.paciente b,
dbamv.recem_nascido c
WHERE
a.CD_ATENDIMENTO = 33079344
AND c.CD_DECLARACAO_NASCIDO_VIVO = 111
AND A.NR_CARTEIRA = 321321321
AND a.cd_atendimento_pai IS NOT NULL
AND a.CD_PACIENTE = b.CD_PACIENTE
AND c.CD_ATENDIMENTO = a.CD_ATENDIMENTO; ```
There are only two options:
The target table recem_nascido has no column NR_CARTEIRA
The table DBAMV.ATENDIME has no column NR_CARTEIRA
Since you only posted the query, but not the table structure, there is no way to narrow this down further.
I have this simple merge statement but it failed when running.
Any advice is appreciated.
MERGE INTO HP.SampleAll as A
USING (
select ALIGNED
from HP.Sample2
) as B
ON (A.md_nbr = B.md_nbr)
WHEN MATCHED THEN UPDATE
SET ALIGNED = A.ALIGNED ;
Error 3810 says that Column does not exist.
md_nbr dont exist in your subquery B - as you don't select it.
Maybe a solution is:
MERGE INTO HP.SampleAll as A
USING (
select ALIGNED, md_nbr
from HP.Sample2
) as B
ON (A.md_nbr = B.md_nbr)
WHEN MATCHED THEN UPDATE
SET ALIGNED = A.ALIGNED ;
or just USING HP.Sample2 as B
I have a stored procedure in which I want to update some columns, so I wrote below code:
PROCEDURE UPDATE_MST_INFO_BKC (
P_SAPID IN NVARCHAR2
) AS
BEGIN
MERGE INTO tbl_ipcolo_billing_mst I
USING (
SELECT
R4G_STATE, -- poilitical state name
R4G_STATECODE, -- poilitical state code
CIRCLE, -- city name
NE_ID,
LATITUDE,
LONGITUDE,
SAP_ID
FROM
R4G_OSP.ENODEB
WHERE
SAP_ID = P_SAPID
AND ROWNUM = 1
)
O ON ( I.SAP_ID = O.SAP_ID )
WHEN MATCHED THEN
UPDATE SET I.POLITICAL_STATE_NAME = O.R4G_STATE,
I.POLITICAL_STATE_CODE = O.R4G_STATECODE,
I.CITY_NAME = O.CIRCLE,
I.NEID = O.NE_ID,
I.FACILITY_LATITUDE = O.LATITUDE,
I.FACILITY_LONGITUDE = O.LONGITUDE,
I.SAP_ID = O.SAP_ID;
END UPDATE_MST_INFO_BKC;
But it is giving me error as
ORA-38104: Columns referenced in the ON Clause cannot be updated: "I"."SAP_ID"
What am I doing wrong?
You are joining the source to destination tables on I.SAP_ID = O.SAP_ID and then, when matched, are trying to update them and set I.SAP_ID = O.SAP_ID. You cannot update the columns used in the join ... and why would you want to as you have already determined that the values are equal.
Just remove the last line of the UPDATE:
...
O ON ( I.SAP_ID = O.SAP_ID )
WHEN MATCHED THEN
UPDATE SET I.POLITICAL_STATE_NAME = O.R4G_STATE,
I.POLITICAL_STATE_CODE = O.R4G_STATECODE,
I.CITY_NAME = O.CIRCLE,
I.NEID = O.NE_ID,
I.FACILITY_LATITUDE = O.LATITUDE,
I.FACILITY_LONGITUDE = O.LONGITUDE;
The error message tells you what the problem is - a MERGE statement cannot update the columns used in the ON clause - and even tells you what column is the problem: "I"."SAP_ID".
So Oracle hurls ORA-38104 because of this line in your WHEN MATCHED branch
I.SAP_ID = O.SAP_ID;
Remove it and your problem disappears. Fortunately the line is unnecessary: I.SAP_ID already equals O.SAP_ID, otherwise the record wouldn't go down the MATCHED branch.
The reason why is quite straightforward: transactional consistency. The MERGE statement operates over a set of records defined by the USING clause and the ON clause. Updating the columns used in the ON clause threatens the integrity of that set, and so Oracle forbids it.
I wish to update a table using, but need to use another table to get the correct field. The new information is not taken from another field from another table.
The following SQL statement returns the correct information:
SELECT PURCHASEHEADER.ORDERNOTES
FROM PURCHASEHEADER, ASSEMBLYLINESOURCE
WHERE ASSEMBLYLINESOURCE.HEADERSYSUNIQUEID = 72637001
AND PURCHASEHEADER.ORDERNUMBER = ASSEMBLYLINESOURCE.PURCHASEORDERNUMBER
I have tried the following:
UPDATE PURCHASEHEADER SET PURCHASEHEADER.ORDERNOTES = 'Updated'
WHERE EXISTS (
SELECT 1 FROM ASSEMBLYLINESOURCE
WHERE PURCHASEHEADER.ORDERNUMBER = ASSEMBLYLINESOURCE.PURCHASEORDERNUMBER
) AND ASSEMBLYLINESOURCE.HEADERSYSUNIQUEID = 72637001
An error is returned saying: " ...Column Unknown ASSEMBLYLINESOURCE.HEADERSYSUNIQUEID..." but it does exist as it works in the first query.
I have seen similar posts from Mark Rotteveel dated July 2017, but still can't get it to work.
There is an issue with your closing bracket. Try this, it worked for me.
UPDATE PURCHASEHEADER set PURCHASEHEADER.ORDERNOTES = 'Updated'
WHERE EXISTS (SELECT 1 FROM ASSEMBLYLINESOURCE WHERE
PURCHASEHEADER.ORDERNUMBER = ASSEMBLYLINESOURCE.PURCHASEORDERNUMBER AND
ASSEMBLYLINESOURCE.HEADERSYSUNIQUEID = 72637001)
Background:
I am wanting to run this merge inside a procedure on a schedule. I have to insert new data into the sql database table and if the data exist, I am wanting to update the quantities.
Problem:
I am trying to do a merge from an Oracle database to a sql database and getting an error (see the title of this question). I have tried using the merge with the same sql script used to create the view and it returned the same error.
Question:
Is the problem something in my code (see below)?
MERGE INTO "receipt_details"#invware d
USING (
SELECT *
FROM raf_po_receiving_details_v
WHERE last_update_date >= '1-AUG-2013' ) s
ON ( "po_header_id" = s.po_header_id
and "po_line_id" = s.po_line_id )
WHEN MATCHED THEN UPDATE
SET "purchased_qty" = s.purchased_qty,
"qty_received" = s.qty_received,
"balance_remaining" = s.balance_remaining,
"qty_billed" = s.qty_billed
WHEN NOT MATCHED THEN INSERT ( "warehouse_code", "po_number", "po_header_id",
"vendor_name", "line_num",
"item_code", "purchased_qty", "qty_received",
"rcv_by", "balance_remaining", "qty_billed",
"closed_code", "rec_date", "need_by_date", "po_line_id" )
VALUES (s.warehouse_code, s.po_number, s.po_header_id, s.vendor_name,
s.line_num, s.item_code, s.purchased_qty, s.qty_received, s.rcv_by,
s.balance_remaining, s.qty_billed, s.closed_code, s.rec_date, s.need_by_date, po_line_id);