WELCOME, GUEST
Minimize
Blogger List

Steven Feuerstein Indicates Oracle ACE director status
PL/SQL Obsession

Guy Harrison Indicates Oracle ACE status
Database topics

Bert Scalzo Indicates Oracle ACE status
Toad for Oracle, Data Modeling, Benchmarking
Dan Hotka Indicates Oracle ACE director status
SQL Tuning & PL/SQL Tips

Valentin Baev
It's all about Toad

Ben Boise
Toad SC Discussions

Dan Clamage
SQL and PL/SQL

Kevin Dalton
Benchmark Factory

Peter Evans 
Business Intelligence, Data Integration, Cloud and Big Data

Vaclav Frolik  
Toad Data Modeler, Toad Extension for Eclipse

Devin Gallagher
Toad SC discussions

Anju Gandhi
Toad for Oracle

Stuart Hodgins
JProbe Discussions

Julie Hyman
Toad for Data Analysts

  Henrik "Mauritz" Johnson
Toad Tips & Tricks on the "other" Toads
  Mark Kurtz
Toad SC discussions
Daniel Norwood
Tips & Tricks on Toad Solutions
Amit Parikh
Toad for Oracle, Benchmark Factory,Quest Backup Reporter
Debbie Peabody
Toad Data Point
Gary Piper
Toad Reports Manager
John Pocknell
Toad Solutions
Jeff Podlasek
Toad for DB2
Kuljit Sangha
Toad SC discussions
Michael Sass 
Toad for DB2
Brad Wulf
Toad SC discussions
Richard To
SQL Optimization
  Toad Data Modeler Opens in a new window
Data Modeling
 
  Toad Higher Education
How Hi-Ed Uses Toad
  Real Automated Code Testing for Oracle
Quest Code Tester blog
  中文技术资料库
技术文章
 

Blogs

Toad World blogs are a mix of insightful how-tos from Quest experts as well as their commentary on experiences with new database technologies.  Have some views of your own to share?  Post your comments!  Note:  Comments are restricted to registered Toad World users.

Do you have a topic that you'd like discussed?  We'd love to hear from you.  Send us your idea for a blog topic.


Aug 22

Written by: StevenFeuersteinTW
Wednesday, August 22, 2007 7:41 AM  RssIcon

Kudos to Alex Nuijten for bringing this gem to light, he wrote in his latest AMIS blog entry that:

"If you are a regular user of the FORALL statement, you are probably also familiar with this message:

PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records

While I was playing around on our Oracle 11g database, I found that this restriction was lifted. How cool is that?"

You are right, Alex, that is very cool. When I read it, I thought to myself, "very cool, but is it supported? Is it really going to be in the final, production version of Oracle11g?" 

Who better to know than Bryn Llewellyn, Oracle PL/SQL Product Manager? So I asked him and here is his reply:

Regarding 

PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records or objects
Cause: table(bulk_index).field is not supported at run-time.
Action: Use FOR loop with instead of the FORALL DML statement (MERGE/INSERT/DELETE/UPDATE).

We have made improvements in this area in response to ER #5186976. Sadly, the documentation was not edited to reflect this, so you'll still find this:

<<
You cannot refer to individual record fields within DML statements invoked by a FORALL statement. Instead, you can specify the entire record with the SET ROW clause in an UPDATE statement, or the VALUES clause in an INSERT statement.
>>

in the 11. PL/SQL Language Reference in Chapter13. PL/SQL Language Elements, in the section titled "FORALL Statement". I just filed doc bug #6355690 to complain about this.
______________________________________________________________________

The following illustrates the changes.

Create a user with tables Emp (CREATE TABLE AS SELECT from Scott.Emp) and Newemp (CREATE TABLE AS SELECT from Emp where 0=1). Use a block with this shape:

declare
  type empcol_t is table of emp%rowtype index by pls_integer;
  empcol empcol_t;
begin
  select * bulk collect into empcol from emp
    where hiredate < to_date('01-JAN-1982', 'DD-MON-YYYY');

  for i in empcol.first..empcol.last loop
    empcol(i).sal := empcol(i).sal * 1.1;
  end loop;

  < test >
end;

Use Case #1: Update rows where some key value (empno in this case) matches the key value in the record bind into the bulk DML operation.

  forall i in empcol.first..empcol.last
    update emp set row = empcol(i)
      where empno = empcol(i).empno;

