Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> 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:
> 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.
>
>
>
>