Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: creating unique text values?
Hi!
SS> Now, I would like to make each Value unique by simply adding Spaces SS> to the right as needed. SS> So it should look like: SS> A ------ SS> B SS> B_ SS> B__ SS> B___ SS> E
SS> Spaces are marked with '_'.
SS> I tried:
SS> UPDATE TEST a SET a.A = RPAD(a.A, (LENGTH(a.A)+ SS> (SELECT COUNT(*) FROM TEST b WHERE b.A=a.A) - 1) );
SS> but get:
SS> Error in Line2:
SS> ORA-00904: invalid column name
SS> 1. Why do I get this Error and
SS> 2. Is there another Solution for this?
You probably use an old Oracle version. This shouldn't raise an error. But any way this wouldn't work because an UPDATE does not see the changes it makes.
Try something like this:
declare
padn number;
laststr varchar(255);
begin
for c in (select rowid, a from test order by a) loop
if laststr is null or laststr <> c.a then laststr := c.a; padn := 0; end if; update test set a = a || rpad(' ',padn) where rowid = c.rowid; padn := padn + 1;
Bye