11.07.2015 Views

Oracle Database 11 g - Online Public Access Catalog

Oracle Database 11 g - Online Public Access Catalog

Oracle Database 11 g - Online Public Access Catalog

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER <strong>11</strong> ■ APPLICATION DEVELOPMENT 463Bulk In-Bind Table of Records in FORALLBefore <strong>Oracle</strong> <strong>Database</strong> <strong>11</strong>g, attempts to use a table of records, as shown here, would result inthe following error:DECLARECURSOR c1 IS SELECT rowid,bar FROM foo ;TYPE rows_t IS TABLE OF c1%ROWTYPE;rows rows_t;BEGINOPEN c1;FETCH c1 BULK COLLECT INTO rows;-- modify bar attribute of rows tableFORALL I IN rows.COUNTUPDATE fooSET bar=rows(i).barWHERE rowid=rows(i).rowid;...END;/The output of the previous PL/SQL block produces the following error:PLS-00436: implementation restriction:cannot reference fields of BULK In-BIND table of recordsPL/SQL did not support tables of records, which is why we used rows(i).bar androws(i).rowid, while a more natural syntax was not allowed. The workaround was to createseparate collections for each column, as shown here:DECLARECURSOR c1 IS SELECT rowid.bar from foo;TYPE rowID_t IS TABLE OF ROWID;TYPE bar_t IS TABLE of foo.bar%TYPE;rids rowId_t;bars bar_t;...BEGIN...FETCH c1 BULK COLLECT INTO rids,bars;....FORALL I IN rows.COUNTUPDATE fooSET bar=bars(i)WHERE rowid=rids(i);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!