Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

bulk collect in dynamic sql

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

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 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

789 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