Solved

bulk collect in dynamic sql

Posted on 2014-10-24
3
271 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

744 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

12 Experts available now in Live!

Get 1:1 Help Now