Question

I am new to PL/SQL and I was wondering if I can use result of a bulk collect like this:

Declare
type result_bulk_type is Table of table1.ID%type;
result_bulk result_bulk_type;
BEGIN
SELECT id BULK COLLECT INTO result_bulk FROM table1;
UPDATE table2 SET status=1 WHERE id IN result_bulk;
END;

I got errors at compilation:

PL/SQL: SQL statement ignored

PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got SYS_PLSQL_22223_23_1

Thanks for your help!

Était-ce utile?

La solution

No, it can't be done in this way. Use FORALL statement instead.
Read this: http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/forall_statement.htm#LNPLS01321

An example:

Declare
  type result_bulk_type is Table of table1.ID%type;
  result_bulk result_bulk_type;
BEGIN
  SELECT id BULK COLLECT INTO result_bulk FROM table1;
  FORALL i IN INDICES OF result_bulk
    UPDATE table2 SET status=1 WHERE id = result_bulk( i );
END;
/

demo: http://sqlfiddle.com/#!4/b3a72/1

Autres conseils

Use 'WHERE id MEMBER OF result_bulk'

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top