Home > database >  Write a procedure, using a cursor, bulk import data submitted to the PL/SQL: ORA - 00947: there is n
Write a procedure, using a cursor, bulk import data submitted to the PL/SQL: ORA - 00947: there is n

Time:09-27

I novice a, write a stored procedure, the complete code is as follows, there is no actual effect, don't give me how to write better, I want to 50 submitted once,
The create or replace procedure piciCommit as
V_count number;
V_num number;
The BEGIN
V_count:=0;
V_num:=1;
- for cur in (select * from emp) loop - if you use these two lines, can normal compile, run normally,
- insert into emp1 values cur;
- * * * * * * * * * in the following two lines of compile time can not have the enough value to error, but the same number of columns, emp1 table structure and the emp table exactly the same, all columns allow null, allowed to repeat,
For cur in (select empno, ename, job, sal, deptno from emp) loop
Insert into emp1 (empno, ename, job, sal, deptno) values cur;
- * * * * * * * * * * * * * * * * *
V_count: v_count +=1;
Dbms_output. Put_line (' first '| | v_count | |' a ');
If v_count & gt;=50 then
Dbms_output. Put_line (' -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the first '| | v_num | |' commit -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ');
V_num:=v_num + 1;
commit;
V_count:=0;
end if;
End loop;
Dbms_output. Put_line (' -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the first '| | v_num | |' commit -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ');
commit;
The end;

Also please the great god to have a look, thanks!

CodePudding user response:

CodePudding user response:

Insert into emp1 (empno, ename, job, sal, deptno) values cur; To insert into emp1 values cur; It is ok

CodePudding user response:

refer to the second floor u012556249 response:
insert into emp1 (empno, ename, job, sal, deptno) values cur; To insert into emp1 values cur; It is ok to


No, I know the answer has been in baidu, should put the insert into emp1 (empno, ename, job, sal, deptno) values cur;
This line of code to the
Insert into emp1 (empno, ename, job, sal, deptno) values (cur. Empno, cur. Ename, cur. Job, cur. Sal, cur, deptno);
Went, he reported to the error when the insert statement do not match the number of values and the number of columns, not two tables do not match the number of fields, is my carelessness,

CodePudding user response:

reference qq_38756843 reply: 3/f
Quote: refer to the second floor u012556249 response:

Insert into emp1 (empno, ename, job, sal, deptno) values cur; To insert into emp1 values cur; It is ok to


No, I know the answer has been in baidu, should put the insert into emp1 (empno, ename, job, sal, deptno) values cur;
This line of code to the
Insert into emp1 (empno, ename, job, sal, deptno) values (cur. Empno, cur. Ename, cur. Job, cur. Sal, cur, deptno);
Went, when he reported to the error number and the number of columns in the insert statement of values, not two tables do not match the number of fields, is my carelessness,


And you this kind of writing is not standard, the normal mode in open cursor, select into and insert into the close cursor this model is more easy to understand, also have better line fault and readability
  • Related