Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Newbie needs help with dynamic column name in SQL

Re: Newbie needs help with dynamic column name in SQL

From: Martin Doherty <martin.doherty_at_elcaro.moc>
Date: Fri, 15 Nov 2002 20:26:21 -0800
Message-ID: <DRjB9.10$GH3.83@news.oracle.com>


Is your table name or WHERE clause also dynamic? Because if it isn't I don't see any point in updating the same rows 20 times in a loop - just issue a single UPDATE that updates all 20 columns at the same time.

Maybe you could expand a little bit on the business problem that is causing you to ask the question, and possibly even mention the version of Oracle you are working with (Yes, it DOES matter).

Martin Doherty

K. C. wrote:

>Hi,
>
>I have a table with 20 columns like this:
>
>Field1, Field2, Field3....Field20
>
>I want to do this:
>
>i:=1;
>WHILE i<=20 LOOP
> fldname:='Field' || TO_CHAR(i);
> UPDATE table1
> SET fldname = 'ABC' <--- fldname would be field1 to field 20
> WHERE blah blah blah;
>
> i:=i+1;
>END LOOP
>
>Is it possible to do this? How do I change the field name dynamically?
>
>Thanks in advance.
>
>KC
>
>
Received on Fri Nov 15 2002 - 22:26:21 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US