Solved

bulk collect in dynamic sql

Posted on 2014-10-24
3
273 Views
Last Modified: 2015-04-08
Why is the syntax for returning the column values as a collection so complicated when using dynamic sql in pl/sql?

For example why is the syntax like:

EXECUTE IMMEDIATE 'DELETE FROM bulk_collect_test RETURNING object_id INTO :1' returning bulk collect into l_tab;

And not like:

EXECUTE IMMEDIATE 'DELETE FROM bulk_collect_test RETURNING object_id BULK COLLECT INTO :1' USING l_tab(i);

Basically why do we need to use RETURNING clause twice - once returning the object_id values into :1 and once again returning bulk collect.
Also how does oracle substitute the bind variable :1 i.e. how does it correlate the variable :1 and the collection l_tab?

By learning the right syntax I can write the statement correctly but wanted to understand the reason the syntax was not made any simpler.

Thanks in advance.
0
Comment
Question by:subratoc
  • 2
3 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40402048
First question I have is:
Why are you using 'execute immediate' with a delete statement?

My guess for the two returning clauses:  Scope.

execute immediate has its own syntax and the statement executed by it has its own syntax.

Again, this is only a guess.
0
 

Author Comment

by:subratoc
ID: 40411095
Actually I was trying to learn how to bulk collect the values of a column while deleting using dynamic sql.
I may never need to use this in real life but was just curious about the syntax.
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40411158
I'm not seeing the need to delete using dynamic SQL.  If you want to learn something that will likely never come up, then by all means, go ahead.

As far as the question asked:  but wanted to understand the reason the syntax was not made any simpler.

I cannot say.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now