This failed to compile in 10.2 with PLS-00436; it compiles and runs fine in 11.1.

Use Case #3: Update a subset of columns in the SET clause with values from the record in bind into the bulk DML operation.


  forall i in empcol.first..empcol.last
    update emp set (sal) = empcol(i).sal
      where empno = empcol(i).empno;

This failed to compile in 10.2 with PLS-00436; it compiles and runs fine in 11.1.

Use Case #4: Variant on Use Case #3, but with insert statement.

  forall i in empcol.first..empcol.last
    insert into newemp (empno, ename, sal)
      values (empcol(i).empno, empcol(i).ename, empcol(i).sal);

This failed to compile in 10.2 with PLS-00436; it compiles and runs fine in 11.1.

NOTE: Use Case #2 still fails to compile. Allow attribute reference in a returning clause.


  forall i in empcol.first..empcol.last
    update emp set row = empcol(i)
      where empno = empcol(i).empno
      returning sal bulk collect into empcol(i).sal;

This failed to compile in 10.2 with PLS-00436; it fails to compile in 11.1 with this error:

PLS-00437: FORALL bulk index cannot be used in RETURNING clause.

Bryn concludes with this exciting news:

You can regard this as the official reply from Oracle's PL/SQL Product Manager: the improvements brought by ER #5186976 are supported from 11.1.0.6 onwards. 

So there you have it, folks! You can reference fields of records in collections that are bound into the DML statement of a FORALL statement – in Oracle11g.

Tags:
Categories:

2 comment(s) so far...


Re: Undocumented But Supported Feature In Oracle11g: Reference Fields Of Records In A FORALL Statement!

Are you sure it's "Bryn.Llewellyn@quest.com"? Or is that just wishful thinking? ;-)

By alexnuijten on   Thursday, August 30, 2007 7:15 AM

Re: Undocumented But Supported Feature In Oracle11g: Reference Fields Of Records In A FORALL Statement!

Yikes! OK, fixed that.... SF

By StevenFeuersteinTW on   Monday, September 17, 2007 3:46 PM
Search Blog Entries
 
Blog Archives
 
Archive
<May 2013>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Monthly
May, 2013 (15)
April, 2013 (13)
March, 2013 (10)
February, 2013 (5)
January, 2013 (7)
December, 2012 (6)
November, 2012 (10)
October, 2012 (8)
September, 2012 (6)
August, 2012 (8)
July, 2012 (8)
June, 2012 (12)
May, 2012 (21)
April, 2012 (10)
March, 2012 (16)
February, 2012 (19)
January, 2012 (20)
December, 2011 (19)
November, 2011 (14)
October, 2011 (12)
September, 2011 (17)
August, 2011 (15)
July, 2011 (16)
June, 2011 (13)
May, 2011 (15)
April, 2011 (8)
March, 2011 (21)
February, 2011 (17)
January, 2011 (16)
December, 2010 (13)
November, 2010 (13)
October, 2010 (7)
September, 2010 (15)
August, 2010 (11)
July, 2010 (13)
June, 2010 (12)
May, 2010 (14)
April, 2010 (12)
March, 2010 (13)
February, 2010 (12)
January, 2010 (7)
December, 2009 (10)
November, 2009 (12)
October, 2009 (15)
September, 2009 (18)
August, 2009 (13)
July, 2009 (23)
June, 2009 (14)
May, 2009 (17)
April, 2009 (7)
March, 2009 (14)
February, 2009 (7)
January, 2009 (12)
December, 2008 (7)
November, 2008 (11)
October, 2008 (19)
September, 2008 (14)
August, 2008 (11)
July, 2008 (14)
June, 2008 (19)
May, 2008 (12)
April, 2008 (18)
March, 2008 (13)
February, 2008 (8)
January, 2008 (7)
December, 2007 (5)
November, 2007 (8)
October, 2007 (13)
September, 2007 (13)
August, 2007 (16)
July, 2007 (11)
June, 2007 (6)
May, 2007 (5)
April, 2007 (5)
March, 2007 (8)
February, 2007 (6)
January, 2007 (6)
December, 2006 (5)
November, 2006 (8)
October, 2006 (4)
August, 2006 (3)