|
|
|
|
|
|
| Author |
Message |
max *nix forums beginner
Joined: 07 Jul 2006
Posts: 2
|
Posted: Mon Jul 17, 2006 8:52 pm Post subject:
Re: Multiple updates w. static SQL vs. single dynamic SQL update
|
|
|
Daniel, thanks for your reply. I got this from the the "Complex IN
Demo":
DECLARE
i PLS_INTEGER;
InStr VARCHAR2(20) := '10,30';
BEGIN
SELECT COUNT(*)
INTO i
FROM emp
WHERE deptno IN (InStr);
dbms_output.put_line(i);
END;
/
This will never work. Assuming deptno is a number you'll get ORA-01722
Invalid Number.
What happens is Oracle tries to convert InStr which is '10,30' to a
number and it can't. It will not try to parse it into 10 and 30 and put
those as the IN clause parameters.
The CAST example is good but we found it would kill the indexes, making
update expensive.
The question is more theoretic. I would like to know what is more
expensive hitting the table a 1000 times to update 1 record at a time
or go with a dynamic SQL with the expense of it being compiled along
with the execution plan being calculated every time the procedure is
executed.
Thanks.
DA Morgan wrote:
| Quote: | max wrote:
Hi,
What would be better (faster):
1.have a stored procedure loop thru a list of values and execute a
statement:
update customers
set active = 1
where customer_code = value
2. create a comma delimited string of values like so:
list := value1 || ',' || value2 || ',' || value3....
and using it in a dynamic SQL like so:
v_sql = 'update customers
set active = 1
where customer_code in ( ' || list || ')'
Thanks.
Single row processing, by definition, is always a bad idea so throw away
the loop if there is an alternative.
Native dynamic SQL is never a first choice so that's not necessarily the
best idea either.
What is impossible to tell from what you've written is why you need
either. Go to www.psoug.org and click on Morgan's Library. Click on
"Conditions" and scroll down to "Complex IN Demo."
Why won't this work?
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org |
|
|
| Back to top |
|
 |
psoug *nix forums Guru
Joined: 15 May 2005
Posts: 3492
|
Posted: Sun Jul 09, 2006 6:21 pm Post subject:
Re: Multiple updates w. static SQL vs. single dynamic SQL update
|
|
|
Malcolm Dew-Jones wrote:
| Quote: | How about 3.
insert the values to be selected into a global temporary table and then
update customers
set active = 1
where customer_code in
( select selected_code from my_selection_table
)
|
Check out the demo I referenced ... inserting into a table is unnecessary.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org |
|
| Back to top |
|
 |
Malcolm Dew-Jones *nix forums Guru
Joined: 04 Mar 2005
Posts: 418
|
Posted: Sat Jul 08, 2006 12:23 am Post subject:
Re: Multiple updates w. static SQL vs. single dynamic SQL update
|
|
|
max (cccp.forever@gmail.com) wrote:
: Hi,
: What would be better (faster):
: 1.have a stored procedure loop thru a list of values and execute a
: statement:
: 2. create a comma delimited string of values like so:
: list := value1 || ',' || value2 || ',' || value3....
: and using it in a dynamic SQL like so:
: v_sql = 'update customers
: set active = 1
: where customer_code in ( ' || list || ')'
How about 3.
insert the values to be selected into a global temporary table and then
update customers
set active = 1
where customer_code in
( select selected_code from my_selection_table
) |
|
| Back to top |
|
 |
psoug *nix forums Guru
Joined: 15 May 2005
Posts: 3492
|
Posted: Fri Jul 07, 2006 10:57 pm Post subject:
Re: Multiple updates w. static SQL vs. single dynamic SQL update
|
|
|
max wrote:
| Quote: | Hi,
What would be better (faster):
1.have a stored procedure loop thru a list of values and execute a
statement:
update customers
set active = 1
where customer_code = value
2. create a comma delimited string of values like so:
list := value1 || ',' || value2 || ',' || value3....
and using it in a dynamic SQL like so:
v_sql = 'update customers
set active = 1
where customer_code in ( ' || list || ')'
Thanks.
|
Single row processing, by definition, is always a bad idea so throw away
the loop if there is an alternative.
Native dynamic SQL is never a first choice so that's not necessarily the
best idea either.
What is impossible to tell from what you've written is why you need
either. Go to www.psoug.org and click on Morgan's Library. Click on
"Conditions" and scroll down to "Complex IN Demo."
Why won't this work?
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org |
|
| Back to top |
|
 |
max *nix forums beginner
Joined: 07 Jul 2006
Posts: 2
|
Posted: Fri Jul 07, 2006 10:07 pm Post subject:
Multiple updates w. static SQL vs. single dynamic SQL update
|
|
|
Hi,
What would be better (faster):
1.have a stored procedure loop thru a list of values and execute a
statement:
update customers
set active = 1
where customer_code = value
2. create a comma delimited string of values like so:
list := value1 || ',' || value2 || ',' || value3....
and using it in a dynamic SQL like so:
v_sql = 'update customers
set active = 1
where customer_code in ( ' || list || ')'
Thanks. |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Sat Nov 22, 2008 2:15 am | All times are GMT
|
|
Property in Spain | Mobile Phones | Secured Loans | Credit Counseling | Free Cingular Ringtones
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|