English 中文(简体)
开放时间,使用大体更新,造成内部错误?
原标题:Run time insert using bulk update ,giving an internal error?

我正试图提出一个称为动态的运行时间表,并在索引表上使用大体更新数据,但在我试图执行这一错误时:

ERROR at line 1: ORA-06550: line 0, column 0: PLS-00801: internal error [74301

declare

     type index_tbl_type IS table of
        number
     index by binary_integer;
     num_tbl index_tbl_type;
     TYPE ref_cur IS REF CURSOR;
     cur_emp ref_cur;
    begin
         execute immediate  create table dynamic (v_num number) ;--Creating a run time tabl

         FOR i in 1..10000 LOOP
              execute immediate  insert into dynamic values( ||i|| ) ;--run time insert
         END LOOP;
        OPEN cur_emp FOR  select * from dynamic ;--opening ref cursor
            FETCH cur_emp bulk collect into num_tbl;--bulk inserting in index by table
        close  cur_emp;

        FORALL i in num_tbl.FIRST..num_tbl.LAST --Bulk update
             execute immediate  insert into dynamic values( ||num_tbl(i)|| ) ;
    end;
问题回答

所有声明均希望发表一份内容表——INSERT、UPDATE或DELETE。 EXECUTE IMMEDIATE是一份PL/SQL声明,因此,你的法典正在对这一例外进行hur击。

种植这种猎物并不是生产的良好想法。 表格应当使用DDL的文字而不是动态。

不管怎样,如果你想以这种充满活力的方式做一些事情的话,这就是如何做到:

第1步:创建一种可用于“质量标准”声明的“质量标准”

SQL> create or replace type my_nums as table of number
  2  /

Type created.

SQL>

步骤2:采用表格类型而不是PL/SQL。 我已将“所有”条款改写成一个动态的INSERT声明,使用TABLE()条款中的收集方法。

SQL> declare
  2
  3        num_tbl my_nums;
  4        TYPE ref_cur IS REF CURSOR;
  5        cur_emp ref_cur;
  6  begin
  7      execute immediate  create table dynamic (v_num number) ;
  8
  9      FOR i in 1..10000 LOOP
 10           execute immediate  insert into dynamic values( ||i|| ) 
 11      END LOOP;
 12      OPEN cur_emp FOR  select * from dynamic ;
 13      FETCH cur_emp bulk collect into num_tbl;
 14      close  cur_emp;
 15
 16      execute immediate 
 17          insert into dynamic select * from table(:1)  using num_tbl;
 18  end;
 19  /

PL/SQL procedure successfully completed.

SQL>

步骤3:

SQL> select count(*) from dynamic
  2  /

  COUNT(*)
----------
     20000

SQL>
DECLARE

            TYPE numlist is table of number index by binary_integer;

            var_num numlist;

BEGIN

            for i in 1..1000 loop

                        var_num(i):=i;

            end loop;

            EXECUTE IMMEDIATE  create table exe_table(col1 number(10)) ;

            forall i in var_num.first..var_num.last

                        EXECUTE IMMEDIATE  INSERT INTO exe_table values(:P)  USING var_num(i);

end loop; 

WHY 当时工作吗?





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签