Execute Immediate

Este forum é dedicado a códigos errados que se encontram por aí, ou seja, coisas que não se deve fazer de jeito nenhum! Não coloque neste forum dúvidas! (apenas situações bizarras do nosso dia a dia :-)
Post Reply
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Someone explains to me why using Immediate execute in this command?

Select all

EXECUTE IMMEDIATE 'DELETE tabela WHERE SUPPLIER_CCN = :CCN' USING P_CCN;
Why did not you direct the delete?

Select all

DELETE tabela WHERE SUPPLIER_CCN = P_CCN; 
:(
diegolenhardt
Moderador
Moderador
Posts: 1177
Joined: Thu, 15 Oct 2009 10:28 am
Location: Recife

I think to reuse the cached instruction,

making only BIND,

: D

should execute various times DELETE, just exchanging parameter não é??

In relation to performance this is great ...

;)
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

It does not run several times ... Should rotate 1 time a day :-(

Another thing:
The BIND is also used here:

Select all

DELETE tabela WHERE SUPPLIER_CCN = P_CCN;
This P_CCN is a procedure parameter. It is the most clean form of SQL command ...


I agree that this

Select all

EXECUTE IMMEDIATE 'DELETE tabela WHERE SUPPLIER_CCN = :CCN' USING P_CCN;
is much better than this:

Select all

EXECUTE IMMEDIATE 'DELETE tabela WHERE SUPPLIER_CCN='|| P_CCN;

But I think a direct delete is better yet ...

Select all

DELETE tabela WHERE SUPPLIER_CCN = P_CCN;
diegolenhardt
Moderador
Moderador
Posts: 1177
Joined: Thu, 15 Oct 2009 10:28 am
Location: Recife

It's true, it seems that there's not much sense, if you say you use bind in the normal delete, it would be in the same same, even more being that it is once soo a day, no need for such ..
99]]
=]
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Yes, in a SQL like this, using variables, Oracle transforms the variables to BIND automatically.

If you run a trace, you will see that you can not see the value of the variables, only SQL. Where you have variables, it alters to: 1,: 2, etc ... -> Binds.

Oracle Rocks.

: -O
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 16 guests