Home » SQL & PL/SQL » SQL & PL/SQL » difference in a bind variable and a PL/SQL variable
difference in a bind variable and a PL/SQL variable [message #7306] Tue, 03 June 2003 17:51 Go to next message
Anna
Messages: 30
Registered: March 2001
Member
Can someone help me with understanding the differences between a bind variable and a PL/SQL variable?
Re: difference in a bind variable and a PL/SQL variable [message #7307 is a reply to message #7306] Tue, 03 June 2003 19:00 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
Tom Kyte explains it a lot better than I can and provides examples too. Please click on the links below for some of his explanations and examples. The first link is to a section called "Use bind variables" in Chapter One of his book "Expert One-On-One Oracle". You can read the entire first chapter on-line. The second link is to one of his responses to a question that deals specifically with PL/SQL variables and bind variables. I suggest that you use the first link first to gain a general understanding, then check the second link. You can also search his site for additional examples. The important thing to remember is to use bind variables within the dynamic SQL within your PL/SQL so that the same query is re-used and avoids re-parsing.



Re: difference in a bind variable and a PL/SQL variable [message #7308 is a reply to message #7306] Tue, 03 June 2003 19:02 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
Apparently the first link that I provided just takes you to the first page of the chapter. The section on bind variables begins on page 27.
Re: difference in a bind variable and a PL/SQL variable [message #7309 is a reply to message #7308] Tue, 03 June 2003 20:12 Go to previous message
Hasmukh Daji
Messages: 3
Registered: May 2003
Junior Member
Anna,

I am no ORACLE geek. I had similar question in my mind couple of days ago. Here is a complete paragraph from O'Reilly's "Mastering Oracle SQL" book on Page 303; which in fact I referred to only this morning.

Using Bind Variables:
---------------------
When multiple users use an application, they actually execute the same set of SQL statements over and over, but with different data values. e.g. One customert service representative may be executing the following statements:

SELECT * FROM CUSTOMER WHERE CUST_NBR = 121;

while another customer service representative will be executing:

SELECT * FROM CUSTOMER WHERE CUST_NBR = 328;

These two statements are similar, but not "identical" - the customer ID numbers are different, therefore Oracle has to parse twice.

Because the only difference between these statements is the value used for the customer number, this application could be rewritten to use bind variables. In that case the SQL statement in question could be as follows:

SELECT * FROM CUSTOMER WHERE CUST_NBR = :X;

Oracle needs to parse thsi statement only once. The actual customer numbers would be supplied after parsing for each execution of the statment. Multiple, concurrently executing programs could chare the same copy of this SQL statement while at the same time supplying different customer number values.

In a multi-user application, situations such as the one described here are very common, and overall performance can be significantly improved by using bind varaibels, thereby reducing unnecessary parsing.

*********** END OF PARAGRAPH **************

Hope this helps to answer basic fundamentals of Bind Variables.

Hasmukh Daji
Previous Topic: Error ORA-00439
Next Topic: How to add a row counter while retriving the records
Goto Forum:
  


Current Time: Thu Apr 25 17:28:05 CDT 2024