SQL Operand Should contain 1 colums PHPMYAdmin - sql

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

Related

Postgres: on conflict, summing two vectrors(arrays)

I'm trying to handle an array of counters column in Postgres
for example, let's say I have this table
name
counters
Joe
[1,3,1,0]
and now I'm adding 2 values ("Ben", [1,3,1,0]) and ("Joe",[2,0,2,1])
I expect the query to sum between the 2 counters vectors on conflict ([1,3,1,0] + [2,0,2,1] = [3,3,3,1])
the expected result:
name
counters
Joe
[3,3,3,1]
Ben
[1,3,1,0]
I tried this query
insert into test (name, counters)
values ("Joe",[2,0,2,1])
on conflict (name)
do update set
counters = array_agg(unnest(test.counters) + unnest([2,0,2,1]))
but it didn't seem to work, what am I missing?
There are two problems with the expression:
array_agg(unnest(test.counters) + unnest([2,0,2,1]))
there is no + operator for arrays,
you cannot use set-valued expressions as an argument in an aggregate function.
You need to unnest both arrays in a single unnest() call placed in the from clause:
insert into test (name, counters)
values ('Joe', array[2,0,2,1])
on conflict (name) do
update set
counters = (
select array_agg(e1 + e2)
from unnest(test.counters, excluded.counters) as u(e1, e2)
)
Also pay attention to the correct data syntax in values and the use of a special record excluded (find the relevant information in the documentation.)
Test it in db<>fiddle.
Based on your reply to my comments that it will always be four elements in the array and the update is being done by a program of some type, I would suggest something like this:
insert into test (name, counters)
values (:NAME, :COUNTERS)
on conflict (name) do
update set
counters[1] = counters[1] + :COUNTERS[1],
counters[2] = counters[2] + :COUNTERS[2],
counters[3] = counters[3] + :COUNTERS[3],
counters[4] = counters[4] + :COUNTERS[4]

Error while Trying to update an Oracle nested table

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';

INSERT INTO WITH SELECT and WHERE (Problem)

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.

Oracle SQL Insert external values

I'm having problems to add some values to a table. The query that i'm using is this one:
INSERT INTO ACTUAR
(CAPITULO,TEMPORADA,COD_GRUPO,COD_LOC)
SELECT NUM_CAP,NUM_TEMPO,CODIGO_GRUPO,CODIGO_LOC
FROM COMENTAR
MINUS
SELECT CAPITULO,TEMPORADA,COD_GRUPO, COD_LOC
FROM ACTUAR;
The ACTUAR table has 2 more values, which I want to add from a value on COMENTAR like this:
NVL(SUBSTR(COMENTARIO,0,10),'SIN PROBLEMA'),
NVL(SUBSTR(COMENTARIO,LENGTH(COMENTARIO)-4),'SIN SOLUCION')
Actuar table
CAPITULO,TEMPORADA,COD_GRUPO,COD_LOC,PROBLEMA,SOLUCION
Comentar table
NUM_CAP,NUM_TEMPO,CODIGO_GRUPO,CODIGO_LOC,COMENTARIO
I want to put the first 10 chars of COMENTARIO on ACTUAR'S PROBLEMA and the last 4 on ACTUAR'S SOLUCION or the text in the nvl if they are null.
I want to insert the result of the minus operation on ACTUAR plus the 10 first chars of COMENTARIO from COMENTAR into ACTUAR'S PROBLEMA and the last 4 on ACTUAR'S SOLUCION
The desired result should be something like
ACTUAR
CAPITULO,TEMPORADA,COD_GRUPO, and COD_LOC the values from the minus operation.
PROBLEMA - first 10 chars of COMENTAR COMENTARIO
SOLUCION - last 4
This solution worked for me. I used merge statement, without update clause.
merge into actuar a
using (
select num_cap, num_tempo, codigo_grupo, codigo_loc,
nvl(substr(comentario,1,10),'SIN PROBLEMA') prob,
nvl(substr(comentario, greatest(length(comentario)-4, 1)),'SIN SOLUCION') sol
from comentar) c
on (a.capitulo = c.num_cap and a.temporada = c.num_tempo
and a.cod_grupo = c.codigo_grupo and a.cod_loc = c.codigo_loc)
when not matched then insert (a.capitulo, a.temporada, a.cod_grupo,
a.cod_loc, a.problema, a.solucion)
values (c.num_cap, c.num_tempo, c.codigo_grupo, c.codigo_loc, c.prob, c.sol)

