niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Oracle
Multiple updates w. static SQL vs. single dynamic SQL update
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
Author Message
max
*nix forums beginner


Joined: 07 Jul 2006
Posts: 2

PostPosted: Mon Jul 17, 2006 8:52 pm    Post subject: Re: Multiple updates w. static SQL vs. single dynamic SQL update Reply with quote

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

PostPosted: Sun Jul 09, 2006 6:21 pm    Post subject: Re: Multiple updates w. static SQL vs. single dynamic SQL update Reply with quote

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

PostPosted: Sat Jul 08, 2006 12:23 am    Post subject: Re: Multiple updates w. static SQL vs. single dynamic SQL update Reply with quote

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

PostPosted: Fri Jul 07, 2006 10:57 pm    Post subject: Re: Multiple updates w. static SQL vs. single dynamic SQL update Reply with quote

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

PostPosted: Fri Jul 07, 2006 10:07 pm    Post subject: Multiple updates w. static SQL vs. single dynamic SQL update Reply with 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.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
The time now is Sat Nov 22, 2008 2:15 am | All times are GMT
navigation Forum index » Databases » Oracle
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Postfix Multiple Relay Hosts? blaze Postfix 0 Wed Jun 25, 2008 5:02 am
No new posts Deliver msg to multiple hosts jures Postfix 2 Fri Feb 29, 2008 4:21 pm
No new posts Dynamic IP Issues, when Sever is on Fixed. spode Postfix 2 Tue Aug 14, 2007 2:10 pm
No new posts database Share Memory Limit (2 GB ) in a Instance is tota... sadanjan@gmail.com IBM DB2 0 Fri Jul 21, 2006 12:57 pm
No new posts Single Bit Error Correction & Double Eror Detection using... Hari C 3 Fri Jul 21, 2006 11:43 am

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
[ Time: 2.3049s ][ Queries: 20 (2.2126s) ][ GZIP on - Debug on ]