Home > database >  Oracle insert group by problems
Oracle insert group by problems

Time:09-21

Declare
V_F1 pls_integer:=0;
The begin
Insert into TABLE1 (F1, F2 and F3)
The select v_F1, A.F 2, sum (A.F (3) as the F3
The from TABLE2 A
Group by F2;
end;

Such syntax, can quote "not GROUP BY expression", if the select v_F1 behind with constant can be directly, but the same syntax, in essentially, there is no problem, ask for help!

CodePudding user response:

Should not be.

Is not add to the group by v_F1 inside, have no effect

CodePudding user response:

Add v_F1 group by the same mistake

CodePudding user response:

Understand the error,
Table1 if there is a field in the table. The default value is sequence nextval, the above statement execution time will be submitted to the group by expression errors, Oracle version of 12 c, it is a little pit dad, how to solve? The great god help!

CodePudding user response:

If the select listed behind the field variables, or change the variables to a constant, is not an error,

CodePudding user response:

 
Declare
V1_1 number:=22;
The begin
Insert into cs1. T2 select v1_1 bm1, bm2, sum (sl2) from cs1. T1 group by bm1, bm2.
/* for rr (in the select v1_1 bm1, bm2, sum (sl2) as nn from cs1. T1 group by bm1, bm2)
Loop
Dbms_output. Put_line (' v1_1 '| | rr. V1_1 | |' bm1 '| | rr. Bm1 | |' bm2 '| | rr. Bm2 | |' sum '| | rr. The nn);
Insert into cs1. T2 values (rr) v1_1, rr. Bm1, rr. Bm2, rr, nn);
End loop;
*/
end;
11.2 test no problem,

12.2.0.1
The measure also ok
The create user cs1 identified by cs1.
Grant dba to cs1;
CREATE TABLE "CS1." "T1"
(" BM1 "VARCHAR2 (20),
"BM2" VARCHAR2 (20),
"SL1" NUMBER (*, 0),
"SL2" NUMBER (*, 0),
"SJ" NUMBER (*, 0)
)
The create table cs1. T2 (n1 number, n2 varchar (50), n3 varchar (50), n4 interchange number)
Select * from cs1. T1 - for update;

BM1 BM2 SL1 SL2 SJ
A101 a01 200 20 1
A101 a01 200 30 2
A101 a01 200 50 3
A101 a01 200 100 4
A102 a03 210 80 1

Select * from cs1. T2;
Declare
V1_1 number:=22;
The begin
Insert into cs1. T2 select v1_1 bm1, bm2, sum (sl2) from cs1. T1 group by bm1, bm2.
commit;
end;
Select * from cs1. T2

CodePudding user response:

The select v_F1, A.F 2, sum (A.F (3) as the F3
The from TABLE2 A
Group by F2;

CodePudding user response:

 insert into TABLE1 (F1, F2 and F3) 
Select v_F1 t.F, 2, 3 (t.F select A.F 2, sum (A.F (3) as the F3
The from TABLE2 A
Group by F2) t;
  • Related