Reputation: 172
Im trying to update values in PL SQL. The problem is that my dbms_output.put_line is working fine, everything is writen good, but execute immediate doesn't work. The funny thing is, that it works once (or even two) but now it doesn't work. I don't know how to resolve this problem.
Program that i write is inserting some random values into table that is created from values that are input veriables. code can be little to long to be throwed here, i put the most important part of code
for looper in 1..y loop
execute immediate 'insert into GAME ' || s_string || ' values '
|| rowGenerator(v_low=>1, v_high=>6, v_x=>x);
end loop;
start_x_point:= round (dbms_random.value( high=>x, low=>1));
start_y_point:= round (dbms_random.value( high=>y, low=>1));
dbms_output.put_line(start_x_point || ' ' || start_y_point);
s_temp:= ' set x' || start_x_point || ' = 0 where ROWNUM = '|| start_y_point;
dbms_output.put_line(s_temp);
execute immediate 'update GAME ' || s_temp;
s_string conteining bracket with columns,
rowGenerator insert random values into table,
start_x_point and start_y_point is the place where i want to put 0 value
and the problem is that it doesn't works. I don't know other way to do that.
that is how my table looks like after puting random values, its a matrix with values
x1 x2 x3 x4 x5 x6 x7 x8
1 2 5 3 2 4 1 1 3
2 2 3 2 5 4 5 3 3
3 4 3 4 2 4 2 6 3
4 2 1 1 4 3 2 4 1
5 1 5 2 5 3 3 5 4
6 1 5 5 1 1 3 5 3
7 5 3 3 4 4 3 1 3
8 5 4 5 6 3 4 3 2
Upvotes: 0
Views: 149
Reputation: 172
Thanks to @Littlefoot i got answer!
i just need to put something like that
select * from (select * from game
where rownum <=start_y_point
order by rownum desc)
where rownum=1;
and i getting the row that i want!
Upvotes: 1
Reputation: 142958
It appears that your problem is ROWNUM = ...
. It'll work only when START_Y_POINT = 1
, and won't work when it is not.
What to do? Don't use ROWNUM
; UPDATE
values that depend on something else (some ID
value, perhaps?).
Upvotes: 4