Oracle DB trigger compiles with warnings. No error available

This is my first db trigger. It compiles with warnings and therefore doesn't work. I've re-read the Oracle docs and searched online but can't work out where I'm going wrong. Any help with my trigger below would gratefully received.
CREATE OR REPLACE TRIGGER oa_mhd_update AFTER
INSERT ON men_mhd FOR EACH row WHEN (new.mhd_tktc LIKE 'OA_A_%'
OR new.mhd_tktc LIKE 'OA_T_%'
OR new.mhd_tktc LIKE 'OA_M_%')
DECLARE seq_var NVARCHAR2 (20);
BEGIN
SELECT (MAX (seq) + 1) into seq_var FROM oa_mhd_data;
INSERT
INTO oa_mhd_data
(
mhd_code,
seq,
mhd_mst1,
mhd_mst2,
mhd_cred,
mhd_cret,
mhd_tsks,
mhd_msgs,
mhd_tktc,
mhd_tref,
mhd_actn,
mhd_eref,
mhd_subj,
mhd_udf1,
mhd_udf2,
mhd_udf3,
mhd_udf4,
mhd_udf5,
mhd_udf6,
mhd_udf7,
mhd_udf8,
mhd_udf9,
mhd_udfa,
mhd_udfb,
mhd_udfc,
mhd_udfd,
mhd_udfe,
mhd_udff,
mhd_udfg,
mhd_udfh,
mhd_udfi,
mhd_udfj,
mhd_udfk,
mhd_updd,
mhd_begd,
mhd_begt,
mhd_endd,
mhd_endt,
mhd_mrcc,
mhd_mhdc,
mhd_mscc,
mhd_pprc,
mhd_ppss,
mhd_inst
)
VALUES
(
:new.mhd_code
seq_var,
:new.mhd_mst1,
:new.mhd_mst2,
:new.mhd_cred,
:new.mhd_cret,
:new.mhd_tsks,
:new.mhd_msgs,
:new.mhd_tktc,
:new.mhd_tref,
:new.mhd_actn,
:new.mhd_eref,
:new.mhd_subj,
:new.mhd_udf1,
:new.mhd_udf2,
:new.mhd_udf3,
:new.mhd_udf4,
:new.mhd_udf5,
:new.mhd_udf6,
:new.mhd_udf7,
:new.mhd_udf8,
:new.mhd_udf9,
:new.mhd_udfa,
:new.mhd_udfb,
:new.mhd_udfc,
:new.mhd_udfd,
:new.mhd_udfe,
:new.mhd_udff,
:new.mhd_udfg,
:new.mhd_udfh,
:new.mhd_udfi,
:new.mhd_udfj,
:new.mhd_udfk,
:new.mhd_updd,
:new.mhd_begd,
:new.mhd_begt,
:new.mhd_endd,
:new.mhd_endt,
:new.mhd_mrcc,
:new.mhd_mhdc,
:new.mhd_mscc,
:new.mhd_pprc,
:new.mhd_ppss,
:new.mhd_inst
)
END;
/
You're missing a comma between the first two elements of the values clause, and a semi-colon at the end of the insert statement:
VALUES
(
:new.mhd_code
seq_var,
:new.mhd_mst1,
...
:new.mhd_ppss,
:new.mhd_inst
)
... should be:
VALUES
(
:new.mhd_code,
seq_var,
:new.mhd_mst1,
...
:new.mhd_ppss,
:new.mhd_inst
);
Odd that you can't see the error though.
Incidentally, the max(seq) + 1 from ... pattern isn't reliable in a multi-user environment. It would be more normal (and safer) to use a proper sequence to generate that value.
Hi there are two syntactical errors
First please add a comma between two values you are inserting
VALUES
(
:new.mhd_,
seq_var,
:new.mhd_mst1,...
and second please add a semi colon at he end of insert statement
...
:new.mhd_pprc,
:new.mhd_ppss,
:new.mhd_inst
);
Hope this will solve your problem