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.
Related
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';
I am trying to make an update on a temporal table I created in Redshift. The code I am trying to run goes like this:
UPDATE #new_emp
SET rpt_to_emp_id = CAST(ht.se_value AS INTEGER),
rpt_to_extrnl_email = ht.extrnl_email_addr,
rpt_to_fst_nm = ht.first_nm,
rpt_to_lst_nm = ht.last_nm,
rpt_to_mdl_init = ht.mdl_nm,
rpt_to_nm = ht.full_nm,
rpt_to_ssn = CAST(ht.ssn AS INTEGER),
FROM #new_emp,
(SELECT DISTINCT t.se_value,h.first_nm,h.last_nm,
h.mdl_nm,h.full_nm,h.ssn,h.extrnl_email_addr
FROM spec_hr.dtbl_translate_codes_dw t, spec_hr.emp_hron h
WHERE t.inf_name = 'system'
AND t.fld_name = 'HRONDirector'
AND h.foreign_emp_id = t.se_value
) ht
WHERE #new_emp.foreign_emp_id <> ht.se_value
AND (#new_emp.emp_status_cd <> 'T'
AND (#new_emp.ult_rpt_emp_id = #new_emp.foreign_emp_id
OR #new_emp.ult_rpt_emp_id = #new_emp.psoft_id
OR #new_emp.ult_rpt_emp_id IS NULL));
I've tried both with and without specyfing the updated table from the FROM command. But it keeps throwing me this error:
ERROR: Target table must be part of an equijoin predicate
Any ideas why is this failing? Thank you!
Redshift needs an equality join condition to know what value to update and with which values. Your join condition is "#new_emp.foreign_emp_id <> ht.se_value" which is an inequality or Redshift speak - this is not "an equijoin predicate". You have a SET of "rpt_to_lst_nm = ht.last_nm" but if the only join condition is an inequality then which value of last_nm is Redshift putting in the table?
To put it the other way around - you need to tell Redshift exactly which rows of the target table are receiving which values (equijoin). The join condition you have doesn't meet this requirement.
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 create this code
INSERT INTO `ordini`(`ora`, `nome`, `indirizzo`, `numero`, `help`,`ID`,`fattorino`,`dreturn`,`flag`)
VALUES ((SELECT `ora`, `nome`, `indirizzo`, `numero`, `help`,`ID` FROM test.dbconsegne WHERE ID = 2),'STRING','CURRENT_TIMESTAMP','0');
and when i try to Execute the query , The PHPMyAdmin push out this error
Operand should contain 1 colum(s)
why? it's not correct
sorry for my bad english
You dont need VALUES, take it out
INSERT INTO `ordini`(`ora`, `nome`, `indirizzo`, `numero`, `help`,`ID`,`fattorino`,`dreturn`,`flag`)
SELECT `ora`, `nome`, `indirizzo`, `numero`, `help`,`ID`,'STRING',CURRENT_TIMESTAMP,'0' FROM test.dbconsegne WHERE ID = 2
Can you please help me in updating DB2 table and is there a better way to update this huge table? Adv thxs.
UPDATE RT.ITEM IM SET
IM.ITEMNAME = GT.ITEM_D, IM.ITEMSIZE = GT.SIZE, IM.COLOR = GT.COL,
IM.ITEMINFO = GT.ITEM_I WHERE IM.RET = 14 AND IM.LAN = 10 and
IM.ITEMK IN ( SELECT GT.SN_N FROM GD.G_TEMP GT );
Trying to update a table(RT.ITEM) from another schema table(GD.G_TEMP) and getting below error msg:
[Code: -206, SQL State: 42703] DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=GT.ITEM_D
Your code won't work. DB2 doesn't support explicit JOIN in UPDATE. But you can do what you want with a correlated subquery:
UPDATE RT.ITEM IM
SET (ITEMNAME, ITEMSIZE, COLOR, ITEMINFO) =
(SELECT GT.ITEM_D, GT.SIZE, GT.COL, GT.ITEM_I
FROM GD.G_TEMP GT
WHERE GT.SN_N = IM.ITEMK
FETCH FIRST 1 ROW ONLY
)
WHERE IM.RET = 14 AND IM.LAN = 10 AND
EXISTS (SELECT 1
FROM GD.G_TEMP GT
WHERE GT.SN_N = IM.ITEMK
);
Hi you can try with merge command, if distinct don't solve your problems in gd_temp table with multiple rows for single sn_n value then you will have to add more filters in subquery.
MERGE INTO RT.ITEM IM
USING
(SELECT DISTINCT
GT.ITEM_D,
GT.SIZE,
GT.COL,
GT.ITEM_I
FROM GD.G_TEMP gt
) gt on gt.sn_n=im.itemk AND IM.RET = 14 AND IM.LAN = 10
WHEN MATCHED THEN UPDATE
SET (im.ITEMNAME, im.ITEMSIZE, im.COLOR, im.ITEMINFO) = (GT.ITEM_D, GT.SIZE, GT.COL, GT.ITEM_I)